From: Kaj-Michael Lang Date: Sun, 4 Nov 2007 16:30:08 +0000 (+0200) Subject: Fix POI add sql and fields. Drop POI cache after adding. X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=42f3806565be7c0fb4708ca68eede886226fa088;p=mapper Fix POI add sql and fields. Drop POI cache after adding. --- diff --git a/src/cb.c b/src/cb.c index da7defc..34ab662 100644 --- a/src/cb.c +++ b/src/cb.c @@ -1051,9 +1051,11 @@ if (strcmp(name, "poi_add")==0) { p->lat=lat; p->lon=lon; poi_edit_dialog(ACTION_ADD_POI, p); -} else if (strcmp(name, "poi_quick_add")==0) + map_poi_cache_clear(); +} else if (strcmp(name, "poi_quick_add")==0) { poi_quick_dialog(lat, lon); -else + map_poi_cache_clear(); +} else g_assert_not_reached(); return TRUE; diff --git a/src/map-poi.c b/src/map-poi.c index e260b7a..70024a7 100644 --- a/src/map-poi.c +++ b/src/map-poi.c @@ -132,6 +132,17 @@ if (gdk_color_parse(hexcolor, &color)) { return def; } +void +map_poi_cache_clear(void) +{ +if (poi_store==NULL) + return; + +gtk_list_store_clear(poi_store); +g_object_unref(G_OBJECT(poi_store)); +poi_store=NULL; +} + static gboolean map_poi_reload_poi(guint unitx, guint unity, gdouble lat1, gdouble lon1, gdouble lat2, gdouble lon2) { @@ -139,10 +150,8 @@ guint pois; /* Reload POIs if we zoom out or have moved */ if ((last_zoom<_zoom || prev_ux!=unitx || prev_uy!=unity) && poi_store!=NULL) { - gtk_list_store_clear(poi_store); - g_object_unref(G_OBJECT(poi_store)); - poi_store=NULL; g_printf("Reloading POIs\n"); + map_poi_cache_clear(); } else { g_printf("Using cached POIs\n"); } diff --git a/src/poi.c b/src/poi.c index 20c51cc..d4fdef1 100644 --- a/src/poi.c +++ b/src/poi.c @@ -291,8 +291,8 @@ poi_db_prepare(sqlite3 *db) return FALSE; /* Insert POI */ - sqlite3_prepare_v2(db, "insert into poi (lat, lon, label, desc, url, postal_code, cat_id, public, source)" - " values (?, ?, ?, ?, ?, ?, ?, 1, ?)", -1, &poisql.insert_poi, NULL); + sqlite3_prepare_v2(db, "insert into poi (lat, lon, label, desc, url, postal_code, cat_id, addtime, public, source)" + " values (?, ?, ?, ?, ?, ?, ?, ?, 1, ?)", -1, &poisql.insert_poi, NULL); /* update poi */ sqlite3_prepare_v2(db, "update poi set label=?, desc=?, cat_id=? where poi_id=?", -1, &poisql.update_poi, NULL); /* delete from poi */ @@ -776,18 +776,25 @@ return TRUE; gboolean poi_add(poi_info *p) { +time_t t; + if (!poidb) return FALSE; if (p->poi_id!=0) return FALSE; +t=time(NULL); + if (SQLITE_OK != sqlite3_bind_double(poisql.insert_poi, 1, p->lat) || SQLITE_OK != sqlite3_bind_double(poisql.insert_poi, 2, p->lon) || SQLITE_OK != sqlite3_bind_text(poisql.insert_poi, 3, p->label, -1, SQLITE_STATIC) || SQLITE_OK != sqlite3_bind_text(poisql.insert_poi, 4, p->desc, -1, SQLITE_STATIC) - || SQLITE_OK != sqlite3_bind_int(poisql.insert_poi, 5, p->cat_id) - || SQLITE_OK != sqlite3_bind_double(poisql.insert_poi, 6, p->source) + || SQLITE_OK != sqlite3_bind_text(poisql.insert_poi, 5, p->url, -1, SQLITE_STATIC) + || SQLITE_OK != sqlite3_bind_text(poisql.insert_poi, 6, p->postal_code, -1, SQLITE_STATIC) + || SQLITE_OK != sqlite3_bind_int(poisql.insert_poi, 7, p->cat_id) + || SQLITE_OK != sqlite3_bind_int(poisql.insert_poi, 8, t) + || SQLITE_OK != sqlite3_bind_int(poisql.insert_poi, 9, p->source) || SQLITE_DONE != sqlite3_step(poisql.insert_poi)) { return FALSE; }