round-triping bytea/buffers
Phil Mayers <p.mayers-AQ/[email protected]>
| Newsgroups | gmane.comp.python.db.psycopg.devel |
|---|---|
| Message-ID | <[email protected]> |
The following script fails with a segfault:
----
import psycopg2
conn = psycopg2.connect(DSN)
cur = conn.cursor()
cur.execute("create temp table foo (id integer, data bytea)")
data = '\x00\x01\x02'
cur.execute("insert into foo (id, data) values (%s,%s)", (1, data))
cur.execute("select data from foo where id=1")
data_fromsql = cur.fetchone()[0]
print "data from sql", repr(data_fromsql), repr(str(data_fromsql))
cur.execute("insert into foo (id, data) values (%s,%s)", (1, data_fromsql))
----
Like so:
2.0.6 (dec dt ext pq3)
data from sql <read-only buffer for 0x2aaaaab12270, size 0, offset 0 at
0x2aaaae7bf1f0> ''
Segmentation fault
However, if I instead do this this:
data_fromsql = cur.fetchone()[0]
data_fromsql = buffer(str(data_fromsql))
...the script works. It seems the buffer objects that psycopg returns
cannot be passed back to psycopg.
Version as above is 2.0.6