1 ////////////////////////////////////////////////////////////////////////////////
3 // CppSQLite3 - A C++ wrapper around the SQLite3 embedded database library.
7 // Copyright (c) 2004 Rob Groves. All Rights Reserved. rob.groves@btinternet.com
11 // Permission to use, copy, modify, and distribute this software and its
13 // documentation for any purpose, without fee, and without a written
15 // agreement, is hereby granted, provided that the above copyright notice,
17 // this paragraph and the following two paragraphs appear in all copies,
19 // modifications, and distributions.
23 // IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT,
25 // INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST
27 // PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
29 // EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 // THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
35 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
37 // PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF
39 // ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS". THE AUTHOR HAS NO OBLIGATION
41 // TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
45 // V3.0 03/08/2004 -Initial Version for sqlite3
49 // V3.1 16/09/2004 -Implemented getXXXXField using sqlite3 functions
51 // -Added CppSQLiteDB3::tableExists()
53 ////////////////////////////////////////////////////////////////////////////////
55 #ifndef _CppSQLite3_H_
57 #define _CppSQLite3_H_
69 #define CPPSQLITE_ERROR 1000
73 class CppSQLite3Exception
81 CppSQLite3Exception(const int nErrCode,
85 bool bDeleteMsg=true);
87 CppSQLite3Exception(const int nErrCode,
89 const char* szErrMess,
91 bool bDeleteMsg=true);
95 CppSQLite3Exception(const CppSQLite3Exception& e);
99 virtual ~CppSQLite3Exception();
103 const int errorCode() { return mnErrCode; }
107 const char* errorMessage() { return mpszErrMess; }
111 static const char* errorCodeAsString(int nErrCode);
129 class CppSQLite3Buffer
145 const char* format(const char* szFormat, ...);
149 operator const char*() { return mpBuf; }
169 class CppSQLite3Binary
185 void setBinary(const unsigned char* pBuf, int nLen);
187 void setEncoded(const unsigned char* pBuf);
191 const unsigned char* getEncoded();
193 const unsigned char* getBinary();
197 int getBinaryLength();
201 unsigned char* allocBuffer(int nLen);
213 unsigned char* mpBuf;
229 class CppSQLite3Query
241 CppSQLite3Query(const CppSQLite3Query& rQuery);
245 CppSQLite3Query(sqlite3* pDB,
255 CppSQLite3Query& operator=(const CppSQLite3Query& rQuery);
259 virtual ~CppSQLite3Query();
267 int fieldIndex(const char* szField);
269 const char* fieldName(int nCol);
273 const char* fieldDeclType(int nCol);
275 int fieldDataType(int nCol);
279 const char* fieldValue(int nField);
281 const char* fieldValue(const char* szField);
285 int getIntField(int nField, int nNullValue=0);
287 int getIntField(const char* szField, int nNullValue=0);
291 double getFloatField(int nField, double fNullValue=0.0);
293 double getFloatField(const char* szField, double fNullValue=0.0);
297 const char* getStringField(int nField, const char* szNullValue="");
299 const char* getStringField(const char* szField, const char* szNullValue="");
303 const unsigned char* getBlobField(int nField, int& nLen);
305 const unsigned char* getBlobField(const char* szField, int& nLen);
309 bool fieldIsNull(int nField);
311 bool fieldIsNull(const char* szField);
351 class CppSQLite3Table
363 CppSQLite3Table(const CppSQLite3Table& rTable);
367 CppSQLite3Table(char** paszResults, int nRows, int nCols);
371 virtual ~CppSQLite3Table();
375 CppSQLite3Table& operator=(const CppSQLite3Table& rTable);
387 const char* fieldName(int nCol);
391 const char* fieldValue(int nField);
393 const char* fieldValue(const char* szField);
397 int getIntField(int nField, int nNullValue=0);
399 int getIntField(const char* szField, int nNullValue=0);
403 double getFloatField(int nField, double fNullValue=0.0);
405 double getFloatField(const char* szField, double fNullValue=0.0);
409 const char* getStringField(int nField, const char* szNullValue="");
411 const char* getStringField(const char* szField, const char* szNullValue="");
415 bool fieldIsNull(int nField);
417 bool fieldIsNull(const char* szField);
421 void setRow(int nRow);
451 class CppSQLite3Statement
459 CppSQLite3Statement();
463 CppSQLite3Statement(const CppSQLite3Statement& rStatement);
467 CppSQLite3Statement(sqlite3* pDB, sqlite3_stmt* pVM);
471 virtual ~CppSQLite3Statement();
475 CppSQLite3Statement& operator=(const CppSQLite3Statement& rStatement);
483 CppSQLite3Query execQuery();
487 void bind(int nParam, const char* szValue);
489 void bind(int nParam, const int nValue);
491 void bind(int nParam, const double dwValue);
493 void bind(int nParam, const unsigned char* blobValue, int nLen);
495 void bindNull(int nParam);
539 virtual ~CppSQLite3DB();
543 void open(const char* szFile);
551 bool tableExists(const char* szTable);
555 int execDML(const char* szSQL);
559 CppSQLite3Query execQuery(const char* szSQL);
563 int execScalar(const char* szSQL);
567 CppSQLite3Table getTable(const char* szSQL);
571 CppSQLite3Statement compileStatement(const char* szSQL);
575 sqlite_int64 lastRowId();
579 void interrupt() { sqlite3_interrupt(mpDB); }
583 void setBusyTimeout(int nMillisecs);
587 static const char* SQLiteVersion() { return SQLITE_VERSION; }
595 CppSQLite3DB(const CppSQLite3DB& db);
597 CppSQLite3DB& operator=(const CppSQLite3DB& db);
601 sqlite3_stmt* compile(const char* szSQL);