gboolean
osm_db_prepare(sqlite3 *db)
{
+/*****************
+ * Place queries *
+ *****************/
+
/* Select nearest place inside lat,lon+-range */
DB_PREP(db, "select name,(($LAT-ilat)*($LAT-ilat))+(($LON-ilon)*($LON-ilon)) as d,"
" ilat,ilon,places.nid,isin_p,isin_c "
" and places.nid=$NID order by d limit 1",
sql.select_place);
-/* Search */
+/* Search place names */
DB_PREP(db, "select places.nid,name,(($LAT-ilat)*($LAT-ilat))+(($LON-ilon)*($LON-ilon)) as d,"
" rlat,rlon,type,isin_p,isin_c "
" from places,nodes where "
" and name like $NAME order by d limit 200",
sql.select_place_search);
-/* Ways */
+/***********************
+ * Way related queries *
+ ***********************/
+
/* Select nearest ways inside lat,lon+-range */
DB_PREP(db, "select w.wid,type,nodes,flags,"
"(($LAT-n.ilat)*($LAT-n.ilat))+(($LON-n.ilon)*($LON-n.ilon)) as d,wn.f,wn.t,n.ilat,n.ilon "
" order by d",
sql.select_way2);
+/* Search way names inside bbox, using both primary and secondary language names */
DB_PREP(db, "select w.wid,w.name as name,"
"(($LAT-ww.lat)*($LAT-ww.lat))+(($LON-ww.lon)*($LON-ww.lon)) as d,ww.lat,ww.lon "
" from way_names as w,way as ww where "
" ww.type between $WTS and $WTY and w.wid=ww.wid and n.name like $NAME "
" and ww.lat between $LAT-$RANGE and $LAT+$RANGE "
" and ww.lon between $LON-$RANGE and $LON+$RANGE "
- " order by name limit 200",
+ " order by d, name limit 500",
sql.select_way_name_search);
+/* Get way segment */
DB_PREP(db, "select wn.t,ilat,ilon from way_n2n as wn,nodes where wid=? and wn.f=? and wn.t=nodes.nid limit 1",
sql.select_way_next_seg);
+/* Get way segment */
DB_PREP(db, "select wn.f,ilat,ilon from way_n2n as wn,nodes where wid=? and wn.t=? and wn.f=nodes.nid limit 1",
sql.select_way_prev_seg);
-/* Way name */
+/* Get Way name */
DB_PREP(db, "select name from way_names where wid=?", sql.select_way_name);
-/* Way ref and int_ref */
+/* Get Way ref and int_ref */
DB_PREP(db, "select ref,int_ref from way_ref where rid=?", sql.select_way_ref);
/* Get next, prev node + way information. For routing. */