[英]sqlite3.OperationalError: near “,”: syntax error python
[英]Python SQLite near “?”: syntax error
另外一個問題。 我正在嘗試:
self.table = 'table'
a = 'column'
b = 'value'
c.execute('INSERT INTO ? (?) VALUES (?)', (self.table, a, b))
但我得到了
<class 'sqlite3.OperationalError'>:near "?": syntax error
與此同時,
c.execute('INSERT INTO {0} ({1}) VALUES ({2})'.format(self.table, a, b))
除安全問題外,工作完美無缺。
我意識到我不是第一個遇到這個問題的人,但我還沒有找到適合我的解決方案。
表名,列名不能參數化。 請嘗試以下方式。
self.table = 'table'
b = 'value'
c.execute('INSERT INTO {} ({}) VALUES (?)'.format(self.table, a), (b,))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.