2019-07-28 10:31:56 +08:00
|
|
|
|
#pragma once
|
2018-12-12 11:16:12 +08:00
|
|
|
|
#include "../acl_cpp_define.hpp"
|
|
|
|
|
#include "../stdlib/string.hpp"
|
|
|
|
|
#include "../db/db_handle.hpp"
|
|
|
|
|
|
2019-05-19 16:54:20 +08:00
|
|
|
|
#if !defined(ACL_CLIENT_ONLY) && !defined(ACL_DB_DISABLE)
|
2019-05-18 21:19:21 +08:00
|
|
|
|
|
2018-12-12 11:16:12 +08:00
|
|
|
|
typedef struct pg_conn PGconn;
|
|
|
|
|
|
|
|
|
|
namespace acl {
|
|
|
|
|
|
|
|
|
|
class pgsql_conf;
|
|
|
|
|
|
|
|
|
|
class ACL_CPP_API db_pgsql : public db_handle
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
db_pgsql(const pgsql_conf& conf);
|
|
|
|
|
~db_pgsql(void);
|
|
|
|
|
|
|
|
|
|
static void load(void);
|
|
|
|
|
|
|
|
|
|
/********************************************************************/
|
2019-07-28 10:31:56 +08:00
|
|
|
|
/* <20><><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD> db_handle <20><><EFBFBD><EFBFBD><EFBFBD>ӿ<EFBFBD> */
|
2018-12-12 11:16:12 +08:00
|
|
|
|
/********************************************************************/
|
|
|
|
|
|
|
|
|
|
const char* dbtype(void) const;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @override
|
|
|
|
|
*/
|
|
|
|
|
int get_errno(void) const;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @override
|
|
|
|
|
*/
|
|
|
|
|
const char* get_error(void) const;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @override
|
|
|
|
|
*/
|
|
|
|
|
bool dbopen(const char* charset = NULL);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @override
|
|
|
|
|
*/
|
|
|
|
|
bool is_opened(void) const;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @override
|
|
|
|
|
*/
|
|
|
|
|
bool close(void);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @override
|
|
|
|
|
*/
|
|
|
|
|
bool tbl_exists(const char* tbl_name);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @override
|
|
|
|
|
*/
|
|
|
|
|
bool sql_select(const char* sql, db_rows* result = NULL);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @override
|
|
|
|
|
*/
|
|
|
|
|
bool sql_update(const char* sql);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @override
|
|
|
|
|
*/
|
|
|
|
|
int affect_count(void) const;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @override
|
|
|
|
|
*/
|
|
|
|
|
bool begin_transaction(void);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @override
|
|
|
|
|
*/
|
|
|
|
|
bool commit(void);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @override
|
|
|
|
|
*/
|
|
|
|
|
bool rollback(void);
|
|
|
|
|
|
|
|
|
|
private:
|
2019-07-28 10:31:56 +08:00
|
|
|
|
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>
|
|
|
|
|
string charset_; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD>õ<EFBFBD><C3B5>ַ<EFBFBD><D6B7><EFBFBD>
|
2018-12-12 11:16:12 +08:00
|
|
|
|
|
|
|
|
|
int conn_timeout_;
|
|
|
|
|
int rw_timeout_;
|
|
|
|
|
|
|
|
|
|
PGconn* conn_;
|
|
|
|
|
int affect_count_;
|
|
|
|
|
|
|
|
|
|
void sane_pgsql_init(const char* dbaddr, const char* dbname,
|
|
|
|
|
const char* dbuser, const char* dbpass, int conn_timeout,
|
|
|
|
|
int rw_timeout, const char* charset);
|
|
|
|
|
void* sane_pgsql_query(const char* sql);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace acl
|
2019-05-18 21:19:21 +08:00
|
|
|
|
|
2019-05-19 16:54:20 +08:00
|
|
|
|
#endif // !defined(ACL_CLIENT_ONLY) && !defined(ACL_DB_DISABLE)
|