From df08f5c0030590980a203b72cdfdba817ff95b30 Mon Sep 17 00:00:00 2001 From: Dave Cramer Date: Mon, 30 Jun 2003 21:10:55 +0000 Subject: [PATCH] patches by Kim Ho to fix getByte, getSort if input has decimal or whitespace setObject if object is a BIT boolean not on list of SQLKeywords --- .../jdbc1/AbstractJdbc1Connection.java | 4 ++- .../jdbc1/AbstractJdbc1DatabaseMetaData.java | 2 +- .../jdbc1/AbstractJdbc1ResultSet.java | 36 ++++++++++++++++++- .../jdbc1/AbstractJdbc1Statement.java | 11 ++++-- .../jdbc2/AbstractJdbc2Connection.java | 4 ++- .../jdbc3/AbstractJdbc3Connection.java | 4 ++- 6 files changed, 54 insertions(+), 7 deletions(-) diff --git a/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Connection.java b/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Connection.java index ff465164a1..cfb8e4e897 100644 --- a/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Connection.java +++ b/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Connection.java @@ -9,7 +9,7 @@ * Copyright (c) 2003, PostgreSQL Global Development Group * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Connection.java,v 1.20 2003/05/29 21:44:47 barry Exp $ + * $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Connection.java,v 1.21 2003/06/30 21:10:55 davec Exp $ * *------------------------------------------------------------------------- */ @@ -1740,6 +1740,7 @@ public abstract class AbstractJdbc1Connection implements BaseConnection "varchar", "text", "name", "filename", "bytea", "bool", + "bit", "date", "time", "abstime", "timestamp", "timestamptz" @@ -1764,6 +1765,7 @@ public abstract class AbstractJdbc1Connection implements BaseConnection Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.BINARY, Types.BIT, + Types.BIT, Types.DATE, Types.TIME, Types.TIMESTAMP, Types.TIMESTAMP, Types.TIMESTAMP diff --git a/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1DatabaseMetaData.java b/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1DatabaseMetaData.java index f0b50c1f62..6afee490f0 100644 --- a/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1DatabaseMetaData.java +++ b/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1DatabaseMetaData.java @@ -12,7 +12,7 @@ public abstract class AbstractJdbc1DatabaseMetaData { private static final String keywords = "abort,acl,add,aggregate,append,archive," + - "arch_store,backward,binary,change,cluster," + + "arch_store,backward,binary,boolean,change,cluster," + "copy,database,delimiter,delimiters,do,extend," + "explain,forward,heavy,index,inherits,isnull," + "light,listen,load,merge,nothing,notify," + diff --git a/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1ResultSet.java b/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1ResultSet.java index ee1db017cf..5f10f11046 100644 --- a/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1ResultSet.java +++ b/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1ResultSet.java @@ -9,7 +9,7 @@ * Copyright (c) 2003, PostgreSQL Global Development Group * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1ResultSet.java,v 1.12 2003/05/03 20:40:45 barry Exp $ + * $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1ResultSet.java,v 1.13 2003/06/30 21:10:55 davec Exp $ * *------------------------------------------------------------------------- */ @@ -189,6 +189,19 @@ public abstract class AbstractJdbc1ResultSet implements BaseResultSet { try { + switch(fields[columnIndex-1].getSQLType()) + { + case Types.NUMERIC: + case Types.REAL: + case Types.DOUBLE: + case Types.FLOAT: + case Types.DECIMAL: + s = (s.indexOf(".")==-1) ? s : s.substring(0,s.indexOf(".")); + break; + case Types.CHAR: + s = s.trim(); + break; + } return Byte.parseByte(s); } catch (NumberFormatException e) @@ -207,6 +220,19 @@ public abstract class AbstractJdbc1ResultSet implements BaseResultSet { try { + switch(fields[columnIndex-1].getSQLType()) + { + case Types.NUMERIC: + case Types.REAL: + case Types.DOUBLE: + case Types.FLOAT: + case Types.DECIMAL: + s = (s.indexOf(".")==-1) ? s : s.substring(0,s.indexOf(".")); + break; + case Types.CHAR: + s = s.trim(); + break; + } return Short.parseShort(s); } catch (NumberFormatException e) @@ -778,6 +804,7 @@ public abstract class AbstractJdbc1ResultSet implements BaseResultSet { try { + s = s.trim(); return Integer.parseInt(s); } catch (NumberFormatException e) @@ -794,6 +821,7 @@ public abstract class AbstractJdbc1ResultSet implements BaseResultSet { try { + s = s.trim(); return Long.parseLong(s); } catch (NumberFormatException e) @@ -811,6 +839,7 @@ public abstract class AbstractJdbc1ResultSet implements BaseResultSet { try { + s = s.trim(); val = new BigDecimal(s); } catch (NumberFormatException e) @@ -837,6 +866,7 @@ public abstract class AbstractJdbc1ResultSet implements BaseResultSet { try { + s = s.trim(); return Float.valueOf(s).floatValue(); } catch (NumberFormatException e) @@ -853,6 +883,7 @@ public abstract class AbstractJdbc1ResultSet implements BaseResultSet { try { + s = s.trim(); return Double.valueOf(s).doubleValue(); } catch (NumberFormatException e) @@ -871,6 +902,7 @@ public abstract class AbstractJdbc1ResultSet implements BaseResultSet // length > 10: SQL Timestamp, assumes PGDATESTYLE=ISO try { + s = s.trim(); return java.sql.Date.valueOf((s.length() == 10) ? s : s.substring(0, 10)); } catch (NumberFormatException e) @@ -885,6 +917,7 @@ public abstract class AbstractJdbc1ResultSet implements BaseResultSet return null; // SQL NULL try { + s = s.trim(); if (s.length() == 8) { //value is a time value @@ -952,6 +985,7 @@ public abstract class AbstractJdbc1ResultSet implements BaseResultSet if (s == null) return null; + s = s.trim(); // We must be synchronized here incase more theads access the ResultSet // bad practice but possible. Anyhow this is to protect sbuf and // SimpleDateFormat objects diff --git a/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java b/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java index c3d7af2513..b76bad5578 100644 --- a/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java +++ b/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java @@ -25,7 +25,7 @@ import java.sql.Timestamp; import java.sql.Types; import java.util.Vector; -/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Statement.java,v 1.25 2003/06/30 16:38:30 barry Exp $ +/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Statement.java,v 1.26 2003/06/30 21:10:55 davec Exp $ * This class defines methods of the jdbc1 specification. This class is * extended by org.postgresql.jdbc2.AbstractJdbc2Statement which adds the jdbc2 * methods. The real Statement class (for jdbc1) is org.postgresql.jdbc1.Jdbc1Statement @@ -1464,7 +1464,10 @@ public abstract class AbstractJdbc1Statement implements BaseStatement switch (targetSqlType) { case Types.INTEGER: - bind(parameterIndex, x.toString(), PG_INTEGER); + if (x instanceof Boolean) + bind(parameterIndex,((Boolean)x).booleanValue() ? "1" :"0", PG_BOOLEAN); + else + bind(parameterIndex, x.toString(), PG_INTEGER); break; case Types.TINYINT: case Types.SMALLINT: @@ -1498,6 +1501,10 @@ public abstract class AbstractJdbc1Statement implements BaseStatement { bind(parameterIndex, ((Boolean)x).booleanValue() ? "TRUE" : "FALSE", PG_TEXT); } + else if (x instanceof Number) + { + bind(parameterIndex, ((Number)x).intValue()==1 ? "TRUE" : "FALSE", PG_TEXT); + } else { throw new PSQLException("postgresql.prep.type"); diff --git a/src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2Connection.java b/src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2Connection.java index 2e896c6f1a..0f5150c1f2 100644 --- a/src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2Connection.java +++ b/src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2Connection.java @@ -7,7 +7,7 @@ import java.sql.SQLData; import java.sql.SQLException; import java.sql.Types; -/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/Attic/AbstractJdbc2Connection.java,v 1.5 2003/05/29 04:39:48 barry Exp $ +/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/Attic/AbstractJdbc2Connection.java,v 1.6 2003/06/30 21:10:55 davec Exp $ * This class defines methods of the jdbc2 specification. This class extends * org.postgresql.jdbc1.AbstractJdbc1Connection which provides the jdbc1 * methods. The real Connection class (for jdbc2) is org.postgresql.jdbc2.Jdbc2Connection @@ -126,6 +126,7 @@ public abstract class AbstractJdbc2Connection extends org.postgresql.jdbc1.Abstr "varchar", "text", "name", "filename", "bytea", "bool", + "bit", "date", "time", "abstime", "timestamp", "timestamptz", @@ -154,6 +155,7 @@ public abstract class AbstractJdbc2Connection extends org.postgresql.jdbc1.Abstr Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.BINARY, Types.BIT, + Types.BIT, Types.DATE, Types.TIME, Types.TIMESTAMP, Types.TIMESTAMP, Types.TIMESTAMP, diff --git a/src/interfaces/jdbc/org/postgresql/jdbc3/AbstractJdbc3Connection.java b/src/interfaces/jdbc/org/postgresql/jdbc3/AbstractJdbc3Connection.java index f76eeb6cc4..fd2f62ff05 100644 --- a/src/interfaces/jdbc/org/postgresql/jdbc3/AbstractJdbc3Connection.java +++ b/src/interfaces/jdbc/org/postgresql/jdbc3/AbstractJdbc3Connection.java @@ -2,7 +2,7 @@ package org.postgresql.jdbc3; import java.sql.*; -/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc3/Attic/AbstractJdbc3Connection.java,v 1.3 2003/05/07 03:03:30 barry Exp $ +/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc3/Attic/AbstractJdbc3Connection.java,v 1.4 2003/06/30 21:10:55 davec Exp $ * This class defines methods of the jdbc3 specification. This class extends * org.postgresql.jdbc2.AbstractJdbc2Connection which provides the jdbc2 * methods. The real Connection class (for jdbc3) is org.postgresql.jdbc3.Jdbc3Connection @@ -415,6 +415,7 @@ public abstract class AbstractJdbc3Connection extends org.postgresql.jdbc2.Abstr "varchar", "text", "name", "filename", "bytea", "bool", + "bit", "date", "time", "abstime", "timestamp", "timestamptz", @@ -443,6 +444,7 @@ public abstract class AbstractJdbc3Connection extends org.postgresql.jdbc2.Abstr Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.BINARY, Types.BIT, + Types.BIT, Types.DATE, Types.TIME, Types.TIMESTAMP, Types.TIMESTAMP, Types.TIMESTAMP, -- 2.40.0