#include "config.h"
-#include <gtk/gtk.h>
+#include <glib.h>
#include <sqlite3.h>
-#define _(String) gettext(String)
-
-#include <libintl.h>
-#include <locale.h>
-
+#include "db.h"
#include "utils.h"
-#include "ui-common.h"
-#include "poi.h"
+/**
+ * A simple check to test if a table exists
+ *
+ */
gboolean db_check(sqlite3 *db, const gchar *table)
{
gchar **pszResult;
snprintf(sql, sizeof(sql),"select count(*) from %s", table);
-if (SQLITE_OK != sqlite3_get_table(db, sql,
- &pszResult, &nRow, &nColumn, NULL))
+if (SQLITE_OK != sqlite3_get_table(db, sql, &pszResult, &nRow, &nColumn, NULL))
return FALSE;
sqlite3_free_table(pszResult);
return TRUE;
}
+/**
+ * Close the database connection
+ *
+ */
gboolean db_close(sqlite3 **db)
{
if (db && *db) {
return TRUE;
}
+/**
+ * Connect to given sqlite database
+ *
+ */
gboolean db_connect(sqlite3 **ndb, const gchar *db_file)
{
- gchar buffer[100];
- gchar *perror;
- gchar **pszResult;
- guint nRow, nColumn;
- sqlite3 *db;
-
- printf("%s()\n", __PRETTY_FUNCTION__);
+sqlite3 *db;
- if (ndb && *ndb)
- db=*ndb;
- else
- db=NULL;
+printf("%s()\n", __PRETTY_FUNCTION__);
- if (db) {
- sqlite3_close(db);
- db = NULL;
- }
+if (ndb && *ndb)
+ db=*ndb;
+else
+ db=NULL;
- if (!db_file)
- return FALSE;
-
- if (SQLITE_OK != (sqlite3_open(db_file, &db))) {
- gchar buffer2[200];
+if (db) {
+ sqlite3_close(db);
+ db = NULL;
+}
- snprintf(buffer2, sizeof(buffer2),
- "%s: %s", _("Problem with database"), sqlite3_errmsg(db));
- sqlite3_close(db);
- db = NULL;
- *ndb=db;
- popup_error(_window, buffer2);
- return FALSE;
- }
+if (!db_file)
+ return FALSE;
+if (SQLITE_OK != (sqlite3_open(db_file, &db))) {
+ sqlite3_close(db);
+ db = NULL;
*ndb=db;
+ return FALSE;
+}
- printf("%s(): return\n", __PRETTY_FUNCTION__);
- return TRUE;
+*ndb=db;
+
+printf("%s(): return\n", __PRETTY_FUNCTION__);
+return TRUE;
}