//  // //  #### # # # -= SQLiteX =-  // // # # ## ## Database.cpp  // //  ## # ###  // //  ## # ### SQLite database representation  // //  # # ## ##  // // #### ##### # # R1 (C)2005 Markus Ewald -> License.txt  // //  // #include "SQLiteX/Database.h" #include "SQLiteX/Query.h" #include "SQLiteX/Transaction.h" #include "SQLiteX/Errors.h" using namespace SQLiteX; namespace { // ############################################################################################# // // # openDatabase() # // // ############################################################################################# // /// Open sqlite database /** Opens an existing sqlite database or creates a new one. More or less a simple wrapper to make sqlite3_open() usable in an initialization list. If an error occurs opening/creating the database, an exception will be thrown. @param sFilename Filename of the database to open or to create @return The sqlite database handle */ sqlite3 *openDatabase(const std::string &sFilename) { sqlite3 *pSQLiteDB; int ErrorCode = ::sqlite3_open(sFilename.c_str(), &pSQLiteDB); struct DatabaseCloser { DatabaseCloser(sqlite3 *pSQLiteDB) : m_pSQLiteDB(pSQLiteDB), m_bDismissed(false) {} ~DatabaseCloser() { if(!m_bDismissed) { ::sqlite3_close(m_pSQLiteDB); } } void dismiss() { m_bDismissed = true; } sqlite3 *m_pSQLiteDB; bool m_bDismissed; } close_SQLiteDB(pSQLiteDB); checkError(pSQLiteDB, ErrorCode); close_SQLiteDB.dismiss(); return pSQLiteDB; } } // anonymous namespace // ############################################################################################# // // # SQLiteX::Database::Database() # // // ############################################################################################# // Database::Database(const std::string &sFilename) : m_SQLiteDB(openDatabase(sFilename)) {} // ############################################################################################# // // # SQLiteX::Database::execute() # // // ############################################################################################# // void Database::execute(const std::string &sStatements) { checkError(m_SQLiteDB, ::sqlite3_exec(m_SQLiteDB, sStatements.c_str(), 0, 0, 0)); } // ############################################################################################# // // # SQLiteX::Database::execute() # // // ############################################################################################# // void Database::execute(Query &TheQuery) { TheQuery.execute(m_SQLiteDB); } // ############################################################################################# // // # SQLiteX::Database::execute() # // // ############################################################################################# // void Database::execute(Transaction &NewTransaction) { NewTransaction.execute(m_SQLiteDB); }