From: Kaj-Michael Lang Date: Tue, 30 Oct 2007 22:07:46 +0000 (+0200) Subject: Working (messy) POI search implemented. X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=674268b5b6f1b28c45b81739e6f3e0ea491e2920;p=mapper Working (messy) POI search implemented. --- diff --git a/src/cb.c b/src/cb.c index b92a605..1c34384 100644 --- a/src/cb.c +++ b/src/cb.c @@ -32,6 +32,7 @@ #include "db.h" #include "latlon.h" #include "cb.h" +#include "poi-gui.h" #include "gps-panels.h" #include "gps-conn.h" #include "help.h" @@ -984,8 +985,11 @@ gboolean cb_poi_search(GtkAction *action) { poi_info poi; +gdouble lat, lon; + +unit2latlon(_center.unitx, _center.unity, lat, lon); -poi_search_dialog(NULL, &poi); +poi_search_dialog(NULL, &poi, lat, lon); return TRUE; } diff --git a/src/poi-gui.c b/src/poi-gui.c index 591400e..965caa8 100644 --- a/src/poi-gui.c +++ b/src/poi-gui.c @@ -39,6 +39,19 @@ struct _poi_search_query { gchar *query; }; +typedef struct _search_dialog search_dialog; +struct _search_dialog { + GtkWidget *dialog; + GtkWidget *list; + GtkWidget *cmb_category; + GtkWidget *search_entry; + GtkListStore *store; + gdouble lat; + gdouble lon; +}; + +static search_dialog sd; + typedef struct _PoiCategoryEditInfo PoiCategoryEditInfo; struct _PoiCategoryEditInfo { GtkWidget *cmb_category; @@ -116,17 +129,22 @@ return cmb; } static void -poi_category_combo_populate(GtkWidget *cmb_category, guint cat_id) +poi_category_combo_populate(GtkWidget *cmb_category, guint cat_id, gboolean add_na) { GtkTreeIter active; GtkListStore *store; +GtkTreeIter iter; gboolean has_active = FALSE; store = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(cmb_category))); gtk_list_store_clear(store); +if (add_na) { + gtk_list_store_append(store, &iter); + gtk_list_store_set(store, &iter, 0, -1, 1, "[Not set]", -1); +} + while (SQLITE_ROW == sqlite3_step(poisql.selall_cat)) { - GtkTreeIter iter; guint cid = sqlite3_column_int(poisql.selall_cat, 0); gtk_list_store_append(store, &iter); gtk_list_store_set(store, &iter, 0, cid, 1, sqlite3_column_text(poisql.selall_cat, 1), -1); @@ -427,6 +445,42 @@ return TRUE; static gboolean poi_search_do_cb(GtkWidget *widget, gpointer data) { +gchar *s; +guint cid; +GtkListStore *store; +GtkTreeIter iter; +search_dialog *sd=(search_dialog *)data; + +if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(sd->cmb_category), &iter)==TRUE) + gtk_tree_model_get(gtk_combo_box_get_model(GTK_COMBO_BOX(sd->cmb_category)), &iter, 0, &cid, -1); +else + cid=-1; + +if ((strlen(gtk_entry_get_text(sd->search_entry))<2) && (cid==-1)) { + popup_error(sd->dialog, _("Query string too short. Minimum 2 characters.")); + return TRUE; +} + +s=g_strdup(gtk_entry_get_text(sd->search_entry)); +g_printf("Search: [%s]\n", s); + +#if 0 +store=gtk_tree_view_get_model(GTK_TREE_VIEW(sd->list)); +if (store) { + gtk_list_store_clear(store); + g_object_unref(G_OBJECT(store)); +} +#endif + +if (poi_search((cid==-1) ? POI_SEARCH_TEXT : POI_SEARCH_TEXT_CAT, sd->lat, sd->lon, s, cid, &sd->store)==TRUE) { + gtk_tree_view_set_model(GTK_TREE_VIEW(sd->list), GTK_TREE_MODEL(sd->store)); + g_object_unref(G_OBJECT(sd->store)); +} else { + sd->store=NULL; + gtk_tree_view_set_model(GTK_TREE_VIEW(sd->list), GTK_TREE_MODEL(sd->store)); +} + +g_free(s); return TRUE; } @@ -434,14 +488,16 @@ static gboolean poi_goto_cb(GtkWidget *widget, gpointer data) { GtkTreeIter iter; +GtkTreeModel *model; gdouble lat, lon; -GtkTreeView *tree=GTK_TREE_VIEW(data); -GtkTreeModel *model = GTK_TREE_MODEL(data); +search_dialog *sd=(search_dialog *)data; -if (!gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(tree)), NULL, &iter)) +if (!gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(sd->list)), NULL, &iter)) { + popup_error(sd->dialog, _("Select one POI from the list.")); return TRUE; +} -model=gtk_tree_view_get_model(GTK_TREE_VIEW(tree)); +model=gtk_tree_view_get_model(GTK_TREE_VIEW(sd->list)); if (!model) return TRUE; @@ -458,13 +514,15 @@ static gboolean poi_route_to_cb(GtkWidget *widget, gpointer data) { GtkTreeIter iter; -GtkTreeView *tree=GTK_TREE_VIEW(data); -GtkTreeModel *model = GTK_TREE_MODEL(data); +GtkTreeModel *model; +search_dialog *sd=(search_dialog *)data; -if (!gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(tree)), NULL, &iter)) +if (!gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(sd->list)), NULL, &iter)) { + popup_error(sd->dialog, _("Select one POI from the list.")); return TRUE; +} -model=gtk_tree_view_get_model(GTK_TREE_VIEW(tree)); +model=gtk_tree_view_get_model(GTK_TREE_VIEW(sd->list)); if (!model) return TRUE; @@ -478,42 +536,44 @@ return TRUE; } gboolean -poi_search_dialog(GtkListStore *store, poi_info *poi) +poi_search_dialog(GtkListStore *store, poi_info *poi, gdouble lat, gdouble lon) { -GtkWidget *dialog, *list, *sw, *cmb_category; -GtkWidget *hbox, *label, *search_entry, *btn_search, *btn_goto, *btn_route_to; +GtkWidget *sw, *hbox, *label, *btn_search, *btn_goto, *btn_route_to; GtkTreeViewColumn *column; GtkCellRenderer *renderer; GtkTreeIter iter; gboolean selected = FALSE; -dialog = gtk_dialog_new_with_buttons(_("Select POI"), +sd.dialog = gtk_dialog_new_with_buttons(_("Select POI"), GTK_WINDOW(_window), - GTK_DIALOG_MODAL, GTK_STOCK_OK, + GTK_DIALOG_MODAL, + GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, NULL); +sd.lat=lat; +sd.lon=lon; -gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->action_area), +gtk_container_add(GTK_CONTAINER(GTK_DIALOG(sd.dialog)->action_area), btn_goto = gtk_button_new_with_label(_("Go"))); -gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->action_area), +gtk_container_add(GTK_CONTAINER(GTK_DIALOG(sd.dialog)->action_area), btn_route_to = gtk_button_new_with_label(_("Route to"))); -gtk_window_set_default_size(GTK_WINDOW(dialog), 500, 300); +gtk_window_set_default_size(GTK_WINDOW(sd.dialog), 500, 300); hbox = gtk_hbox_new(FALSE, 4), -gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox, FALSE, FALSE, 0); +gtk_box_pack_start(GTK_BOX(GTK_DIALOG(sd.dialog)->vbox), hbox, FALSE, FALSE, 0); label=gtk_label_new(_("Search:")); gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); -cmb_category = category_combo_new(); -gtk_box_pack_start(GTK_BOX(hbox), cmb_category, FALSE, FALSE, 0); -poi_category_combo_populate(cmb_category, 0); +sd.cmb_category = category_combo_new(); +gtk_box_pack_start(GTK_BOX(hbox), sd.cmb_category, FALSE, FALSE, 0); +poi_category_combo_populate(sd.cmb_category, 0, TRUE); -search_entry=gtk_entry_new(); -gtk_box_pack_start(GTK_BOX(hbox), search_entry, TRUE, TRUE, 0); +sd.search_entry=gtk_entry_new(); +gtk_box_pack_start(GTK_BOX(hbox), sd.search_entry, TRUE, TRUE, 0); btn_search=gtk_button_new_with_label(_("Search")); gtk_box_pack_start(GTK_BOX(hbox), btn_search, FALSE, FALSE, 0); @@ -521,53 +581,59 @@ gtk_box_pack_start(GTK_BOX(hbox), btn_search, FALSE, FALSE, 0); sw = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), GTK_SHADOW_ETCHED_IN); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); -gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), sw, TRUE, TRUE, 0); +gtk_box_pack_start(GTK_BOX(GTK_DIALOG(sd.dialog)->vbox), sw, TRUE, TRUE, 0); -list = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); -gtk_container_add(GTK_CONTAINER(sw), list); -g_object_unref(G_OBJECT(store)); +if (store!=NULL) { + sd.list=gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); + sd.store=store; + g_object_unref(G_OBJECT(store)); +} else { + sd.list=gtk_tree_view_new(); + sd.store=NULL; +} +gtk_container_add(GTK_CONTAINER(sw), sd.list); -gtk_tree_selection_set_mode(gtk_tree_view_get_selection (GTK_TREE_VIEW(list)), GTK_SELECTION_SINGLE); -gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(list), TRUE); -gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (list), TRUE); -gtk_tree_view_set_search_column (GTK_TREE_VIEW (list), POI_LABEL); +gtk_tree_selection_set_mode(gtk_tree_view_get_selection (GTK_TREE_VIEW(sd.list)), GTK_SELECTION_SINGLE); +gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(sd.list), TRUE); +gtk_tree_view_set_rules_hint (GTK_TREE_VIEW(sd.list), TRUE); +gtk_tree_view_set_search_column (GTK_TREE_VIEW(sd.list), POI_LABEL); renderer = gtk_cell_renderer_text_new(); column = gtk_tree_view_column_new_with_attributes(_("Location"), renderer, "text", POI_LATLON, NULL); -gtk_tree_view_append_column(GTK_TREE_VIEW(list), column); +gtk_tree_view_append_column(GTK_TREE_VIEW(sd.list), column); renderer = gtk_cell_renderer_text_new(); column = gtk_tree_view_column_new_with_attributes(_("Label"), renderer, "text", POI_LABEL, NULL); gtk_tree_view_column_set_sort_column_id (column, POI_LABEL); -gtk_tree_view_append_column(GTK_TREE_VIEW(list), column); +gtk_tree_view_append_column(GTK_TREE_VIEW(sd.list), column); renderer = gtk_cell_renderer_text_new(); column = gtk_tree_view_column_new_with_attributes(_("Category"), renderer, "text", POI_CATLAB, NULL); gtk_tree_view_column_set_sort_column_id (column, POI_CATLAB); -gtk_tree_view_append_column(GTK_TREE_VIEW(list), column); - -g_signal_connect(G_OBJECT(btn_search), "clicked", G_CALLBACK(poi_search_do_cb), NULL); -g_signal_connect(G_OBJECT(btn_goto), "clicked", G_CALLBACK(poi_goto_cb), list); -g_signal_connect(G_OBJECT(btn_route_to), "clicked", G_CALLBACK(poi_route_to_cb), list); - -gtk_widget_show_all(dialog); - -while (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) { - if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(list)), NULL, &iter)) { - gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, POI_POIID, &(poi->poi_id), -1); - gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, POI_CATID, &(poi->cat_id), -1); - gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, POI_LAT, &(poi->lat), -1); - gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, POI_LON, &(poi->lon), -1); - gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, POI_LABEL, &(poi->label), -1); - gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, POI_DESC, &(poi->desc), -1); +gtk_tree_view_append_column(GTK_TREE_VIEW(sd.list), column); + +g_signal_connect(G_OBJECT(btn_search), "clicked", G_CALLBACK(poi_search_do_cb), &sd); +g_signal_connect(G_OBJECT(btn_goto), "clicked", G_CALLBACK(poi_goto_cb), &sd); +g_signal_connect(G_OBJECT(btn_route_to), "clicked", G_CALLBACK(poi_route_to_cb), &sd); + +gtk_widget_show_all(sd.dialog); + +while (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(sd.dialog))) { + if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(sd.list)), NULL, &iter)) { + gtk_tree_model_get(GTK_TREE_MODEL(sd.store), &iter, POI_POIID, &(poi->poi_id), -1); + gtk_tree_model_get(GTK_TREE_MODEL(sd.store), &iter, POI_CATID, &(poi->cat_id), -1); + gtk_tree_model_get(GTK_TREE_MODEL(sd.store), &iter, POI_LAT, &(poi->lat), -1); + gtk_tree_model_get(GTK_TREE_MODEL(sd.store), &iter, POI_LON, &(poi->lon), -1); + gtk_tree_model_get(GTK_TREE_MODEL(sd.store), &iter, POI_LABEL, &(poi->label), -1); + gtk_tree_model_get(GTK_TREE_MODEL(sd.store), &iter, POI_DESC, &(poi->desc), -1); selected = TRUE; break; } else { - popup_error(dialog, _("Select one POI from the list.")); + popup_error(sd.dialog, _("Select one POI from the list.")); } } -gtk_widget_destroy(dialog); +gtk_widget_destroy(sd.dialog); return selected; } @@ -577,6 +643,7 @@ poi_select(guint unitx, guint unity, poi_info *poi) GtkListStore *store; guint num_cats; GtkTreeIter iter; +gdouble lat, lon; if (poi_get_list_near(unitx, unity, &store, &num_cats)==FALSE) return FALSE; @@ -602,14 +669,15 @@ case 1: break; } -return poi_search_dialog(store, poi); +unit2latlon(unitx, unity, lat, lon); +return poi_search_dialog(store, poi, lat, lon); } gboolean poi_edit_cat(GtkWidget * widget, PoiCategoryEditInfo * data) { if (poi_category_list()) - poi_category_combo_populate(data->cmb_category, data->cat_id); + poi_category_combo_populate(data->cmb_category, data->cat_id, FALSE); return TRUE; } @@ -717,7 +785,7 @@ desc_txt = gtk_text_view_get_buffer(GTK_TEXT_VIEW(txt_desc)); gtk_entry_set_text(GTK_ENTRY(txt_label), poi.label); /* category */ -poi_category_combo_populate(cmb_category, poi.cat_id); +poi_category_combo_populate(cmb_category, poi.cat_id, FALSE); /* poi_desc */ gtk_text_buffer_set_text(desc_txt, poi.desc, -1); @@ -740,14 +808,12 @@ while (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) { continue; } - if (!gtk_combo_box_get_active_iter - (GTK_COMBO_BOX(cmb_category), &iter)) { + if (!gtk_combo_box_get_active_iter(GTK_COMBO_BOX(cmb_category), &iter)) { 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); + gtk_text_buffer_get_bounds(desc_txt, &begin, &end); 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); diff --git a/src/poi-gui.h b/src/poi-gui.h index 0c95043..fc40f7e 100644 --- a/src/poi-gui.h +++ b/src/poi-gui.h @@ -8,7 +8,7 @@ gboolean poi_select(guint unitx, guint unity, poi_info *poi); gboolean poi_category_dialog(guint cat_id); gboolean poi_category_list(); gboolean poi_dialog(POIAction action, guint unitx, guint unity); -gboolean poi_search_dialog(GtkListStore *store, poi_info *poi); +gboolean poi_search_dialog(GtkListStore *store, poi_info *poi, gdouble lat, gdouble lon); gboolean poi_quick_dialog(guint unitx, guint unity); #endif diff --git a/src/poi.c b/src/poi.c index 8253eb6..6374b46 100644 --- a/src/poi.c +++ b/src/poi.c @@ -198,37 +198,40 @@ gboolean poi_db_prepare(sqlite3 *db) { /* select from poi */ - sqlite3_prepare_v2(db, + if (sqlite3_prepare_v2(db, "select p.lat, p.lon, p.poi_id, p.label, p.desc," " p.cat_id, c.label, c.desc, c.icon, c.color" " from poi p, category c " " where p.lat between ? and ? " " and p.lon between ? and ? " " and c.enabled = 1 and p.cat_id = c.cat_id", - -1, &poisql.select_poi, NULL); + -1, &poisql.select_poi, NULL)!=SQLITE_OK) + return FALSE; /* Search POI label */ - sqlite3_prepare_v2(db, + if (sqlite3_prepare_v2(db, "select p.lat, p.lon, p.poi_id, p.label, p.desc," " p.cat_id, c.label, c.desc, c.icon, c.color" " from poi p, category c " " where p.lat between ? and ? " " and p.lon between ? and ? " " and c.enabled = 1 and p.cat_id = c.cat_id and p.label like ? order by p.label", - -1, &poisql.select_poi_search, NULL); + -1, &poisql.select_poi_search, NULL)!=SQLITE_OK) + return FALSE; /* Search POI label && category */ - sqlite3_prepare_v2(db, + if (sqlite3_prepare_v2(db, "select p.lat, p.lon, p.poi_id, p.label, p.desc," " p.cat_id, c.label, c.desc, c.icon, c.color" " from poi p, category c " " where p.lat between ? and ? " " and p.lon between ? and ? " " and c.enabled = 1 and p.cat_id = c.cat_id and p.label like ? and c.cat_id = ? order by p.label", - -1, &poisql.select_poi_search_cat, NULL); + -1, &poisql.select_poi_search_cat, NULL)!=SQLITE_OK) + return FALSE; /* select nearest pois */ - sqlite3_prepare_v2(db, + if (sqlite3_prepare_v2(db, "select p.lat, p.lon, p.label, c.label, c.icon, c.color" " from poi p, category c " " where c.enabled = 1 and p.cat_id = c.cat_id " @@ -236,7 +239,8 @@ poi_db_prepare(sqlite3 *db) " and p.lon between $LON-0.10 and $LAT+0.10 " " order by (($LAT - p.lat) * ($LAT - p.lat) " "+ ($LON - p.lon) * ($LON - p.lon)) limit 1", - -1, &poisql.select_nearest_poi, NULL); + -1, &poisql.select_nearest_poi, NULL)!=SQLITE_OK) + return FALSE; /* insert poi */ sqlite3_prepare_v2(db, @@ -447,7 +451,7 @@ gboolean poi_search(poi_search_type pst, gdouble lat, gdouble lon, gchar *text, guint cat, GtkListStore **store) { GtkTreeIter iter; -sqlite3_stmt *sql; +sqlite3_stmt *sql=NULL; gchar *ltext=NULL; guint rows=0; gchar tmp1[16], tmp2[16]; @@ -455,6 +459,8 @@ gchar tmp1[16], tmp2[16]; if (!_db) return FALSE; +g_printf("POI Search: [%s] around %.6f %.6f (%d)\n", text, lat, lon, cat); + switch (pst) { case POI_SEARCH_NEAR: if (SQLITE_OK != sqlite3_bind_double(poisql.select_poi, 1, lat-0.5) || @@ -462,36 +468,41 @@ switch (pst) { SQLITE_OK != sqlite3_bind_double(poisql.select_poi, 3, lon-0.5) || SQLITE_OK != sqlite3_bind_double(poisql.select_poi, 4, lon+0.5)) { g_printerr("Failed to bind values for poisql.select_poi\n"); + sqlite3_clear_bindings(sql); return FALSE; } - sql=&poisql.select_poi; + sql=poisql.select_poi; break; case POI_SEARCH_TEXT: ltext=g_strdup_printf("%s%%", text); - if (SQLITE_OK != sqlite3_bind_double(poisql.select_poi_search, 1, lat-4) || - SQLITE_OK != sqlite3_bind_double(poisql.select_poi_search, 2, lat+4) || - SQLITE_OK != sqlite3_bind_double(poisql.select_poi_search, 3, lon-4) || - SQLITE_OK != sqlite3_bind_double(poisql.select_poi_search, 4, lon+4) || - SQLITE_OK != sqlite3_bind_text(poisql.select_poi_search, 5, ltext, -1, SQLITE_STATIC)) { + if (SQLITE_OK != sqlite3_bind_double(poisql.select_poi_search, 1, lat-1) || + SQLITE_OK != sqlite3_bind_double(poisql.select_poi_search, 2, lat+1) || + SQLITE_OK != sqlite3_bind_double(poisql.select_poi_search, 3, lon-1) || + SQLITE_OK != sqlite3_bind_double(poisql.select_poi_search, 4, lon+1) || + SQLITE_OK != sqlite3_bind_text(poisql.select_poi_search, 5, ltext, -1, SQLITE_TRANSIENT)) { g_printerr("Failed to bind values for poisql.select_poi_search\n"); + sqlite3_clear_bindings(sql); + g_free(ltext); return FALSE; } - sql=&poisql.select_poi_search; + sql=poisql.select_poi_search; break; case POI_SEARCH_TEXT_CAT: ltext=g_strdup_printf("%s%%", text); - if (SQLITE_OK != sqlite3_bind_double(poisql.select_poi_search_cat, 1, lat-4) || - SQLITE_OK != sqlite3_bind_double(poisql.select_poi_search_cat, 2, lat+4) || - SQLITE_OK != sqlite3_bind_double(poisql.select_poi_search_cat, 3, lon-4) || - SQLITE_OK != sqlite3_bind_double(poisql.select_poi_search_cat, 4, lon+4) || + if (SQLITE_OK != sqlite3_bind_double(poisql.select_poi_search_cat, 1, lat-1) || + SQLITE_OK != sqlite3_bind_double(poisql.select_poi_search_cat, 2, lat+1) || + SQLITE_OK != sqlite3_bind_double(poisql.select_poi_search_cat, 3, lon-1) || + SQLITE_OK != sqlite3_bind_double(poisql.select_poi_search_cat, 4, lon+1) || SQLITE_OK != sqlite3_bind_int(poisql.select_poi_search_cat, 6, cat) || - SQLITE_OK != sqlite3_bind_text(poisql.select_poi_search_cat, 5, ltext, -1, SQLITE_STATIC)) { + SQLITE_OK != sqlite3_bind_text(poisql.select_poi_search_cat, 5, ltext, -1, SQLITE_TRANSIENT)) { g_printerr("Failed to bind values for poisql.select_poi_search_cat\n"); + sqlite3_clear_bindings(sql); + g_free(ltext); return FALSE; } - sql=&poisql.select_poi_search_cat; + sql=poisql.select_poi_search_cat; break; default: g_assert_not_reached(); @@ -521,8 +532,8 @@ while (SQLITE_ROW == sqlite3_step(sql)) { gtk_list_store_set(*store, &iter, POI_POIID, sqlite3_column_int(sql, 2), POI_CATID, sqlite3_column_int(sql, 5), - POI_LAT, lat, - POI_LON, lon, + POI_LAT, rlat, + POI_LON, rlon, POI_LATLON, g_strdup_printf("%s, %s", tmp1, tmp2), POI_LABEL, sqlite3_column_text(sql, 3), POI_DESC, sqlite3_column_text(sql, 4), @@ -530,10 +541,15 @@ while (SQLITE_ROW == sqlite3_step(sql)) { -1); rows++; } + +g_printf("Found: %d items\n", rows); + sqlite3_reset(sql); sqlite3_clear_bindings(sql); + if (ltext) g_free(ltext); + return TRUE; }