Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #95529
| From | John Gordon <gordon@panix.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Every character of a string becomes a binding |
| Date | 2015-08-21 17:02 +0000 |
| Organization | PANIX Public Access Internet and UNIX, NYC |
| Message-ID | <mr7lit$fpo$1@reader1.panix.com> (permalink) |
| References | <871tewppdr.fsf@Equus.decebal.nl> |
In <871tewppdr.fsf@Equus.decebal.nl> Cecil Westerhof <Cecil@decebal.nl> writes:
> I have the following with sqlite3:
> urls = c.execute('SELECT URL FROM LINKS WHERE URL = ?', url).fetchall()
> But this gives:
> Traceback (most recent call last):
> File "./createDB.py", line 52, in <module>
> urls = c.execute('SELECT URL FROM LINKS WHERE URL = ?', url).fetchall()
> sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 1, and there are 40 supplied.
> The number of bindings is the length of the string.
> What is happening here? Why is every character of the string seen as a
> binding, instead of the string being the binding?
The second argument to execute() is supposed to be a sequence (usually a
tuple) containing the items to be used a parameters in the SQL statement.
You're probably defining url like this:
url = 'http://somewhere.com/something'
But it should be:
url = ('http://somewhere.com/something', )
In which case, I wouldn't call it "url", but rather "args" or something
like that.
To answer your stated question: a string *is* a sequence, so technically
you're passing the correct sort of object as the second argument to
execute(). But the SQL statement only asks for one parameter, so sqlite
is wondering where it should put the other 39 items.
--
John Gordon A is for Amy, who fell down the stairs
gordon@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Every character of a string becomes a binding Cecil Westerhof <Cecil@decebal.nl> - 2015-08-21 18:39 +0200
Re: Every character of a string becomes a binding Zachary Ware <zachary.ware+pylist@gmail.com> - 2015-08-21 11:50 -0500
Re: Every character of a string becomes a binding Cecil Westerhof <Cecil@decebal.nl> - 2015-08-21 19:04 +0200
Re: Every character of a string becomes a binding Johannes Bauer <dfnsonfsduifb@gmx.de> - 2015-08-22 11:45 +0200
Re: Every character of a string becomes a binding John Gordon <gordon@panix.com> - 2015-08-21 17:02 +0000
Re: Every character of a string becomes a binding Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-08-21 20:47 -0400
Re: Every character of a string becomes a binding Chris Angelico <rosuav@gmail.com> - 2015-08-22 11:03 +1000
csiph-web