不断获取“错误绑定参数 0 - 可能不受支持的类型"; [英] Keeps getting "error binding parameter 0 - probably unsupported type"

查看:60
本文介绍了不断获取“错误绑定参数 0 - 可能不受支持的类型";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将 eric4(qtdesigner、pyqt、python 等)与 sqlite 一起使用,当我运行我编写的程序时,我不断收到错误绑定参数 0 - 可能不受支持的类型".

I'm using eric4 (qtdesigner, pyqt, python, etc) with sqlite and I keep getting "error binding parameter 0 - probably unsupported type" when I'm running the program I've coded.

我使用 eric4 + qtdesigner 制作了一些 GUI 并生成了对话框代码.当我在 qtdesigner 中制作的窗口的其中一个按钮被按下时,它应该访问数据库,然后提交并将信息保存在数据库中.我已经制作了一个单独的 py 文件用于访问和保存数据库.

I've made some GUIs using eric4 + qtdesigner and generated dialog codes. When one of the buttons of the windows I've made in qtdesigner are pressed, it should access the database and would then commits and saves the information in the database. I've made a separate py file for accessing and saving for the database.

以下是我的部分代码,它们很可能是我不断收到错误的根源.

Here are parts of my code which are most likely sources of the error I keep getting.

在生成的 ui 对话框(我导入了单独的 py 文件):

At generated dialog of the ui (which I imported the separate py file):

    def on_button_Save_released(self):
        """
        Slot documentation goes here.
        """
        # TODO: not implemented yet
        Nik = self.LineEdit_Nickname.text()
        NFirst = self.LineEdit_NameFirst.text()
        NMid = self.LineEdit_NameMiddle.text()
        NLast = self.LineEdit_NameLast.text()
        BMon = self.ComboBox_BirthMonth.currentText()
        BDay = self.ComboBox_BirthDay.currentText()
        BYear = self.ComboBox_BirthYear.currentText()
        CNum = self.LineEdit_ContactNum.text()
        EM = self.LineEdit_EMail.text()
        MAd = self.LineEdit_MailAdd.text()

        self.NMem = NewMem()
        self.NMem.input_data(Nik,  NFirst, NMid,  NLast,  BMon,  BDay,  BYear,  CNum,  EM,  MAd)

这是在单独的py文件中访问和写入的数据库:

And this at the database accessing and writing which is on a separate py file:

import sqlite3
import datetime, time

con = sqlite3.connect("Members.db") #access database
cur = con.cursor()  #cursor object for database


class NewMem:
    def input_data(self,  Nik,  NFirst, NMid,  NLast,  BMon,  BDay,  BYear,  CNum,  EM,  MAd):

        def adapt_datetime(ts):
            return time.mktime(ts.timetuple())

        #Get current time and date
        sqlite3.register_adapter(datetime.datetime, adapt_datetime) 
        now = datetime.datetime.now()  

        #created if first time to make a table
        try: 
            cur.execute('create table Members (ID integer primary key autoincrement not null, Nick string not null, NameFirst string, NameMiddle string, NameLast string, BirthMonth string, BirthDay string, BirthYear string, ContactNum string, EMail string, MailAdd string, MemberSince string)')
        except:
            pass

        cur.execute("insert into Members (Nick,NameFirst,NameMiddle,NameLast,BirthMonth,BirthDay,BirthYear,ContactNum,EMail,MailAdd,MemberSince) values (?,?,?,?,?,?,?,?,?,?,?)",(Nik,  NFirst, NMid,  NLast,  BMon,  BDay,  BYear,  CNum,  EM,  MAd, now))

        con.commit()
        cur.close()
        con.close()

我在谷歌上读过一些搜索,可能是引号和?参数,但我已经检查过,它们似乎是正确的.还在某处阅读它与字符映射(UTF?)有关的地方,但老实说我不知道​​如何检查......我还添加了一些打印内容,以查看它们是否显示了我输入的正确数据以及它们是否正确.所以很奇怪为什么我仍然收到错误.

I've read some searches at google that it might be the quotation marks and ? parameters but I've checked and they are correct it seems. Also read somewhere that it has to do with the character map (UTF?) but I honestly don't know how to check... I've also added some print to see if they are showing the correct data I've input and they are correct. So it's quite boggling why I'm still getting the error.

非常感谢任何帮助深深鞠躬

推荐答案

QlineEdit.text() 返回一个 QString.将它传递给 unicode 构造函数以获得可用的东西.

QlineEdit.text() returns a QString. Pass it to the unicode constructor to get something usable.

这篇关于不断获取“错误绑定参数 0 - 可能不受支持的类型";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