我试图遍历名为Throughput的表中的所有行,但针对特定的设备名(我已将其存储在data['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):
您还可以parameterize语句:
这是一种更好的方法,原因如下:
在不知道列DeviceName的类型和数据库服务器的情况下,我将引用用于约束DeviceName的字符串
看看会发生什么。
相关问题 更多 >
编程相关推荐