Re: BUG #6510: A simple prompt is displayed using wrong charset

From: Alexander LAW <exclusion(at)gmail(dot)com>
To: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
Cc: Pg Bugs <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: BUG #6510: A simple prompt is displayed using wrong charset
Date: 2012-03-18 09:04:51
Message-ID: 4F65A533.7090208@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-general pgsql-hackers

I see two ways to resolve the issue.
First is to use CharToOemBuff when writing a string to the "con" and
OemToCharBuff when reading an input from it.
The other is to always use stderr/stdin for Win32 as it was done for
msys before. I think it's more straightforward.
I tested the attached patch (build the source with msvc) and it fixes
the issue. If it looks acceptible, then probably DEVTTY should not be
used on Windows at all.
I found two other references of DEVTTY at
psql/command.c
success = saveHistory(fname ? fname : DEVTTY, -1, false, false);

and
contrib/pg_upgrade/option.c
log_opts.debug_fd = fopen(DEVTTY, "w");

By the way, is there any reason to use stderr for the prompt output, not
stdout?

Regards,
Alexander

16.03.2012 23:13, Alvaro Herrera пишет:
> Excerpts from exclusion's message of sáb mar 03 15:44:37 -0300 2012:
>
>> I'm using postgresSQL in Windows with Russian locale and get unreadable
>> messages when the postgres utilities prompting me for input.
>> Please look at the screenshot:
>> http://oi44.tinypic.com/aotje8.jpg
>> (The psql writes the unreadable message prompting for the password.)
>> But at the same time the following message (WARINING) displayed right.
>>
>> I believe it's related to setlocale and the difference between OEM and ANSI
>> encoding, which we had in Windows with the Russian locale.
>> The startup code of psql sets locale with the call setlocale(LC_ALL, "") and
>> MSDN documentation says that the call:
>> Sets the locale to the default, which is the user-default ANSI code page
>> obtained from the operating system.
>>
>> After the call all the strings printed with the printf(stdout) will go
>> through the ANSI->OEM conversion.
>>
>> But in the simple_prompt function strings written to con, and such writes go
>> without conversion.
> Were you able to come up with some way to make this work?
>

Attachment Content-Type Size
sprompt.diff text/x-patch 721 bytes

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message prem tolani 2012-03-18 12:44:49 Applicatin crashing with on postgresql 8.1 service restart
Previous Message prem tolani 2012-03-18 05:13:21 Fw: Bug in postgresql 8.1

Browse pgsql-general by date

  From Date Subject
Next Message mgould 2012-03-18 12:26:32 Re: why no create variable
Previous Message Jasen Betts 2012-03-18 04:57:37 Re: why no create variable

Browse pgsql-hackers by date

  From Date Subject
Next Message Daniel Farina 2012-03-18 10:38:45 Re: Gsoc2012 Idea --- Social Network database schema
Previous Message Joachim Wieland 2012-03-18 05:39:06 Re: patch for parallel pg_dump