2 * This file is part of mapper
4 * Copyright (C) 2007 Kaj-Michael Lang
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 gchar *_mapper_db=NULL;
32 * A simple check to test if a table exists
36 db_check(sqlite3 *db, const gchar *table)
42 g_snprintf(sql, sizeof(sql),"select count(*) from %s", table);
44 if (SQLITE_OK != sqlite3_get_table(db, sql, &pszResult, &nRow, &nColumn, NULL))
47 sqlite3_free_table(pszResult);
52 * Helper that execs a given prepared sql statment and resets clears bindings.
53 * return TRUE or FALSE depending on success of the query.
57 db_exec(sqlite3_stmt *sql)
63 sqlite3_clear_bindings(sql);
65 return (r==SQLITE_OK) ? TRUE : FALSE;
69 * Close the database connection
73 db_close(sqlite3 **db)
76 g_print("Closing database.\n");
84 * Connect to given sqlite database
88 db_connect(sqlite3 **db, const gchar *mapper_db)
98 if (SQLITE_OK!=(sqlite3_open(mapper_db, db))) {
104 /* Use smaller cache as the IT does not have much memory to spare */
105 #ifdef WITH_DEVICE_770
106 sqlite3_exec(*db, "PRAGMA cache_size = 1000;", NULL, NULL, NULL);
108 sqlite3_exec(*db, "PRAGMA cache_size = 8000;", NULL, NULL, NULL);