pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
UTF8 is a better option than US-ASCII for the default encoding of PGStream
5+ messages / 3 participants
[nested] [flat]

* UTF8 is a better option than US-ASCII for the default encoding of PGStream
@ 2015-10-13 07:42 Chang Chao <charleschung.cn@gmail.com>
  2015-10-13 12:34 ` Re: UTF8 is a better option than US-ASCII for the default encoding of PGStream Dave Cramer <pg@fastcrypt.com>
  0 siblings, 1 reply; 5+ messages in thread

From: Chang Chao @ 2015-10-13 07:42 UTC (permalink / raw)
  To: pgsql-jdbc

Hi,all
The problem I encountered is that,when lc_messages = 'ja_JP.UTF-8' is set
in postgresql.conf,and initial connection to database server failed(for
example:user name,password or dbname is misspelled),I see garbled error
message text in the client .The reason is that,in PGStream
constrcutor,default encoding of ASCII is
set(Encoding.getJVMEncoding("US-ASCII")).For the following reasons,maybe
UTF8 is a better option for default encoding.

1.When initializing connection ,jdbcclient send client_encoding parameter
as UTF-8
 see
org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(HostSpec[],
String, String, Properties, Logger)

2. When initial connection to server completes,jdbc client only receive the
value for client_encoding as UTF-8
 see
org.postgresql.core.v3.ConnectionFactoryImpl.readStartupMessages(PGStream,
ProtocolConnectionImpl, Logger)

if (name.equals("client_encoding"))
                {
                    if (!value.equals("UTF8"))
                        throw new PSQLException(GT.tr("Protocol error.
Session setup failed."), PSQLState.PROTOCOL_VIOLATION);

pgStream.setEncoding(Encoding.getDatabaseEncoding("UTF8"));
                }

So there seems no reason to initiate the encoding as US-ASCII.

Best regards.
Charles.

^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: UTF8 is a better option than US-ASCII for the default encoding of PGStream
  2015-10-13 07:42 UTF8 is a better option than US-ASCII for the default encoding of PGStream Chang Chao <charleschung.cn@gmail.com>
@ 2015-10-13 12:34 ` Dave Cramer <pg@fastcrypt.com>
  0 siblings, 0 replies; 5+ messages in thread

From: Dave Cramer @ 2015-10-13 12:34 UTC (permalink / raw)
  To: Chang Chao <charleschung.cn@gmail.com>; +Cc: pgsql-jdbc

Hi Chang,

Seems reasonable to me. US-ASCII is actually a subset so it really won't
change anything for the part of the world that does use US-ASCII

Dave Cramer

davec@postgresintl.com
www.postgresintl.com

On 13 October 2015 at 03:42, Chang Chao <charleschung.cn@gmail.com> wrote:

