我正在尝试使用mysql-flask python扩展来执行一些sql.由于某种原因,下面的代码总是返回long.
stringify = lambda x : '"' + x + '"' if request.method == 'POST': sql = "select * from users where username = " + stringify(request.form['username']) user = g.db.cursor().execute(sql).fetchall()
@H_404_8@错误:
user = g.db.cursor().execute(sql).fetchall() AttributeError: 'long' object has no attribute 'fetchall'
@H_404_8@为什么不返回结果集?
另外,我可以很好地执行insert语句.
修复(答案):
def get_data(g,sql): cursor = g.db.cursor() cursor.execute(sql) data = [dict((cursor.description[idx][0],value) for idx,value in enumerate(row)) for row in cursor.fetchall()] return data
@H_404_8@
最佳答案