From: Kaj-Michael Lang Date: Thu, 25 Oct 2007 10:17:14 +0000 (+0300) Subject: Cleanup variable mess X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bbf70edd2f85ab5d7ff954e02fed379c59ba6252;p=mapper Cleanup variable mess --- 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; }