Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vXQqw-00A8sK-0S for pgsql-general@arkaria.postgresql.org; Sun, 21 Dec 2025 21:20:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vXQpt-00CN7H-2p for pgsql-general@arkaria.postgresql.org; Sun, 21 Dec 2025 21:19:30 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vXQpt-00CN79-1j for pgsql-general@lists.postgresql.org; Sun, 21 Dec 2025 21:19:30 +0000 Received: from mail.hjp.at ([212.17.106.138] helo=rorschach.hjp.at) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vXQpr-001rXb-29 for pgsql-general@lists.postgresql.org; Sun, 21 Dec 2025 21:19:29 +0000 Received: by rorschach.hjp.at (Postfix, from userid 1000) id 4C92D1A4F3; Sun, 21 Dec 2025 22:19:25 +0100 (CET) Date: Sun, 21 Dec 2025 22:19:25 +0100 From: "Peter J. Holzer" To: pgsql-general@lists.postgresql.org Subject: Re: PQexecPrepared() question Message-ID: <6uz5ppdgqhlovw3df2dmzgzrfbfmmy5pys37ln7u4kyidaftgo@gxgkvkbwk3zh> Mail-Followup-To: pgsql-general@lists.postgresql.org References: <2547700.1765940917@sss.pgh.pa.us> <9a0ce31a49f149d8d982d2b359095560655f781e.camel@cybertec.at> <852dee881b6cc82b9d4b51d69d48c415e2a87b4d.camel@cybertec.at> <61121.1766295563@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="p53bmtfgqlbgc6uw" Content-Disposition: inline In-Reply-To: <61121.1766295563@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --p53bmtfgqlbgc6uw Content-Type: text/plain; protected-headers=v1; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Subject: Re: PQexecPrepared() question MIME-Version: 1.0 On 2025-12-21 00:39:23 -0500, Tom Lane wrote: > Igor Korot writes: > > I added the following code in my app: > > res =3D PQexec( m_db, "SHOW client_encoding" ); > > auto value =3D PQgetvalue( res, 0, 0 ); > > PQclear( res ); > > and the value of the "value" variable is "UTF8". >=20 > Okay ... >=20 > > The exact error message is: > > ERROR: invalid byte sequence for encoding UTF8: 0xdf > > CONTEXT: unnamed portal parameter $1 > > on the INSERT. >=20 > client_encoding governs both the encoding that the server will > send, and the encoding that it expects to receive. You are > sending a parameter string that is not valid UTF8. As I see it, Igor has two options: 1) Send UTF8. wcstombs is the wrong tool for this, since it uses the current locale which is obviously not using UTF-8. I don't program in C++, but I'm pretty sure there is a portable way to encode a string in UTF-8. 2) Figure out which encoding his locale is using and then set client_encoding appropriately. The first step to do that is to find the current locale. Igor, add #include ... char *current_locale =3D setlocale(LC_CTYPE, ""); to your code. What's the value of current_locale? I think 1) is the better strategy, but them I've been a UTF-8 fan-boy for over 30 years ;-). hjp --=20 _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp@hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" --p53bmtfgqlbgc6uw Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEETtJbRjyPwVTYGJ5k8g5IURL+KF0FAmlIZFMACgkQ8g5IURL+ KF2bOQ//Z77q+1vstj4rXJVYGJ/7qG3OQje3QY69ybsMcueudi2DIIwGohXIoleU gRx0Zhnn61mxTEOpGW69OOmHAqet05xZyzBub6JtfHio7b+oOnaLS2DMMVkCnZSe 8msLS0dzWzbrBjukj16IMxjgeq1zH4Kyvvnu/5686cFhXGs8fGWLOghiWx8KoxFs mob5WGqyDwtSpQ03GqaX9XnCs1LtPq8BhRRBQGalJJb9z1CRgGEenlu3+cqUU5hk yNYJYeQjmrGmcsE7wiP9a0p59nOfi7nEZRRjNkvIOcmKmQpX86GeKApcLxkj05qQ 6EbusvahuY01xPGDflTYWLH+OMd92EjmCqDYUGbEthqKRGL0U0UfADIdDOimM3AW b18I8EMk7pssjKz/KAF640SJyUM26MpIVFp8TQIl55X2VjhbEuH9I+vOnWWqSCJw 94fg12aIbTIHtHgDk5fgQ0lMrv27atAVTWSmecYPF3+1O8T/D7xjtZ+OUrdWccBW QFl1tOI6nTstoOQ7b78vPaJu1lf3oLsAjzbJbhgjWr3JRjXjxhG4QYj+MsrdpNu4 GgryZZ84CAzdftYjICYn0qhnqUZeyPwwZB/tbvctuMaPa42X9VKge66QoQldJHQx cJERL8JQ3d43z2iBFzzBnxl7ItyB8P5PaB94CvDmMe6K6W49T8Y= =80Bt -----END PGP SIGNATURE----- --p53bmtfgqlbgc6uw--