I have the following query that I execute using a Python script (using the MySQLdb module).
conn=MySQLdb.connect (host = "localhost", user = "root",passwd = "<password>",db = "test")
cursor = conn.cursor ()
preamble='set @radius=%s; set @o_lat=%s; set @o_lon=%s; '%(radius,latitude,longitude)
query='SELECT *, (6371*1000 * acos(cos(radians(@o_lat)) * cos(radians(lat)) * cos(radians(lon) - radians(@o_lon)) + sin(radians(@o_lat)) * sin(radians(lat))) as distance FROM poi_table HAVING distance < @radius ORDER BY distance ASC LIMIT 0, 50)'
complete_query=preamble+query
results=cursor.execute (complete_query)
print results
The values ββof radius, latitude and longitude are not important, but they are determined when the script is executed. My concern is that the code snippet above does not return results; which means that the way the request is executed is unstable. I executed an SQL query (including given variables with actual values ββand returned the correct number of results).
If I modify the query simply as a simple SELECT FROM ( SELECT * FROM poi_table) query , it returns the results. What's going on here?
EDIT: Calculation of Encapsulated Haversin Formula in Parentheses
source
share