我试图遍历一个名为Throughput的表中的所有行,但对于特定的DeviceName (我已将其存储在数据“DeviceName”中)。我尝试过以下方法,但不起作用:
for row in cursor.execute("select * from Throughput where DeviceName=%s"), %(data['DeviceName']):编辑:我也试过了,但不起作用:
for row in cursor.execute("select * from Throughput where(DeviceName), values(?)", (data['DeviceName']) ):EDIT2:我的最终工作代码片段:
query = "select * from Throughput where DeviceName = '%s'" % data['Device Name']
try:
for row in cursor.execute(query):发布于 2012-03-02 01:55:38
您还可以对语句执行parameterize操作:
...
cursor.execute("select * from Throughput where DeviceName = ?", data['DeviceName'])
...这是一种更好的方法,原因如下:
发布于 2021-05-10 13:46:27
我不知道我的问题是否与你的相似,但我的问题是因为我写了一个像WHERE date > ?" "OR date NOT LIKE '9%'这样的查询,而我忘记在第一行或第二行的末尾放一个简单的空格(‘')。最后,我通过这样做解决了这个问题。最后的代码如下所示:
WHERE date > ? "
"OR date NOT LIKE '9%'注意:注意第一行末尾的最后一个‘’。
https://stackoverflow.com/questions/9518148
复制相似问题