[DB-SIG] MySQL Python module bugs or what?
Chris Cogdon
chris@cogdon.org
Tue, 8 Oct 2002 08:43:14 -0700
On Tuesday, Oct 8, 2002, at 01:10 US/Pacific, Jekabs Andrushaitis wrote:
> SQL code:
> CREATE TABLE testtable(testfield longint);
> INSERT INTO testtable(testfield) VALUES(1);
>
> Python code:
> ...
> # this works
> dbc.execute("SELECT testfield FROM testtable WHERE testfield<1")
> print dbc.fetchall()
>
> # this fails by saying that integer is required for parameter!!!
> dbc.execute("SELECT testfield FROM testtable WHERE testfield<%d",(1,))
> print dbc.fetchall()
>
> # this also fails by saying that integer is required for parameter!!!
> dbc.execute("SELECT testfield FROM testtable WHERE
> testfield<%(testfield)d",{"testfield":1})
> print dbc.fetchall()
>
> # and naturally this produces same
> dbc.execute("SELECT testfield FROM testtable WHERE
> testfield<%ld",(long(1),))
> print dbc.fetchall()
>
> # white this works...
> dbc.execute("SELECT testfield FROM testtable WHERE testfield<%s",(1,))
> print dbc.fetchall()
>
> Am I missing something serious, or this is a bug in MySQLdb module? Was
> using latest stable release
> from sourceforge.net. Also, I never managed to insert a longblob value
> whose
> side exceeded 1Mb into
> table.
>
> Not that I care about this much now, I did it couple weeks earlier
> when I
> had to migrate bug/request/feature request
> tracking data from our own Python/PostgreSQL/mod_python based solution
> to
> Bugzilla (sad, but I liked our own
> tracking application MUCH better than Bugzilla and the PHP).
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.
--
("`-/")_.-'"``-._ Chris Cogdon <chris@cogdon.org>
. . `; -._ )-;-,_`)
(v_,)' _ )`-.\ ``-'
_.- _..-_/ / ((.'
((,.-' ((,/ fL