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 {
|
|
|
|
|
|
2015-10-25 14:15:07 +08:00
|
|
|
|
class mysql_conf;
|
|
|
|
|
|
2014-11-19 00:25:21 +08:00
|
|
|
|
class ACL_CPP_API db_mysql : public db_handle
|
|
|
|
|
{
|
|
|
|
|
public:
|
2015-10-25 14:15:07 +08:00
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD>캯<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽһ
|
|
|
|
|
* @param dbaddr {const char*} <EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ TCP <EFBFBD>ӿڻ<EFBFBD><EFBFBD><EFBFBD> UNIX
|
|
|
|
|
* ƽ̨<EFBFBD>µ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӿڣ<EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD>磺127.0.0.1:3306<EFBFBD><EFBFBD><EFBFBD><EFBFBD> /tmp/mysql.sock
|
|
|
|
|
* @param dbname {const char*} <EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƣ<EFBFBD><EFBFBD><EFBFBD> NULL
|
|
|
|
|
* @param dbuser {const char*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param dbpass {const char*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param dbflags {unsigned long} <EFBFBD><EFBFBD><EFBFBD><EFBFBD> MYSQL ʱ<EFBFBD>ı<EFBFBD>־λ
|
|
|
|
|
* @param auto_commit {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>Ƿ<EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD>ύ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param conn_timeout {int} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><EFBFBD>ij<EFBFBD>ʱʱ<EFBFBD>䣨<EFBFBD>룩
|
|
|
|
|
* @param rw_timeout {int} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>ij<EFBFBD>ʱʱ<EFBFBD>䣨<EFBFBD>룩
|
|
|
|
|
* @param charset {const char*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD>ʱ<EFBFBD>ı<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>gbk, utf8, ...<EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
2014-11-19 00:25:21 +08:00
|
|
|
|
db_mysql(const char* dbaddr, const char* dbname,
|
|
|
|
|
const char* dbuser, const char* dbpass,
|
|
|
|
|
unsigned long dbflags = 0, bool auto_commit = true,
|
2015-10-25 14:15:07 +08:00
|
|
|
|
int conn_timeout = 60, int rw_timeout = 60,
|
|
|
|
|
const char* charset = "utf8");
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <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>
|
|
|
|
|
* @param conf {const mysql_conf&} mysql <EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
db_mysql(const mysql_conf& conf);
|
2014-11-19 00:25:21 +08:00
|
|
|
|
~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_;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-12 16:48:24 +08:00
|
|
|
|
/********************************************************************/
|
2015-08-19 20:10:52 +08:00
|
|
|
|
/* <20><><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD> db_handle <20><><EFBFBD><EFBFBD><EFBFBD>ӿ<EFBFBD> */
|
2015-08-12 16:48:24 +08:00
|
|
|
|
/********************************************************************/
|
2014-11-19 00:25:21 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @return {const char*}
|
|
|
|
|
*/
|
2015-08-02 18:21:24 +08:00
|
|
|
|
const char* dbtype() const;
|
2014-11-19 00:25:21 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <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}
|
|
|
|
|
*/
|
2015-08-02 18:21:24 +08:00
|
|
|
|
int get_errno() const;
|
2014-11-19 00:25:21 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <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*}
|
|
|
|
|
*/
|
2015-08-02 18:21:24 +08:00
|
|
|
|
const char* get_error() const;
|
2014-11-19 00:25:21 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> db_handle <EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӿ<EFBFBD>
|
|
|
|
|
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD>
|
|
|
|
|
*/
|
2015-10-25 14:15:07 +08:00
|
|
|
|
bool dbopen();
|
2014-11-19 00:25:21 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <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>
|
|
|
|
|
*/
|
2015-08-02 18:21:24 +08:00
|
|
|
|
bool is_opened() const;
|
2014-11-19 00:25:21 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> db_handle <EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӿ<EFBFBD>
|
|
|
|
|
* @return {bool} <EFBFBD>ر<EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD>
|
|
|
|
|
*/
|
2015-08-02 18:21:24 +08:00
|
|
|
|
bool close(void);
|
2014-11-19 00:25:21 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <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>
|
|
|
|
|
*/
|
2015-08-02 18:21:24 +08:00
|
|
|
|
bool tbl_exists(const char* tbl_name);
|
2014-11-19 00:25:21 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> db_handle <EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӿ<EFBFBD>
|
2015-08-22 18:05:46 +08:00
|
|
|
|
* @param sql {const char*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD> SELECT 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>
|
2014-11-19 00:25:21 +08:00
|
|
|
|
* @return {bool} ִ<EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD>
|
|
|
|
|
*/
|
2015-08-02 18:21:24 +08:00
|
|
|
|
bool sql_select(const char* sql);
|
2014-11-19 00:25:21 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> db_handle <EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӿ<EFBFBD>
|
2015-08-22 18:05:46 +08:00
|
|
|
|
* @param sql {const char*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD> INSERT/UPDATE/DELETE SQL <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>
|
2014-11-19 00:25:21 +08:00
|
|
|
|
* @return {bool} ִ<EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD>
|
|
|
|
|
*/
|
2015-08-02 18:21:24 +08:00
|
|
|
|
bool sql_update(const char* sql);
|
2014-11-19 00:25:21 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <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>
|
|
|
|
|
*/
|
2015-08-02 18:21:24 +08:00
|
|
|
|
int affect_count() const;
|
|
|
|
|
|
2015-08-19 20:10:52 +08:00
|
|
|
|
/**
|
|
|
|
|
* <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><EFBFBD>ʽ<EFBFBD><EFBFBD>
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD> db_mysql <EFBFBD>Ĺ<EFBFBD><EFBFBD>캯<EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD><EFBFBD><EFBFBD> auto_commit Ϊ false
|
|
|
|
|
* @return {bool}
|
|
|
|
|
*/
|
|
|
|
|
bool begin_transaction();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <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>
|
|
|
|
|
* @return {bool}
|
|
|
|
|
*/
|
|
|
|
|
bool commit();
|
|
|
|
|
|
2014-11-19 00:25:21 +08:00
|
|
|
|
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>
|
2015-10-25 14:15:07 +08:00
|
|
|
|
char* charset_; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD>õ<EFBFBD><C3B5>ַ<EFBFBD><D6B7><EFBFBD>
|
2014-11-19 00:25:21 +08:00
|
|
|
|
|
|
|
|
|
unsigned long dbflags_;
|
|
|
|
|
int conn_timeout_;
|
|
|
|
|
int rw_timeout_;
|
|
|
|
|
bool auto_commit_;
|
|
|
|
|
MYSQL* conn_;
|
|
|
|
|
|
|
|
|
|
bool sane_mysql_query(const char* sql);
|
2015-10-25 14:15:07 +08:00
|
|
|
|
void sane_mysql_init(const char* dbaddr, const char* dbname,
|
|
|
|
|
const char* dbuser, const char* dbpass,
|
|
|
|
|
unsigned long dbflags, bool auto_commit,
|
|
|
|
|
int conn_timeout, int rw_timeout,
|
|
|
|
|
const char* charset);
|
2014-11-19 00:25:21 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace acl
|