[DB-SIG] MySQL Python module bugs or what?

Chris Cogdon chris@cogdon.org
Tue, 8 Oct 2002 09:13:32 -0700

On Tuesday, Oct 8, 2002, at 08:48 US/Pacific, Jekabs Andrushaitis wrote:

>> You have to use %s, even if you're dealing with integers. The
>> 'quoting'
>> code inside the DBI module turns all the parameters into
>> strings before
>> passing it to a python % operator.
> Is it how that is SUPPOSED to be, or just a case about MySQLdb?
> psycopg module in pyformat binding mode happily accepts most format
> strings like regular % operator does.
> I havent looked into DBAPI about this, but it seems to me that
> binding methods should be consistent between different modules.

You can probably use %s for any DBI module. The documentation 
predicates using %s

It's possible that psycopg just happens to pass through integers as 
integers, which both %d and %s will handle, but other DBIs always pass 
through as strings.

So, yes, I believe it will work if you use %s ALL the time.

> We already have 4 different types of binding (if not more), but 
> speaking
> of pyformat - isnt it supposed to accept anything Python % would 
> accept?

No. 'pyformat' means specifically using pythons %(variable)s dictionary 
binding, rather than the more C-like %s array binding. It was not 
intended to reference the variable types.

    ("`-/")_.-'"``-._        Chris Cogdon <chris@cogdon.org>
     . . `; -._    )-;-,_`)
    (v_,)'  _  )`-.\  ``-'
   _.- _..-_/ / ((.'
((,.-'   ((,/   fL