Files
gjm 164968b62e chore
把非utf8-bom编码的cpp/h文件改为 utf8 bom 编码, msvc识别utf8编码时,如果不是bom格式的,会使用当前cp_oem来解码.
2026-10-04 00:04:20 +08:00

95 lines
1.4 KiB
C++

#pragma once
#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:
// 如果 pBuffer 为 NULL,则 返回的是所需内存的长度
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;
};