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

118 lines
2.8 KiB
C++
Raw Normal View History

2014-11-19 00:25:21 +08:00
#pragma once
2017-06-02 14:47:24 +08:00
#include "../acl_cpp_define.hpp"
2014-11-19 00:25:21 +08:00
#include <list>
2017-06-02 14:47:24 +08:00
#include "../ipc/ipc_service.hpp"
#include "../stdlib/string.hpp"
2014-11-19 00:25:21 +08:00
namespace acl {
typedef enum
{
DB_OK,
DB_ERR_OPEN,
DB_ERR_EXEC_SQL,
} db_status;
//////////////////////////////////////////////////////////////////////////
class db_rows;
class ACL_CPP_API db_query
{
public:
db_query(void) {}
virtual ~db_query(void) {}
virtual void on_error(db_status status) = 0;
virtual void on_ok(const db_rows* rows, int affected) = 0;
/**
* <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> destroy <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><EFBFBD> delete this <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><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
virtual void destroy(void) {}
protected:
private:
};
//////////////////////////////////////////////////////////////////////////
class db_handle;
class aio_socket_stream;
/**
* <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><EFBFBD><EFBFBD><EFBFBD>
* һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̹߳<EFBFBD><EFBFBD><EFBFBD>
*/
class ACL_CPP_API db_service : public ipc_service
{
public:
/**
* <EFBFBD><EFBFBD>Ϊ sqlite <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>
* @param nthread {int} <EFBFBD><EFBFBD><EFBFBD>̳߳ص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD><EFBFBD><EFBFBD>
* @param win32_gui {bool} <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> _WIN32 <EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ȼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD>õ<EFBFBD><EFBFBD>׽<EFBFBD>
2014-11-19 00:25:21 +08:00
* <EFBFBD><EFBFBD>ͨѶ<EFBFBD><EFBFBD>ʽ
*/
db_service(size_t dblimit = 100, int nthread = 2, bool win32_gui = false);
virtual ~db_service(void);
/**
* <EFBFBD>ִ<EFBFBD><EFBFBD> SQL <EFBFBD><EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param sql {const char*} Ҫִ<EFBFBD>еı<EFBFBD>׼ SQL <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param query {db_query*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD>н<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
void sql_select(const char* sql, db_query* query);
/**
* <EFBFBD>ִ<EFBFBD><EFBFBD> SQL <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param sql {const char*} Ҫִ<EFBFBD>еı<EFBFBD>׼ SQL <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param query {db_query*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD>н<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
void sql_update(const char* sql, db_query* query);
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӷ<EFBFBD><EFBFBD><EFBFBD>
* @param db {db_handle*} <EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӷ<EFBFBD><EFBFBD><EFBFBD>
*/
void push_back(db_handle* db);
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>
* @return {db_handle*}
*/
virtual db_handle* db_create() = 0;
/**
* <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 client {aio_socket_stream*} <EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>µĿͻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
virtual void on_accept(aio_socket_stream* client);
#if defined(_WIN32) || defined(_WIN64)
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><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̵߳<EFBFBD> win32 <EFBFBD><EFBFBD>Ϣʱ<EFBFBD>Ļص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param hWnd {HWND} <EFBFBD><EFBFBD><EFBFBD>ھ<EFBFBD><EFBFBD><EFBFBD>
* @param msg {UINT} <EFBFBD>û<EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD>
* @param wParam {WPARAM} <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param lParam {LPARAM} <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
virtual void win32_proc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
#endif
private:
// <20><><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
std::list<db_handle*> dbpool_;
// <20><><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD>ӳصĸ<D8B5><C4B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
size_t dblimit_;
// <20><>ǰ<EFBFBD><C7B0><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD>ӳصĸ<D8B5><C4B8><EFBFBD>
size_t dbsize_;
};
} // namespace acl