Path: csiph.com!news.swapon.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Cecil Westerhof Newsgroups: comp.lang.python Subject: Re: Every character of a string becomes a binding Date: Fri, 21 Aug 2015 19:04:24 +0200 Organization: Decebal Computing Lines: 28 Message-ID: <87wpwoo9nr.fsf@Equus.decebal.nl> References: <871tewppdr.fsf@Equus.decebal.nl> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="528adfd6ad074c92fdc6a7f8fb9e23d8"; logging-data="11457"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19GjCFkhQdBfVQBtJ+InEWjhbh+WyBSqhQ=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) X-Homepage: http://www.decebal.nl/ Cancel-Lock: sha1:vziWfYQUjXMdv2SGXBBf4EEiVlM= sha1:9pX9VZnqvFOKgpDmYDQkY11X09w= Xref: csiph.com comp.lang.python:95530 On Friday 21 Aug 2015 18:50 CEST, Zachary Ware wrote: > On Fri, Aug 21, 2015 at 11:39 AM, Cecil Westerhof 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 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