X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.192]) by svr1.postgresql.org (Postfix) with ESMTP id 8AAAACCD6F for ; Fri, 18 Jul 2003 17:07:05 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr4.postgresql.org [64.117.224.192]) (amavisd-new, port 10024) with ESMTP id 01467-02 for ; Fri, 18 Jul 2003 17:07:36 +0000 (GMT) Received: from touchme.toronto.redhat.com (to-telus.redhat.com [207.219.125.105]) by svr1.postgresql.org (Postfix) with ESMTP id 6E19ECCD78 for ; Fri, 18 Jul 2003 14:07:03 -0300 (ADT) Received: from topanga.toronto.redhat.com (topanga.toronto.redhat.com [172.16.14.11]) by touchme.toronto.redhat.com (Postfix) with ESMTP id 3D4BE800091; Fri, 18 Jul 2003 13:07:17 -0400 (EDT) Subject: Re: Prepared Statements From: Kim Ho To: Fernando Nasser Cc: Barry Lind , pgsql-jdbc-list In-Reply-To: <3F18259C.6090503@redhat.com> References: <3F174BFF.3070704@xythos.com> <3F1801C5.9030104@openratings.com> <3F181A81.70208@xythos.com> <3F18259C.6090503@redhat.com> Content-Type: multipart/mixed; boundary="=-2cZzvChw5yLayCjPJZ77" X-Mailer: Ximian Evolution 1.0.8 (1.0.8-11) Date: 18 Jul 2003 13:07:17 -0400 Message-Id: <1058548037.19658.159.camel@topanga.toronto.redhat.com> Mime-Version: 1.0 X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200307/141 X-Sequence-Number: 7525 --=-2cZzvChw5yLayCjPJZ77 Content-Type: text/plain Content-Transfer-Encoding: 7bit To speed things up a bit, since the regoutParam patch is not likely to be approved anytime soon. This patch - adds single quotes for numbers in setObject and also setInt/Byte/etc. - Improves getInt/Long when you may have parser errors if you're too close to Integer.MIN_VALUE or Integer.MAX_VALUE. Thanks to Fujitsu. - Improves radix point handling when using setObject to an integer parameter while passing in a float. This is especially important in callable statements. Cheers, Kim On Fri, 2003-07-18 at 12:51, Fernando Nasser wrote: > Barry Lind wrote: > > Dmitry, > > > > That is a bug. Thanks for pointing it out. Anyone care to submit a patch? > > > > Kim's patch fixes this. It is pending approval. > > > > -- > Fernando Nasser > Red Hat Canada Ltd. E-Mail: fnasser@redhat.com > 2323 Yonge Street, Suite #300 > Toronto, Ontario M4P 2C9 > > > ---------------------------(end of broadcast)--------------------------- > TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org --=-2cZzvChw5yLayCjPJZ77 Content-Disposition: attachment; filename=setObjectNumbers.diff Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; name=setObjectNumbers.diff; charset=UTF-8 ? temp.diff Index: org/postgresql/jdbc1/AbstractJdbc1ResultSet.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: /projects/cvsroot/pgsql-server/src/interfaces/jdbc/org/postgresql= /jdbc1/AbstractJdbc1ResultSet.java,v retrieving revision 1.13 diff -c -p -r1.13 AbstractJdbc1ResultSet.java *** org/postgresql/jdbc1/AbstractJdbc1ResultSet.java 30 Jun 2003 21:10:55 -= 0000 1.13 --- org/postgresql/jdbc1/AbstractJdbc1ResultSet.java 18 Jul 2003 17:02:20 -= 0000 *************** public abstract class AbstractJdbc1Resul *** 805,811 **** try { s =3D s.trim(); ! return Integer.parseInt(s); } catch (NumberFormatException e) { --- 805,811 ---- try { s =3D s.trim(); ! return Float.valueOf(s).intValue(); } catch (NumberFormatException e) { *************** public abstract class AbstractJdbc1Resul *** 822,828 **** try { s =3D s.trim();=09=09 ! return Long.parseLong(s); } catch (NumberFormatException e) { --- 822,828 ---- try { s =3D s.trim();=09=09 ! return Double.valueOf(s).longValue(); } catch (NumberFormatException e) { Index: org/postgresql/jdbc1/AbstractJdbc1Statement.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: /projects/cvsroot/pgsql-server/src/interfaces/jdbc/org/postgresql= /jdbc1/AbstractJdbc1Statement.java,v retrieving revision 1.27 diff -c -p -r1.27 AbstractJdbc1Statement.java *** org/postgresql/jdbc1/AbstractJdbc1Statement.java 9 Jul 2003 05:12:04 -0= 000 1.27 --- org/postgresql/jdbc1/AbstractJdbc1Statement.java 18 Jul 2003 17:02:22 -= 0000 *************** public abstract class AbstractJdbc1State *** 920,926 **** */ public void setByte(int parameterIndex, byte x) throws SQLException { ! bind(parameterIndex, Integer.toString(x), PG_TEXT); } =20=20 /* --- 920,926 ---- */ public void setByte(int parameterIndex, byte x) throws SQLException { ! bind(parameterIndex, "'" + Integer.toString(x) + "'", PG_TEXT); } =20=20 /* *************** public abstract class AbstractJdbc1State *** 933,939 **** */ public void setShort(int parameterIndex, short x) throws SQLException { ! bind(parameterIndex, Integer.toString(x), PG_INT2); } =20=20 /* --- 933,939 ---- */ public void setShort(int parameterIndex, short x) throws SQLException { ! bind(parameterIndex, "'" + Integer.toString(x) + "'" , PG_INT2); } =20=20 /* *************** public abstract class AbstractJdbc1State *** 946,952 **** */ public void setInt(int parameterIndex, int x) throws SQLException { ! bind(parameterIndex, Integer.toString(x), PG_INTEGER); } =20=20 /* --- 946,952 ---- */ public void setInt(int parameterIndex, int x) throws SQLException { ! bind(parameterIndex, "'" + Integer.toString(x) + "'", PG_INTEGER); } =20=20 /* *************** public abstract class AbstractJdbc1State *** 959,965 **** */ public void setLong(int parameterIndex, long x) throws SQLException { ! bind(parameterIndex, Long.toString(x), PG_INT8); } =20=20 /* --- 959,965 ---- */ public void setLong(int parameterIndex, long x) throws SQLException { ! bind(parameterIndex, "'" + Long.toString(x) + "'", PG_INT8); } =20=20 /* *************** public abstract class AbstractJdbc1State *** 972,978 **** */ public void setFloat(int parameterIndex, float x) throws SQLException { ! bind(parameterIndex, Float.toString(x), PG_FLOAT); } =20=20 /* --- 972,978 ---- */ public void setFloat(int parameterIndex, float x) throws SQLException { ! bind(parameterIndex, "'" + Float.toString(x) + "'", PG_FLOAT); } =20=20 /* *************** public abstract class AbstractJdbc1State *** 985,991 **** */ public void setDouble(int parameterIndex, double x) throws SQLException { ! bind(parameterIndex, Double.toString(x), PG_DOUBLE); } =20=20 /* --- 985,991 ---- */ public void setDouble(int parameterIndex, double x) throws SQLException { ! bind(parameterIndex, "'" + Double.toString(x) + "'", PG_DOUBLE); } =20=20 /* *************** public abstract class AbstractJdbc1State *** 1003,1009 **** setNull(parameterIndex, Types.DECIMAL); else { ! bind(parameterIndex, x.toString(), PG_NUMERIC); } } =20=20 --- 1003,1009 ---- setNull(parameterIndex, Types.DECIMAL); else { ! bind(parameterIndex, "'" + x.toString() + "'", PG_NUMERIC); } } =20=20 *************** public abstract class AbstractJdbc1State *** 1464,1486 **** switch (targetSqlType) { case Types.INTEGER: - if (x instanceof Boolean) - bind(parameterIndex,((Boolean)x).booleanValue() ? "1" :"0", PG_BOOLE= AN); - else - bind(parameterIndex, x.toString(), PG_INTEGER); - break; case Types.TINYINT: case Types.SMALLINT: case Types.BIGINT: case Types.REAL: case Types.FLOAT: case Types.DOUBLE: case Types.DECIMAL: case Types.NUMERIC: ! if (x instanceof Boolean) ! bind(parameterIndex, ((Boolean)x).booleanValue() ? "1" : "0", PG_BOO= LEAN); ! else ! bind(parameterIndex, x.toString(), PG_NUMERIC); break; case Types.CHAR: case Types.VARCHAR: --- 1464,1484 ---- switch (targetSqlType) { case Types.INTEGER: case Types.TINYINT: case Types.SMALLINT: + x =3D removeRadix(x,Types.INTEGER); + bindNumber(parameterIndex,x,PG_INTEGER); + break; case Types.BIGINT: + x =3D removeRadix(x,Types.BIGINT); + bindNumber(parameterIndex,x,PG_INT8); + break; case Types.REAL: case Types.FLOAT: case Types.DOUBLE: case Types.DECIMAL: case Types.NUMERIC: ! bindNumber(parameterIndex,x,PG_NUMERIC); break; case Types.CHAR: case Types.VARCHAR: *************** public abstract class AbstractJdbc1State *** 2026,2031 **** --- 2024,2056 ---- if (parameterIndex !=3D 1) throw new PSQLException("postgresql.call.noinout"); } +=20=09 + private void bindNumber(int parameterIndex, Object x, String pgtype) thr= ows SQLException + { + if (x instanceof Boolean) + bind(parameterIndex,((Boolean)x).booleanValue() ? "'1'" :"'0'", pgtype= ); + else + bind(parameterIndex, "'"+x.toString()+"'", pgtype); + } +=20=09 +=20 + private Object removeRadix(Object x, int sqlType) + { + if (x.toString().indexOf(".")>0) + { + switch (sqlType) + { + case Types.BIGINT: + x =3D String.valueOf(Double.valueOf(x.toString()).longValue()); + break; + default: + x =3D String.valueOf(Float.valueOf(x.toString()).intValue()); + break; + } + } + return x; + } +=20=09 =20=20 =20=20 =20=20 --=-2cZzvChw5yLayCjPJZ77--