Re: Prepared Statements

Ben Lamb <[email protected]>
Newsgroups gmane.comp.python.db.pypgsql.user
Message-ID <[email protected]>
Thank-very much for your help Gerhard and Karsten. I've just implemented the 
code suggested by Gerhard and it does exactly what I require.

It can see it should work with the Bytea stuff but I need to make some more 
changes to by app before I can test that.

Thanks again,

Ben.

P.S. If anyone is writing web apps I can highly recommend the combination 
Postgres, pyPgSQL and mod_python. It runs extremely quickly on four year old 
hardware.


On Monday 14 Apr 2003 2:42 pm, Karsten Hilbert wrote:
> > sql = "UPDATE %s SET " % bizobj.table
> > for field in bizobj.fields:
> > 	sql += "%s = '%s' " % (field.name, field.value)
> > sql += ";"
>
> I always had to use
>
> sql = "update table set field=%s;"
> cursor.execute(sql, PgBytea(value))
>
> with bytea data. It didn't work the other way.
>
> Note that it is permissible to have more formatters in a
> string than there are values to replace them. Just be careful
> to replace the right ones at the right time.
>
> > TypeError: query() argument 1 must be string without null bytes, not str
>
> '%s' % value will in effect insert str(value) which isn't
> right for ByteA.
>
> Karsten



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.