2014-11-19 00:25:21 +08:00
|
|
|
|
#pragma once
|
|
|
|
|
#include "acl_cpp/acl_cpp_define.hpp"
|
|
|
|
|
#include "acl_cpp/db/db_handle.hpp"
|
|
|
|
|
|
|
|
|
|
typedef struct st_mysql MYSQL;
|
|
|
|
|
|
|
|
|
|
namespace acl {
|
|
|
|
|
|
|
|
|
|
class ACL_CPP_API db_mysql : public db_handle
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
db_mysql(const char* dbaddr, const char* dbname,
|
|
|
|
|
const char* dbuser, const char* dbpass,
|
|
|
|
|
unsigned long dbflags = 0, bool auto_commit = true,
|
|
|
|
|
int conn_timeout = 60, int rw_timeout = 60);
|
|
|
|
|
~db_mysql(void);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> mysql <EFBFBD>ͻ<EFBFBD><EFBFBD>˿<EFBFBD><EFBFBD>İ汾<EFBFBD><EFBFBD>
|
|
|
|
|
* @return {unsigned long}
|
|
|
|
|
*/
|
|
|
|
|
unsigned long mysql_libversion() const;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> mysql <EFBFBD>ͻ<EFBFBD><EFBFBD>˿<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
|
|
|
|
* @return {const char*}
|
|
|
|
|
*/
|
|
|
|
|
const char* mysql_client_info() const;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* ֱ<EFBFBD>ӻ<EFBFBD><EFBFBD><EFBFBD> mysql <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> NULL <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ mysql <EFBFBD><EFBFBD>û<EFBFBD>д<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>ڲ<EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD>ر<EFBFBD><EFBFBD><EFBFBD> mysql <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @return {MYSQL*}
|
|
|
|
|
*/
|
|
|
|
|
MYSQL* get_conn() const
|
|
|
|
|
{
|
|
|
|
|
return conn_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
|
/* <20><><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD> db_handle <20><><EFBFBD><EFBFBD><EFBFBD>ӿ<EFBFBD> */
|
|
|
|
|
/************************************************************************/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @return {const char*}
|
|
|
|
|
*/
|
|
|
|
|
virtual const char* dbtype() const;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ij<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @return {int}
|
|
|
|
|
*/
|
|
|
|
|
virtual int get_errno() const;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ij<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @return {const char*}
|
|
|
|
|
*/
|
|
|
|
|
virtual const char* get_error() const;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> db_handle <EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӿ<EFBFBD>
|
|
|
|
|
* @param local_charset {const char*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
virtual bool open(const char* local_charset = "GBK");
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> db_handle <EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӿڣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>Ѿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD> true <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><EFBFBD>Ѿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
virtual bool is_opened() const;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> db_handle <EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӿ<EFBFBD>
|
|
|
|
|
* @return {bool} <EFBFBD>ر<EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
virtual bool close(void);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> db_handle <EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӿڣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD>ִ˽ӿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݱ<EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @return {bool} <EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
virtual bool tbl_exists(const char* tbl_name);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> db_handle <EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӿ<EFBFBD>
|
|
|
|
|
* @param sql {const char*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD> SQL <EFBFBD><EFBFBD><EFBFBD>䣬<EFBFBD>ǿգ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫע<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* SQL <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>뾭<EFBFBD><EFBFBD>ת<EFBFBD>崦<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Է<EFBFBD>ֹ SQL ע<EFBFBD>빥<EFBFBD><EFBFBD>
|
|
|
|
|
* @return {bool} ִ<EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
virtual bool sql_select(const char* sql);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> db_handle <EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӿ<EFBFBD>
|
|
|
|
|
* @param sql {const char*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD> SQL <EFBFBD><EFBFBD><EFBFBD>䣬<EFBFBD>ǿգ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫע<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* SQL <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>뾭<EFBFBD><EFBFBD>ת<EFBFBD>崦<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Է<EFBFBD>ֹ SQL ע<EFBFBD>빥<EFBFBD><EFBFBD>
|
|
|
|
|
* @return {bool} ִ<EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
virtual bool sql_update(const char* sql);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> db_handle <EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӿڣ<EFBFBD><EFBFBD>ϴ<EFBFBD> sql <EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӱ<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>¼<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @return {int} Ӱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>-1 <EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
virtual int affect_count() const;
|
|
|
|
|
protected:
|
|
|
|
|
private:
|
|
|
|
|
char* dbaddr_; // <20><><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
|
|
|
|
|
char* dbname_; // <20><><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD>
|
|
|
|
|
char* dbuser_; // <20><><EFBFBD>ݿ<EFBFBD><DDBF>˺<EFBFBD>
|
|
|
|
|
char* dbpass_; // <20><><EFBFBD>ݿ<EFBFBD><DDBF>˺<EFBFBD><CBBA><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
unsigned long dbflags_;
|
|
|
|
|
int conn_timeout_;
|
|
|
|
|
int rw_timeout_;
|
|
|
|
|
bool auto_commit_;
|
|
|
|
|
MYSQL* conn_;
|
|
|
|
|
|
|
|
|
|
bool sane_mysql_query(const char* sql);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace acl
|