我对 Python 很陌生,我面临着 Python-SQLite 连接的问题。
con=connection()
cur=con.cursor()
cur.execute("""UPDATE table1 SET column1=%s WHERE column2=%d""",(var1,var2))
if(cur.rowcount > 1):
cur.commit()
else:
return["Error"]
Run Code Online (Sandbox Code Playgroud)
其中var1存储一个字符串,并var2存储一个整数。
错误如下:
SQLError('SQLError: 接近“%”: 语法错误',)
我在这里阅读了大量关于如何使用变量编写查询的教程和线程,但我陷入了死胡同。
根据您要使用的sqlite文档?为你的变量。例子:
cur.execute("""update table1 set column1=? where column2=?""", (var1, var2))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10016 次 |
| 最近记录: |