testid = 69
query = """SELECT * FROM basic_info WHERE ownerid=%s"""
cur.execute(query, testid)
print cur.fetchone()
尝试此操作时出现整数错误。我试过把testid转换成一个没有运气的字符串。
答案 0 :(得分:0)
我更喜欢这种插入参数的方法,因为它很清楚:
query = "SELECT * FROM basic_info WHERE ownerid = %(testid)s"
cur.execute(query, params = { 'testid': testid })
答案 1 :(得分:0)
Cursor.execute
的第二个参与者应该是序列(tuple
或list
)或映射(dict
):
testid = 69
query = """SELECT * FROM basic_info WHERE ownerid=%s"""
cur.execute(query, [testid]) # <--
print cur.fetchone()