当我尝试将元组传递给子句的IN
参数时WHERE
,它会被双引号引起来,因此我的查询失败。例如,如果我这样做,
# Connect to DB
import MySQLdb
cnxn = MySQLdb.connect(connectString)
curs = cnxn.cursor()
# Setup query
accounts = ('Hyvaco','TLC')
truck_type = 'fullsize'
query_args = (truck_type, accounts)
sql ='SELECT * FROM archive.incoming WHERE LastCapacity=%s AND Account IN %s'
# Run query and print
curs.execute(sql, query_args)
print(curs._executed)
然后我得到零行,查询打印为
SELECT * FROM archive.incoming WHERE LastCapacity='fullsize'
AND Account IN ("'Hyvaco'", "'TLC'")
从元组切换accounts
到列表不会影响结果。我应该如何传递这些论点?