2026-10-04 00:04:20 +08:00
|
|
|
#pragma once
|
2026-09-28 15:28:50 +08:00
|
|
|
#include <string>
|
|
|
|
|
#include <tchar.h>
|
|
|
|
|
|
|
|
|
|
#ifndef UNICODE
|
|
|
|
|
#define QueryText QueryTextA
|
|
|
|
|
#define toText toTextA
|
|
|
|
|
#else
|
|
|
|
|
#define QueryText QueryTextW
|
|
|
|
|
#define toText toTextW
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef DLL_EXPORT
|
|
|
|
|
#define TSQLITEAPI __declspec(dllexport)
|
|
|
|
|
#else
|
|
|
|
|
#define TSQLITEAPI
|
|
|
|
|
#endif // TSQLITE_DLL
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct sqlite3;
|
|
|
|
|
struct sqlite3_stmt;
|
|
|
|
|
typedef struct Mem sqlite3_value;
|
|
|
|
|
|
|
|
|
|
class TSQLITEAPI TSQLite
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
TSQLite();
|
|
|
|
|
~TSQLite();
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
enum TSQLITE
|
|
|
|
|
{
|
|
|
|
|
eINTEGER = 0,
|
|
|
|
|
eFLOAT,
|
|
|
|
|
eBLOB,
|
|
|
|
|
eNULL,
|
|
|
|
|
eTEXT,
|
|
|
|
|
eSQLITE_ROW,
|
|
|
|
|
eNONE,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
class TSQLITEAPI TValue
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
TValue(sqlite3_value *p) : m_pV(p){}
|
|
|
|
|
public:
|
2026-10-04 00:04:20 +08:00
|
|
|
// 如果 pBuffer 为 NULL,则 返回的是所需内存的长度
|
2026-09-28 15:28:50 +08:00
|
|
|
int toBlob(void *pBuffer, const int &len);
|
|
|
|
|
int toInt();
|
|
|
|
|
__int64 toInt64();
|
|
|
|
|
double toDouble();
|
|
|
|
|
std::string toTextA();
|
|
|
|
|
std::wstring toTextW();
|
|
|
|
|
TSQLITE getType();
|
|
|
|
|
private:
|
|
|
|
|
sqlite3_value *m_pV;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
static std::string unicode2utf8(const wchar_t *psz);
|
|
|
|
|
static std::wstring utf82unicode(const char *psz);
|
|
|
|
|
static std::string utf82OEM(const char *psz);
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
bool open(const TCHAR *filename);
|
|
|
|
|
|
|
|
|
|
bool close();
|
|
|
|
|
|
|
|
|
|
bool prepare(const TCHAR *sql);
|
|
|
|
|
|
|
|
|
|
bool exec(const TCHAR *sql);
|
|
|
|
|
|
|
|
|
|
TSQLITE oneStep();
|
|
|
|
|
|
|
|
|
|
TValue query(int iCol);
|
|
|
|
|
|
|
|
|
|
int countOfCloumn();
|
|
|
|
|
|
|
|
|
|
std::string getErrMsg();
|
|
|
|
|
|
|
|
|
|
void beginTrans();
|
|
|
|
|
|
|
|
|
|
void commitTrans();
|
|
|
|
|
|
|
|
|
|
void rollbackTrans();
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
sqlite3 *m_pSQLite;
|
|
|
|
|
sqlite3_stmt *m_pStmt;
|
|
|
|
|
std::string m_sErr;
|
|
|
|
|
};
|
|
|
|
|
|