Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

parametrizing a sqlite query

1 view
Skip to first unread message

Sebastian Bassi

unread,
Feb 24, 2010, 12:07:07 PM2/24/10
to pytho...@python.org
c.execute("SELECT bin FROM bins WHERE qtl LIKE '%:keys%'",{'keys':keywords})

This query returns empty. When it is executed, keywords = 'harvest'.
To check it, I do it on the command line and it works as expected:

sqlite> SELECT bin FROM bins WHERE qtl LIKE '%harvest%';
11C
11D
12F

I guess there is a problem with the "%".

Jon Clements

unread,
Feb 24, 2010, 12:21:11 PM2/24/10
to


You might want:
c.execute("SELECT bin FROM bins where qtl like $keys", {'keys':
keywords} )

Cheers,

Jon.

Jon Clements

unread,
Feb 24, 2010, 12:29:22 PM2/24/10
to

As soon as I posted that, the $ didn't look right; the docs use :keys
syntax.

Cheers,

Jon.

Diez B. Roggisch

unread,
Feb 24, 2010, 1:12:59 PM2/24/10
to
Am 24.02.10 18:07, schrieb Sebastian Bassi:

You aren't supposed to put ' into the query. The thing you pass needs to
be the full literal.

Use

c.execute("select ... qtl like :keys", dict(keys="%%%s%%" % keywords))


Diez

Message has been deleted

Sebastian Bassi

unread,
Feb 25, 2010, 12:48:10 AM2/25/10
to Dennis Lee Bieber, pytho...@python.org
On Wed, Feb 24, 2010 at 3:41 PM, Dennis Lee Bieber
<wlf...@ix.netcom.com> wrote:
>        No there isn't... The problem is that you need to put the wildcards
> into the parameter instead of the placeholder.

Thank you, it works now.
Best,
SB

0 new messages