Re: libpq, PQExecParams and the inserting of binary data - Mailing list pgsql-interfaces

From Tom Lane
Subject Re: libpq, PQExecParams and the inserting of binary data
Date
Msg-id 6424.1117820918@sss.pgh.pa.us
Whole thread Raw
In response to libpq, PQExecParams and the inserting of binary data  (David Hinkle <drachs@gmail.com>)
Responses Re: libpq, PQExecParams and the inserting of binary data
Re: libpq, PQExecParams and the inserting of binary data
List pgsql-interfaces
David Hinkle <drachs@gmail.com> writes:
> As you can see, I assumed I could use PQexapeBytea to escape the
> binary data and then just use the returned value as a text parameter. 

No, because PQescapeBytea is designed to do the escaping that would be
needed to put the bytea value into a string literal in a SQL command.
There's an extra level of backslashing involved to do that (because
backslashes are special to both the string-literal syntax and the
text input syntax for bytea).

But this is really the hard way to do it considering that you are using 
PQexecParams.  Just tell PQexecParams that you want this parameter to be
binary format, and pass the *raw* binary string as the parameter.

> I couldn't find any documentation on using PQExecParams
> with binary parameters,

src/test/examples/testlibpq3.c ... that example is reproduced in
the libpq manual, as well.
        regards, tom lane


pgsql-interfaces by date:

Previous
From: David Hinkle
Date:
Subject: Re: libpq, PQExecParams and the inserting of binary data
Next
From: "Daniel Verite"
Date:
Subject: Re: libpq, PQExecParams and the inserting of binary data