agora inbox for pgsql-interfaces@postgresql.org
help / color / mirror / Atom feedFrom: CN <cnliou9@fastmail.fm>
To: pgsql-interfaces@postgresql.org
Subject: Re: libpq - characterset encoding error from selecting BYTEA
Date: Tue, 15 Mar 2016 22:40:07 +0800
Message-ID: <1458052807.2085089.549773330.2CD59643@webmail.messagingengine.com> (raw)
In-Reply-To: <18018.1458050231@sss.pgh.pa.us>
References: <1458049871.2074609.549741642.32C1352A@webmail.messagingengine.com>
<18018.1458050231@sss.pgh.pa.us>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-interfaces>
On Tue, Mar 15, 2016, at 09:57 PM, Tom Lane wrote:
> > PGconn* first switches to "BIG5" client encoding:
> > PQexec(conn,"SET CLIENT_ENCODING TO BIG5");
>
> > version 1:
>
> > const char *pValues[]={"5","6"};
> > PGresult *r=PQexecParams(conn,"SELECT c3::BYTEA FROM t1 WHERE c1=$1 AND
> > c2=$2",2,NULL,pValues,NULL,NULL,1);
>
> > What is strange is that above PQexecParams() works in one portion of my
> > program but in another portion it yields the following error:
>
> > ERROR: character with byte sequence 0x98 0xe1 in encoding "BIG5" has no
> > equivalent in encoding "UTF8"
>
> Given the way the complaint is phrased, the problem is with data going
> *to* the server, not *from* the server. I don't think the returned bytea
> is your issue at all; it must be either in the SQL query string or the
> parameter values being sent. Probably you should review how you're
> setting up the parameter strings.
Thanks a lot for your always prompt and professional help!
I must have made the unforgivable mistake - miss using temporary, like
so:
std::ostringstream oss1,oss2;
oss1 << 5;
oss2 << 6;
const char *pValues[]={oss1.str().c_str(),oss2.str().c_str()};
PGresult *r=PQexecParams(conn,"SELECT c3 FROM t1 WHERE c1=$1 AND
c2=$2",2,NULL,pValues,NULL,NULL,1);
Humm... Maybe it is my compiler's issue. Maybe I should take a break
now.
Anyway, the error seems to be gone with the following slightly modified
version:
std::ostringstream oss1,oss2;
oss1 << 5;
oss2 << 6;
std::string s1(oss1.str()),s2(oss2.str());
const char *pValues[]={s1.c_str(),s2.c_str()};
PGresult *r=PQexecParams(conn,"SELECT c3 FROM t1 WHERE c1=$1 AND
c2=$2",2,NULL,pValues,NULL,NULL,1);
Best Regards,
CN
--
http://www.fastmail.com - Or how I learned to stop worrying and
love email again
--
Sent via pgsql-interfaces mailing list (pgsql-interfaces@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-interfaces
view thread (3+ messages)
Message-ID: <1458052807.2085089.549773330.2CD59643@webmail.messagingengine.com>
Permalink: ../1458052807.2085089.549773330.2CD59643@webmail.messagingengine.com/
Also on: postgresql.org/message-id/1458052807.2085089.549773330.2CD59643@webmail.messagingengine.com
reply
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 using the --to and --cc options:
reply via email
To: pgsql-interfaces@postgresql.org
Cc: cnliou9@fastmail.fm
Subject: Re: libpq - characterset encoding error from selecting BYTEA
In-Reply-To: <1458052807.2085089.549773330.2CD59643@webmail.messagingengine.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox