python - sqlite InterfaceError: Error binding parameter 0 - 可能是不受支持的类型 [英] python - sqlite InterfaceError: Error binding parameter 0 - probably unsupported type

查看:49
本文介绍了python - sqlite InterfaceError: Error binding parameter 0 - 可能是不受支持的类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 sqlite3 将值存储到数据库中,我的问题是我创建了 lineedits,通过它我提取值并将其存储到变量并将此变量传递给插入查询,但是我在行值(?,?,?,?,?)......如果我直接将值硬引用到变量中,它会被保存到数据库中,我在做什么错误?请帮忙.......这是我的代码

i am using sqlite3 to store values into database, My problem is i have created lineedits through which i extract values and store it to variables and pass this variables to insert query but i am getting above error at line values(?,?,?,?,?)......if i hard quote the values directly to variables it gets saved into database what is the mistake am i doing? please help.......here is my code

            self.uname = self.le1.text()
            self.passwd = self.le2.text()
            self.permssn = self.le3.text()
            self.queryCurs.execute('''CREATE TABLE IF NOT EXISTS USER
            (USERNAME TEXT NOT NULL, PASSWORD TEXT NOT NULL, PERMISSION TEXT NOT NULL)''')
            self.queryCurs.execute('''INSERT INTO USER(USERNAME, PASSWORD, PERMISSION) 
            VALUES(?,?,?)''',(self.uname,self.passwd,self.permssn))
            print ('inserted row')
            self.createDb.commit()

我哪里出错了?

推荐答案

获取文本le1.text()"的方法不以字符串格式存储值.我遇到了同样的错误,发现我的数据类型不匹配.我将此值转换为字符串,并且工作正常.

The method from where you're getting the text "le1.text()", doesn't stores the value in string format. I was getting the same error, sorted out that my data type was mismatched. I converted this value to string and it worked fine.

也不要错过最后添加逗号,因为执行查询需要郁金香.

Also don't miss to add comma in the end because the execute query takes tulip.

self.queryCurs.execute('''INSERT INTO USER(USERNAME, PASSWORD, PERMISSION) 
        VALUES(?,?,?)''',(str(self.uname),str(self.passwd),str(self.permssn),))

这篇关于python - sqlite InterfaceError: Error binding parameter 0 - 可能是不受支持的类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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