Python Sqlite3子查询参数化

Python Sqlite3子查询参数化,python,python-3.x,sqlite,Python,Python 3.x,Sqlite,我正在使用Python3.3中的Sqlite3。我正在尝试运行以下查询: c.execute('INSERT OR REPLACE INTO system (id, date,code,number) VALUES ((select id from system where date=:date, code=:thiscode), :date,:thiscode, coalesce((select profiles from system where date=:date, code=:th

我正在使用Python3.3中的Sqlite3。我正在尝试运行以下查询:

c.execute('INSERT OR REPLACE INTO system (id, date,code,number) VALUES 
((select id from system where date=:date, code=:thiscode), :date,:thiscode, 
coalesce((select profiles from system where date=:date, code=:thiscode), 1))', 
{"date": mdate, "thiscode": thiscode})
该表用于跟踪一个月内发生的代码实例数。如果月份的日期/代码组合已经存在,则将1添加到其编号中,否则使用number=1创建它

给出的错误是无济于事的

sqlite3.OperationalError: near ",": syntax error
我猜原因涉及子查询参数化,因为我还没有看到其他人使用它的例子,但我愿意接受建议

where date=:date, code=:thiscode
这是什么意思? 我猜你想写这个:

where date=:date and code=:thiscode

Python DB-API为数据库模块指定参数样式。sqlite3参数样式为?。您是否尝试过使用运行查询?符号作为您的参数占位符?如self.c.execute“插入或替换到系统id、日期、代码、数字值从系统中选择id,其中日期=?、代码=?、?、?,合并从系统中选择数字,其中日期=?、代码=?、1',mdate、thiscode、mdate、thiscode、mdate、thiscode?那也不行。和以前一样的错误。此外,由于重复,命名参数似乎是更好的解决方案。