| From: | "Peter J(dot) Holzer" <hjp-pgsql(at)hjp(dot)at> |
|---|---|
| To: | pgsql-general(at)lists(dot)postgresql(dot)org |
| Subject: | Re: PQexecPrepared() question |
| Date: | 2025-12-22 09:55:16 |
| Message-ID: | 47v26pfhc2hnz3ax2u6ogke7npeyghbkxghov5hysv2f7ttchs@c5vrfavj7oqe |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
On 2025-12-21 17:30:38 -0800, Igor Korot wrote:
> On Sun, Dec 21, 2025 at 1:19 PM Peter J. Holzer <hjp-pgsql(at)hjp(dot)at> 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 ;-).
>
> Maybe all I need is something like this:
>
> convert(char *dest, const std::wstring src)
> {
> const wchar_t *temp = src.c_str();
> while( *dest )
> {
> dest++;
> }
> while( *temp )
> {
> *dest = *temp;
> dest++;
> temp++;
> }
> *dest++ = '\0';
> *dest = '\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.
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.
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(at)hjp(dot)at | -- Charles Stross, "Creative writing
__/ | http://www.hjp.at/ | challenge!"
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Igor Korot | 2025-12-22 23:07:52 | Re: PQexecPrepared() question |
| Previous Message | Laurenz Albe | 2025-12-22 08:18:57 | Re: PQexecPrepared() question |