sqlite3.InterfaceError 的其他原因:错误绑定参数 0 - 可能不受支持的类型 [英] Other reasons for sqlite3.InterfaceError: Error binding parameter 0 - probably unsupported type
问题描述
我正在使用此代码检查给定的事务 ID 是否存在于我的 sqlite 数据库中.
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:
文件RtMetaMaster.py",第 182 行,位于 sync_ticket_to_db(transaction.transactionid,)) sqlite3.InterfaceError:错误绑定参数 0 - 可能是不受支持的类型.
File "RtMetaMaster.py", line 182, in sync_ticket_to_db (transaction.transactionid,)) sqlite3.InterfaceError: Error binding parameter 0 - probably unsupported type.
打印语句的输出:
('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.
两次transactionid 的类型都是'str' 类,但它第二次以某种方式失败了.还有哪些错误会导致错误绑定参数"?
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"?
推荐答案
我通过在每次 c.execute 调用后添加一个 self.dbconn.commit() 解决了这个问题.对此,可能有更好的解决方案.
I solved it by adding a self.dbconn.commit() after every c.execute call. There's probably a better solution for this.
这篇关于sqlite3.InterfaceError 的其他原因:错误绑定参数 0 - 可能不受支持的类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!