sqliteDatabaseConnector.h
Go to the documentation of this file.
/******************************************************
* Presage, an extensible predictive text entry system
* ---------------------------------------------------
*
* Copyright (C) 2008 Matteo Vescovi <matteo.vescovi@yahoo.co.uk>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
**********(*)*/
#ifndef SQLITEDATABASECONNECTOR_H
#define SQLITEDATABASECONNECTOR_H
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#if defined(HAVE_SQLITE3_H)
# include <sqlite3.h>
#elif defined(HAVE_SQLITE_H)
# include <sqlite.h>
#else
# error "SQLite is required. Please install SQLite."
#endif
#include "databaseConnector.h"
#include "../../presageException.h"
class SqliteDatabaseConnector : public DatabaseConnector {
public:
SqliteDatabaseConnector(const std::string db,
const size_t cardinality,
const bool read_write);
SqliteDatabaseConnector(const std::string db,
const size_t cardinality,
const bool read_write,
const std::string logger_level);
~SqliteDatabaseConnector();
virtual void openDatabase();
virtual void closeDatabase();
virtual NgramTable executeSql(const std::string query) const;
class SqliteDatabaseConnectorException : public PresageException {
public:
SqliteDatabaseConnectorException(presage_error_code_t code, const std::string& errormsg) throw() : PresageException(code, errormsg) { }
virtual ~SqliteDatabaseConnectorException() throw() { }
private:
SqliteDatabaseConnectorException() throw() : PresageException(PRESAGE_ERROR, "") {};
};
protected:
private:
static int callback(void *pArg, int argc, char **argv, char **columnNames);
#if defined(HAVE_SQLITE3_H)
sqlite3* db;
#elif defined(HAVE_SQLITE_H)
sqlite* db;
#endif
};
#endif // SQLITEDATABASECONNECTOR_H
presage_error_code_t
presage_error_code_t
Definition: presageException.h:32
SqliteDatabaseConnector::executeSql
virtual NgramTable executeSql(const std::string query) const
Definition: sqliteDatabaseConnector.cpp:130
SqliteDatabaseConnector::SqliteDatabaseConnector
SqliteDatabaseConnector(const std::string db, const size_t cardinality, const bool read_write)
Definition: sqliteDatabaseConnector.cpp:31
PRESAGE_ERROR
Definition: presageException.h:35
SqliteDatabaseConnector
Definition: sqliteDatabaseConnector.h:43
PresageException::PresageException
PresageException(presage_error_code_t code, const std::string &msg)
Definition: presageException.h:69
SqliteDatabaseConnector::closeDatabase
virtual void closeDatabase()
Definition: sqliteDatabaseConnector.cpp:119
SqliteDatabaseConnector::SqliteDatabaseConnectorException::SqliteDatabaseConnectorException
SqliteDatabaseConnectorException()
Definition: sqliteDatabaseConnector.h:64
SqliteDatabaseConnector::SqliteDatabaseConnectorException::SqliteDatabaseConnectorException
SqliteDatabaseConnectorException(presage_error_code_t code, const std::string &errormsg)
Definition: sqliteDatabaseConnector.h:60
DatabaseConnector
Definition: databaseConnector.h:44
DatabaseConnector::cardinality
size_t cardinality
Definition: databaseConnector.h:165
databaseConnector.h
PresageException
Definition: presageException.h:67
PresageException::code
virtual const presage_error_code_t code() const
Definition: presageException.h:86
SqliteDatabaseConnector::callback
static int callback(void *pArg, int argc, char **argv, char **columnNames)
Definition: sqliteDatabaseConnector.cpp:170
SqliteDatabaseConnector::SqliteDatabaseConnectorException
Definition: sqliteDatabaseConnector.h:58
NgramTable
std::vector< Ngram > NgramTable
Definition: databaseConnector.h:39
SqliteDatabaseConnector::SqliteDatabaseConnectorException::~SqliteDatabaseConnectorException
virtual ~SqliteDatabaseConnectorException()
Definition: sqliteDatabaseConnector.h:61
SqliteDatabaseConnector::openDatabase
virtual void openDatabase()
Definition: sqliteDatabaseConnector.cpp:53
SqliteDatabaseConnector::~SqliteDatabaseConnector
~SqliteDatabaseConnector()
Definition: sqliteDatabaseConnector.cpp:48