Thread: [NOVICE] LibPQ, C, BLOB or BYTEA

[NOVICE] LibPQ, C, BLOB or BYTEA

From
Ruslan R. Laishev
Date:
Hi All!
 
Is there a way to pass BYTEA values w/o formating to escape/hex binary ASCII strings from C to plpqsql stored function ?
 
 
-- 
С уважением,
Ruslan R. Laishev
OpenVMS bigot, natural born system/network progger, C contractor.
+79013163222
+79910009922
 

Re: [NOVICE] LibPQ, C, BLOB or BYTEA

From
Merlin Moncure
Date:
On Mon, Oct 23, 2017 at 7:00 AM, Ruslan R. Laishev <zator@yandex.ru> wrote:
> Hi All!
>
> Is there a way to pass BYTEA values w/o formating to escape/hex binary ASCII
> strings from C to plpqsql stored function ?

From a C client application?  Yes, you need to use the binary wire format.

merlin


-- 
Sent via pgsql-novice mailing list (pgsql-novice@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-novice

Re: [NOVICE] LibPQ, C, BLOB or BYTEA

From
Tom Lane
Date:
Merlin Moncure <mmoncure@gmail.com> writes:
> On Mon, Oct 23, 2017 at 7:00 AM, Ruslan R. Laishev <zator@yandex.ru> wrote:
>> Is there a way to pass BYTEA values w/o formating to escape/hex binary ASCII
>> strings from C to plpqsql stored function ?

> From a C client application?  Yes, you need to use the binary wire format.

Yeah, specifically see PQexecParams() or one of its sibling functions.
You need to execute some command like "SELECT myfunc($1::bytea)" and
then pass the parameter value in binary format.
        regards, tom lane


--
Sent via pgsql-novice mailing list (pgsql-novice@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-novice

Re: [NOVICE] LibPQ, C, BLOB or BYTEA

From
Ruslan R. Laishev
Date:
The question was "How To?". :-)
I looking for something like follows:
...
char __data_bytea[128];
 
 
RAND_bytes(__data_bytea, sizeof(__data_byte));
...
argv[0] = __data_bytea;
argl[0] = sizeof(__data_bytea);
 
...
PQexecPrepared ( ... argv, argl , ...);
 
 
 
PS:I know way conversion binary data to "binary data ASCII string" by PQescapeByteaConn(), but it's way to for real jedi.


23.10.2017, 16:20, "Merlin Moncure" <mmoncure@gmail.com>:

On Mon, Oct 23, 2017 at 7:00 AM, Ruslan R. Laishev <zator@yandex.ru> wrote:

 Hi All!

 Is there a way to pass BYTEA values w/o formating to escape/hex binary ASCII
 strings from C to plpqsql stored function ?


From a C client application? Yes, you need to use the binary wire format.

merlin



-- 
С уважением,
Ruslan R. Laishev
OpenVMS bigot, natural born system/network progger, C contractor.
+79013163222
+79910009922

Re: [NOVICE] LibPQ, C, BLOB or BYTEA

From
Merlin Moncure
Date:
On Mon, Oct 23, 2017 at 9:18 AM, Ruslan R. Laishev <zator@yandex.ru> wrote:
> The question was "How To?". :-)
> I looking for something like follows:
> ...
> char __data_bytea[128];
>
>
> RAND_bytes(__data_bytea, sizeof(__data_byte));
> ...
> argv[0] = __data_bytea;
> argl[0] = sizeof(__data_bytea);
>
> ...
> PQexecPrepared ( ... argv, argl , ...);

check out libpqtypes -- it does exactly what you want.

merlin


-- 
Sent via pgsql-novice mailing list (pgsql-novice@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-novice

Re: [NOVICE] LibPQ, C, BLOB or BYTEA

From
Ruslan R. Laishev
Date:
Thanks, will look later ...
At the time I looking for a way to solve the problem w/o introducing a yet another API.


24.10.2017, 00:08, "Merlin Moncure" <mmoncure@gmail.com>:

On Mon, Oct 23, 2017 at 9:18 AM, Ruslan R. Laishev <zator@yandex.ru> wrote:

 The question was "How To?". :-)
 I looking for something like follows:
 ...
 char __data_bytea[128];


 RAND_bytes(__data_bytea, sizeof(__data_byte));
 ...
 argv[0] = __data_bytea;
 argl[0] = sizeof(__data_bytea);

 ...
 PQexecPrepared ( ... argv, argl , ...);


check out libpqtypes -- it does exactly what you want.

merlin



-- 
С уважением,
Ruslan R. Laishev
OpenVMS bigot, natural born system/network progger, C contractor.
+79013163222
+79910009922