Migrated sqlite plugin to INIT/METHOD macros
This commit is contained in:
@@ -213,10 +213,8 @@ static bool sqlite_enumerator_enumerate(sqlite_enumerator_t *this, ...)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(database_t, query, enumerator_t*,
|
||||||
* Implementation of database_t.query.
|
private_sqlite_database_t *this, char *sql, ...)
|
||||||
*/
|
|
||||||
static enumerator_t* query(private_sqlite_database_t *this, char *sql, ...)
|
|
||||||
{
|
{
|
||||||
sqlite3_stmt *stmt;
|
sqlite3_stmt *stmt;
|
||||||
va_list args;
|
va_list args;
|
||||||
@@ -248,10 +246,8 @@ static enumerator_t* query(private_sqlite_database_t *this, char *sql, ...)
|
|||||||
return (enumerator_t*)enumerator;
|
return (enumerator_t*)enumerator;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(database_t, execute, int,
|
||||||
* Implementation of database_t.execute.
|
private_sqlite_database_t *this, int *rowid, char *sql, ...)
|
||||||
*/
|
|
||||||
static int execute(private_sqlite_database_t *this, int *rowid, char *sql, ...)
|
|
||||||
{
|
{
|
||||||
sqlite3_stmt *stmt;
|
sqlite3_stmt *stmt;
|
||||||
int affected = -1;
|
int affected = -1;
|
||||||
@@ -283,10 +279,8 @@ static int execute(private_sqlite_database_t *this, int *rowid, char *sql, ...)
|
|||||||
return affected;
|
return affected;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(database_t, get_driver, db_driver_t,
|
||||||
* Implementation of database_t.get_driver
|
private_sqlite_database_t *this)
|
||||||
*/
|
|
||||||
static db_driver_t get_driver(private_sqlite_database_t *this)
|
|
||||||
{
|
{
|
||||||
return DB_SQLITE;
|
return DB_SQLITE;
|
||||||
}
|
}
|
||||||
@@ -302,10 +296,8 @@ static int busy_handler(private_sqlite_database_t *this, int count)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(database_t, destroy, void,
|
||||||
* Implementation of database_t.destroy
|
private_sqlite_database_t *this)
|
||||||
*/
|
|
||||||
static void destroy(private_sqlite_database_t *this)
|
|
||||||
{
|
{
|
||||||
sqlite3_close(this->db);
|
sqlite3_close(this->db);
|
||||||
this->mutex->destroy(this->mutex);
|
this->mutex->destroy(this->mutex);
|
||||||
@@ -329,14 +321,17 @@ sqlite_database_t *sqlite_database_create(char *uri)
|
|||||||
}
|
}
|
||||||
file = uri + 9;
|
file = uri + 9;
|
||||||
|
|
||||||
this = malloc_thing(private_sqlite_database_t);
|
INIT(this,
|
||||||
|
.public = {
|
||||||
this->public.db.query = (enumerator_t* (*)(database_t *this, char *sql, ...))query;
|
.db = {
|
||||||
this->public.db.execute = (int (*)(database_t *this, int *rowid, char *sql, ...))execute;
|
.query = _query,
|
||||||
this->public.db.get_driver = (db_driver_t(*)(database_t*))get_driver;
|
.execute = _execute,
|
||||||
this->public.db.destroy = (void(*)(database_t*))destroy;
|
.get_driver = _get_driver,
|
||||||
|
.destroy = _destroy,
|
||||||
this->mutex = mutex_create(MUTEX_TYPE_RECURSIVE);
|
},
|
||||||
|
},
|
||||||
|
.mutex = mutex_create(MUTEX_TYPE_RECURSIVE),
|
||||||
|
);
|
||||||
|
|
||||||
if (sqlite3_open(file, &this->db) != SQLITE_OK)
|
if (sqlite3_open(file, &this->db) != SQLITE_OK)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -31,10 +31,8 @@ struct private_sqlite_plugin_t {
|
|||||||
sqlite_plugin_t public;
|
sqlite_plugin_t public;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
METHOD(plugin_t, destroy, void,
|
||||||
* Implementation of plugin_t.destroy
|
private_sqlite_plugin_t *this)
|
||||||
*/
|
|
||||||
static void destroy(private_sqlite_plugin_t *this)
|
|
||||||
{
|
{
|
||||||
lib->db->remove_database(lib->db,
|
lib->db->remove_database(lib->db,
|
||||||
(database_constructor_t)sqlite_database_create);
|
(database_constructor_t)sqlite_database_create);
|
||||||
@@ -46,9 +44,15 @@ static void destroy(private_sqlite_plugin_t *this)
|
|||||||
*/
|
*/
|
||||||
plugin_t *sqlite_plugin_create()
|
plugin_t *sqlite_plugin_create()
|
||||||
{
|
{
|
||||||
private_sqlite_plugin_t *this = malloc_thing(private_sqlite_plugin_t);
|
private_sqlite_plugin_t *this;
|
||||||
|
|
||||||
this->public.plugin.destroy = (void(*)(plugin_t*))destroy;
|
INIT(this,
|
||||||
|
.public = {
|
||||||
|
.plugin = {
|
||||||
|
.destroy = _destroy,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
lib->db->add_database(lib->db,
|
lib->db->add_database(lib->db,
|
||||||
(database_constructor_t)sqlite_database_create);
|
(database_constructor_t)sqlite_database_create);
|
||||||
|
|||||||
Reference in New Issue
Block a user