acl/lib_acl_cpp/include/acl_cpp/db/mysql_manager.hpp

65 lines
2.0 KiB
C++
Raw Normal View History

2015-08-12 16:48:24 +08:00
#pragma once
2017-06-02 14:47:24 +08:00
#include "../acl_cpp_define.hpp"
2015-08-12 16:48:24 +08:00
#include <map>
2017-06-02 14:47:24 +08:00
#include "../stdlib/string.hpp"
#include "../connpool/connect_manager.hpp"
2015-08-12 16:48:24 +08:00
#if !defined(ACL_CLIENT_ONLY) && !defined(ACL_DB_DISABLE)
2015-08-12 16:48:24 +08:00
namespace acl {
class mysql_conf;
class ACL_CPP_API mysql_manager : public connect_manager
{
public:
mysql_manager(time_t idle_ttl = 120);
2015-08-12 16:48:24 +08:00
~mysql_manager();
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD>ʵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ
2015-08-12 16:48:24 +08:00
* @param dbaddr {const char*} mysql <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD>IP:PORT<EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD> UNIX ƽ̨<EFBFBD>¿<EFBFBD><EFBFBD><EFBFBD>Ϊ UNIX <EFBFBD><EFBFBD><EFBFBD>׽ӿ<EFBFBD>
* @param dbname {const char*} <EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><EFBFBD><EFBFBD>
* @param dbuser {const char*} <EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><EFBFBD>û<EFBFBD>
* @param dbpass {const char*} <EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><EFBFBD>û<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param dblimit {size_t} <EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӳص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2015-08-12 16:48:24 +08:00
* @param dbflags {unsigned long} mysql <EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ
* @param auto_commit {bool} <EFBFBD>Ƿ<EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD>
* @param conn_timeout {int} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿʱʱ<EFBFBD><EFBFBD>(<EFBFBD><EFBFBD>)
* @param rw_timeout {int} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD>ͨ<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>IOʱ<EFBFBD><EFBFBD>(<EFBFBD><EFBFBD>)
* @param charset {const char*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>
2015-08-12 16:48:24 +08:00
* @return {mysql_manager&}
*/
mysql_manager& add(const char* dbaddr, const char* dbname,
const char* dbuser, const char* dbpass,
size_t dblimit = 64, unsigned long dbflags = 0,
2015-08-12 16:48:24 +08:00
bool auto_commit = true, int conn_timeout = 60,
int rw_timeout = 60, const char* charset = "utf8");
2015-08-12 16:48:24 +08:00
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD>ʵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2015-08-12 16:48:24 +08:00
* @param conf {const mysql_conf&}
* @return {mysql_manager&}
*/
mysql_manager& add(const mysql_conf& conf);
protected:
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> connect_manager <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><EFBFBD>
* @param addr {const char*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD>ip:port
* @param count {size_t} <EFBFBD><EFBFBD><EFBFBD>ӳصĴ<EFBFBD>С<EFBFBD><EFBFBD><EFBFBD>ƣ<EFBFBD><EFBFBD><EFBFBD>ֵΪ 0 ʱ<EFBFBD><EFBFBD>û<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2015-08-12 16:48:24 +08:00
* @param idx {size_t} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӳض<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><EFBFBD>±<EFBFBD>λ<EFBFBD><EFBFBD>(<EFBFBD><EFBFBD> 0 <EFBFBD><EFBFBD>ʼ)
* @return {connect_pool*} <EFBFBD><EFBFBD><EFBFBD>ش<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӳض<EFBFBD><EFBFBD><EFBFBD>
*/
connect_pool* create_pool(const char* addr, size_t count, size_t idx);
2015-08-12 16:48:24 +08:00
private:
time_t idle_ttl_; // <20><><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD>ӵĿ<D3B5><C4BF>й<EFBFBD><D0B9><EFBFBD>ʱ<EFBFBD><CAB1>
2015-08-12 16:48:24 +08:00
std::map<string, mysql_conf*> dbs_;
};
} // namespace acl
#endif // !defined(ACL_CLIENT_ONLY) && !defined(ACL_DB_DISABLE)