" FROM gpx_files,gps_points "+
"WHERE gpx_files.id=gpx_id "+
" AND gpx_files.user_id=#{user.id} "+
- " AND "+OSM.sql_for_area(ymin,xmin,ymax,xmax)+
+ " AND "+OSM.sql_for_area(ymin,xmin,ymax,xmax,"gps_points.")+
" AND (gps_points.timestamp IS NOT NULL) "+
"ORDER BY fileid DESC,ts "+
"LIMIT 10000"
else
sql="SELECT latitude*0.000001 AS lat,longitude*0.000001 AS lon,gpx_id AS fileid,UNIX_TIMESTAMP(timestamp) AS ts "+
" FROM gps_points "+
- "WHERE "+OSM.sql_for_area(ymin,xmin,ymax,xmax)+
+ "WHERE "+OSM.sql_for_area(ymin,xmin,ymax,xmax,"gps_points.")+
" AND (gps_points.timestamp IS NOT NULL) "+
"ORDER BY fileid DESC,ts "+
"LIMIT 10000"
end
# Return an SQL fragment to select a given area of the globe
- def self.sql_for_area(minlat, minlon, maxlat, maxlon)
- tilesql = QuadTile.sql_for_area(minlat, minlon, maxlat, maxlon)
+ def self.sql_for_area(minlat, minlon, maxlat, maxlon, prefix = nil)
+ tilesql = QuadTile.sql_for_area(minlat, minlon, maxlat, maxlon, prefix)
minlat = (minlat * 1000000).round
minlon = (minlon * 1000000).round
maxlat = (maxlat * 1000000).round
maxlon = (maxlon * 1000000).round
- return "#{tilesql} AND latitude BETWEEN #{minlat} AND #{maxlat} AND longitude BETWEEN #{minlon} AND #{maxlon}"
+ return "#{tilesql} AND #{prefix}latitude BETWEEN #{minlat} AND #{maxlat} AND #{prefix}longitude BETWEEN #{minlon} AND #{maxlon}"
end
end
end
end
- def self.sql_for_area(minlat, minlon, maxlat, maxlon)
+ def self.sql_for_area(minlat, minlon, maxlat, maxlon, prefix)
sql = Array.new
single = Array.new
if first == last
single.push(first)
else
- sql.push("tile BETWEEN #{first} AND #{last}")
+ sql.push("#{prefix}tile BETWEEN #{first} AND #{last}")
end
end
- sql.push("tile IN (#{single.join(',')})") if single.size > 0
+ sql.push("#{prefix}tile IN (#{single.join(',')})") if single.size > 0
return "( " + sql.join(" OR ") + " )"
end