parametrizing a sqlite query

Jon Clements joncle at googlemail.com
Wed Feb 24 18:29:22 CET 2010


On Feb 24, 5:21 pm, Jon Clements <jon... at googlemail.com> wrote:
> On Feb 24, 5:07 pm, Sebastian Bassi <sba... at clubdelarazon.org> wrote:
>
> > 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 "%".
>
> You might want:
> c.execute("SELECT bin FROM bins where qtl like $keys", {'keys':
> keywords} )
>
> Cheers,
>
> Jon.

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

Cheers,

Jon.



More information about the Python-list mailing list