【发布时间】:2016-08-19 14:11:46
【问题描述】:
好的,基本上我正在尝试使用实例变量(typ 和 lvl)更新现有的 SQLite3 数据库
#Set variables
typ = 'Test'
lvl = 6
#Print Databse
print("\nHere's a listing of all the records in the table:\n")
for row in cursor.execute("SELECT rowid, * FROM fieldmap ORDER BY rowid"):
print(row)
#Update Info
sql = """
UPDATE fieldmap
SET buildtype = typ, buildlevel = lvl
WHERE rowid = 11
"""
cursor.execute(sql)
#Print Databse
print("\nHere's a listing of all the records in the table:\n")
for row in cursor.execute("SELECT rowid, * FROM fieldmap ORDER BY rowid"):
print(row)
作为一个错误我得到了
sqlite3.OperationalError: no such column: typ
现在我基本上知道问题是我的变量以错误的语法插入,但我终生无法找到正确的变量。它适用于字符串和整数,就像这样:
sql = """
UPDATE fieldmap
SET buildtype = 'house', buildlevel = 3
WHERE rowid = 11
"""
但是一旦我切换到变量,它就会抛出错误。
【问题讨论】:
标签: python sqlite instance-variables