X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 603639DCDD8 for ; Fri, 3 Mar 2006 05:22:14 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 06371-04 for ; Fri, 3 Mar 2006 05:22:15 -0400 (AST) X-Greylist: delayed 00:06:37.896153 by SQLgrey- Received: from mail.do.pixelboxx.de (mail.do.pixelboxx.de [213.9.29.34]) by postgresql.org (Postfix) with SMTP id 09D929DC891 for ; Fri, 3 Mar 2006 05:22:11 -0400 (AST) Received: (qmail 10088 invoked from network); 3 Mar 2006 09:15:25 -0000 Received: from unknown (HELO atlantik.do.pixelboxx.de) (10.0.2.142) by 10.0.2.1 with SMTP; 3 Mar 2006 09:15:25 -0000 Received: (qmail 12784 invoked from network); 3 Mar 2006 09:15:32 -0000 Received: from spiekeroog.do.pixelboxx.de (HELO ?10.0.2.21?) (10.0.2.21) by 10.0.7.142 with SMTP; 3 Mar 2006 09:15:32 -0000 Message-ID: <44080934.4030605@pixelboxx.de> Date: Fri, 03 Mar 2006 10:15:32 +0100 From: Eberhard Schulte User-Agent: Mozilla/5.0 (X11; U; Linux i686; de-AT; rv:1.7) Gecko/20040616 X-Accept-Language: de, en MIME-Version: 1.0 To: pgsql-jdbc@postgresql.org Subject: Enhancement: toBoolean() and empty String Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200603/15 X-Sequence-Number: 14796 Hello, I habe two enhancements. I found the problems even in older versions. 1. Encoding.decode() creates for each empty String a new String object. M= emory is wasted unnecessary. Index: Encoding.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/org/postgresql/core/Encoding.j= ava,v retrieving revision 1.21 diff -u -r1.21 Encoding.java --- Encoding.java 4 Jul 2005 02:18:32 -0000 1.21 +++ Encoding.java 3 Mar 2006 08:45:12 -0000 @@ -175,6 +175,10 @@ */ public String decode(byte[] encodedString, int offset, int length) = throws IOException { + if(encodedString =3D=3D null || encodedString.length =3D=3D 0) {= + return ""; // do not create new String() use constant String= + } + if (encoding =3D=3D null) return new String(encodedString, offset, length); 2. AbstractJdbc2ResultSet.toBoolean(): there is no explicite false check.= A false is produced by an NumberFormatException. Index: AbstractJdbc2ResultSet.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/org/postgresql/jdbc2/AbstractJ= dbc2ResultSet.java,v retrieving revision 1.83 diff -u -r1.83 AbstractJdbc2ResultSet.java --- AbstractJdbc2ResultSet.java 4 Dec 2005 21:40:33 -0000 1.83 +++ AbstractJdbc2ResultSet.java 3 Mar 2006 08:54:53 -0000 @@ -2434,22 +2434,28 @@ //----------------- Formatting Methods ------------------- - public static boolean toBoolean(String s) + public static boolean toBoolean(String s) throws PSQLException { if (s !=3D null) { s =3D s.trim(); - if (s.equalsIgnoreCase("true") || s.equalsIgnoreCase("t")) - return true; - + if (s.equalsIgnoreCase("t") || s.equalsIgnoreCase("true")) {= // examine the most frequent case first + return true; + } else if (s.equalsIgnoreCase("f") || s.equalsIgnoreCase("fa= lse")) { // explicite false check + return false; + } + try { if (Double.valueOf(s).doubleValue() =3D=3D 1) return true; + // TODO / FIXME: explicite false check } catch (NumberFormatException e) { + // throw exception if occurs + throw new PSQLException ("postgresql.res.baddouble", PSQ= LState.NUMERIC_VALUE_OUT_OF_RANGE, e); } } return false; // SQL NULL Sch=F6nen Gru=DF Eberhard Schulte