PQunescapeBytea

From: Iker Arizmendi <iker(at)research(dot)att(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: PQunescapeBytea
Date: 2004-02-10 19:40:13
Message-ID: 4029339D.5040302@research.att.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


The first part of the following piece of code should, and
does, take an array of 5 characters and convert it to an
escaped string of 10 characters (including the terminating
byte).

However, when going in the other direction PQunescapeBytea
reports (in unescaped_len) that the resulting binary data
has a length of 8 instead of 5 and is different than a[].
Am I using the escape/unescape functions incorrectly? I was
expecting the unescape function to produce an exact
duplicate of a[].

Thanks,
Iker

========================
unsigned char a[5];
a[0] = 'a';
a[1] = 'a';
a[2] = 'a';
a[3] = 'a';
a[4] = 0;

for (unsigned int i = 0; i < 5; ++i)
printf("%c\n", a[i]);

size_t escaped_len;
size_t unescaped_len;

unsigned char* escaped = PQescapeBytea(a, 5, &escaped_len);
unsigned char* unescaped = PQunescapeBytea(escaped, &unescaped_len);

printf("\n");
printf("unescaped_len: %d\n", unescaped_len);
for (unsigned int i = 0; i < unescaped_len; ++i)
printf("%c\n", unescaped[i]);

========================
OUTPUT:

a
a
a
a
@ <== this is an unprintable character

unescaped_len: 8
a
a
a
a
\
0
0
0

Responses

Browse pgsql-general by date

  From Date Subject
Next Message CSN 2004-02-10 19:51:10 Join query on 1M row table slow
Previous Message Andrew Sullivan 2004-02-10 19:18:33 Re: I want to use postresql for this app, but...