From e2a9b703ea6fbfbc33ca79ec39cb7c19f0283662 Mon Sep 17 00:00:00 2001 From: Kaj-Michael Lang Date: Fri, 27 Jul 2007 15:27:35 +0300 Subject: [PATCH] Move clearing of old data to their own functions. --- src/osm.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/osm.c b/src/osm.c index ce5b1bb..9340c0d 100644 --- a/src/osm.c +++ b/src/osm.c @@ -29,6 +29,7 @@ static gint dbnode_cnt=0; static gint dbnoded_cnt=0; static gint dbway_cnt=0; +static gboolean is_update=FALSE; static XML_Parser xp; typedef struct _node_data node_data; @@ -877,13 +878,19 @@ g_slist_free(osm_poi); /*********************************************************************/ +void +osm_planet_clear_nodes(void) +{ +g_print("Clearing old nodes\n"); +sqlite3_step(sql.delete_nodes); +} + void osm_planet_save_nodes(void) { g_print("Storing nodes...\n"); sqlite3_exec(db, "begin;", NULL, NULL, NULL); -sqlite3_step(sql.delete_nodes); g_hash_table_foreach(osm_nodes, osm_node_save_node, NULL); sqlite3_exec(db, "commit;", NULL, NULL, NULL); } @@ -902,16 +909,18 @@ if (dbway_cnt % 8192==0) { } void -osm_planet_save_ways(void) +osm_planet_clear_ways(void) { -g_print("Storing ways...\n"); - g_print("Clearing old data:\n"); sqlite3_step(sql.delete_way); sqlite3_step(sql.delete_way_seg); sqlite3_step(sql.delete_way_name); sqlite3_step(sql.delete_way_ref); +} +void +osm_planet_save_ways(void) +{ g_print("Inserting new ways:\n"); sqlite3_exec(db, "begin;", NULL, NULL, NULL); g_slist_foreach(osm_ways, osm_node_save_way, NULL); @@ -924,10 +933,18 @@ void osm_planet_save_to_db(void) { g_printf("Saving planet to database:\n"); + osm_planet_poi_clear_nodes(); osm_planet_poi_save_nodes(); + +if (!is_update) { + osm_planet_clear_nodes(); + osm_planet_clear_ways(); +} + osm_planet_save_nodes(); osm_planet_save_ways(); + g_printf("Data saved.\n"); } @@ -1172,7 +1189,7 @@ switch (t) { /************************************************************************/ -gboolean +void osm_planet_parse_init(void) { xp=XML_ParserCreate(NULL); @@ -1322,4 +1339,5 @@ storage_free(); sqlite3_close(db); sync(); +return 0; } -- 2.39.5