<分区>
我目前正在使用 python 和 Flask 查询数据库。我有以下功能:`
def get_details(username):
conn = database_connect()
if(conn is None):
return ERROR_CODE
cur = conn.cursor()
val = None
try:
cur.execute("""SELECT username, name, age, address
FROM users
WHERE username = %s;""",(username))
val = cur.fetchone()
except:
print("failed to retrieve")
cur.close()
conn.close()
return val
“用户”表中的用户名是主键,因此此查询仅返回一个元组(通过在 postgress 中手动查询确认)。然而,“val”始终是“none”。我也尝试过使用 fetchall() 但这也不起作用。
查询本身有问题吗?我应该如何编码?