#include "osm.h"
#include "latlon.h"
#include "db.h"
+#include "osm-sql-tables.h"
#if 0
#define VERBOSE
void osm_free_way_data(way *w);
void print_way(way *w);
-void db_prepare(void);
+void db_prepare(sqlite3 *db);
gboolean db_insert_node(node *n);
guint32 osm_find_way_place(way *w, node_type_t nt);
}
void
-db_prepare(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)
{
/* Way nodes */
sqlite3_prepare_v2(db, "insert or replace into nodes (nid,ilat,ilon,rlat,rlon,l,f) values (?,?,?,?,?,0,?)", -1, &sql.insert_node, NULL);
{
gint32 lat, lon;
+g_assert(n);
sqlite3_bind_int(sql.insert_node, 1, n->id);
lat=lat2mp_int(n->lat);
static gboolean
db_insert_place(node *n)
{
+g_assert(n);
if (!n->data)
return FALSE;
if (!n->data->name)
static gboolean
db_insert_poi(node *n)
{
+g_assert(n);
sqlite3_bind_int(sql.insert_poi, 1, n->id);
sqlite3_bind_double(sql.insert_poi, 2, n->lat);
sqlite3_bind_double(sql.insert_poi, 3, n->lon);
static gboolean
db_update_node_links(node *n)
{
+g_assert(n);
sqlite3_bind_int(sql.update_node, 1, n->id);
return db_exec(sql.update_node);
if (n->type>NODE_POI_START && n->type<NODE_POI_END) {
print_node(n);
db_insert_poi(n);
+ osm_free_node_data(n);
} else if (n->type>NODE_PLACE_START && n->type<NODE_PLACE_END) {
print_node(n);
db_insert_place(n);
return FALSE;
}
-/* Free the extra info, we don't need it anymore */
-#if 0
-osm_free_node_data(n);
-#endif
return TRUE;
}
int main (int argc, char **argv)
{
+gchar *in_file;
+gchar *out_file;
+
if (argc<2) {
return print_fail("Give bzip2 compressed planet XML file as argument", 1);
}
-g_printf("Using file: %s\n", argv[1]);
+
+out_file=OSM_DB_FILE;
+in_file=argv[1];
+g_printf("Using file: %s\n", in_file);
if (argc==6) {
use_bbox=TRUE;
g_print("Note: missing nodes can't be reported.\n");
} else use_bbox=FALSE;
-if (db_connect(&db, OSM_DB_FILE)!=TRUE)
+if (db_connect(&db, out_file)!=TRUE)
return print_fail("Database open failed", 2);
-db_prepare();
+
+db_create_tables(db);
+db_create_indexes(db);
+db_prepare(db);
print_memory_usage();
osm_planet_parser_init();
if (osm_planet_parse_file(argv[1])==FALSE) {
- g_printf("Failed to parse file: %s\n", argv[1]);
+ g_printf("Failed to parse file: %s\n", in_file);
return 1;
}