PQescapeByteaConn - returns wrong string for PG9.1 Beta3

Lists: pgsql-hackers
From: "Petro Meier" <Petro85(at)gmx(dot)de>
To: pgsql-hackers(at)postgresql(dot)org
Subject: PQescapeByteaConn - returns wrong string for PG9.1 Beta3
Date: 2011-07-27 06:51:22
Message-ID: 20110727065122.205180@gmx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Normal 0 21 false
false false DE X-NONE X-NONE

MicrosoftInternetExplorer4
















If  I use PQescapeByteaConn() for a conenction to a PG9.1 Beta3 server,
this function returns (e.g.) "\xea2abd8ef31...(and so on.)...".

Here the problem: there should be a second backslash in the prefix.
The SQL Statement which uses this string (INSERT statement in my case)
returns with an error ("Invalid byte sequence..."). If I add the second
backslash manually everything works fine.

When connecting to a PG9.0 server and using this function, the
return value is correct (with two backslashes): "\\xea2abd8ef31...( and so
on.)...".

This should be a bug in PG9.1 Beta3

  Regards

Petro
--
NEU: FreePhone - 0ct/min Handyspartarif mit Geld-zurück-Garantie!
Jetzt informieren: http://www.gmx.net/de/go/freephone


From: Florian Pflug <fgp(at)phlo(dot)org>
To: "Petro Meier" <Petro85(at)gmx(dot)de>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: PQescapeByteaConn - returns wrong string for PG9.1 Beta3
Date: 2011-07-27 17:57:44
Message-ID: 806A04FD-FF77-45F6-A556-77D94A3D8423@phlo.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Jul27, 2011, at 08:51 , Petro Meier wrote:
> If I use PQescapeByteaConn() for a conenction to a PG9.1 Beta3 server, this function returns (e.g.) "\xea2abd8ef31...(and so on.)...".
> Here the problem: there should be a second backslash in the prefix. The SQL Statement which uses this string (INSERT statement in my case) returns with an error ("Invalid byte sequence..."). If I add the second backslash manually everything works fine.
> When connecting to a PG9.0 server and using this function, the return value is correct (with two backslashes): "\\xea2abd8ef31...( and so on.)...".
> This should be a bug in PG9.1 Beta3

Sounds as if PQescapeByteaConn() is confused about whether standard_conforming_strings is on or off. What value does that setting have in your 9.0 and 9.1 instances?

BTW, I think 9.1 is the first release where that settings defaults to "on", so maybe that adds to PQescapeByteaConn()'s confusion. In theory it shouldn't since PQescapeByteaConn() should simply detect the server's setting and react accordingly, but who knows...

best regards,
Florian Pflug


From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: Petro Meier <petro85(at)gmx(dot)de>
Cc: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: PQescapeByteaConn - returns wrong string for PG9.1 Beta3
Date: 2011-07-27 18:05:10
Message-ID: 1311789809-sup-3275@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Excerpts from Petro Meier's message of mié jul 27 02:51:22 -0400 2011:

> If  I use PQescapeByteaConn() for a conenction to a PG9.1 Beta3 server,
> this function returns (e.g.) "\xea2abd8ef31...(and so on.)...".
>
> Here the problem: there should be a second backslash in the prefix.
> The SQL Statement which uses this string (INSERT statement in my case)
> returns with an error ("Invalid byte sequence..."). If I add the second
> backslash manually everything works fine.

You're just being bitten by the fact that the
standard_conforming_strings setting changed its default from false to
true. If you want the old behavior, you can just flip the switch, but
the recommended action is to change your expectations. You can use E''
if you want backslashes to continue working without changing the switch.

--
Álvaro Herrera <alvherre(at)commandprompt(dot)com>
The PostgreSQL Company - Command Prompt, Inc.
PostgreSQL Replication, Consulting, Custom Development, 24x7 support


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
Cc: Petro Meier <petro85(at)gmx(dot)de>, Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: PQescapeByteaConn - returns wrong string for PG9.1 Beta3
Date: 2011-07-27 19:43:35
Message-ID: 14596.1311795815@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Alvaro Herrera <alvherre(at)commandprompt(dot)com> writes:
> Excerpts from Petro Meier's message of mi jul 27 02:51:22 -0400 2011:
>> If I use PQescapeByteaConn() for a conenction to a PG9.1 Beta3 server,
>> this function returns (e.g.) "\xea2abd8ef31...(and so on.)...".
>>
>> Here the problem: there should be a second backslash in the prefix.

> You're just being bitten by the fact that the
> standard_conforming_strings setting changed its default from false to
> true.

Well, the question is why is it actually failing for him. AFAICS the
value being emitted is correct for the 9.1 server. Perhaps we need to
see a complete example...

regards, tom lane


From: Florian Pflug <fgp(at)phlo(dot)org>
To: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
Cc: Petro Meier <petro85(at)gmx(dot)de>, Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: PQescapeByteaConn - returns wrong string for PG9.1 Beta3
Date: 2011-07-27 19:44:06
Message-ID: F3FDB41A-4352-4367-B905-0BB4546CB7E1@phlo.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Jul27, 2011, at 20:05 , Alvaro Herrera wrote:
> Excerpts from Petro Meier's message of mié jul 27 02:51:22 -0400 2011:
>
>> If I use PQescapeByteaConn() for a conenction to a PG9.1 Beta3 server,
>> this function returns (e.g.) "\xea2abd8ef31...(and so on.)...".
>>
>> Here the problem: there should be a second backslash in the prefix.
>> The SQL Statement which uses this string (INSERT statement in my case)
>> returns with an error ("Invalid byte sequence..."). If I add the second
>> backslash manually everything works fine.
>
> You're just being bitten by the fact that the
> standard_conforming_strings setting changed its default from false to
> true. If you want the old behavior, you can just flip the switch, but
> the recommended action is to change your expectations. You can use E''
> if you want backslashes to continue working without changing the switch.

Hm, but PQescapeByteaConn() shouldn't produce a literal that the server
later rejects, no matter what standard_conforming_strings is set to.

It looks like PQescapeByteaConn() does the right thing here, though -
it doesn't escape the backslash in it's result when dealing with 9.1,
presumably because that server has wstandard_conforming_strings set to on.
But why then is the server rejecting the result?

The only way I can see that make that happend would be to prefix the
string returned by PQescapeByteaConn() with 'E'.

@OP: Could you post the code fragment that causes the error?

best regards,
Florian Pflug


From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
Cc: Petro Meier <petro85(at)gmx(dot)de>, Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: PQescapeByteaConn - returns wrong string for PG9.1 Beta3
Date: 2011-07-27 21:19:39
Message-ID: 4E3080EB.7090008@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 07/27/2011 02:05 PM, Alvaro Herrera wrote:
> Excerpts from Petro Meier's message of mié jul 27 02:51:22 -0400 2011:
>
>> If I use PQescapeByteaConn() for a conenction to a PG9.1 Beta3 server,
>> this function returns (e.g.) "\xea2abd8ef31...(and so on.)...".
>>
>> Here the problem: there should be a second backslash in the prefix.
>> The SQL Statement which uses this string (INSERT statement in my case)
>> returns with an error ("Invalid byte sequence..."). If I add the second
>> backslash manually everything works fine.
> You're just being bitten by the fact that the
> standard_conforming_strings setting changed its default from false to
> true. If you want the old behavior, you can just flip the switch, but
> the recommended action is to change your expectations. You can use E''
> if you want backslashes to continue working without changing the switch.

Or even better don't interpolate it into SQL at all, but use a statement
placeholder.

cheers

andrew