⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 database.h

📁 MySql++ wrapper
💻 H
字号:
/** **	Database.h ** **	Published / author: 2001-02-15 / grymse@alhem.net **//*Copyright (C) 2001  Anders HedstromThis program is free software; you can redistribute it and/ormodify it under the terms of the GNU General Public Licenseas published by the Free Software Foundation; either version 2of the License, or (at your option) any later version.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program; if not, write to the Free SoftwareFoundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.*/#ifndef _DATABASE_H#define _DATABASE_H#include <string>#include <list>class IError;class Query;class Database {public:	struct OPENDB {		OPENDB() : busy(false) {}		MYSQL mysql;		bool busy;	};	typedef std::list<OPENDB *> opendb_v;public:  /** Use embedded libmysqld */  Database(const std::string& database,    IError * = NULL);  /** Connect to a MySQL server*/	Database(const std::string& host,		const std::string& user,		const std::string& password = "",		const std::string& database = "",		IError * = NULL);  virtual ~Database();  /** Callback after mysql_init */  virtual void OnMyInit(OPENDB *);  /** try to establish connection with given host */	bool Connected();	void RegErrHandler(IError *);	void error(Query&,const char *format, ...);	/** Request a database connection.The "grabdb" method is used by the Query class, so that each object instance of Query gets a uniquedatabase connection. I will reimplement your connection check logic in the Query class, as that's wherethe database connection is really used.It should be used something like this.{    Query q(db);    if (!q.Connected())       return false;    q.execute("delete * from user"); // well maybe not}When the Query object is deleted, then "freedb" is called - the database connection stays open in them_opendbs vector. New Query objects can then reuse old connections.	*/	OPENDB *grabdb();	void freedb(OPENDB *odb);private:	void error(const char *format, ...);	//	std::string host;	std::string user;	std::string password;	std::string database;	opendb_v m_opendbs;	IError *m_errhandler;  bool m_embedded;};#endif // _DATABASE_H

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -