#pragma once #include #include #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; };