#include <CppSQLite3.h>
Public Member Functions | |
CppSQLite3DB () | |
virtual | ~CppSQLite3DB () |
void | open (const char *szFile) |
void | close () |
bool | tableExists (const char *szTable) |
int | execDML (const char *szSQL) |
CppSQLite3Query | execQuery (const char *szSQL) |
int | execScalar (const char *szSQL) |
CppSQLite3Table | getTable (const char *szSQL) |
CppSQLite3Statement | compileStatement (const char *szSQL) |
sqlite_int64 | lastRowId () |
void | interrupt () |
void | setBusyTimeout (int nMillisecs) |
Static Public Member Functions | |
static const char * | SQLiteVersion () |
Private Member Functions | |
CppSQLite3DB (const CppSQLite3DB &db) | |
CppSQLite3DB & | operator= (const CppSQLite3DB &db) |
sqlite3_stmt * | compile (const char *szSQL) |
void | checkDB () |
Private Attributes | |
sqlite3 * | mpDB |
int | mnBusyTimeoutMs |
Definition at line 527 of file CppSQLite3.h.
CppSQLite3DB::CppSQLite3DB | ( | ) |
Definition at line 2215 of file CppSQLite3.cpp.
References mnBusyTimeoutMs, and mpDB.
{ mpDB = 0; mnBusyTimeoutMs = 60000; // 60 seconds }
CppSQLite3DB::~CppSQLite3DB | ( | ) | [virtual] |
Definition at line 2243 of file CppSQLite3.cpp.
References close().
{ close(); }
CppSQLite3DB::CppSQLite3DB | ( | const CppSQLite3DB & | db | ) | [private] |
Definition at line 2229 of file CppSQLite3.cpp.
References mnBusyTimeoutMs, and mpDB.
{ mpDB = db.mpDB; mnBusyTimeoutMs = 60000; // 60 seconds }
void CppSQLite3DB::checkDB | ( | ) | [private] |
Definition at line 2553 of file CppSQLite3.cpp.
References CPPSQLITE_ERROR, DONT_DELETE_MSG, and mpDB.
Referenced by compile(), compileStatement(), execDML(), execQuery(), and getTable().
{ if (!mpDB) { throw CppSQLite3Exception(CPPSQLITE_ERROR, "Database not open", DONT_DELETE_MSG); } }
void CppSQLite3DB::close | ( | ) |
Definition at line 2299 of file CppSQLite3.cpp.
References mpDB.
Referenced by ~CppSQLite3DB().
sqlite3_stmt * CppSQLite3DB::compile | ( | const char * | szSQL | ) | [private] |
Definition at line 2575 of file CppSQLite3.cpp.
References checkDB(), and mpDB.
Referenced by compileStatement(), and execQuery().
{ checkDB(); char* szError=0; const char* szTail=0; sqlite3_stmt* pVM; int nRet = sqlite3_prepare(mpDB, szSQL, -1, &pVM, &szTail); if (nRet != SQLITE_OK) { throw CppSQLite3Exception(nRet, szError); } return pVM; }
CppSQLite3Statement CppSQLite3DB::compileStatement | ( | const char * | szSQL | ) |
Definition at line 2319 of file CppSQLite3.cpp.
References checkDB(), compile(), and mpDB.
{ checkDB(); sqlite3_stmt* pVM = compile(szSQL); return CppSQLite3Statement(mpDB, pVM); }
int CppSQLite3DB::execDML | ( | const char * | szSQL | ) |
Definition at line 2359 of file CppSQLite3.cpp.
References checkDB(), and mpDB.
Referenced by creaImageIO::SQLiteTreeHandler::DBCreate(), and creaImageIO::SQLiteTreeHandler::DBOpen().
{ checkDB(); char* szError=0; int nRet = sqlite3_exec(mpDB, szSQL, 0, 0, &szError); if (nRet == SQLITE_OK) { return sqlite3_changes(mpDB); } else { throw CppSQLite3Exception(nRet, szError); } }
CppSQLite3Query CppSQLite3DB::execQuery | ( | const char * | szSQL | ) |
Definition at line 2397 of file CppSQLite3.cpp.
References checkDB(), compile(), DONT_DELETE_MSG, and mpDB.
Referenced by execScalar().
{ checkDB(); sqlite3_stmt* pVM = compile(szSQL); int nRet = sqlite3_step(pVM); if (nRet == SQLITE_DONE) { // no rows return CppSQLite3Query(mpDB, pVM, true/*eof*/); } else if (nRet == SQLITE_ROW) { // at least 1 row return CppSQLite3Query(mpDB, pVM, false/*eof*/); } else { nRet = sqlite3_finalize(pVM); const char* szError= sqlite3_errmsg(mpDB); throw CppSQLite3Exception(nRet, (char*)szError, DONT_DELETE_MSG); } }
int CppSQLite3DB::execScalar | ( | const char * | szSQL | ) |
Definition at line 2451 of file CppSQLite3.cpp.
References CPPSQLITE_ERROR, DONT_DELETE_MSG, CppSQLite3Query::eof(), execQuery(), CppSQLite3Query::fieldValue(), and CppSQLite3Query::numFields().
Referenced by tableExists().
{ CppSQLite3Query q = execQuery(szSQL); if (q.eof() || q.numFields() < 1) { throw CppSQLite3Exception(CPPSQLITE_ERROR, "Invalid scalar query", DONT_DELETE_MSG); } return atoi(q.fieldValue(0)); }
CppSQLite3Table CppSQLite3DB::getTable | ( | const char * | szSQL | ) |
Definition at line 2481 of file CppSQLite3.cpp.
References checkDB(), and mpDB.
{ checkDB(); char* szError=0; char** paszResults=0; int nRet; int nRows(0); int nCols(0); nRet = sqlite3_get_table(mpDB, szSQL, &paszResults, &nRows, &nCols, &szError); if (nRet == SQLITE_OK) { return CppSQLite3Table(paszResults, nRows, nCols); } else { throw CppSQLite3Exception(nRet, szError); } }
void CppSQLite3DB::interrupt | ( | ) | [inline] |
sqlite_int64 CppSQLite3DB::lastRowId | ( | ) |
Definition at line 2527 of file CppSQLite3.cpp.
References mpDB.
Referenced by creaImageIO::SQLiteTreeHandler::DBInsert().
{ return sqlite3_last_insert_rowid(mpDB); }
void CppSQLite3DB::open | ( | const char * | szFile | ) |
Definition at line 2271 of file CppSQLite3.cpp.
References DONT_DELETE_MSG, mnBusyTimeoutMs, mpDB, and setBusyTimeout().
Referenced by creaImageIO::Synchronizer::CreateDB(), creaImageIO::TimestampDatabaseHandler::DBCreate(), creaImageIO::SQLiteTreeHandler::DBCreate(), creaImageIO::TimestampDatabaseHandler::DBOpen(), creaImageIO::SQLiteTreeHandler::DBOpen(), and creaImageIO::Synchronizer::Initialize().
{ int nRet = sqlite3_open(szFile, &mpDB); if (nRet != SQLITE_OK) { const char* szError = sqlite3_errmsg(mpDB); throw CppSQLite3Exception(nRet, (char*)szError, DONT_DELETE_MSG); } setBusyTimeout(mnBusyTimeoutMs); }
CppSQLite3DB & CppSQLite3DB::operator= | ( | const CppSQLite3DB & | db | ) | [private] |
Definition at line 2255 of file CppSQLite3.cpp.
References mnBusyTimeoutMs, and mpDB.
{ mpDB = db.mpDB; mnBusyTimeoutMs = 60000; // 60 seconds return *this; }
void CppSQLite3DB::setBusyTimeout | ( | int | nMillisecs | ) |
Definition at line 2539 of file CppSQLite3.cpp.
References mnBusyTimeoutMs, and mpDB.
Referenced by open().
{ mnBusyTimeoutMs = nMillisecs; sqlite3_busy_timeout(mpDB, mnBusyTimeoutMs); }
static const char* CppSQLite3DB::SQLiteVersion | ( | ) | [inline, static] |
Definition at line 587 of file CppSQLite3.h.
Referenced by creaImageIO::TimestampDatabaseHandler::TimestampDatabaseHandler().
{ return SQLITE_VERSION; }
bool CppSQLite3DB::tableExists | ( | const char * | szTable | ) |
Definition at line 2337 of file CppSQLite3.cpp.
References execScalar().
Referenced by creaImageIO::SQLiteTreeHandler::DBImportTreeDescription().
{ char szSQL[128]; sprintf(szSQL, "select count(*) from sqlite_master where type='table' and name='%s'", szTable); int nRet = execScalar(szSQL); return (nRet > 0); }
int CppSQLite3DB::mnBusyTimeoutMs [private] |
Definition at line 611 of file CppSQLite3.h.
Referenced by CppSQLite3DB(), open(), operator=(), and setBusyTimeout().
sqlite3* CppSQLite3DB::mpDB [private] |
Definition at line 609 of file CppSQLite3.h.
Referenced by checkDB(), close(), compile(), compileStatement(), CppSQLite3DB(), execDML(), execQuery(), getTable(), interrupt(), lastRowId(), open(), operator=(), and setBusyTimeout().