2014-11-19 00:25:21 +08:00
|
|
|
|
#pragma once
|
2017-06-02 14:47:24 +08:00
|
|
|
|
#include "../acl_cpp_define.hpp"
|
|
|
|
|
#include "../stdlib/string.hpp"
|
|
|
|
|
#include "../db/db_handle.hpp"
|
2014-11-19 00:25:21 +08:00
|
|
|
|
|
|
|
|
|
typedef struct sqlite3 sqlite3;
|
|
|
|
|
|
|
|
|
|
namespace acl {
|
|
|
|
|
|
|
|
|
|
class charset_conv;
|
|
|
|
|
|
|
|
|
|
class ACL_CPP_API db_sqlite : public db_handle
|
|
|
|
|
{
|
|
|
|
|
public:
|
2015-10-25 14:15:07 +08:00
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD>캯<EFBFBD><EFBFBD>
|
|
|
|
|
* @param charset {const char*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>(gbk, utf-8, ...)
|
|
|
|
|
*/
|
|
|
|
|
db_sqlite(const char* dbfile, const char* charset = "utf-8");
|
2014-11-19 00:25:21 +08:00
|
|
|
|
~db_sqlite(void);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD>ǰ<EFBFBD><EFBFBD> sqlite <EFBFBD>İ汾<EFBFBD><EFBFBD>Ϣ
|
|
|
|
|
*/
|
|
|
|
|
const char* version(void) const;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><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><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ã<EFBFBD>
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD>ϸ<EFBFBD><EFBFBD><EFBFBD>ѭ sqlite <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD>
|
|
|
|
|
* @param pragma {const char*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><EFBFBD><EFBFBD>ʽΪ<EFBFBD><EFBFBD>
|
|
|
|
|
* PRAGMA xxx=xxx
|
|
|
|
|
* <EFBFBD>磺PRAGMA synchronous = NORMAL
|
|
|
|
|
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
bool set_conf(const char* pragma);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <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 pragma {const char*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><EFBFBD><EFBFBD>ʽΪ<EFBFBD><EFBFBD>
|
|
|
|
|
* PRAGMA xxx
|
|
|
|
|
* <EFBFBD>磺PRAGMA synchronous
|
|
|
|
|
* @param out {string&} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD>ǿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>洢<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @return {const char*} Ϊ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ò<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD>δ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
const char* get_conf(const char* pragma, string& out);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <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 pragma {const char*} ָ<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>PRAGMA xxx<EFBFBD><EFBFBD><EFBFBD>磺PRAGMA synchronous
|
|
|
|
|
*/
|
|
|
|
|
void show_conf(const char* pragma = NULL);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><EFBFBD><EFBFBD><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>
|
|
|
|
|
*/
|
|
|
|
|
int affect_total_count() const;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* ֱ<EFBFBD>ӻ<EFBFBD><EFBFBD><EFBFBD> sqlite <EFBFBD>ľ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> NULL <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ sqlite <EFBFBD><EFBFBD>û<EFBFBD>д<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>ڲ<EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD>ر<EFBFBD><EFBFBD><EFBFBD> sqlite
|
|
|
|
|
* @return {sqlite3*}
|
|
|
|
|
*/
|
|
|
|
|
sqlite3* get_conn() const
|
|
|
|
|
{
|
|
|
|
|
return db_;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-24 11:44:12 +08:00
|
|
|
|
/********************************************************************/
|
|
|
|
|
/* <20><><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD> db_handle <20><><EFBFBD><EFBFBD><EFBFBD>ӿ<EFBFBD> */
|
|
|
|
|
/********************************************************************/
|
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>
|
2015-11-09 22:11:21 +08:00
|
|
|
|
* @param charset {const char*} <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>
|
2014-11-19 00:25:21 +08:00
|
|
|
|
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD>
|
|
|
|
|
*/
|
2015-11-09 22:11:21 +08:00
|
|
|
|
bool dbopen(const char* charset = NULL);
|
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> SQL <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>뾭<EFBFBD><EFBFBD>ת<EFBFBD>崦<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Է<EFBFBD>ֹ SQL ע<EFBFBD>빥<EFBFBD><EFBFBD>
|
2017-03-25 23:05:44 +08:00
|
|
|
|
* @param result {db_rows*} <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_handle <EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>洢<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2014-11-19 00:25:21 +08:00
|
|
|
|
* @return {bool} ִ<EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD>
|
|
|
|
|
*/
|
2017-03-25 23:05:44 +08:00
|
|
|
|
bool sql_select(const char* sql, db_rows* result = NULL);
|
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;
|
|
|
|
|
|
2014-11-19 00:25:21 +08:00
|
|
|
|
private:
|
|
|
|
|
// sqlite <20><><EFBFBD><EFBFBD>
|
|
|
|
|
sqlite3* db_;
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD>ݴ洢<DDB4>ļ<EFBFBD>
|
|
|
|
|
string dbfile_;
|
|
|
|
|
|
|
|
|
|
// <20>ַ<EFBFBD><D6B7><EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD>
|
|
|
|
|
charset_conv* conv_;
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
|
2015-10-25 14:15:07 +08:00
|
|
|
|
string charset_;
|
2014-11-19 00:25:21 +08:00
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>ִ<EFBFBD><D6B4>SQL<51><4C>ѯ<EFBFBD>ĺ<EFBFBD><C4BA><EFBFBD>
|
2017-03-25 23:05:44 +08:00
|
|
|
|
bool exec_sql(const char* sql, db_rows* result = NULL);
|
2014-11-19 00:25:21 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace acl
|