Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 80790105896E for ; Sat, 5 Nov 2011 08:15:09 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 16072-10 for ; Sat, 5 Nov 2011 11:15:03 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0-rc2 Received: from lo.gmane.org (lo.gmane.org [80.91.229.12]) by mail.postgresql.org (Postfix) with ESMTP id 0C2CA105896D for ; Sat, 5 Nov 2011 08:12:32 -0300 (ADT) Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1RMeAm-00053Z-CE for pgsql-jdbc@postgresql.org; Sat, 05 Nov 2011 12:12:28 +0100 Received: from ppp-188-174-94-51.dynamic.mnet-online.de ([188.174.94.51]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 05 Nov 2011 12:12:28 +0100 Received: from spam_eater by ppp-188-174-94-51.dynamic.mnet-online.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 05 Nov 2011 12:12:28 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-jdbc@postgresql.org From: Thomas Kellerer Subject: Encoding for error messages during connect Date: Sat, 05 Nov 2011 12:12:31 +0100 Lines: 37 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 8bit X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: ppp-188-174-94-51.dynamic.mnet-online.de User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.1.21) Gecko/20090302 Thunderbird/2.0.0.21 Mnenhy/0.7.5.666 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-3.1 tagged_above=-10 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, RP_MATCHES_RCVD=-1.201 X-Spam-Level: X-Archive-Number: 201111/8 X-Sequence-Number: 22343 Hi, when the server is set to e.g. lc_messages = 'German_Germany.1252' then error messages during connect are not properly decoded by the driver (or encoded by the server?) At least when the passwort is incorrect the german error message Passwort-Authentifizierung für Benutzer »thomas« fehlgeschlagen is incorrectly received by the driver as Passwort-Authentifizierung f?r Benutzer ?thomas? fehlgeschlagen After debugging the driver I found out that the driver creates the stream for the startup communication using US_ASCII encoding which will yield incorrect characters beyond ASCII 127. I debugged the data that is received from the server and that proofed that the message is received as a single byte encoding. Which seems correct as 'German_Germany.1252' is indeed a single byte encoding. I changed the stream that the driver uses during connect to use a different encoding, by changing org.postgresql.core.v3.ConnectionFactoryImpl and adding the line newStream.setEncoding(Encoding.getDatabaseEncoding("ISO-8859-1")); after Line 77 (where newStream = new PGStream(host, port) is done) And in that case the error message is decoded properly by the driver. Now I don't think it would be possible for the driver to find out which encoding to use for that stream before actually having a connection. So it would need to evaluate some kind of client side information, e.g. the lc_messages environment variable on the client or through a connection property that would then be used to initialize the stream correctly. Personally I'd prefer a connection property (something like "messageEncoding") to control this as this can be part of the JDBC URL which is usually configurable in a Java environment. What do you think? Regards Thomas