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 1vXUlA-00CHZ4-23 for pgsql-general@arkaria.postgresql.org; Mon, 22 Dec 2025 01:30:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vXUl8-00CmGt-0d for pgsql-general@arkaria.postgresql.org; Mon, 22 Dec 2025 01:30:50 +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 1vXUl7-00CmGk-2R for pgsql-general@lists.postgresql.org; Mon, 22 Dec 2025 01:30:50 +0000 Received: from mail-yx1-xb12f.google.com ([2607:f8b0:4864:20::b12f]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vXUl6-001tIQ-2N for pgsql-general@lists.postgresql.org; Mon, 22 Dec 2025 01:30:49 +0000 Received: by mail-yx1-xb12f.google.com with SMTP id 956f58d0204a3-64455a2a096so2679949d50.3 for ; Sun, 21 Dec 2025 17:30:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766367047; x=1766971847; darn=lists.postgresql.org; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=P1k5UlIEFNgulQyATT9iLn1rkIjOruKMiE0q3+AJo1o=; b=H8RSZqFgnt11YjDEq0JIlgFlZXzg7XiqZXhVn4dRJGF8v7I9x9tfyyKxL/2vwGDVn4 RMJzN0hjcm48rOjATtvWFWBswSGLx0XL+k52mwzh7N7ZDOpmRhiNq1ZVrBJDPgXaviie k0zt7LoXhbD3jVkV0LsbrRG/SNyghmmq4B3TCII+hCxKHUa6w5VweeDPtSXFUadKEQkN /2i0HKmma11Uud6EEachrXt90dXnpkNHyqyzFJhxKiq6XtUlV5mbSCt01/Q9gAYhhdZ7 gbCpxE9Mks87vuh0HZUxCMGSVnVk0uQGTV5+sZ3t3EaBcBPPQITxpamRARxdb3RoECoa 5qxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766367047; x=1766971847; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=P1k5UlIEFNgulQyATT9iLn1rkIjOruKMiE0q3+AJo1o=; b=GFp8DYQkIhYiIGtEs8uWQeIn+Bb2HYsPH9QaaxjZTDVIJBZlzJDyoK05pydmCZGWcP FM1XOA6qKsWGBnoTlqZoD2nY27nZcZgHbWdxnGhO9q7O0emMZh91R+54jrGWuV5ZS4/E TzS/s2osE7B7nHay4JRxT+jvI6yuzboPC3cooW4JsNO9NmMRGpMInn7rwlXAAyeV8rSc 0IZ1anVaPgxTvo8fjLWybDZTKRCDKntrrz8cYHSR3Qi27DRmBPmU0H9boCeRImr2BMl0 oIuacdJcC2gi5xEDORhTqyTCRsdm+ahaWR9NMkchUWu1901WAn1h8iOzHAC2vDh9LdSz Pilg== X-Gm-Message-State: AOJu0YwVR//kBO4lffaIDUvKW1wO9vB52zPuwhewnOFLAaX6Ct5ep4hO XMefLrwMRW8rMLQq5x9ydbyv77ecG86W/cEHlA3Wzo6A+UYdt8a53MllG+otQtuAm4B8NGbtZ6X 5SjP+Rbcj2uolQZDUDeAEoxv0EFshEu/P3vxfa1A= X-Gm-Gg: AY/fxX5mxb+MZnKk4k7EhCjtV4hBG5GdQspT6oOGbeWQfr8ltSLTQRNHB2GfFOACuTw /VNyCuNIsxdlTvbSq5LQp05+imkd/DWq62F7JqSqeFK56boO2HJgr78q9uRVpoRFoy9125i7ZdO tFMGL+3bGCaQa0KqiBQ3thb3xq0BuVNMao+cayu5+i+hV/1hfCeKd/iQd1RO+nKE/nO2N7qDUg2 yqfHyR0QBMLYtwDSYpOXjQ1DuSLJoELGeW/aLnsIlMOKxvvGk5tJQDvByujVxD5ifa/sL/otNB+ PXAFJxzzRwktGiXTIznVM0BS+4o= X-Google-Smtp-Source: AGHT+IHhv3pD3AcnzVbdiH3UxLGENhT7I39aYzfoKDD2X8CKdhS9AQSibz8OJ/n+6Iyq54LIWFNSiPmw0/2hk8iYpOA= X-Received: by 2002:a05:690c:c4f6:b0:786:5afa:375c with SMTP id 00721157ae682-78fb40d9808mr170941637b3.67.1766367047135; Sun, 21 Dec 2025 17:30:47 -0800 (PST) MIME-Version: 1.0 References: <2547700.1765940917@sss.pgh.pa.us> <9a0ce31a49f149d8d982d2b359095560655f781e.camel@cybertec.at> <852dee881b6cc82b9d4b51d69d48c415e2a87b4d.camel@cybertec.at> <61121.1766295563@sss.pgh.pa.us> <6uz5ppdgqhlovw3df2dmzgzrfbfmmy5pys37ln7u4kyidaftgo@gxgkvkbwk3zh> In-Reply-To: <6uz5ppdgqhlovw3df2dmzgzrfbfmmy5pys37ln7u4kyidaftgo@gxgkvkbwk3zh> From: Igor Korot Date: Sun, 21 Dec 2025 17:30:38 -0800 X-Gm-Features: AQt7F2oJz72UZAmQQnObTuyHeJV6ebrignBeu_ql87EOPXvfiCTZ0jlqFFXswfg Message-ID: Subject: Re: PQexecPrepared() question To: pgsql-general@lists.postgresql.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On Sun, Dec 21, 2025 at 1:19=E2=80=AFPM Peter J. Holzer = wrote: > > 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". > > > > Okay ... > > > > > The exact error message is: > > > ERROR: invalid byte sequence for encoding UTF8: 0xdf > > > CONTEXT: unnamed portal parameter $1 > > > on the INSERT. > > > > 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 ;-). Maybe all I need is something like this: 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'; } ? Thank you. > > hjp > > -- > _ | Peter J. Holzer | Story must make more sense than reality. > |_|_) | | > | | | hjp@hjp.at | -- Charles Stross, "Creative writing > __/ | http://www.hjp.at/ | challenge!"