Python 如何使用APSW更新字段
我试图在使用数据库条目时更新其时间戳,但似乎无法使update语句正常工作Python 如何使用APSW更新字段,python,sqlite,python-2.7,Python,Sqlite,Python 2.7,我试图在使用数据库条目时更新其时间戳,但似乎无法使update语句正常工作 import apsw from datetime import datetime def updateTimestamp(primary, timestamp): tableName = 'Images' connection = apsw.Connection('Images') cursor = connection.cursor()
import apsw
from datetime import datetime
def updateTimestamp(primary, timestamp):
tableName = 'Images'
connection = apsw.Connection('Images')
cursor = connection.cursor()
sql = "UPDATE %s SET timestamp = %s WHERE id = %s" %(tableName, timestamp, primary)
print "ok so far"
cursor.execute(sql)
if connection:
connection.close()
currentTime = datetime.now()
#remove spaces from timestamp
currentTime = str(currentTime).replace(' ', '')
updateTimestamp(1, currentTime)
我正在使用apsw尝试更新一个字段,但它不起作用,我得到了错误
"apsw.SQLError: SQLError: near ":05": syntax error"
我的桌子看起来像:
sql = 'CREATE TABLE IF NOT EXISTS ' + tableName + '(id INTEGER PRIMARY KEY
AUTOINCREMENT, Name TEXT, Metadata TEXT, Mods TEXT, Certification TEXT,
Product TEXT, Email TEXT, notes TEXT, timestamp TEXT, ftpLink TEXT)'
您正在构造如下所示的SQL命令: 更新图像集时间戳=2013-01-3121:59:00.427408,其中id=1 正确的语法应该如下所示:
更新图像集时间戳='2013-01-31 21:59:00.427408',其中id=1
但是,为避免字符串格式问题,应使用以下参数:
sql=“更新%s设置时间戳=?其中id=?”%(表名)
执行(sql,(时间戳,主))
primary和timestamp
sql='CREATE TABLE IF note EXISTS'+tableName+'(id INTEGER主键自动递增、名称文本、元数据文本、Mods文本、认证文本、产品文本、电子邮件文本、注释文本、时间戳文本、ftpLink文本)的值是什么'您可以在代码底部看到传入调用的值