problem with quoted strings while inserting into varchar field of database.

Carsten Haese carsten at uniqsys.com
Mon May 7 10:50:47 EDT 2007


On Mon, 2007-05-07 at 07:26 -0700, Daniele Varrazzo wrote:
> > >> >> >     cur.execute("INSERT INTO datatable (data) VALUES (%s);",
> > >> >> > (pickled_data,))
> 
> > %s is not a placeholder IMHO.
> 
> > What happens when using %s is, that the string given will be inserted where
> > %s is; that is something python does as with every print or such.
> 
> It is indeed. The behavior you describe would be true if i had used
> the "%" operator. Read better what i have written: There is no "%"
> operator.

This confusion is precisely why I think the (py)format paramstyles
should be deprecated in a future version of the DB-API spec. Question
marks make it immediately obvious that something other than string
formatting is happening, and if I'm not mistaken, question marks are SQL
standard.

-- 
Carsten Haese
http://informixdb.sourceforge.net





More information about the Python-list mailing list