return TRUE;
}
+typedef enum {
+ PS_LAT=0,
+ PS_LON,
+ PS_ID,
+ PS_LABEL,
+ PS_DESC,
+ PS_CAT_ID,
+ PS_CAT_LABEL,
+ PS_CAT_DESC,
+ PS_CAT_ICON,
+ PS_CAT_COLOR,
+ PS_SOURCE,
+ PS_PUBLIC,
+ PS_URL,
+ PS_POSTAL_CODE,
+} poi_sql_column;
+
+#define POI_BASE_SQL_FIELDS "p.lat, p.lon, p.poi_id, p.label, p.desc, p.cat_id, c.label, c.desc, c.icon, c.color, p.source, p.public, p.url, p.postal_code"
+#define POI_MINI_SQL_FIELDS "p.lat, p.lon, p.poi_id, p.label, p.desc, p.cat_id, c.label, c.desc"
+
gboolean
poi_db_prepare(sqlite3 *db)
{
/* Select POIs inside given minmax lat,lon */
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"
+ "select "
+ POI_BASE_SQL_FIELDS
" from poi p, category c "
" where p.lat between ? and ? "
" and p.lon between ? and ? "
/* Get POI with given ID */
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"
+ "select "
+ POI_BASE_SQL_FIELDS
" from poi p, category c "
" where p.poi_id = ? "
" and p.cat_id=c.cat_id",
/* Search POIs by label */
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"
+ "select "
+ POI_BASE_SQL_FIELDS
" from poi p, category c "
" where p.lat between ? and ? "
" and p.lon between ? and ? "
/* Search POI by label and specific category */
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"
+ "select "
+ POI_BASE_SQL_FIELDS
" from poi p, category c "
" where p.lat between ? and ? "
" and p.lon between ? and ? "
/* Search specific category */
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"
+ "select "
+ POI_BASE_SQL_FIELDS
" from poi p, category c "
" where p.lat between ? and ? "
" and p.lon between ? and ? "
/* Select nearest POI */
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 "
+ "select "
+ POI_MINI_SQL_FIELDS
" from poi p, category c "
" where c.enabled = 1 and p.cat_id = c.cat_id "
" and p.lat between $LAT-0.10 and $LAT+0.10 "
return poi_get_list_inside(lat1, lon1, lat2, lon2, store, num_poi);
}
+poi_info *
+poi_get_by_id(guint id)
+{
+poi_info *p=NULL;
+
+if (SQLITE_OK!=sqlite3_bind_double(poisql.select_poi_by_id, 1, id))
+ return NULL;
+
+if (SQLITE_ROW==sqlite3_step(poisql.select_poi_by_id)) {
+ p=poi_new();
+ p->poi_id=sqlite3_column_int(poisql.select_poi_by_id, PS_ID);
+ p->lat=sqlite3_column_int(poisql.select_poi_by_id, PS_LAT);
+ p->lon=sqlite3_column_int(poisql.select_poi_by_id, PS_LON);
+ p->source=sqlite3_column_int(poisql.select_poi_by_id, PS_SOURCE);
+ p->public=sqlite3_column_int(poisql.select_poi_by_id, PS_PUBLIC)==1 ? TRUE : FALSE;
+ p->label=g_strdup(sqlite3_column_text(poisql.select_poi_by_id, PS_LABEL));
+ p->desc=g_strdup(sqlite3_column_text(poisql.select_poi_by_id, PS_DESC));
+ p->url=g_strdup(sqlite3_column_text(poisql.select_poi_by_id, PS_URL));
+ p->postal_code=g_strdup(sqlite3_column_text(poisql.select_poi_by_id, PS_POSTAL_CODE));
+
+ p->cat_id=sqlite3_column_int(poisql.select_poi_by_id, PS_CAT_ID);
+ p->cat_label=g_strdup(sqlite3_column_text(poisql.select_poi_by_id, PS_CAT_LABEL));
+ p->cat_desc=g_strdup(sqlite3_column_text(poisql.select_poi_by_id, PS_CAT_DESC));
+}
+
+return p;
+}
+
gboolean
poi_update(poi_info *p)
{