]> err.no Git - mapper/commitdiff
Database init changes. Rename some variables.
authorKaj-Michael Lang <milang@tal.org>
Tue, 30 Oct 2007 20:08:04 +0000 (22:08 +0200)
committerKaj-Michael Lang <milang@tal.org>
Tue, 30 Oct 2007 20:08:04 +0000 (22:08 +0200)
src/osm-db.c
src/osm-db.h
src/poi.c
src/poi.h
src/settings-gui.c

index fcc8d742bea01cfc0e17b6da295cbb21c7d611c2..2d375eb23411ca1830d516f387f2ecb38eb5f68e 100644 (file)
@@ -45,6 +45,8 @@
 #define OSM_RANGE_STEP  (8192)
 #define OSM_RANGE_STOP  (65535)
 
+static sqlite3 *osmdb;
+
 struct sql_select_stmt {
        sqlite3_stmt *select_way;
        sqlite3_stmt *select_way2;
@@ -63,7 +65,7 @@ static GTimer *dbt;
 static GtkProgressBar *dbpw=NULL;
 
 /* Cache hash tables */
-static GHashTable *_place_cache;
+static GHashTable *place_cache;
 
 static guint way_dist_range=OSM_RANGE_WAY;
 
@@ -192,21 +194,31 @@ if (sqlite3_prepare_v2(db, "select ref,int_ref from way_ref where rid=?",
 return TRUE;
 }
 
-gboolean
-osm_init(void)
-{
-_place_cache=g_hash_table_new(g_direct_hash, g_direct_equal);
-dbt=g_timer_new();
-return TRUE;
-}
-
 void
 osm_deinit(void)
 {
-g_hash_table_destroy(_place_cache);
+osmdb=NULL;
+g_hash_table_destroy(place_cache);
 g_timer_destroy(dbt);
 }
 
+gboolean
+osm_init(sqlite3 **db)
+{
+if (!db || !*db)
+       return FALSE;
+
+osmdb=*db;
+if (osm_db_prepare(osmdb)==FALSE) {
+       g_printerr("Failed to prepare OSM SQL statements:");
+       g_printf("SQLITE: %s\n", sqlite3_errmsg(osmdb));
+       return FALSE;
+}
+place_cache=g_hash_table_new(g_direct_hash, g_direct_equal);
+dbt=g_timer_new();
+return TRUE;
+}
+
 /*****************************************************************************/
 
 osm_way_node *
@@ -289,21 +301,21 @@ return g_slice_new0(osm_place);
 static osm_place *
 osm_place_cache_lookup(guint32 id)
 {
-return g_hash_table_lookup(_place_cache, GINT_TO_POINTER(id));
+return g_hash_table_lookup(place_cache, GINT_TO_POINTER(id));
 }
 
 static void
 osm_place_cache_add(osm_place *p)
 {
 if (osm_place_cache_lookup(p->id)==NULL)
-       g_hash_table_insert(_place_cache, GINT_TO_POINTER(p->id), p);
+       g_hash_table_insert(place_cache, GINT_TO_POINTER(p->id), p);
 }
 
 static void
 osm_place_cache_gc(void)
 {
 gint r;
-r=g_hash_table_foreach_remove(_place_cache, osm_place_remove, NULL);
+r=g_hash_table_foreach_remove(place_cache, osm_place_remove, NULL);
 }
 
 static void
@@ -335,7 +347,7 @@ if (n) {
 n=NULL;
 
 /* XXX: better place for this */
-if (g_hash_table_size(_place_cache)>OSM_PLACE_CACHE_MAX_ITEMS)
+if (g_hash_table_size(place_cache)>OSM_PLACE_CACHE_MAX_ITEMS)
        osm_place_cache_gc();
 
 sqlite3_clear_bindings(sql.select_place);
index f2bec4d33488c8a3068de45464a2de36b27bfe65..2f9a0728e3acb63fd6ac64de8706c0399f29e4d7 100644 (file)
@@ -26,7 +26,7 @@
 
 #define OSM_RANGE_WAY (20000)
 
-gboolean osm_init(void);
+gboolean osm_init(sqlite3 **db);
 void osm_deinit(void);
 
 void osm_set_way_range_from_speed(gfloat speed);
index a0d10b71a435df891e091af5af84a49ec1e80353..8253eb6f56675d87f711e65454866a9fb8c62201 100644 (file)
--- a/src/poi.c
+++ b/src/poi.c
@@ -29,6 +29,8 @@
 #include "osm.h"
 #include "osm-db.h"
 
+static sqlite3 *poidb;
+
 struct _poi_categories {
        node_type_t type;
        const gchar *name, *desc, *icon, *color;
@@ -289,38 +291,19 @@ poi_db_prepare(sqlite3 *db)
 }
 
 gboolean
-mapper_db_disconnect(sqlite3 **db)
+poi_init(sqlite3 **db)
 {
-if (db && *db) {
-       /* XXX: Handle the prepared statements */
-#if 0
-       poi_db_unprepare(*db);
-       osm_db_unprepare(*db);
-#endif 
-       sqlite3_close(*db);
-       return TRUE;
-}
-return FALSE;
-}
+if (!db || !*db)
+       return FALSE;
 
-gboolean
-mapper_db_connect(sqlite3 **db, const gchar *data_db)
-{
-if (db_connect(db, data_db)) {
-       poi_db_create(*db);
-       if (poi_db_prepare(*db)==FALSE) {
-               g_printerr("Failed to prepare POI SQL statements:");
-               g_printf("SQLITE: %s\n", sqlite3_errmsg(*db));
-               return FALSE;
-       }
-       if (osm_db_prepare(*db)==FALSE) {
-               g_printerr("Failed to prepare OSM SQL statements:");
-               g_printf("SQLITE: %s\n", sqlite3_errmsg(*db));
-               return FALSE;
-       }
-       return TRUE;
+poidb=*db;
+poi_db_create(poidb);
+if (poi_db_prepare(poidb)==FALSE) {
+       g_printerr("Failed to prepare POI SQL statements:");
+       g_printf("SQLITE: %s\n", sqlite3_errmsg(poidb));
+       return FALSE;
 }
-return FALSE;
+return TRUE;
 }
 
 poi_info *
index 5afc924bd2916da32f64418ace515341e267abcf..09cb4f4f3f492a0af478839ed8943270ae04e7e6 100644 (file)
--- a/src/poi.h
+++ b/src/poi.h
@@ -81,6 +81,8 @@ struct sql_poi_stmt poisql;
 
 guint _poi_zoom;
 
+gboolean poi_init(sqlite3 **db);
+
 gboolean poi_db_create(sqlite3 *db);
 gboolean poi_db_prepare(sqlite3 *db);
 
index 5b559d85b2475a73f7aed527a7a36a18b9f9d1a2..d4c35bc6c2a7598d64adf6b7c12dde684ee815e2 100644 (file)
@@ -656,13 +656,13 @@ settings_dialog(void)
                speak_set_parameters(_voice_speed, _voice_pitch);
 
                if (_db) {
-                       mapper_db_disconnect(&_db);
+                       db_close(&_db);
                        _db = NULL;
                }
                g_free(_mapper_db);
                if (strlen(gtk_entry_get_text(GTK_ENTRY(txt_mapper_db)))) {
                        _mapper_db = g_strdup(gtk_entry_get_text(GTK_ENTRY(txt_mapper_db)));
-                       mapper_db_connect(&_db, _mapper_db);
+                       db_connect(&_db, _mapper_db);
                } else {
                        _mapper_db = NULL;
                }