From e282217e4447018f7f18fe44ae40f6bc034760d5 Mon Sep 17 00:00:00 2001 From: Kaj-Michael Lang Date: Mon, 4 Feb 2008 17:03:10 +0200 Subject: [PATCH] Move table and index creation to db.c --- src/db.c | 42 ++++++++++++++++++++++++++++++++++++++++++ src/db.h | 3 +++ src/osm.c | 42 ++++-------------------------------------- 3 files changed, 49 insertions(+), 38 deletions(-) diff --git a/src/db.c b/src/db.c index 3081295..1a6725f 100644 --- a/src/db.c +++ b/src/db.c @@ -24,10 +24,49 @@ #include #include "db.h" +#include "osm-sql-tables.h" sqlite3 *_db=NULL; gchar *_mapper_db=NULL; +void +db_create_tables(sqlite3 *db) +{ +sqlite3_exec(db, OSM_TABLE_NODES,NULL, NULL, NULL); +sqlite3_exec(db, OSM_TABLE_NODE_TAGS,NULL, NULL, NULL); +sqlite3_exec(db, OSM_TABLE_WAY,NULL, NULL, NULL); +sqlite3_exec(db, OSM_TABLE_WAY_TAGS,NULL, NULL, NULL); +sqlite3_exec(db, OSM_TABLE_WAY_UPDATES,NULL, NULL, NULL); +sqlite3_exec(db, OSM_TABLE_WAY_N2N,NULL, NULL, NULL); +sqlite3_exec(db, OSM_TABLE_WAY_NAMES,NULL, NULL, NULL); +sqlite3_exec(db, OSM_TABLE_WAY_PC,NULL, NULL, NULL); +sqlite3_exec(db, OSM_TABLE_WAY_NAMES_NLS,NULL, NULL, NULL); +sqlite3_exec(db, OSM_TABLE_WAY_REF,NULL, NULL, NULL); +sqlite3_exec(db, OSM_TABLE_PLACES,NULL, NULL, NULL); +sqlite3_exec(db, OSM_TABLE_POI,NULL, NULL, NULL); +sqlite3_exec(db, OSM_TABLE_POI_CATEGORY,NULL, NULL, NULL); +} + +void +db_create_indexes(sqlite3 *db) +{ +sqlite3_exec(db, OSM_INDEX_1, NULL, NULL, NULL); +sqlite3_exec(db, OSM_INDEX_2, NULL, NULL, NULL); +sqlite3_exec(db, OSM_INDEX_3, NULL, NULL, NULL); +sqlite3_exec(db, OSM_INDEX_4, NULL, NULL, NULL); +sqlite3_exec(db, OSM_INDEX_5, NULL, NULL, NULL); +sqlite3_exec(db, OSM_INDEX_6, NULL, NULL, NULL); +sqlite3_exec(db, OSM_INDEX_7, NULL, NULL, NULL); +sqlite3_exec(db, OSM_INDEX_8, NULL, NULL, NULL); +sqlite3_exec(db, OSM_INDEX_9, NULL, NULL, NULL); +sqlite3_exec(db, OSM_INDEX_10, NULL, NULL, NULL); +sqlite3_exec(db, OSM_INDEX_11, NULL, NULL, NULL); +sqlite3_exec(db, OSM_INDEX_12, NULL, NULL, NULL); +sqlite3_exec(db, OSM_INDEX_13, NULL, NULL, NULL); +sqlite3_exec(db, OSM_INDEX_14, NULL, NULL, NULL); +sqlite3_exec(db, OSM_INDEX_15, NULL, NULL, NULL); +} + /** * A simple check to test if a table exists * @@ -110,3 +149,6 @@ sqlite3_exec(*db, "PRAGMA cache_size = 8000;", NULL, NULL, NULL); return TRUE; } + + + diff --git a/src/db.h b/src/db.h index b84a2da..2277039 100644 --- a/src/db.h +++ b/src/db.h @@ -32,4 +32,7 @@ gboolean db_check(sqlite3 *db, const gchar *table); gboolean db_close(sqlite3 **db); gboolean db_exec(sqlite3_stmt *sql); +void db_create_tables(sqlite3 *db); +void db_create_indexes(sqlite3 *db); + #endif diff --git a/src/osm.c b/src/osm.c index ee9aa82..53f9bcc 100644 --- a/src/osm.c +++ b/src/osm.c @@ -50,7 +50,7 @@ #include "osm.h" #include "latlon.h" #include "db.h" -#include "osm-sql-tables.h" + #if 0 #define VERBOSE @@ -437,43 +437,7 @@ sqlite3_finalize(sql.delete_way_names_nls); sqlite3_finalize(sql.insert_way_names_nls); } -void -db_create_tables(sqlite3 *db) -{ -sqlite3_exec(db, OSM_TABLE_NODES,NULL, NULL, NULL); -sqlite3_exec(db, OSM_TABLE_NODE_TAGS,NULL, NULL, NULL); -sqlite3_exec(db, OSM_TABLE_WAY,NULL, NULL, NULL); -sqlite3_exec(db, OSM_TABLE_WAY_TAGS,NULL, NULL, NULL); -sqlite3_exec(db, OSM_TABLE_WAY_UPDATES,NULL, NULL, NULL); -sqlite3_exec(db, OSM_TABLE_WAY_N2N,NULL, NULL, NULL); -sqlite3_exec(db, OSM_TABLE_WAY_NAMES,NULL, NULL, NULL); -sqlite3_exec(db, OSM_TABLE_WAY_PC,NULL, NULL, NULL); -sqlite3_exec(db, OSM_TABLE_WAY_NAMES_NLS,NULL, NULL, NULL); -sqlite3_exec(db, OSM_TABLE_WAY_REF,NULL, NULL, NULL); -sqlite3_exec(db, OSM_TABLE_PLACES,NULL, NULL, NULL); -sqlite3_exec(db, OSM_TABLE_POI,NULL, NULL, NULL); -sqlite3_exec(db, OSM_TABLE_POI_CATEGORY,NULL, NULL, NULL); -} -void -db_create_indexes(sqlite3 *db) -{ -sqlite3_exec(db, OSM_INDEX_1, NULL, NULL, NULL); -sqlite3_exec(db, OSM_INDEX_2, NULL, NULL, NULL); -sqlite3_exec(db, OSM_INDEX_3, NULL, NULL, NULL); -sqlite3_exec(db, OSM_INDEX_4, NULL, NULL, NULL); -sqlite3_exec(db, OSM_INDEX_5, NULL, NULL, NULL); -sqlite3_exec(db, OSM_INDEX_6, NULL, NULL, NULL); -sqlite3_exec(db, OSM_INDEX_7, NULL, NULL, NULL); -sqlite3_exec(db, OSM_INDEX_8, NULL, NULL, NULL); -sqlite3_exec(db, OSM_INDEX_9, NULL, NULL, NULL); -sqlite3_exec(db, OSM_INDEX_10, NULL, NULL, NULL); -sqlite3_exec(db, OSM_INDEX_11, NULL, NULL, NULL); -sqlite3_exec(db, OSM_INDEX_12, NULL, NULL, NULL); -sqlite3_exec(db, OSM_INDEX_13, NULL, NULL, NULL); -sqlite3_exec(db, OSM_INDEX_14, NULL, NULL, NULL); -sqlite3_exec(db, OSM_INDEX_15, NULL, NULL, NULL); -} void db_prepare(sqlite3 *db) @@ -947,7 +911,7 @@ g_print("\n"); } #endif -static gboolean +static inline gboolean osm_node_check_box(gdouble nlat, gdouble nlon) { if (use_bbox==FALSE) @@ -1014,6 +978,8 @@ static node * osm_find_node(guint32 nid) { node *n; + +g_assert(osm_nodes); n=g_hash_table_lookup(osm_nodes, GINT_TO_POINTER(nid)); #if 0 if (!n) -- 2.39.5