presage
0.8.7
|
00001 00002 /****************************************************** 00003 * Presage, an extensible predictive text entry system 00004 * --------------------------------------------------- 00005 * 00006 * Copyright (C) 2008 Matteo Vescovi <matteo.vescovi@yahoo.co.uk> 00007 00008 This program is free software; you can redistribute it and/or modify 00009 it under the terms of the GNU General Public License as published by 00010 the Free Software Foundation; either version 2 of the License, or 00011 (at your option) any later version. 00012 00013 This program is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 GNU General Public License for more details. 00017 00018 You should have received a copy of the GNU General Public License along 00019 with this program; if not, write to the Free Software Foundation, Inc., 00020 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00021 * 00022 **********(*)*/ 00023 00024 00025 #ifndef SQLITEDATABASECONNECTOR_H 00026 #define SQLITEDATABASECONNECTOR_H 00027 00028 #ifdef HAVE_CONFIG_H 00029 # include "config.h" 00030 #endif 00031 00032 #if defined(HAVE_SQLITE3_H) 00033 # include <sqlite3.h> 00034 #elif defined(HAVE_SQLITE_H) 00035 # include <sqlite.h> 00036 #else 00037 # error "SQLite is required. Please install SQLite." 00038 #endif 00039 00040 #include "databaseConnector.h" 00041 #include "../../presageException.h" 00042 00043 class SqliteDatabaseConnector : public DatabaseConnector { 00044 public: 00045 SqliteDatabaseConnector(const std::string db); 00046 SqliteDatabaseConnector(const std::string db, const std::string logger_level); 00047 ~SqliteDatabaseConnector(); 00048 00049 virtual void openDatabase(); 00050 virtual void closeDatabase(); 00051 virtual NgramTable executeSql(const std::string query) const; 00052 00053 class SqliteDatabaseConnectorException : public PresageException { 00054 public: 00055 SqliteDatabaseConnectorException(presage_error_code_t code, const std::string& errormsg) throw() : PresageException(code, errormsg) { } 00056 virtual ~SqliteDatabaseConnectorException() throw() { } 00057 00058 private: 00059 SqliteDatabaseConnectorException() throw() : PresageException(PRESAGE_ERROR, "") {}; 00060 00061 }; 00062 00063 protected: 00064 00065 private: 00066 static int callback(void *pArg, int argc, char **argv, char **columnNames); 00067 00068 std::string db_name; 00069 #if defined(HAVE_SQLITE3_H) 00070 sqlite3* db; 00071 #elif defined(HAVE_SQLITE_H) 00072 sqlite* db; 00073 #endif 00074 00075 }; 00076 00077 #endif // SQLITEDATABASECONNECTOR_H