| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430 | ////////////////////////////////////////////////////////////////////////////////// CppSQLite3U is a C++ unicode wrapper around the SQLite3 embedded database library.//// Copyright (c) 2006  Tyushkov Nikolay.  All Rights Reserved. http://softvoile.com////// Based on beautiful wrapper written by Rob Groves  // (https://secure.codeproject.com/database/CppSQLite.asp). // Very good wrapper, but without unicode support unfortunately. // So, I have reconstructed it for unicode.////  CppSQLite3 wrapper://  Copyright (c) 2004 Rob Groves. All Rights Reserved. rob.groves@btinternet.com//// Permission to use, copy, modify, and distribute this software and its// documentation for any purpose, without fee, and without a written// agreement, is hereby granted, provided that the above copyright notice, // this paragraph and the following two paragraphs appear in all copies, // modifications, and distributions.//// IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT,// INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST// PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,// EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.//// THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A// PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF// ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS". THE AUTHOR HAS NO OBLIGATION// TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.// // If you want to get some documentation look at // https://secure.codeproject.com/database/CppSQLite.asp// Note, not all features from CppSQLite3 were implemented in CppSQLite3U//// V1.0		11/06/2006	- Initial Public Version////  Noteses : //   I have tested this wrapper only in unicode version, so I have no idea //   about its work in ANSI configuration, I think it doesn't work without modification;)////  Home page : http://softvoile.com/development/CppSQLite3U///  Please send all bug report and comment to mail2@softvoile.com// // ////////////////////////////////////////////////////////////////////////////////#pragma once#include "stdafx.h"#include "sqlite3.h"namespace OTSSQLITE{#define SQL_MAXSIZE    2048#define CPPSQLITE_ERROR 1000static const bool DONT_DELETE_MSG = false;CString DoubleQuotes(CString in);class CppSQLite3DB;class CppSQLite3Query;class CppSQLite3Statement;typedef std::shared_ptr<CppSQLite3DB> CppSQLite3DBPtr;class  CppSQLite3Exception{public:    CppSQLite3Exception(const int a_nErrCode,					    LPTSTR  a_sErrMess,					    bool a_bDeleteMsg = true);    CppSQLite3Exception(const CppSQLite3Exception&  ex);    virtual ~CppSQLite3Exception();    const int GetErrorCode() { return m_nErrCode; }    LPCTSTR GetErrorMessage() { return m_sErrMessage; }    static LPCTSTR GetErrorCodeAsString(int a_nErrCode);private:    int m_nErrCode;    CString m_sErrMessage;};class CppSQLite3Statement{public:	CppSQLite3Statement();	CppSQLite3Statement(const CppSQLite3Statement& rStatement);	CppSQLite3Statement(CppSQLite3DBPtr a_pDB, sqlite3_stmt* pVM);    void setDB(CppSQLite3DBPtr a_pDB) { m_pDBPtr = a_pDB; }	virtual ~CppSQLite3Statement();	CppSQLite3Statement& operator=(const CppSQLite3Statement& rStatement);	int execDML();	CppSQLite3Query execQuery();	void bind(int nParam, LPCTSTR szValue);	void bind(int nParam, const int nValue);	void bind(int nParam, const double dwValue);	void bind(int nParam, const unsigned char* blobValue, int nLen);	void bindNull(int nParam);	void reset();	void finalize();private:	void checkDB();	void checkVM();    CppSQLite3DBPtr m_pDBPtr;	sqlite3_stmt* m_pVM;};typedef std::shared_ptr<CppSQLite3Statement> CppSQLite3StatementPtr;class  CppSQLite3Query{public:	CppSQLite3Query();	CppSQLite3Query(const CppSQLite3Query& rQuery);	CppSQLite3Query(CppSQLite3DBPtr a_pDB,		sqlite3_stmt* pVM,		bool bEof,		bool bOwnVM=true);	CppSQLite3Query& operator=(const CppSQLite3Query& rQuery);	virtual ~CppSQLite3Query();	int numFields();	int fieldIndex(LPCTSTR szField);	LPCTSTR fieldName(int nCol);	LPCTSTR fieldDeclType(int nCol);	int fieldDataType(int nCol);	LPCTSTR fieldValue(int nField);	LPCTSTR fieldValue(LPCTSTR szField);	int getIntField(int nField, int nNullValue=0);	int getIntField(LPCTSTR szField, int nNullValue=0);	double getFloatField(int nField, double fNullValue=0.0);	double getFloatField(LPCTSTR szField, double fNullValue=0.0);	LPCTSTR getStringField(int nField, LPCTSTR szNullValue=_T(""));	LPCTSTR getStringField(LPCTSTR szField, LPCTSTR szNullValue=_T(""));	const unsigned char* getBlobField(int nField, int& nLen);	const unsigned char* getBlobField(LPCTSTR szField, int& nLen);	bool fieldIsNull(int nField);	bool fieldIsNull(LPCTSTR szField);	bool eof();	void nextRow();	void finalize();private:	void checkVM();    CppSQLite3DBPtr m_pDBPtr;	sqlite3_stmt* m_pVM;	bool m_bEof;	int m_nCols;	bool m_bOwnVM;};typedef std::shared_ptr<CppSQLite3Query> CppSQLite3QueryPtr;class  CppSQLite3DB : public std::enable_shared_from_this<CppSQLite3DB>{// Constructionpublic:	CppSQLite3DB();// Operationspublic:    virtual ~CppSQLite3DB();    void open(LPCTSTR szFile);    bool isOpened();    void close();    bool tableExists(LPCTSTR szTable);    int execDML(LPCTSTR szSQL);    CppSQLite3QueryPtr execQuery(LPCTSTR szSQL);    int execScalar(LPCTSTR szSQL);	CString execScalarStr(LPCTSTR szSQL);    CppSQLite3StatementPtr compileStatement(LPCTSTR szSQL);    sqlite_int64 lastRowId();    void interrupt() { sqlite3_interrupt(m_pDB); }    void setBusyTimeout(int nMillisecs);    static const char* SQLiteVersion() { return SQLITE_VERSION; }private:    CppSQLite3DB(const CppSQLite3DB& db);    CppSQLite3DB& operator=(const CppSQLite3DB& db);    sqlite3_stmt* compile(LPCTSTR szSQL);    void checkDB();public:    sqlite3* m_pDB;    int m_nBusyTimeoutMs;};///////////////////////////////////////////////////////////////////////////////// TCHAR based sqlite3 function names for Unicode/MCBS builds.//#if defined(_UNICODE) || defined(UNICODE)//#pragma message(Reminder "Unicode Selected.")#define _sqlite3_aggregate_context      sqlite3_aggregate_context#define _sqlite3_aggregate_count        sqlite3_aggregate_count#define _sqlite3_bind_blob              sqlite3_bind_blob#define _sqlite3_bind_double            sqlite3_bind_double#define _sqlite3_bind_int               sqlite3_bind_int#define _sqlite3_bind_int64             sqlite3_bind_int64#define _sqlite3_bind_null              sqlite3_bind_null#define _sqlite3_bind_parameter_count   sqlite3_bind_parameter_count#define _sqlite3_bind_parameter_index   sqlite3_bind_parameter_index#define _sqlite3_bind_parameter_name    sqlite3_bind_parameter_name#define _sqlite3_bind_text              sqlite3_bind_text16#define _sqlite3_bind_text16            sqlite3_bind_text16#define _sqlite3_busy_handler           sqlite3_busy_handler#define _sqlite3_busy_timeout           sqlite3_busy_timeout#define _sqlite3_changes                sqlite3_changes#define _sqlite3_close                  sqlite3_close#define _sqlite3_collation_needed       sqlite3_collation_needed16#define _sqlite3_collation_needed16     sqlite3_collation_needed16#define _sqlite3_column_blob            sqlite3_column_blob#define _sqlite3_column_bytes           sqlite3_column_bytes16#define _sqlite3_column_bytes16         sqlite3_column_bytes16#define _sqlite3_column_count           sqlite3_column_count#define _sqlite3_column_decltype        sqlite3_column_decltype16#define _sqlite3_column_decltype16      sqlite3_column_decltype16#define _sqlite3_column_double          sqlite3_column_double#define _sqlite3_column_int             sqlite3_column_int#define _sqlite3_column_int64           sqlite3_column_int64#define _sqlite3_column_name            sqlite3_column_name16#define _sqlite3_column_name16          sqlite3_column_name16#define _sqlite3_column_text            sqlite3_column_text16#define _sqlite3_column_text16          sqlite3_column_text16#define _sqlite3_column_type            sqlite3_column_type#define _sqlite3_commit_hook            sqlite3_commit_hook#define _sqlite3_complete               sqlite3_complete16#define _sqlite3_complete16             sqlite3_complete16#define _sqlite3_create_collation       sqlite3_create_collation16#define _sqlite3_create_collation16     sqlite3_create_collation16#define _sqlite3_create_function        sqlite3_create_function16#define _sqlite3_create_function16      sqlite3_create_function16#define _sqlite3_data_count             sqlite3_data_count#define _sqlite3_errcode                sqlite3_errcode#define _sqlite3_errmsg                 sqlite3_errmsg16#define _sqlite3_errmsg16               sqlite3_errmsg16#define _sqlite3_exec                   sqlite3_exec#define _sqlite3_finalize               sqlite3_finalize#define _sqlite3_free                   sqlite3_free#define _sqlite3_free_table             sqlite3_free_table#define _sqlite3_get_table              sqlite3_get_table#define _sqlite3_interrupt              sqlite3_interrupt#define _sqlite3_last_insert_rowid      sqlite3_last_insert_rowid#define _sqlite3_libversion             sqlite3_libversion#define _sqlite3_mprintf                sqlite3_mprintf#define _sqlite3_open                   sqlite3_open16#define _sqlite3_open16                 sqlite3_open16#define _sqlite3_prepare                sqlite3_prepare16#define _sqlite3_prepare16              sqlite3_prepare16#define _sqlite3_progress_handler       sqlite3_progress_handler#define _sqlite3_reset                  sqlite3_reset#define _sqlite3_result_blob            sqlite3_result_blob#define _sqlite3_result_double          sqlite3_result_double#define _sqlite3_result_error           sqlite3_result_error16#define _sqlite3_result_error16         sqlite3_result_error16#define _sqlite3_result_int             sqlite3_result_int#define _sqlite3_result_int64           sqlite3_result_int64#define _sqlite3_result_null            sqlite3_result_null#define _sqlite3_result_text            sqlite3_result_text16#define _sqlite3_result_text16          sqlite3_result_text16#define _sqlite3_result_text16be        sqlite3_result_text16be#define _sqlite3_result_text16le        sqlite3_result_text16le#define _sqlite3_result_value           sqlite3_result_value#define _sqlite3_set_authorizer         sqlite3_set_authorizer#define _sqlite3_step                   sqlite3_step#define _sqlite3_total_changes          sqlite3_total_changes#define _sqlite3_trace                  sqlite3_trace#define _sqlite3_user_data              sqlite3_user_data#define _sqlite3_value_blob             sqlite3_value_blob#define _sqlite3_value_bytes            sqlite3_value_bytes16#define _sqlite3_value_bytes16          sqlite3_value_bytes16#define _sqlite3_value_double           sqlite3_value_double#define _sqlite3_value_int              sqlite3_value_int#define _sqlite3_value_int64            sqlite3_value_int64#define _sqlite3_value_text             sqlite3_value_text16#define _sqlite3_value_text16           sqlite3_value_text16#define _sqlite3_value_text16be         sqlite3_value_text16be#define _sqlite3_value_text16le         sqlite3_value_text16le#define _sqlite3_value_type             sqlite3_value_type#define _sqlite3_vmprintf               sqlite3_vmprintf#else//#pragma message(Reminder "MCBS Selected.")#define _sqlite3_aggregate_context      sqlite3_aggregate_context#define _sqlite3_aggregate_count        sqlite3_aggregate_count#define _sqlite3_bind_blob              sqlite3_bind_blob#define _sqlite3_bind_double            sqlite3_bind_double#define _sqlite3_bind_int               sqlite3_bind_int#define _sqlite3_bind_int64             sqlite3_bind_int64#define _sqlite3_bind_null              sqlite3_bind_null#define _sqlite3_bind_parameter_count   sqlite3_bind_parameter_count#define _sqlite3_bind_parameter_index   sqlite3_bind_parameter_index#define _sqlite3_bind_parameter_name    sqlite3_bind_parameter_name#define _sqlite3_bind_text              sqlite3_bind_text#define _sqlite3_bind_text16            sqlite3_bind_text16#define _sqlite3_busy_handler           sqlite3_busy_handler#define _sqlite3_busy_timeout           sqlite3_busy_timeout#define _sqlite3_changes                sqlite3_changes#define _sqlite3_close                  sqlite3_close#define _sqlite3_collation_needed       sqlite3_collation_needed#define _sqlite3_collation_needed16     sqlite3_collation_needed16#define _sqlite3_column_blob            sqlite3_column_blob#define _sqlite3_column_bytes           sqlite3_column_bytes#define _sqlite3_column_bytes16         sqlite3_column_bytes16#define _sqlite3_column_count           sqlite3_column_count#define _sqlite3_column_decltype        sqlite3_column_decltype#define _sqlite3_column_decltype16      sqlite3_column_decltype16#define _sqlite3_column_double          sqlite3_column_double#define _sqlite3_column_int             sqlite3_column_int#define _sqlite3_column_int64           sqlite3_column_int64#define _sqlite3_column_name            sqlite3_column_name#define _sqlite3_column_name16          sqlite3_column_name16#define _sqlite3_column_text            sqlite3_column_text#define _sqlite3_column_text16          sqlite3_column_text16#define _sqlite3_column_type            sqlite3_column_type#define _sqlite3_commit_hook            sqlite3_commit_hook#define _sqlite3_complete               sqlite3_complete#define _sqlite3_complete16             sqlite3_complete16#define _sqlite3_create_collation       sqlite3_create_collation#define _sqlite3_create_collation16     sqlite3_create_collation16#define _sqlite3_create_function        sqlite3_create_function#define _sqlite3_create_function16      sqlite3_create_function16#define _sqlite3_data_count             sqlite3_data_count#define _sqlite3_errcode                sqlite3_errcode#define _sqlite3_errmsg                 sqlite3_errmsg#define _sqlite3_errmsg16               sqlite3_errmsg16#define _sqlite3_exec                   sqlite3_exec#define _sqlite3_finalize               sqlite3_finalize#define _sqlite3_free                   sqlite3_free#define _sqlite3_free_table             sqlite3_free_table#define _sqlite3_get_table              sqlite3_get_table#define _sqlite3_interrupt              sqlite3_interrupt#define _sqlite3_last_insert_rowid      sqlite3_last_insert_rowid#define _sqlite3_libversion             sqlite3_libversion#define _sqlite3_mprintf                sqlite3_mprintf#define _sqlite3_open                   sqlite3_open#define _sqlite3_open16                 sqlite3_open16#define _sqlite3_prepare                sqlite3_prepare#define _sqlite3_prepare16              sqlite3_prepare16#define _sqlite3_progress_handler       sqlite3_progress_handler#define _sqlite3_reset                  sqlite3_reset#define _sqlite3_result_blob            sqlite3_result_blob#define _sqlite3_result_double          sqlite3_result_double#define _sqlite3_result_error           sqlite3_result_error#define _sqlite3_result_error16         sqlite3_result_error16#define _sqlite3_result_int             sqlite3_result_int#define _sqlite3_result_int64           sqlite3_result_int64#define _sqlite3_result_null            sqlite3_result_null#define _sqlite3_result_text            sqlite3_result_text#define _sqlite3_result_text16          sqlite3_result_text16#define _sqlite3_result_text16be        sqlite3_result_text16be#define _sqlite3_result_text16le        sqlite3_result_text16le#define _sqlite3_result_value           sqlite3_result_value#define _sqlite3_set_authorizer         sqlite3_set_authorizer#define _sqlite3_step                   sqlite3_step#define _sqlite3_total_changes          sqlite3_total_changes#define _sqlite3_trace                  sqlite3_trace#define _sqlite3_user_data              sqlite3_user_data#define _sqlite3_value_blob             sqlite3_value_blob#define _sqlite3_value_bytes            sqlite3_value_bytes#define _sqlite3_value_bytes16          sqlite3_value_bytes16#define _sqlite3_value_double           sqlite3_value_double#define _sqlite3_value_int              sqlite3_value_int#define _sqlite3_value_int64            sqlite3_value_int64#define _sqlite3_value_text             sqlite3_value_text#define _sqlite3_value_text16           sqlite3_value_text16#define _sqlite3_value_text16be         sqlite3_value_text16be#define _sqlite3_value_text16le         sqlite3_value_text16le#define _sqlite3_value_type             sqlite3_value_type#define _sqlite3_vmprintf               sqlite3_vmprintf#endif} // namespace Datastore
 |