#include <SQLiteUtil.h>
Classes | |
struct | Mapping |
Public Types | |
typedef long long | key_t |
typedef unsigned long | syncml_time_t |
Public Member Functions | |
const Mapping & | getMapping (int i) |
void | open (const string &name, const string &fileid, const Mapping *mapping, const char *schema) |
void | close () |
void | throwError (const string &operation) |
sqlite3_stmt * | prepareSQL (const char *sqlfmt,...) |
sqlite3_stmt * | prepareSQLWrapper (const char *sql, const char **nextsql=NULL) |
int | checkSQL (int res, const char *operation="SQLite call") |
string | toString (key_t key) |
key_t | findKey (const char *database, const char *keyname, const char *key) |
string | findColumn (const char *database, const char *keyname, const char *key, const char *column, const char *def) |
string | getTextColumn (sqlite3_stmt *stmt, int col, const char *def="") |
syncml_time_t | getTimeColumn (sqlite3_stmt *stmt, int col) |
void | rowToVObject (sqlite3_stmt *stmt, vocl::VObject &vobj) |
sqlite3_stmt * | vObjectToRow (vocl::VObject &vobj, const string &tablename, int numparams, const string &cols, const string &values) |
Static Public Member Functions | |
static string | time2str (syncml_time_t t) |
Definition at line 49 of file SQLiteUtil.h.
typedef long long SQLiteUtil::key_t |
type used for row keys
Definition at line 109 of file SQLiteUtil.h.
typedef unsigned long SQLiteUtil::syncml_time_t |
Definition at line 122 of file SQLiteUtil.h.
int SQLiteUtil::checkSQL | ( | int | res, | |
const char * | operation = "SQLite call" | |||
) | [inline] |
checks the result of an sqlite3 call, throws an error if faulty, otherwise returns the result
Definition at line 101 of file SQLiteUtil.h.
References throwError().
Referenced by SQLiteContactSource::createItem(), SQLiteContactSource::deleteItem(), findColumn(), findKey(), SQLiteContactSource::insertItem(), SQLiteContactSource::listAllItems(), open(), prepareSQLWrapper(), and vObjectToRow().
void SQLiteUtil::close | ( | ) |
Definition at line 267 of file SQLiteUtil.cpp.
Referenced by SQLiteContactSource::close(), and open().
string SQLiteUtil::findColumn | ( | const char * | database, | |
const char * | keyname, | |||
const char * | key, | |||
const char * | column, | |||
const char * | def | |||
) |
return a specific column for a row identified by a certain key column as text, returns default text if not found
Definition at line 76 of file SQLiteUtil.cpp.
References checkSQL(), and prepareSQL().
Referenced by SQLiteContactSource::insertItem(), and SQLiteContactSource::logItem().
SQLiteUtil::key_t SQLiteUtil::findKey | ( | const char * | database, | |
const char * | keyname, | |||
const char * | key | |||
) |
return row ID for a certain row
Definition at line 64 of file SQLiteUtil.cpp.
References checkSQL(), and prepareSQL().
const Mapping& SQLiteUtil::getMapping | ( | int | i | ) | [inline] |
Definition at line 60 of file SQLiteUtil.h.
Referenced by SQLiteContactSource::createItem(), and SQLiteContactSource::insertItem().
string SQLiteUtil::getTextColumn | ( | sqlite3_stmt * | stmt, | |
int | col, | |||
const char * | def = "" | |||
) |
a wrapper for sqlite3_column_test() which will check for NULL and returns default text instead
Definition at line 90 of file SQLiteUtil.cpp.
Referenced by SQLiteContactSource::createItem().
SQLiteUtil::syncml_time_t SQLiteUtil::getTimeColumn | ( | sqlite3_stmt * | stmt, | |
int | col | |||
) |
transform column to same time base as used by SyncML libary (typically time())
Definition at line 96 of file SQLiteUtil.cpp.
Referenced by SQLiteContactSource::listAllItems().
void SQLiteUtil::open | ( | const string & | name, | |
const string & | fileid, | |||
const Mapping * | mapping, | |||
const char * | schema | |||
) |
name | a name for the data source, used for error messages | |
fileid | a descriptor which identifies the file to be opened: currently valid syntax is file:// followed by path | |
mapping | array with database mapping, terminated by NULL colname | |
schema | database schema to use when creating new databases, may be NULL |
Definition at line 187 of file SQLiteUtil.cpp.
References checkSQL(), close(), SQLiteUtil::Mapping::colname, prepareSQL(), prepareSQLWrapper(), eptr< T, base, R >::set(), and throwError().
Referenced by SQLiteContactSource::open().
sqlite3_stmt * SQLiteUtil::prepareSQL | ( | const char * | sqlfmt, | |
... | ||||
) |
wrapper around sqlite3_prepare() which operates on the current database and throws an error if the call fails
sqlfmt | printf-style format string for query, followed by parameters for sprintf |
Definition at line 51 of file SQLiteUtil.cpp.
References prepareSQLWrapper().
Referenced by SQLiteContactSource::createItem(), SQLiteContactSource::deleteItem(), findColumn(), findKey(), SQLiteContactSource::insertItem(), SQLiteContactSource::listAllItems(), open(), and vObjectToRow().
sqlite3_stmt * SQLiteUtil::prepareSQLWrapper | ( | const char * | sql, | |
const char ** | nextsql = NULL | |||
) |
wrapper around sqlite3_prepare() which operates on the current database and throws an error if the call fails
sql | preformatted SQL statement(s) | |
nextsql | pointer to next statement in sql |
Definition at line 43 of file SQLiteUtil.cpp.
References checkSQL().
Referenced by open(), and prepareSQL().
void SQLiteUtil::rowToVObject | ( | sqlite3_stmt * | stmt, | |
vocl::VObject & | vobj | |||
) |
copies all columns which directly map to a property into the vobj
Definition at line 109 of file SQLiteUtil.cpp.
Referenced by SQLiteContactSource::createItem().
void SQLiteUtil::throwError | ( | const string & | operation | ) |
throw error for a specific sqlite3 operation on m_db
operation | a description of the operation which failed |
Definition at line 30 of file SQLiteUtil.cpp.
Referenced by checkSQL(), and open().
string SQLiteUtil::time2str | ( | SQLiteUtil::syncml_time_t | t | ) | [static] |
convert time to string
Definition at line 102 of file SQLiteUtil.cpp.
Referenced by SQLiteContactSource::insertItem(), and SQLiteContactSource::listAllItems().
string SQLiteUtil::toString | ( | key_t | key | ) | [inline] |
sqlite3_stmt * SQLiteUtil::vObjectToRow | ( | vocl::VObject & | vobj, | |
const string & | tablename, | |||
int | numparams, | |||
const string & | cols, | |||
const string & | values | |||
) |
Creates a SQL INSERT INTO <tablename> ( <cols> ) VALUES ( <values> ) statement and binds all rows/values that map directly from the vobj.
numparams | number of ? placeholders in values; the caller has to bind those before executing the statement |
Definition at line 131 of file SQLiteUtil.cpp.
References checkSQL(), prepareSQL(), and eptr< T, base, R >::release().
Referenced by SQLiteContactSource::insertItem().