Other reasons for sqlite3.InterfaceError: Error binding parameter 0 - probably unsupported type

♀尐吖头ヾ 提交于 2019-12-25 09:26:56

问题


I'm checking whether a given transactionid exists in my sqlite database with this code.

print((transaction.transactionid,))
print(type(transaction.transactionid))
c.execute("SELECT EXISTS(SELECT transactionid FROM Transactions WHERE transactionid=?);", 
          (transaction.transactionid,))
self.dbconn.commit()
transaction_exists, = c.fetchone()
print(transaction_exists)

It always fails with this error on the second iteration:

File "RtMetaMaster.py", line 182, in sync_ticket_to_db (transaction.transactionid,)) sqlite3.InterfaceError: Error binding parameter 0 - probably unsupported type.

Output of the print statements:

('626007',)
<class 'str'>
0    
('625952',)
<class 'str'>
Traceback (most recent call last):
  [..]
  File "RtMetaMaster.py", line 182, in sync_ticket_to_db
    (transaction.transactionid,))
sqlite3.InterfaceError: Error binding parameter 0 - probably unsupported type.

Both times the transactionid is of type class 'str' but it somehow fails the second time. What other mistakes could lead to "Error binding parameter"?


回答1:


I solved it by adding a self.dbconn.commit() after every c.execute call. There's probably a better solution for this.



来源:https://stackoverflow.com/questions/44498628/other-reasons-for-sqlite3-interfaceerror-error-binding-parameter-0-probably-u

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!