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 1vYa9j-007nHG-14 for pgsql-general@arkaria.postgresql.org; Thu, 25 Dec 2025 01:28:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vYa9h-006E6P-07 for pgsql-general@arkaria.postgresql.org; Thu, 25 Dec 2025 01:28:41 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vYa9g-006E6H-1r for pgsql-general@lists.postgresql.org; Thu, 25 Dec 2025 01:28:41 +0000 Received: from mail-yx1-xb129.google.com ([2607:f8b0:4864:20::b129]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vYa9e-002bte-1k for pgsql-general@lists.postgresql.org; Thu, 25 Dec 2025 01:28:41 +0000 Received: by mail-yx1-xb129.google.com with SMTP id 956f58d0204a3-6468f0d5b1cso2013204d50.1 for ; Wed, 24 Dec 2025 17:28:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766626117; x=1767230917; 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=KahpgA+c9t5dEgxs+kfhYOCbm8LzbiT/vTnoKcp4avQ=; b=MJTHa9M0/88PRW3QNznVcT+/ZSoZ5iY6jln9wkT4NFt5v7LbarVtSKX3MjyKXwOWu8 r6hCCef3pXphBD+AoTSvTpkgojfx+z/Ab1dvpGHNgBTmVYuTbMXJBKn9S6qtmfN2arBi LRbrjhaH9hAo9TPZzcapnyd1jvn7Yg3lJCX6d510v/Yiu778qImeEAREP4aJ5MKIpVKy 11d9j2yhFtUMmWOmPsoJMxhAK41NBeEDLUV5EPr32N4JsqKwcW0bdSWgQuchC5EmlXUe y+4gatukkW4Sv+R7Qm94QUgwi8PNqaagUQ/ov3Ziey71rcwR40ms8tODp1Gf9Urm5XmZ DdCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766626117; x=1767230917; 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=KahpgA+c9t5dEgxs+kfhYOCbm8LzbiT/vTnoKcp4avQ=; b=PDSPJU1zlUiCBoa5rhntir9xrR+2xnPdVyJGU7j63uJ2O8cqFzx4Z9OXfHHRQqCfe7 kYSwacDFX/tx5t1c5qHS4XbkhG5cs5tdxhwSv/bBB87OktM/vAxNY22hwvMAQm6bzGzC hauNtzUUgUFz3i2Y37CQ53rJ//K0Vafofzh8CUaCZ33ZfD4J1w/vqkGuj5gq9rM1qzwv f7b/Lqzsxvj6qZ4zMhoijkqQzwUWo8sklwgEaKQEcw9gpMtHsvpTscv75YDceidm6xmc RufRmb0Qs40IUpNT9g2Vn/z6EcNK1yuYOaR7fz+zfZDRaT6lhx48ZN5UxQcolzX3qfJV pVOg== X-Gm-Message-State: AOJu0Yz410VodNF9JWbSWAVhP0iKqsi1MgnhQ3qEEVlJgcB16zmZBk+c 4+PCJ/Yah6QKWSrFuO/01UYZpzWGxEdIBHwDgetGQ/dX7lvj0R+nZobYJ+tSLe1esstTG4VPX7S Ei+UgD54wckob80iv/78yvKzCXCXQ1U3M9ZJ+l/E= X-Gm-Gg: AY/fxX6ZI+mGRQh+hATsc6yxnfphQ4KyM7F8IYoJU1KQbkuJB9FmZyrJl/cLew+NyZa vyORNYEl05CFbD2LXmI7FT84aq++ILuU8Tzv6SZn5DmdAXf3PodBjdSxRMpPwnPkMmcSjub5gJm 0bsEP5FOJSDliClbRio5gAMBaK91M4gEpjYI02HZ6LZ+r+ar5m1H9HTEbHWYCdt8Sk0Zo++DEog 5pXXk0QqjmGjFMpbRrmMR2hzY6nad88lwXrXOUu99h5ECitdPOvo7sQQi+scphf8aLi+tUX5nDX Gi+AIS8+NZT8V9NS3PgcgSMH2LvTFZOHaQAdog== X-Google-Smtp-Source: AGHT+IHmNs69A5wpO7tDzs5nHwb3JZ8mbJYJHuK1Q4FXGUIpX/MEySNAM3gufTOB4zfplfJDSKgFCS3VFmR5crHoSAI= X-Received: by 2002:a53:d846:0:b0:644:477a:92b7 with SMTP id 956f58d0204a3-6466a90117dmr13409942d50.56.1766626117161; Wed, 24 Dec 2025 17:28:37 -0800 (PST) MIME-Version: 1.0 References: <9a0ce31a49f149d8d982d2b359095560655f781e.camel@cybertec.at> <852dee881b6cc82b9d4b51d69d48c415e2a87b4d.camel@cybertec.at> <61121.1766295563@sss.pgh.pa.us> <6uz5ppdgqhlovw3df2dmzgzrfbfmmy5pys37ln7u4kyidaftgo@gxgkvkbwk3zh> <47v26pfhc2hnz3ax2u6ogke7npeyghbkxghov5hysv2f7ttchs@c5vrfavj7oqe> In-Reply-To: From: Igor Korot Date: Wed, 24 Dec 2025 17:28:23 -0800 X-Gm-Features: AQt7F2pun3S7Xa-X3i8zQnrXBSZoIRx-Z78h9PLkjItVucx5w0fJWtZw_m61RGE 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, ALL, My current code is below: std::wstring query1 =3D L"SELECT t.table_catalog AS catalog, t.table_schema AS schema, t.table_name AS table, u.usename AS owner, c.oid AS table_id FROM information_schema.tables t, pg_catalog.pg_class c, pg_catalog.pg_user u WHERE t.table_name =3D c.relname AND c.relowner =3D usesysid AND (t.table_type =3D 'BASE TABLE' OR t.table_type =3D 'VIEW' OR t.table_type =3D 'LOCAL TEMPORARY') ORDER BY table_name;"; std::wstring query7 =3D L"INSERT INTO \"abcattbl\" VALUES( 0, $1, (SELECT c.oid FROM pg_class c, pg_namespace nc WHERE nc.oid =3D c.relnamespace AND c.relname =3D $2 AND nc.nspname =3D $3), \'\', 8, 400, \'N\', \'N\', 0, 1, 0, \'MS Sans Serif\', 8, 400, \'N\', \'N\', 0, 1, 0, \'MS Sans Serif\', 8, 400, \'N\', \'N\', 0, 1, 0, \'MS Sans Serif\', \'\' ) ON CONFLICT DO NOTHING;"; for( int i =3D 0; i < PQntuples( res ) && !result; i++ ) { std::wstring cat =3D m_pimpl->m_myconv.from_bytes( PQgetvalue( res, i, 0 ) ); std::wstring schema =3D m_pimpl->m_myconv.from_bytes( PQgetvalue( res, i, 1 ) ); std::wstring table =3D m_pimpl->m_myconv.from_bytes( PQgetvalue( res, i, 2 ) ); std::wstring table_owner =3D m_pimpl->m_myconv.from_bytes( PQgetvalue( res, i, 3 ) ); pimpl.m_tableDefinitions[cat].push_back( TableDefinition( cat, schema, table ) ); count++; paramValues =3D schema + L"." + table; params[0] =3D new char[paramValues.length() + 2]; memset( params[0], '\0', paramValues.length() + 2 ); auto temp =3D m_pimpl->m_myconv.to_bytes( paramValues.c_str() ).c_str(); params[0] =3D const_cast( m_pimpl->m_myconv.to_bytes( paramValues.c_str() ).c_str() ); params[1] =3D new char[table.length() + 2]; memset( params[1], '\0', table.length() + 2 ); params[1] =3D const_cast( m_pimpl->m_myconv.to_bytes( table.c_str() ).c_str() ); params[2] =3D new char[table_owner.length() + 2]; memset( params[2], '\0', table_owner.length() + 2 ); params[2] =3D const_cast( m_pimpl->m_myconv.to_bytes( table_owner.c_str() ).c_str() ); paramFormat[0] =3D paramFormat[1] =3D paramFormat[2] =3D 0; paramLength[0] =3D paramValues.length(); paramLength[1] =3D table.length(); paramLength[2] =3D table_owner.length(); res8 =3D PQexecPrepared( m_db, "set_table_prop", 3, params, paramLength, paramFormat, 0 ); if( PQresultStatus( res8 ) !=3D PGRES_COMMAND_OK ) { std::wstring err =3D m_pimpl->m_myconv.from_bytes( PQerrorMessage( m_db ) ); errorMsg.push_back( L"Error executing query: " + err ); result =3D 1; } PQclear( res8 ); delete[] params[0]; params[0] =3D nullptr; delete[] params[1]; params[1] =3D nullptr; delete[] params[2]; params[2] =3D nullptr; } This code crashes on the PQexecParam. I am completely puzzled. Could anyone help? Thank you. On Mon, Dec 22, 2025 at 3:07=E2=80=AFPM Igor Korot wro= te: > > Hi, Peter, > > On Mon, Dec 22, 2025 at 1:55=E2=80=AFAM Peter J. Holzer wrote: > > > > 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 th= e > > > > current locale which is obviously not using UTF-8. I don't progr= am in > > > > C++, but I'm pretty sure there is a portable way to encode a str= ing > > > > in UTF-8. > > [...] > > > > I think 1) is the better strategy, but them I've been a UTF-8 fan-b= oy > > > > 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'; > > > } > > > > > > ? > > > > 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. > > At least MSVC 2017 did not. > However, trying didn't solve it. Same error. > > > > > 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. > > I think ICU IS a replacement for wstring_comvert. > Will check it. > > > > > 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 > > > > -- > > _ | Peter J. Holzer | Story must make more sense than reality. > > |_|_) | | > > | | | hjp@hjp.at | -- Charles Stross, "Creative writing > > __/ | http://www.hjp.at/ | challenge!"