从数据库中读取使用SQLite和Python:绑定提供数有误 [英] Reading from database with SQLite and Python: Incorrect number of binding supplied

查看:923
本文介绍了从数据库中读取使用SQLite和Python:绑定提供数有误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读出用下面的python脚本的数据库:

am reading out of a database with the following python script:

cur.execute("SELECT * FROM pending where user = ?", (ID))

其中id是别人的名字,在这种情况下,乔纳森。

Where ID is someone's name, in this case "Jonathan".

然而,当我尝试运行此脚本时,我得到的错误说

However, when I try to run this script, I get the error saying

Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.7/cherrypy/_cprequest.py", line 606, in respond
    cherrypy.response.body = self.handler()
  File "/usr/lib/pymodules/python2.7/cherrypy/_cpdispatch.py", line 25, in __call__
    return self.callable(*self.args, **self.kwargs)
  File "proj1base.py", line 470, in editFriends
    cur.execute("SELECT * FROM pending where user = ?", (ID))
ProgrammingError: Incorrect number of bindings supplied. The current statement uses 1, and there are 8 supplied.

我很新的SQLite的,所以我猜我只是做语法非常愚蠢的错误。网上搜索了一段时间后,但我似乎无法找到任何不同,我比别人做的事情。

I am very new to SQLite, so i'm guessing I just made a very silly mistake in syntax. However after searching around online for a while, i can't seem to find anything different that I am doing than others.

任何帮助将是非常美联社preciated。或者,如果你需要更多的code,请让我知道。

Any help would be much appreciated. Or if you need more code, please let me know.

感谢

推荐答案

您必须绑定提供值的序列。 ID 是一个字符串,所以它看起来像8值序列。

You must supply a sequence of values for the binding. ID is a string, so it looks like a sequence of 8 values.

你可能会想,(ID)应该是一个元素的元组,但事实并非如此。括号并非在Python元组制作的语法(除了空的元组)。逗号。使用(ID,),而不是得到一个元组的一个元素。另外,使用列表: [ID]

You're probably thinking that (ID) should be a tuple with one element, but it isn't. Parenthesis aren't the tuple-making syntax in Python (except for the empty tuple). Commas are. Use (ID,) instead to get a tuple with one element. Alternatively, use a list: [ID].

这篇关于从数据库中读取使用SQLite和Python:绑定提供数有误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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