From 29d4dffea3d788ed88906d86ab7470b5c11a6636 Mon Sep 17 00:00:00 2001 From: Kaj-Michael Lang Date: Fri, 20 Jul 2007 17:49:16 +0300 Subject: [PATCH] Move more direct sqlite handling from poi-gui.c to poi.c --- src/poi-gui.c | 70 ++++++++------------------------------------------- src/poi.c | 36 +++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 60 deletions(-) diff --git a/src/poi-gui.c b/src/poi-gui.c index f67ab53..2580398 100644 --- a/src/poi-gui.c +++ b/src/poi-gui.c @@ -51,23 +51,8 @@ gboolean category_delete(GtkWidget * widget, DeletePOI * dpoi) gtk_widget_destroy(GTK_WIDGET(dialog)); if (i == GTK_RESPONSE_OK) { - /* delete dpoi->poi_id */ - if (SQLITE_OK != sqlite3_bind_int(_stmt_delete_poi_by_catid, 1, dpoi->id) || - SQLITE_DONE != sqlite3_step(_stmt_delete_poi_by_catid)) { - MACRO_BANNER_SHOW_INFO(_window, _("Problem deleting POI")); - sqlite3_reset(_stmt_delete_poi_by_catid); - return FALSE; - } - sqlite3_reset(_stmt_delete_poi_by_catid); - - if (SQLITE_OK != sqlite3_bind_int(_stmt_delete_cat, 1, dpoi->id) - || SQLITE_DONE != sqlite3_step(_stmt_delete_cat)) { - MACRO_BANNER_SHOW_INFO(_window, _("Problem deleting category")); - sqlite3_reset(_stmt_delete_cat); - return FALSE; - } - sqlite3_reset(_stmt_delete_cat); - + if (poi_category_delete(dpoi)==FALSE) + MACRO_BANNER_SHOW_INFO(_window, _("Problem deleting category or POI")); gtk_widget_hide_all(dpoi->dialog); map_force_redraw(); } @@ -95,8 +80,7 @@ gboolean category_dialog(guint cat_id) printf("%s()\n", __PRETTY_FUNCTION__); if (cat_id > 0) { - if (SQLITE_OK != - sqlite3_bind_double(_stmt_select_cat, 1, cat_id) + if (SQLITE_OK != sqlite3_bind_double(_stmt_select_cat, 1, cat_id) || SQLITE_ROW != sqlite3_step(_stmt_select_cat)) { vprintf("%s(): return FALSE\n", __PRETTY_FUNCTION__); sqlite3_reset(_stmt_select_cat); @@ -890,70 +874,38 @@ gboolean poi_dialog(POIAction action, guint unitx, guint unity) if (strlen(gtk_entry_get_text(GTK_ENTRY(txt_label)))) poi_label = gtk_entry_get_text(GTK_ENTRY(txt_label)); else { - popup_error(dialog, - _("Please specify a name for the POI.")); + popup_error(dialog, _("Please specify a name for the POI.")); continue; } if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX(cmb_category), &iter)) { - popup_error(dialog, - _ - ("Please specify a category for the POI.")); + popup_error(dialog, _("Please specify a category for the POI.")); continue; } gtk_text_buffer_get_iter_at_offset(desc_txt, &begin, 0); gtk_text_buffer_get_end_iter(desc_txt, &end); - poi_desc = - gtk_text_buffer_get_text(desc_txt, &begin, &end, TRUE); + poi_desc = gtk_text_buffer_get_text(desc_txt, &begin, &end, TRUE); - gtk_tree_model_get(gtk_combo_box_get_model - (GTK_COMBO_BOX(cmb_category)), &iter, 0, - &poi.cat_id, -1); + gtk_tree_model_get(gtk_combo_box_get_model(GTK_COMBO_BOX(cmb_category)), &iter, 0, &poi.cat_id, -1); if (action == ACTION_EDIT_POI) { /* edit poi */ - if (SQLITE_OK != - sqlite3_bind_text(_stmt_update_poi, 1, poi_label, - -1, SQLITE_STATIC) - || SQLITE_OK != sqlite3_bind_text(_stmt_update_poi, - 2, poi_desc, -1, - g_free) - || SQLITE_OK != sqlite3_bind_int(_stmt_update_poi, - 3, poi.cat_id) - || SQLITE_OK != sqlite3_bind_int(_stmt_update_poi, - 4, poi.poi_id) - || SQLITE_DONE != sqlite3_step(_stmt_update_poi)) { - MACRO_BANNER_SHOW_INFO(_window, - _ - ("Problem updating POI")); + if (poi_update(poi.poi_id, poi.cat_id, poi_label, poi_desc)==FALSE) { + MACRO_BANNER_SHOW_INFO(_window, _("Problem updating POI")); } else { MACRO_MAP_RENDER_DATA(); } - sqlite3_reset(_stmt_update_poi); } else { /* add poi */ g_ascii_dtostr(slat1, sizeof(slat1), poi.lat); g_ascii_dtostr(slon1, sizeof(slon1), poi.lon); - if (SQLITE_OK != - sqlite3_bind_double(_stmt_insert_poi, 1, poi.lat) - || SQLITE_OK != sqlite3_bind_double(_stmt_insert_poi, 2, poi.lon) - || SQLITE_OK != sqlite3_bind_text(_stmt_insert_poi, - 3, poi_label, -1, - g_free) - || SQLITE_OK != sqlite3_bind_text(_stmt_insert_poi, - 4, poi_desc, -1, - g_free) - || SQLITE_OK != sqlite3_bind_int(_stmt_insert_poi, - 5, poi.cat_id) - || SQLITE_DONE != sqlite3_step(_stmt_insert_poi)) { - MACRO_BANNER_SHOW_INFO(_window, - _("Problem adding POI")); + if (poi_add(poi.lat, poi.lon, poi.cat_id, poi_label, poi_desc)==FALSE) { + MACRO_BANNER_SHOW_INFO(_window, _("Problem adding POI")); } else { MACRO_MAP_RENDER_DATA(); } - sqlite3_reset(_stmt_insert_poi); } break; } diff --git a/src/poi.c b/src/poi.c index be8c048..dbe860e 100644 --- a/src/poi.c +++ b/src/poi.c @@ -85,7 +85,7 @@ poi_cb_populate_categories(sqlite3 *db) sqlite3_stmt *sql_cat; gint i; -g_printf("Checking default categories..."); +g_printf("Checking default categories\n"); sqlite3_prepare(db,"insert into category (cat_id, label, desc, enabled)" " values (?, ?, ?, 1)", -1, &sql_cat, NULL); @@ -297,6 +297,7 @@ if (SQLITE_OK != sqlite3_bind_int(_stmt_delete_poi_by_catid, 1, dpoi->id) return FALSE; } sqlite3_reset(_stmt_delete_poi_by_catid); +sqlite3_clear_bindings(_stmt_delete_poi_by_catid); if (SQLITE_OK != sqlite3_bind_int(_stmt_delete_cat, 1, dpoi->id) || SQLITE_DONE != sqlite3_step(_stmt_delete_cat)) { @@ -304,6 +305,7 @@ if (SQLITE_OK != sqlite3_bind_int(_stmt_delete_cat, 1, dpoi->id) || return FALSE; } sqlite3_reset(_stmt_delete_cat); +sqlite3_clear_bindings(_stmt_delete_cat); return TRUE; } @@ -317,7 +319,39 @@ if (SQLITE_OK != sqlite3_bind_int(_stmt_delete_poi, 1, dpoi->id) || return FALSE; } else { sqlite3_reset(_stmt_delete_poi); + sqlite3_clear_bindings(_stmt_delete_poi); } return TRUE; } +gboolean +poi_update(gint poi_id, gint cat_id, gchar *poi_label, gchar *poi_desc) +{ +if (SQLITE_OK != sqlite3_bind_text(_stmt_update_poi, 1, poi_label, -1, SQLITE_STATIC) + || SQLITE_OK != sqlite3_bind_text(_stmt_update_poi, 2, poi_desc, -1, g_free) + || SQLITE_OK != sqlite3_bind_int(_stmt_update_poi, 3, cat_id) + || SQLITE_OK != sqlite3_bind_int(_stmt_update_poi, 4, poi_id) + || SQLITE_DONE != sqlite3_step(_stmt_update_poi)) { + return FALSE; + } +sqlite3_reset(_stmt_update_poi); +sqlite3_clear_bindings(_stmt_update_poi); +return TRUE; +} + +gboolean +poi_add(gdouble lat, gdouble lon, gint cat_id, gchar *poi_label, gchar *poi_desc) +{ +if (SQLITE_OK != sqlite3_bind_double(_stmt_insert_poi, 1, lat) + || SQLITE_OK != sqlite3_bind_double(_stmt_insert_poi, 2, lon) + || SQLITE_OK != sqlite3_bind_text(_stmt_insert_poi, 3, poi_label, -1, g_free) + || SQLITE_OK != sqlite3_bind_text(_stmt_insert_poi, 4, poi_desc, -1, g_free) + || SQLITE_OK != sqlite3_bind_int(_stmt_insert_poi, 5, cat_id) + || SQLITE_DONE != sqlite3_step(_stmt_insert_poi)) { + return FALSE; + } +sqlite3_reset(_stmt_insert_poi); +sqlite3_clear_bindings(_stmt_insert_poi); +return TRUE; +} + -- 2.39.5