Why isn't this query working in python?

Steve Holden steve at holdenweb.com
Sat May 26 17:03:03 EDT 2007


erikcw 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?
> 
> Thanks!
> Erik
> 
It *could* be that there aren't any data meeting the criteria in your 
query. Is there any chance that the current date/time has passed the 
expire date since you ran the query manually?

regards
  Steve
-- 
Steve Holden        +1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd           http://www.holdenweb.com
Skype: holdenweb      http://del.icio.us/steve.holden
------------------ Asciimercial ---------------------
Get on the web: Blog, lens and tag your way to fame!!
holdenweb.blogspot.com        squidoo.com/pythonology
tagged items:         del.icio.us/steve.holden/python
All these services currently offer free registration!
-------------- Thank You for Reading ----------------




More information about the Python-list mailing list