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 1vXcdP-00H1VK-17 for pgsql-general@arkaria.postgresql.org; Mon, 22 Dec 2025 09:55:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vXcdO-00E8Ny-0x for pgsql-general@arkaria.postgresql.org; Mon, 22 Dec 2025 09:55:23 +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 1vXcdN-00E8NR-33 for pgsql-general@lists.postgresql.org; Mon, 22 Dec 2025 09:55:22 +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 1vXcdM-001wee-13 for pgsql-general@lists.postgresql.org; Mon, 22 Dec 2025 09:55:21 +0000 Received: by rorschach.hjp.at (Postfix, from userid 1000) id D4EE31A88E; Mon, 22 Dec 2025 10:55:16 +0100 (CET) Date: Mon, 22 Dec 2025 10:55:16 +0100 From: "Peter J. Holzer" To: pgsql-general@lists.postgresql.org Subject: Re: PQexecPrepared() question Message-ID: <47v26pfhc2hnz3ax2u6ogke7npeyghbkxghov5hysv2f7ttchs@c5vrfavj7oqe> Mail-Followup-To: pgsql-general@lists.postgresql.org References: <9a0ce31a49f149d8d982d2b359095560655f781e.camel@cybertec.at> <852dee881b6cc82b9d4b51d69d48c415e2a87b4d.camel@cybertec.at> <61121.1766295563@sss.pgh.pa.us> <6uz5ppdgqhlovw3df2dmzgzrfbfmmy5pys37ln7u4kyidaftgo@gxgkvkbwk3zh> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="muba47sq7uuzxj6x" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --muba47sq7uuzxj6x Content-Type: text/plain; protected-headers=v1; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Subject: Re: PQexecPrepared() question MIME-Version: 1.0 On 2025-12-21 17:30:38 -0800, Igor Korot wrote: > On Sun, Dec 21, 2025 at 1:19=E2=80=AFPM Peter J. Holzer wrote: > > 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. [...] > > I think 1) is the better strategy, but them I've been a UTF-8 fan-boy > > for over 30 years ;-). >=20 > Maybe all I need is something like this: >=20 > convert(char *dest, const std::wstring src) > { > const wchar_t *temp =3D src.c_str(); > while( *dest ) > { > dest++; > } > while( *temp ) > { > *dest =3D *temp; > dest++; > temp++; > } > *dest++ =3D '\0'; > *dest =3D '\0'; > } >=20 > ? I hope your compiler complains loudly about that code. You can't just assign a wchar_t to a char and expect it to do anything sensible. A short search points to std::wstring_convert, but that has been deprecated in C++17, and it's not obvious to me what the replacement is. There is always ICU, of course, but that feels like cracking a nut with a sledgehammer.=20 Personally, I might roll my own if an hour of googling doesn't turn up anything promising (UTF-8 encoding is quite simple), but that shouldn't be necessary. hjp --=20 _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp@hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" --muba47sq7uuzxj6x Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEETtJbRjyPwVTYGJ5k8g5IURL+KF0FAmlJFXoACgkQ8g5IURL+ KF12YQ/8C91jdhfgRpcIJEkSbdUBzhAb5uKxC4YFRp/KSYr8bd3bu5iGJ9EAB1rW W7f+8KgaBIADUEGVK5Ob4AiHAmob8xWDhPHN/9pSs6V3pvOsLbYcQsQEWbJ/7aG0 ljDrK7gDoZ2H/x5Crl/4JlOeyaYwj9Gjv+6d71G1phhWFVCsYb7MYMdw2Kz+4SDx Oa+tx3bnMEXOIBPGtKLYjWR9ju7eoG0HX7evORG8bK0I6D1udSVvYQnivFIbvIQl iJff4OoCU9MUj0i+feXVopy+6A69EdwCKgARTTqsV4j3o+H0QX+LWzLI9Vd0IfAh 3wAG/RVFuW4pO8hgmtDa83LO8OEIWb+RBWrr3lWVHQfRbzpWiFvFPi/nExSa7+Yg ZKOfeYL8doxKvOItg3eCsz36ozvuB7VLSrpV0ulax/mhZiHntwDTxIGVTgnW3mzs Sd9VA5QSpP53NRRneDE03DUPQEJJdk9VNKYkXoDLGXT5ZnCtWCjzRMPAVM8uSEby ubDJeZJgYCO4VjqEX3ZNt4KiSkyTSy6I5iKSVoD5Lyx47VkYBLVBzGfRwibfgAl0 mPhEk/JrjJVOxhkZK5+La7C6PAMJyVuEBwYIZ2fa2Bo7ln3hk26vGp/GABgmDOdX ijtRKbS1DYebXZ4guVbXYVoExEtD6oq0ljzgoiN6kshTivnK2U8= =d4C4 -----END PGP SIGNATURE----- --muba47sq7uuzxj6x--