Thread: PQescapeLiteral in Libpq

PQescapeLiteral in Libpq

From
"lmanorders"
Date:
I'm using the libpq.dll libraries to connect to postgress. When I issue a call to PQescapeLiteral with a file path as the argument, the result string seems to always start with a bogus " E". For example, "C:\MyFile" is returned as " E'C:\\:MyFile'" (not including the double quotes). Is this a normal result or can't PQescapeLiteral be used to escape a file path literal? If not, are there any functions that can be used to "escape" a file path?
 
Thanks, Lynn
 

Re: PQescapeLiteral in Libpq

From
Tom Lane
Date:
"lmanorders" <lmanorders@gmail.com> writes:
> I'm using the libpq.dll libraries to connect to postgress. When I issue a call to PQescapeLiteral with a file path as
theargument, the result string seems to always start with a bogus " E". 

That's not bogus, it's the intended behavior.  Per the source code:

     * If we are escaping a literal that contains backslashes, we use the
     * escape string syntax so that the result is correct under either value
     * of standard_conforming_strings.  We also emit a leading space in this
     * case, to guard against the possibility that the result might be
     * interpolated immediately following an identifier.

            regards, tom lane


Re: PQescapeLiteral in Libpq

From
David Johnston
Date:
lmanorders wrote
> I'm using the libpq.dll libraries to connect to postgress. When I issue a
> call to PQescapeLiteral with a file path as the argument, the result
> string seems to always start with a bogus " E". For example, "C:\MyFile"
> is returned as " E'C:\\:MyFile'" (not including the double quotes). Is
> this a normal result or can't PQescapeLiteral be used to escape a file
> path literal? If not, are there any functions that can be used to "escape"
> a file path?
>
> Thanks, Lynn

What do you expect it to give in this instance?

I don't get why there is an extra colon in your output (typo on your part?)
but the "E" and the double-backslash are present because the "E" converts
the literal into one that accepts escape sequences (of the form
backslash-something, e.g., \n for a newline).  Since backslash is an escape
indicator in order to output a literal "\" you have to double/escape it
"\\".

David J.




--
View this message in context: http://postgresql.1045698.n5.nabble.com/PQescapeLiteral-in-Libpq-tp5786141p5786147.html
Sent from the PostgreSQL - novice mailing list archive at Nabble.com.


Re: PQescapeLiteral in Libpq

From
"lmanorders"
Date:
----- Original Message -----
From: "David Johnston" <polobo@yahoo.com>
To: <pgsql-novice@postgresql.org>
Sent: Thursday, January 09, 2014 12:35 PM
Subject: Re: [NOVICE] PQescapeLiteral in Libpq


> lmanorders wrote
>> I'm using the libpq.dll libraries to connect to postgress. When I issue a
>> call to PQescapeLiteral with a file path as the argument, the result
>> string seems to always start with a bogus " E". For example, "C:\MyFile"
>> is returned as " E'C:\\:MyFile'" (not including the double quotes). Is
>> this a normal result or can't PQescapeLiteral be used to escape a file
>> path literal? If not, are there any functions that can be used to
>> "escape"
>> a file path?
>>
>> Thanks, Lynn
>
> What do you expect it to give in this instance?

I didn't expect the " E" in front of the literal.

>
> I don't get why there is an extra colon in your output (typo on your
> part?)
> but the "E" and the double-backslash are present because the "E" converts
> the literal into one that accepts escape sequences (of the form
> backslash-something, e.g., \n for a newline).  Since backslash is an
> escape
> indicator in order to output a literal "\" you have to double/escape it
> "\\".

The second colon is a typo. I did expect the "\" to be doubled, just not the
leading " E" in the result.

Thanks for the quick responses!

>
> David J.
>
>
>
>
> --
> View this message in context:
> http://postgresql.1045698.n5.nabble.com/PQescapeLiteral-in-Libpq-tp5786141p5786147.html
> Sent from the PostgreSQL - novice mailing list archive at Nabble.com.
>
>
> --
> Sent via pgsql-novice mailing list (pgsql-novice@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-novice
>