From: luiz <luiz@planit.com.br>
To: pgsql-odbc@postgresql.org
Subject: Odbc and Bytea
Date: Tue, 26 Feb 2008 12:55:54 -0300
Message-ID: <20080226154156.M96166@planit.com.br> (raw)
Hi,
I discovered that ODBC driver has a slightly different behavior than libpq on
the conversion from bytea escaped sequence to the unescaped form.
Well, I was sent a wrong escaped string to a bytea column, and Odbc driver
don“t return the same wrong string when retrieve it. :(
Altought for correct strings they works well, I think that is interesting that
both routines have the same behaviour.
So,I attached a modification (algorithm extracted from libpq ;) ).
Hope this can help to improve the driver.
Best Regards
Luiz
--
Plan IT Tecnologia Informatica Ltda.
Attachments:convert.diff (application/octet-stream, 1.7K) download
Index: convert.c
===================================================================
RCS file: /cvsroot/psqlodbc/psqlodbc/convert.c,v
retrieving revision 1.166
diff -r1.166 convert.c
4789a4790,4791
> #define ISFIRSTOCTDIGIT(CH) ((CH) >= '0' && (CH) <= '3')
> #define ISOCTDIGIT(CH) ((CH) >= '0' && (CH) <= '7')
4802c4804
< if (value[i] == BYTEA_ESCAPE_CHAR)
---
> switch (value[i])
4804,4805c4806,4837
< if (value[i + 1] == BYTEA_ESCAPE_CHAR)
< {
---
> case BYTEA_ESCAPE_CHAR:
> i++;
> if (value[i] == BYTEA_ESCAPE_CHAR)
> if (rgbValue)
> rgbValue[o] = value[i];
>
> o++;
> i++;
> else
> {
> if ((ISFIRSTOCTDIGIT(value[i])) &&
> (ISOCTDIGIT(value[i + 1])) &&
> (ISOCTDIGIT(value[i + 2])))
> {
> if (rgbValue)
> rgbValue[o] = conv_from_octal(&value[i]);
>
> o++;
> i += 3;
> }
> }
>
> /*
> * Note: if we see '\' followed by something that isn't a
> * recognized escape sequence, we loop around having done
> * nothing except advance i. Therefore the something will be
> * emitted as ordinary data on the next cycle. Corner case:
> * '\' at end of string will just be discarded.
> */
> break;
>
> default:
4808,4821c4840,4843
< i += 2;
< }
< else
< {
< if (rgbValue)
< rgbValue[o] = conv_from_octal(&value[i]);
< i += 4;
< }
< }
< else
< {
< if (rgbValue)
< rgbValue[o] = value[i];
< i++;
---
>
> i++;
> o++
> break;
4823,4825d4844
< /** if (rgbValue)
< mylog("convert_from_pgbinary: i=%d, rgbValue[%d] = %d, %c\n", i, o, rgbValue[o], rgbValue[o]); ***/
< o++;
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-odbc@postgresql.org
Cc: luiz@planit.com.br
Subject: Re: Odbc and Bytea
In-Reply-To: <20080226154156.M96166@planit.com.br>
References: <20080226154156.M96166@planit.com.br>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox