def json_query_simple(query, query_args=[], empty_ok=False):
"""Do a SQL query that selects one column and dump those values as
a JSON array"""
if request.method != 'GET':
return not_allowed()
try:
cursor = dbcursor_query(query, query_args)
except Exception as ex:
return error(str(ex))
if cursor.rowcount == 0:
cursor.close()
if empty_ok:
return json_response([])
else:
return not_found()
result = []
for row in cursor:
result.append(row[0])
cursor.close()
return json_response(result)
评论列表
文章目录