Python SQLite 3:SQLite InterfaceError:绑定参数0时出错-可能是不支持的类型
我正在使用sqlite3 python模块,下面的代码返回错误Python SQLite 3:SQLite InterfaceError:绑定参数0时出错-可能是不支持的类型,python,sqlite,Python,Sqlite,我正在使用sqlite3 python模块,下面的代码返回错误 > Exception in Tkinter callback Traceback (most recent call last): > File "C:\Python34\lib\tkinter\__init__.py", line 1533, in __call__ > return self.func(*args) File "C:\MonitorSoft\MonitorSoft.py", l
> Exception in Tkinter callback Traceback (most recent call last):
> File "C:\Python34\lib\tkinter\__init__.py", line 1533, in __call__
> return self.func(*args) File "C:\MonitorSoft\MonitorSoft.py", line 199, in LoadSQL
> CurFiles.execute('SELECT * FROM Files WHERE CheckSum = ?', (WinRedactor.Table.item(WinRedactor.Table.selection()[0],
> option='values')[3],))
>
> sqlite3.InterfaceError: Error binding parameter 0 - probably
> unsupported type.
def LoadSQL(event):
con = sqlite3.connect('C:/MonitorSoft/SoftMon.db')
CurPackets = con.cursor()
CurFiles = con.cursor()
CurFilesIn = con.cursor()
curFilesPackets = con.cursor()
CurPackets.execute('SELECT * FROM Packets WHERE PacketName = ?', (WinRedactor.Combobox.get(),))
for RowPackets in CurPackets:
if WinRedactor.Combobox.get() !='NULL':
while WinRedactor.Table.selection() != '':
CurFilesIn.execute('INSERT INTO Files (id, FilePath, FileName, Size, CheckSum) VALUES(NULL, ?, ?, ?, ?)',((WinRedactor.Table.item(WinRedactor.Table.selection()[0], option='values')[0]), (WinRedactor.Table.item(WinRedactor.Table.selection()[0], option='values')[1]), (WinRedactor.Table.item(WinRedactor.Table.selection()[0], option='values')[2]),(WinRedactor.Table.item(WinRedactor.Table.selection()[0], option='values')[3])))
con.commit()
CurFiles.execute('SELECT * FROM Files WHERE CheckSum = ?', (WinRedactor.Table.item(WinRedactor.Table.selection()[0], option='values')[3],))
for RowFiles in CurFiles:
if RowFiles[4] == (WinRedactor.Table.item(WinRedactor.Table.selection()[0], option='values')[3]):
curFilesPackets.execute('INSERT INTO FilesPackets (IDFile, IDPacket) VALUES(?,?)',((RowFiles[0]), (RowPackets[0])))
con.commit()
WinRedactor.Table.delete(WinRedactor.Table.selection()[0])
con.commit()
con.close()
BtnLoadSQL = Button(WinRedactor)
BtnLoadSQL["text"] = "LOAD SQL"
BtnLoadSQL.bind("<Button-1>",LoadSQL)
BtnLoadSQL.pack()
这是最后两个结论,最后,正如您所看到的,有一个bug。要解决这个问题,第一步应该是打印出所有立即值,以便您可以验证它们是否是您所认为的。作为一个副作用,这使select语句更易于阅读 例如:
selection = WinRedactor.Table.selection()
print("selection is", selection)
first_selection = selection[0]
print("first selection is", first_selection)
values = WinRedactor.Table.item(first_selection, option='values')
print("values are", values)
checksum = values[3]
print("checksum:", checksum)
CurFiles.execute('SELECT * FROM Files WHERE CheckSum = ?', (checksum,))
我猜,你会对你所看到的感到惊讶。至少,你有更多的数据来回答你的问题,这样我们就可以准确地知道这些数据是什么 你能检查一下这些值是否正确吗?WinRedactor.Table.itemWinRedactor.Table.selection[0],option='values'[3],那么printtypeWinRedactor.Table.itemWinRedactor.Table.selection[0],option='values'[3]会产生什么呢?printreprWinRedactor.Table.itemWinRedactor.Table.selection[0],option='values'[3]如何?它处理大量记录,然后给出错误“05b3f32c7f3bd125446d024a30373c9d”“23ecf1c97b1eb5d94a25dc677ec464e5”“Tkinter回调回溯中的异常最后一次调用:文件C:\Python34\lib\Tkinter_init_u2;.py,第1533行,在调用返回self.func*args文件C:\MonitorSoft\MonitorSoft.py,第201行,LoadSQL CurFiles中。执行'SELECT*FROM Files WHERE CheckSum=?',WinRedactor.Table.itemWinRedactor.Table.selection[0],option='values'[3],sqlite3.InterfaceError:绑定参数0时出错-可能是不支持的类型。@sia:您需要向我们显示引发异常的值的类型,而不是成功的类型。引发异常的值的类型也是str。此值提供了一个exeption“23ecf1c97b1eb5d94a25dc677ec464e5”
selection = WinRedactor.Table.selection()
print("selection is", selection)
first_selection = selection[0]
print("first selection is", first_selection)
values = WinRedactor.Table.item(first_selection, option='values')
print("values are", values)
checksum = values[3]
print("checksum:", checksum)
CurFiles.execute('SELECT * FROM Files WHERE CheckSum = ?', (checksum,))