By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,663 Members | 1,375 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,663 IT Pros & Developers. It's quick & easy.

Help: ecpg bytea and PQescapeBytea()/PQunescapeBytea()

P: n/a
I'm currently trying to insert binary data into postgres using the
ecpg interface and standard embedded sql.

I have a table defined as...

CREATE TABLE bintest
(
fsize numeric,
bindata bytea
);

I'm reading a binary file using fread() and storing the read results
into an unsigned char buffer.

From reading the newsgroups I guess I'm suppose to escape certain
bytes so the data can be parsed and inserted. I'm currently using
PQescapeBytea() with little success. After escaping the data the
insert fails with bad string or something like that. Do I have to
do anything else before calling the EXEC SQL?

I'm not even sure if the PQescapeBytea() and PQunescapeBytea() can be
used with embedded SQL. I did try putting single quotes around the
result of PQescapeBytea() and that seemed to work for inserting.
When I selected the data back out of the database and used
PQunescapeBytea() the binary data was messed up.

I don't need LO support and bytea seemed the easiest way to go.
Incidently I'm using postgresql 7.3 on Redhat 9.

Any comments, suggestions and help is greatly appreciated.

Cheers!
Nov 12 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.