Hi,
I've been wanting to implement prepared statements, not sure if that's
considered to be supported by pygresql.
I found that I can do:
>>> import pg
>>> d=pg.DB('ts')
>>> d.query('prepare c AS INSERT INTO t VALUES($1)') -- note postgres $1
>>> parameter
>>> d.query_formatted('EXECUTE c(1)')
'1'
And:
>>> d.query_formatted('EXECUTE c(%s)', [1], inline=True)
'1'
But this fails:
>>> d.query_formatted('EXECUTE c(%s)', [1])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/python2.7/site-packages/pg.py", line 1870, in query_formatted
command, parameters, types, inline))
File "/usr/lib64/python2.7/site-packages/pg.py", line 1852, in query
return self.db.query(command, args)
pg.DatabaseError: ERROR: bind message supplies 1 parameters, but prepared
statement "" requires 0
Looks like pygres converts my %s and is sending:
sendto(5, "P\0\0\0\25\0EXECUTE c($1)\0\0\0B\0\0\0\23\0\0\0\0\0"..., 64,
MSG_NOSIGNAL, NULL, 0) = 64
which I think is maybe itself executing an anonymous, prepared statement to
execute my named, prepared statement (??)
Is there a nice way to execute a prepared statement, preferably with
inline=False to send as a list of params rather than constructing a statement
which then has to be parsed ?
Thanks,
Justin
_______________________________________________
PyGreSQL mailing list
[email protected]
https://mail.vex.net/mailman/listinfo/pygresql