Why isn't this query working in python?

John Machin sjmachin at lexicon.net
Sat May 26 20:21:30 EDT 2007


On May 27, 5:25 am, erikcw <erikwickst... at gmail.com> wrote:
> On May 25, 11:28 am, Carsten Haese <cars... at uniqsys.com> wrote:
>
>
>
> > On Fri, 2007-05-25 at 09:51 -0500, Dave Borne wrote:
> > > > I'm trying to run the following query:
> > > ...
> > > > member_id=%s AND expire_date > NOW() AND completed=1 AND (product_id
>
> > > Shouldn't you be using the bind variable '?' instead of '%s' ?
>
> > The parameter placeholder for MySQLdb is, indeed and unfortunately, %s.
> > The OP is using parameter substitution correctly, though in an
> > obfuscated fashion. 'sql' is a misnamed tuple containing both the query
> > string *and* the parameters, which is being unpacked with '*' into two
> > arguments to the execute call.
>
> > The only problem I see is that the parameters should be a sequence, i.e.
> > (self.uid,) instead of just (self.uid).
>
> > HTH,
>
> > --
> > Carsten Haesehttp://informixdb.sourceforge.net
>
> I tried adding the comma to make it a sequence - but now change.
>
> ('SELECT payment_id FROM amember_payments WHERE member_id=%s AND
> expire_date > NOW() AND completed=1 AND (product_id >11 AND product_id
> <21)', (1608L,))
> ()
>
> What else could it be?
>

Possibly a type mismatch. How is member_id declared in the CREATE
TABLE? For diagnostic purposes, try passing in (1608,) and ('1608',).




More information about the Python-list mailing list