2014-11-19 00:25:21 +08:00
|
|
|
|
#pragma once
|
|
|
|
|
#include "db.h"
|
|
|
|
|
|
|
|
|
|
class acl::db_handle; // db_handle.hpp
|
|
|
|
|
class acl::locker; // locker.hpp
|
|
|
|
|
|
|
|
|
|
class db_driver;
|
|
|
|
|
class database;
|
|
|
|
|
class idx_host;
|
|
|
|
|
class dat_host;
|
|
|
|
|
|
|
|
|
|
struct NAME_TYPE;
|
|
|
|
|
struct DB_HOST;
|
|
|
|
|
struct DB_TBL;
|
|
|
|
|
struct TBL_IDX;
|
|
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
|
{
|
|
|
|
|
NAME_TYPE_DB = 0,
|
|
|
|
|
NAME_TYPE_TBL = 1,
|
|
|
|
|
NAME_TYPE_IDX = 2
|
|
|
|
|
} name_type_t;
|
|
|
|
|
|
|
|
|
|
enum
|
|
|
|
|
{
|
|
|
|
|
DB_CTL_OK = 0,
|
|
|
|
|
DB_CTL_ERR = 1,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class db_ctl
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
db_ctl(void);
|
|
|
|
|
~db_ctl(void);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><EFBFBD><EFBFBD>Ϣ
|
|
|
|
|
*/
|
|
|
|
|
void load();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <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>NULL
|
|
|
|
|
* @param dbname {const char*} <EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param dbuser {const char*} <EFBFBD>û<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param dbpass {const char*} <EFBFBD>û<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @return {database*} <EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> NULL <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾʧ<EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
database* db_open(const char* dbname, const char* dbuser = NULL,
|
|
|
|
|
const char* dbpass = NULL);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD>
|
|
|
|
|
* @param dbname {const char*} <EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param dbuser {const char*} <EFBFBD>û<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param dbpass {const char*} <EFBFBD>û<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @return {database*} <EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> NULL <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾʧ<EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
database* db_create(const char* dbname, const char* dbuser = NULL,
|
|
|
|
|
const char* dbpass = NULL);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD>ر<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD>
|
|
|
|
|
* @param {database*} db
|
|
|
|
|
*/
|
|
|
|
|
void db_close(database* db);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݱ<EFBFBD>
|
|
|
|
|
* @param db {database*} <EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param tbl_name {const char*} <EFBFBD><EFBFBD><EFBFBD>ݱ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @return {db_tbl*} <EFBFBD>ǿ<EFBFBD>ֵ<EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD>ӳɹ<EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
db_tbl* db_add_tbl(database* db, const char* tbl_name);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param tbl {db_tbl*} <EFBFBD><EFBFBD><EFBFBD>ݱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param tbl_idx {const char*} <EFBFBD><EFBFBD><EFBFBD>ݱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param idx_type {idx_type_t} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @return {db_idx*} <EFBFBD>ǿ<EFBFBD>ֵ<EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD>ӳɹ<EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
db_idx* db_add_idx(db_tbl* tbl, const char* tbl_idx, idx_type_t idx_type);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param db {database*} <EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param tbl_name {const char*} <EFBFBD><EFBFBD><EFBFBD>ݱ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param tbl_idx {const char*} <EFBFBD><EFBFBD><EFBFBD>ݱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param idx_type {idx_type_t} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @return {db_idx*} <EFBFBD>ǿ<EFBFBD>ֵ<EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD>ӳɹ<EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
db_idx* db_add_idx(database* db, const char* tbl_name,
|
|
|
|
|
const char* tbl_idx, idx_type_t idx_type);
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
/**
|
|
|
|
|
* <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><EFBFBD><EFBFBD>ݿ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param db {database*}
|
|
|
|
|
* @return {bool}
|
|
|
|
|
*/
|
|
|
|
|
bool db_host_set(database* db);
|
|
|
|
|
private:
|
|
|
|
|
int errnum_;
|
|
|
|
|
db_driver* driver_;
|
|
|
|
|
acl::locker* lock_; // db_ctl <20><><EFBFBD><EFBFBD><EFBFBD>Ļ<EFBFBD><C4BB><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
acl::locker* ctl_conn_lock_; // ctl_conn_ <20><><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD>ӵĻ<D3B5><C4BB><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
acl::db_handle* ctl_conn_; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
std::map<std::string, database*> dbs_; // <20><><EFBFBD>ݿ<EFBFBD><DDBF>б<EFBFBD>
|
|
|
|
|
std::vector<idx_host*> idx_hosts_; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>
|
|
|
|
|
std::vector<dat_host*> dat_hosts_; // <20><><EFBFBD>ݷ<EFBFBD><DDB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>
|
|
|
|
|
|
|
|
|
|
std::list<NAME_TYPE*> names_;
|
|
|
|
|
std::list<DB_HOST*> db_hosts_;
|
|
|
|
|
std::list<DB_TBL*> db_tbls_;
|
|
|
|
|
std::list<TBL_IDX*> tbl_idxes_;
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD>ر<EFBFBD> tbl_name_type
|
|
|
|
|
int load_names(void);
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD>ر<EFBFBD> tbl_idx_host
|
|
|
|
|
int load_idx_hosts(void);
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD>ر<EFBFBD> tbl_dat_host
|
|
|
|
|
int load_dat_hosts(void);
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD>ر<EFBFBD> tbl_db_host
|
|
|
|
|
int load_db_hosts(void);
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD>ر<EFBFBD> tbl_db_tbl
|
|
|
|
|
int load_db_tbls(void);
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD>ر<EFBFBD> tbl_tbl_idx
|
|
|
|
|
int load_tbl_idxes(void);
|
|
|
|
|
|
|
|
|
|
// <20><> NAME_TYPE <20>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>и<EFBFBD><D0B8><EFBFBD>ID<49>ż<EFBFBD><C5BC><EFBFBD><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD> NAME_TYPE <20>ṹ<EFBFBD><E1B9B9><EFBFBD><EFBFBD>
|
|
|
|
|
NAME_TYPE* get_name(unsigned int id, name_type_t type) const;
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD> NAME_TYPE<50><45><EFBFBD><EFBFBD><EFBFBD><EFBFBD> names_ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
void add_name(const char* name, unsigned int id, name_type_t type);
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD><C2B5><EFBFBD><EFBFBD>ּ<EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD>ݿ⣬<DDBF><E2A3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ID<49><44>
|
|
|
|
|
unsigned int db_add_name(const char* name, name_type_t type);
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݱ<EFBFBD><DDB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
|
|
|
|
void build_db(void);
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>ݿ⼯<DDBF><E2BCAF><EFBFBD>и<EFBFBD><D0B8><EFBFBD>ID<49>Ż<EFBFBD><C5BB><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
database* get_db(unsigned int id) const;
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD>ö<EFBFBD>ӦID<49>ŵ<EFBFBD><C5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
idx_host* get_idx_host(unsigned int id) const;
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD>ӱ<EFBFBD><D3B1>ṹ<EFBFBD><E1B9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
void add_tbl(database* db, DB_TBL* tbl);
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>µı<C2B5><C4B1><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD> db_tbls_ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
void add_tbl(unsigned int id_db, unsigned int id_tbl,
|
|
|
|
|
long long int count);
|
|
|
|
|
};
|