00001 /*************************************************************************** 00002 * Copyright (C) 2008 by Sverre Rabbelier * 00003 * sverre@rabbelier.nl * 00004 * * 00005 * This program is free software; you can redistribute it and/or modify * 00006 * it under the terms of the GNU General Public License as published by * 00007 * the Free Software Foundation; either version 3 of the License, or * 00008 * (at your option) any later version. * 00009 * * 00010 * This program is distributed in the hope that it will be useful, * 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00013 * GNU General Public License for more details. * 00014 * * 00015 * You should have received a copy of the GNU General Public License * 00016 * along with this program; if not, write to the * 00017 * Free Software Foundation, Inc., * 00018 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 00019 ***************************************************************************/ 00020 00021 #pragma once 00022 00030 #include "Types.h" 00031 #include <Database.h> 00032 00033 class Statements; 00034 typedef SmartPtr<Statements> StatementsPtr; 00036 class StatementStrings; 00037 typedef SmartPtr<StatementStrings> StatementStringsPtr; 00039 typedef std::map<TableImpl*, StatementsPtr> TableStatements; 00040 typedef std::map<TableImpl*, StatementStringsPtr> TableStatementStrings; 00045 class SqliteMgr : public Singleton<SqliteMgr> 00046 { 00047 public: 00049 void doInsert(SavableManager* bindable); 00050 00052 void doErase(SavableManager* bindable); 00053 00055 void doUpdate(SavableManager* bindable); 00056 00058 void doSelect(SavableManager* bindable); 00059 00061 void doLookup(SavableManager* bindable, FieldPtr field); 00062 00064 void doSelectMulti(SelectionMask* mask); 00065 00067 void doCount(SelectionMask* mask); 00068 00069 00071 std::string tableQuery(TableImplPtr table) const; 00072 00074 bool databasePopulated(); 00075 00077 void initTable(TableImplPtr table); 00078 00080 bool tableValid(TableImplPtr table); 00081 00082 private: 00088 SqliteMgr(); 00089 00095 ~SqliteMgr(); 00096 friend class Singleton<SqliteMgr>; 00097 00099 bool doStatement(sqlite3_stmt* stmt); 00100 00102 void commit(TableImpl* table); 00103 00104 00106 sqlite3_stmt* getInsertStmt(TableImpl* table); 00107 00109 sqlite3_stmt* getEraseStmt(TableImpl* table); 00110 00112 sqlite3_stmt* getUpdateStmt(TableImpl* table); 00113 00115 sqlite3_stmt* getSelectStmt(TableImpl* table); 00116 00118 sqlite3_stmt* getLookupStmt(TableImpl* table, FieldPtr field); 00119 00125 sqlite3_stmt* getSelectMultiStmt(SelectionMask* table, bool count); 00126 00127 00129 StatementsPtr getStatements(TableImpl* table); 00130 00132 StatementStringsPtr getStatementStrings(TableImpl* table); 00133 00134 00141 std::string creationQuery(TableImplPtr table, bool verify = false) const; 00142 00144 std::string creationString(FieldImplPtr table) const; 00145 00146 00147 Database* m_db; 00148 Database::OPENDB* m_odb; 00149 const char* m_leftover; 00151 TableStatements m_statements; 00152 TableStatementStrings m_statementstrings; 00153 };