Trouble with Myqsl
Jon Ribbens
jon+usenet at unequivocal.co.uk
Wed Apr 24 19:11:45 EDT 2002
In article <aa7c52$ehu$0 at 216.39.172.122>, Bengt Richter wrote:
> So is cc.execute(...) acting like
> >>> def dummyccx(fmt, params):
> ... for tup in params:
> ... print fmt % tuple(map(repr,tup))
> ...
> >>> dummyccx(
> ... "INSERT INTO tmp (k, s) VALUES (%s, %s)",
> ... [(1, "one"), (2, 'two'), (3, 'three')]
> ... )
> INSERT INTO tmp (k, s) VALUES (1, 'one')
> INSERT INTO tmp (k, s) VALUES (2, 'two')
> INSERT INTO tmp (k, s) VALUES (3, 'three')
Sort of that one. Except it isn't 'repr', it's a function which
examines the type of the parameter and converts it into appropriate
MySQL representation (i.e. for strings put "'" at the beginning and
end and quote various characters with a "\", for numbers convert them
to strings, etc etc).
Oh, except you shouldn't be relying on the 'for tup in params', you
should imagine it is doing:
def dummyccx(fmt, params):
print fmt % tuple(map(sql_quote, params))
Except it's more complicated than this because you might be using a
mapping not a sequence for the parameters. See
http://www.python.org/topics/database/DatabaseAPI-2.0.html
for details.
More information about the Python-list
mailing list