我试图遍历一个名为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'])
...这是一种更好的方法,原因如下:
https://stackoverflow.com/questions/9518148
复制相似问题