From bbf70edd2f85ab5d7ff954e02fed379c59ba6252 Mon Sep 17 00:00:00 2001 From: Kaj-Michael Lang Date: Thu, 25 Oct 2007 13:17:14 +0300 Subject: [PATCH] Cleanup variable mess --- src/db.c | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/src/db.c b/src/db.c index d8449d5..86dcd64 100644 --- a/src/db.c +++ b/src/db.c @@ -13,7 +13,8 @@ gchar *_mapper_db=NULL; * A simple check to test if a table exists * */ -gboolean db_check(sqlite3 *db, const gchar *table) +gboolean +db_check(sqlite3 *db, const gchar *table) { gchar **pszResult; guint nRow, nColumn; @@ -32,9 +33,11 @@ return TRUE; * Close the database connection * */ -gboolean db_close(sqlite3 **db) +gboolean +db_close(sqlite3 **db) { if (db && *db) { + g_print("Closing database.\n"); sqlite3_close(*db); *db=NULL; } @@ -45,38 +48,29 @@ return TRUE; * Connect to given sqlite database * */ -gboolean db_connect(sqlite3 **ndb, const gchar *mapper_db) +gboolean +db_connect(sqlite3 **db, const gchar *mapper_db) { -sqlite3 *db; - -if (ndb && *ndb) - db=*ndb; -else - db=NULL; - -if (db) { - sqlite3_close(db); - db = NULL; +if (db && *db) { + sqlite3_close(*db); + *db=NULL; } if (!mapper_db) return FALSE; -if (SQLITE_OK != (sqlite3_open(mapper_db, &db))) { - sqlite3_close(db); - db = NULL; - *ndb=db; +if (SQLITE_OK!=(sqlite3_open(mapper_db, db))) { + sqlite3_close(*db); + *db=NULL; return FALSE; } /* Use smaller cache as the IT does not have much memory to spare */ #ifdef WITH_DEVICE_770 -sqlite3_exec(db, "PRAGMA cache_size = 1000;", NULL, NULL, NULL); +sqlite3_exec(*db, "PRAGMA cache_size = 1000;", NULL, NULL, NULL); #else -sqlite3_exec(db, "PRAGMA cache_size = 8000;", NULL, NULL, NULL); +sqlite3_exec(*db, "PRAGMA cache_size = 8000;", NULL, NULL, NULL); #endif -*ndb=db; - return TRUE; } -- 2.39.5