On 7 Mag, 10:46, "Stefan Sonnenberg-Carstens"
<[EMAIL PROTECTED]> wrote:
> On Mo, 7.05.2007, 10:30, Daniele Varrazzo wrote:
>
> > On 7 Mag, 08:55, "krishnakant Mane" <[EMAIL PROTECTED]> wrote:
> >> On 6 May 2007 11:22:52 -0700, Daniele Varrazzo
> >> <[EMAIL PROTECTED]> >> Every serious database driver has a
> >> complete and solid SQL escaping
> >> > mechanism. This mechanism tipically involves putting placeholders in
> >> > your SQL strings and passing python data in a separate tuple or
> >> > dictionary. Kinda
>
> >> >     cur.execute("INSERT INTO datatable (data) VALUES (%s);",
> >> > (pickled_data,))
>
> >> I will try doing that once I get back to the lab.
> >> mean while I forgot to mention in my previous email that I use MySQLdb
> >> for python-mysql connection.
>
> Why not use qmark parameter passing (PEP 249) ?
>
> cur.execute("INSERT INTO datatable (data) VALUES (?);" , (pickled_data,))
>
> Then the DB driver will take care for you.

>>> import MySQLdb
>>> print MySQLdb.paramstyle
format

MySQLdb (as many other drivers) use format parameter passing. Not much
difference w.r.t. qmark, at least when passing positional parameters:
the placeholder is "%s" instead of "?". A difference is that "format"
also allows named parameters (actually it should have been "pyformat",
but IIRC MySQLdb can also use named placeholders, even if they
advertise "format").

Anyway it is only a matter of placeholder style: they both allow the
driver to take care of data escaping, the concept the OT didn't know
about.

-- Daniele

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to