1

我正在尝试在 python 中执行以下代码,但它会syntax error near '('导致executemany(..). 当我从中删除名字sql并只写%s它时,也会导致错误,there are more placeholders thant the variables 有人知道我该如何解决吗?

upInfo ={"aa": "aaa","bb": "bbb","cc": "ccc"}
sql = 'UPDATE table SET a=  %(aa)s WHERE b= %(bb)s and c= %(cc)s'
con = pymssql.connect(...)
con.autocommit(True)
cur = con.cursor()
cur.executemany(sql, upInfo)
4

1 回答 1

0

由于这是executemany(),它应该是一个字典列表:

upInfo = [{"aa": "aaa", "bb": "bbb", "cc": "ccc"}]

或者,使用常规execute()

cur.execute(sql, upInfo)
于 2015-01-28T14:47:07.820 回答