> Hi,all
> The problem I encountered is that,when lc_messages = 'ja_JP.UTF-8' is set
> in postgresql.conf,and initial connection to database server failed(for
> example:user name,password or dbname is misspelled),I see garbled error
> message text in the client .The reason is that,in PGStream
> constrcutor,default encoding of ASCII is
> set(Encoding.getJVMEncoding("US-ASCII")).For the following reasons,maybe
> UTF8 is a better option for default encoding.
>
> 1.When initializing connection ,jdbcclient send client_encoding parameter
> as UTF-8
>  see
> org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(HostSpec[],
> String, String, Properties, Logger)
>
> 2. When initial connection to server completes,jdbc client only receive
> the value for client_encoding as UTF-8
>  see
> org.postgresql.core.v3.ConnectionFactoryImpl.readStartupMessages(PGStream,
> ProtocolConnectionImpl, Logger)
>
> if (name.equals("client_encoding"))
>                 {
>                     if (!value.equals("UTF8"))
>                         throw new PSQLException(GT.tr("Protocol error.
> Session setup failed."), PSQLState.PROTOCOL_VIOLATION);
>
> pgStream.setEncoding(Encoding.getDatabaseEncoding("UTF8"));
>                 }
>
> So there seems no reason to initiate the encoding as US-ASCII.
>
> Best regards.
> Charles.
>
>

^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* UTF8 is a better option than US-ASCII for the default encoding of PGStream
@ 2015-10-13 07:48 Chang Chao <charleschung.cn@gmail.com>
  2015-10-13 08:04 ` Re: UTF8 is a better option than US-ASCII for the default encoding of PGStream Chang Chao <charleschung.cn@gmail.com>
  0 siblings, 1 reply; 5+ messages in thread

From: Chang Chao @ 2015-10-13 07:48 UTC (permalink / raw)
  To: pgsql-jdbc

Hi,all
The problem I encountered is that,when lc_messages = 'ja_JP.UTF-8' is set
in postgresql.conf,and initial connection to database server failed(for
example:user name,password or dbname is misspelled),I see garbled error
message text in the client .The reason is that,in PGStream
constrcutor,default encoding of ASCII is
set(Encoding.getJVMEncoding("US-ASCII")).For the following reasons,maybe
UTF8 is a better option for default encoding.

1.When initializing connection ,jdbcclient send client_encoding parameter
as UTF-8
 see
org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(HostSpec[],
String, String, Properties, Logger)

2. When initial connection to server completes,jdbc client only receive the
value for client_encoding as UTF-8
 see
org.postgresql.core.v3.ConnectionFactoryImpl.readStartupMessages(PGStream,
ProtocolConnectionImpl, Logger)

if (name.equals("client_encoding"))
                {
                    if (!value.equals("UTF8"))
                        throw new PSQLException(GT.tr("Protocol error.
Session setup failed."), PSQLState.PROTOCOL_VIOLATION);

pgStream.setEncoding(Encoding.getDatabaseEncoding("UTF8"));
                }

So there seems no reason to initiate the encoding as US-ASCII.

Best regards.
Chao.

^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: UTF8 is a better option than US-ASCII for the default encoding of PGStream
  2015-10-13 07:48 UTF8 is a better option than US-ASCII for the default encoding of PGStream Chang Chao <charleschung.cn@gmail.com>
@ 2015-10-13 08:04 ` Chang Chao <charleschung.cn@gmail.com>
  2015-10-13 09:18   ` Re: UTF8 is a better option than US-ASCII for the default encoding of PGStream Álvaro Hernández Tortosa <aht@8Kdata.com>
  0 siblings, 1 reply; 5+ messages in thread

From: Chang Chao @ 2015-10-13 08:04 UTC (permalink / raw)
  To: pgsql-jdbc

After some googling,found that the same issue was already discussed before.
http://postgresql.nabble.com/JDBC-Default-Encoding-td2172427.html
So to prevent the error message text garbling,we have to change the value
of lc_messages from  'ja_JP.UTF-8' to "en_US.UTF8"?

On Tue, Oct 13, 2015 at 4:48 PM, Chang Chao <charleschung.cn@gmail.com>
wrote:

> Hi,all
> The problem I encountered is that,when lc_messages = 'ja_JP.UTF-8' is set
> in postgresql.conf,and initial connection to database server failed(for
> example:user name,password or dbname is misspelled),I see garbled error
> message text in the client .The reason is that,in PGStream
> constrcutor,default encoding of ASCII is
> set(Encoding.getJVMEncoding("US-ASCII")).For the following reasons,maybe
> UTF8 is a better option for default encoding.
>
> 1.When initializing connection ,jdbcclient send client_encoding parameter
> as UTF-8
>  see
> org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(HostSpec[],
> String, String, Properties, Logger)
>
> 2. When initial connection to server completes,jdbc client only receive
> the value for client_encoding as UTF-8
>  see
> org.postgresql.core.v3.ConnectionFactoryImpl.readStartupMessages(PGStream,
> ProtocolConnectionImpl, Logger)
>
> if (name.equals("client_encoding"))
>                 {
>                     if (!value.equals("UTF8"))
>                         throw new PSQLException(GT.tr("Protocol error.
> Session setup failed."), PSQLState.PROTOCOL_VIOLATION);
>
> pgStream.setEncoding(Encoding.getDatabaseEncoding("UTF8"));
>                 }
>
> So there seems no reason to initiate the encoding as US-ASCII.
>
> Best regards.
> Chao.
>

^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: UTF8 is a better option than US-ASCII for the default encoding of PGStream
  2015-10-13 07:48 UTF8 is a better option than US-ASCII for the default encoding of PGStream Chang Chao <charleschung.cn@gmail.com>
  2015-10-13 08:04 ` Re: UTF8 is a better option than US-ASCII for the default encoding of PGStream Chang Chao <charleschung.cn@gmail.com>
@ 2015-10-13 09:18   ` Álvaro Hernández Tortosa <aht@8Kdata.com>
  0 siblings, 0 replies; 5+ messages in thread

From: Álvaro Hernández Tortosa @ 2015-10-13 09:18 UTC (permalink / raw)
  To: pgsql-jdbc@postgresql.org, Chang Chao <charleschung.cn@gmail.com>


On 13/10/15 10:04, Chang Chao wrote:
> After some googling,found that the same issue was already discussed 
> before.
> http://postgresql.nabble.com/JDBC-Default-Encoding-td2172427.html
> So to prevent the error message text garbling,we have to change the 
> value of lc_messages from  'ja_JP.UTF-8' to "en_US.UTF8"?

     Hi Chang!

     Based on 
http://www.postgresql.org/message-id/4678.1438350389@sss.pgh.pa.us, what 
I'd say is that the best thing to do should be to send *in the startup 
message*:

- client_encoding:    desired client encoding
- lc_messages: C

     and encode the startup message in US_ASCII (lowest common 
denominator). And of course switch the encoding of further messages if 
server replies (ParameterStatus) with a different encoding (which should 
happen if we sent in StartupMessage a different encoding request).

     Hope this helps. Cheers,

     Álvaro

-- 
Álvaro Hernández Tortosa


-----------
8Kdata



>
> On Tue, Oct 13, 2015 at 4:48 PM, Chang Chao <charleschung.cn@gmail.com 
> <mailto:charleschung.cn@gmail.com>> wrote:
>
>     Hi,all
>     The problem I encountered is that,when lc_messages = 'ja_JP.UTF-8'
>     is set in postgresql.conf,and initial connection to database
>     server failed(for example:user name,password or dbname is
>     misspelled),I see garbled error message text in the client .The
>     reason is that,in PGStream constrcutor,default encoding of ASCII
>     is set(Encoding.getJVMEncoding("US-ASCII")).For the following
>     reasons,maybe UTF8 is a better option for default encoding.
>
>     1.When initializing connection ,jdbcclient send client_encoding
>     parameter as UTF-8
>      see
>     org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(HostSpec[],
>     String, String, Properties, Logger)
>
>     2. When initial connection to server completes,jdbc client only
>     receive the value for client_encoding as UTF-8
>      see
>     org.postgresql.core.v3.ConnectionFactoryImpl.readStartupMessages(PGStream,
>     ProtocolConnectionImpl, Logger)
>
>     if (name.equals("client_encoding"))
>                     {
>                         if (!value.equals("UTF8"))
>     throw new PSQLException(GT.tr("Protocol error. Session setup
>     failed."), PSQLState.PROTOCOL_VIOLATION);
>     pgStream.setEncoding(Encoding.getDatabaseEncoding("UTF8"));
>                     }
>
>     So there seems no reason to initiate the encoding as US-ASCII.
>
>     Best regards.
>     Chao.
>
>

^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2015-10-13 12:34 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2015-10-13 07:42 UTF8 is a better option than US-ASCII for the default encoding of PGStream Chang Chao <charleschung.cn@gmail.com>
2015-10-13 12:34 ` Dave Cramer <pg@fastcrypt.com>
2015-10-13 07:48 UTF8 is a better option than US-ASCII for the default encoding of PGStream Chang Chao <charleschung.cn@gmail.com>
2015-10-13 08:04 ` Chang Chao <charleschung.cn@gmail.com>
2015-10-13 09:18   ` Álvaro Hernández Tortosa <aht@8Kdata.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox