X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 6C3BDD1B178 for ; Thu, 15 Jul 2004 13:30:58 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 43377-09 for ; Thu, 15 Jul 2004 16:30:49 +0000 (GMT) Received: from mail.svhost.com.ar (mail.svhost.com.ar [200.80.239.22]) by svr1.postgresql.org (Postfix) with ESMTP id 9EE26D1B16E for ; Thu, 15 Jul 2004 13:30:47 -0300 (ADT) Received: from sistemat.com.ar (devel.sistemat.com.ar [192.168.1.40]) by mail.svhost.com.ar (Postfix) with ESMTP id E7B3139BCF; Thu, 15 Jul 2004 13:29:10 -0300 (ART) Message-ID: <40F6B35E.4010600@sistemat.com.ar> Date: Thu, 15 Jul 2004 13:39:58 -0300 From: "Dario V. Fassi" Organization: SISTEMATICA ingenieria de software srl User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax) X-Accept-Language: es, es-ar, en-us, en MIME-Version: 1.0 To: Tom Lane Cc: Oliver Jowett , "pgsql-jdbc@postgresql.org" Subject: Re: Very strange Error in Updates References: <40F6172D.10301@sistemat.com.ar> <40F619A0.8030506@opencloud.com> <40F61CC2.5030704@sistemat.com.ar> <40F61F0E.6020907@opencloud.com> <20559.1089900977@sss.pgh.pa.us> In-Reply-To: <20559.1089900977@sss.pgh.pa.us> Content-Type: multipart/alternative; boundary="------------050704030607060404040803" X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.5 tagged_above=0.0 required=5.0 tests=HTML_MESSAGE, HTML_TITLE_EMPTY X-Spam-Level: X-Archive-Number: 200407/188 X-Sequence-Number: 10572 This is a multi-part message in MIME format. --------------050704030607060404040803 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit My problem it's that the data is just inside the postgresql server (with SQL_ASCII encoding), inserted by Win32/ODBC clients. Now from JDBC I can't handle any row with any field that has one o more 8 bits characters. At same time , Win32/ODBC programs continue to use it without any problem. This situation let me in a hard to explain situation. One more question, using the PreparedStatement.setBytes() , can be done the treatment that ODBC does with that fields ? Thanks all for your help. Dario. Tom Lane wrote: >Oliver Jowett writes: > > >>The JDBC driver always speaks UNICODE when it can, since that matches >>Java's internal string representation. I suspect that what's happening is: >> >> >>0) the driver sets client_encoding = UNICODE during connection setup >> >> >Right. > > >>1) the driver encodes the parameter as UNICODE (== UTF8); for characters >>above 127 this encoding will result in more than one byte per character. >> >> > >Right. > > >>2) the server converts from client_encoding UNICODE to database encoding >>SQL_ASCII; for characters that are invalid in SQL_ASCII (>127) it does >>some arbitary conversion, probably just copying the illegal values >>unchanged. >> >> > >Not really. SQL_ASCII encoding basically means "we don't know what this >data is, just store it verbatim". So the UTF-8 string sent by the >driver is stored verbatim. > > >>3) you end up with extra characters in the resulting value which exceeds >>the varchar's size. >> >> > >Right. Since the server does not know what encoding is in use, it falls >back to the assumption that 1 character == 1 byte, under which >assumption the string violates the varchar(30) constraint. > >Had the server known which encoding was in use, it would have counted >the characters correctly. > > >>The solution is to use a database encoding that matches your data. >> >> > >Actually, if you intend to access the database primarily through JDBC, >it'd be best to use server encoding UNICODE. The JDBC driver will >always want UNICODE on the wire, and I see no reason to force extra >character set conversions. Non-UNICODE-aware clients can be handled by >setting client_encoding properly. > > regards, tom lane > > --------------050704030607060404040803 Content-Type: text/html; charset=us-ascii Content-Transfer-Encoding: 7bit
My problem it's that the data is just inside the postgresql server (with SQL_ASCII encoding), inserted by Win32/ODBC clients.

Now from JDBC I can't handle any row with any field that has one o more 8 bits characters.
At same time , Win32/ODBC programs continue to use it without any problem.
This situation let me in a hard to explain situation.

One more question, using the PreparedStatement.setBytes() , can be done the treatment that ODBC does with that fields ?
Thanks all for your help.
Dario.

Tom Lane wrote:
Oliver Jowett <oliver@opencloud.com> writes:
  
The JDBC driver always speaks UNICODE when it can, since that matches 
Java's internal string representation. I suspect that what's happening is:
    
0) the driver sets client_encoding = UNICODE during connection setup
    
Right.
  
1) the driver encodes the parameter as UNICODE (== UTF8); for characters 
above 127 this encoding will result in more than one byte per character.
    

Right.
  
2) the server converts from client_encoding UNICODE to database encoding 
SQL_ASCII; for characters that are invalid in SQL_ASCII (>127) it does 
some arbitary conversion, probably just copying the illegal values 
unchanged.
    

Not really.  SQL_ASCII encoding basically means "we don't know what this
data is, just store it verbatim".  So the UTF-8 string sent by the
driver is stored verbatim.
  
3) you end up with extra characters in the resulting value which exceeds 
the varchar's size.
    

Right.  Since the server does not know what encoding is in use, it falls
back to the assumption that 1 character == 1 byte, under which
assumption the string violates the varchar(30) constraint.

Had the server known which encoding was in use, it would have counted
the characters correctly.
  
The solution is to use a database encoding that matches your data.
    

Actually, if you intend to access the database primarily through JDBC,
it'd be best to use server encoding UNICODE.  The JDBC driver will
always want UNICODE on the wire, and I see no reason to force extra
character set conversions.  Non-UNICODE-aware clients can be handled by
setting client_encoding properly.

			regards, tom lane
  

--------------050704030607060404040803--