1

我有一个工作 python 脚本,它从 sqlite3 db 中检索数据。不过,我需要将其转换为与 mysql db 对话,这是让我感到悲伤的第一行:

PRODUCT_CODE_ID = "SELECT id FROM localsite_productcode WHERE localsite_productcode.product_code=?"
cur.execute(PRODUCT_CODE_ID,(product_code,))

当我尝试使用 mysql 时,出现以下错误:

Traceback (most recent call last):
  File "gen-csv.py", line 85, in <module>
    cur.execute(PRODUCT_CODE_ID,(product_code,))
  File "/usr/lib/pymodules/python2.6/MySQLdb/cursors.py", line 151, in execute
    query = query % db.literal(args)
TypeError: not all arguments converted during string formatting

我在这里做错了什么?

4

1 回答 1

1

我不认为 MySQL 的 DB API 支持?作为占位符 - 只是尝试%s

于 2012-11-29T14:02:52.090 回答