Every character of a string becomes a binding

Cecil Westerhof Cecil at decebal.nl
Fri Aug 21 19:04:24 CEST 2015

On Friday 21 Aug 2015 18:50 CEST, Zachary Ware wrote:

> On Fri, Aug 21, 2015 at 11:39 AM, Cecil Westerhof <Cecil at decebal.nl> wrote:
>> 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?
> Because the execute method expects the bindings to be passed as a
> sequence, which means to pass a single binding you need to wrap it
> in a sequence: `c.execute('SELECT url FROM links WHERE url = ?',
> (url,))`

Yeah, I found that. I solved it a little differently:
    urls = c.execute('SELECT URL FROM links WHERE URL = ?', [url]).fetchall()

Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

More information about the Python-list mailing list