X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id A38BD9FA32D for ; Wed, 17 May 2006 09:07:05 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 90755-03 for ; Wed, 17 May 2006 09:06:56 -0300 (ADT) X-Greylist: delayed 00:06:38.996593 by SQLgrey- Received: from iplocks.co.jp (iplocks.co.jp [211.19.47.137]) by postgresql.org (Postfix) with SMTP id 9BE259F9C18 for ; Wed, 17 May 2006 09:06:55 -0300 (ADT) Received: (qmail 17969 invoked from network); 17 May 2006 20:59:52 +0900 Received: from unknown (HELO ebihara) (216.132.219.66) by iplocks.co.jp with SMTP; 17 May 2006 20:59:52 +0900 From: "EBIHARA, Yuichiro" To: Subject: how to handle data containing '\0' Date: Wed, 17 May 2006 21:01:30 +0900 Message-ID: <001f01c679a9$a3627350$360aa8c0@ipljp.local> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook, Build 10.0.6626 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2869 Importance: Normal X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200605/70 X-Sequence-Number: 15198 Hi experts, I need to handle String data containing '\0' in my Java + JDBC program. = Such data can happen at other systems and be sent to PostgreSQL. Here is a sample to simulate it in Java code. char c =3D '\0'; String val =3D "abc" + c + "def"; Now I have to support two versions of drivers, 7.4 and 8.1, but the = behavior of driver depends on versions when I insert this String value. =3D=3D=3D pg74.216.jdbc3.jar =3D=3D=3D java.lang.IllegalArgumentException: \0 not allowed at = org.postgresql.jdbc1.AbstractJdbc1Statement.escapeString(AbstractJdbc1Sta= tement.java:1152) at = org.postgresql.jdbc1.AbstractJdbc1Statement.setString(AbstractJdbc1Statem= ent.java:1133) at = org.postgresql.jdbc1.AbstractJdbc1Statement.setString(AbstractJdbc1Statem= ent.java:1116) at Bug5391.main(Bug5391.java:24) =3D=3D=3D postgresql-8.1-405.jdbc3.jar =3D=3D=3D Successfully finished without exception but the string is truncated at = '\0' and only the first three characters, "abc", is inserted. (I verified this with psql on the server side) I understand the current protocol does not allow '\0' in String and = basically I should remove '\0' before I try to insert but I and team members may forget it somewhere. I'm feeling the 8.1 behavior is = worse than 7.4 because user data is truncated without notice. For the sample above, I expect "abcdef" rather than "abc". What do you think about this? My idea is to introduce new connection parameter to determine how to = behave against '\0'. Options may be - throws an exception - truncates at '\0' - removes '\0' Thanks, ebi