SELECT A.* , haversine('34.0160',' -118.4925', A.lat, A.long, 'MILES') AS dist FROM merchant_details A HAVING haversine('34.0160', '-118.4925', A.lat, A.long, 'MILES') <6000
我尝试了以下代码,但没有成功,我得到“长”对象没有属性“fetchall”:
@app.route('/api/results/')
def results():
db = connect_db()
cur = db.execute("SELECT A.* , haversine('34.0160',' -118.4925', A.lat, A.long, 'MILES') AS dist FROM merchant_details A HAVING haversine('34.0160', '-118.4925', A.lat, A.long, 'MILES') <6000 LIMIT 1")
entries = [dict(id=row[0], merchant_id=row[1], merchant_name=row[2], first_name=row[3]) for row in cur.fetchall()]
return repr(entries)
任何帮助将不胜感激。
已编辑>
这是 connect_db 函数:
from torndb import Connection
LOCALHOST = "localhost"
DBNAME = "XXXX"
DBUSER = "XXXX"
DBPASSWORD = "XXXX"
#connect with DB
def connect_db():
db = Connection(LOCALHOST,DBNAME, user=DBUSER, password=DBPASSWORD)
return db
#close the connection from DB
def close_db(db):
db.close()