diff options
author | Marc G. Fournier <scrappy@hub.org> | 1998-06-03 19:43:29 +0000 |
---|---|---|
committer | Marc G. Fournier <scrappy@hub.org> | 1998-06-03 19:43:29 +0000 |
commit | 85f91d0e8e2fa996a2c7ec629037387e1a9cfd88 (patch) | |
tree | 123c0ee674a4d2016996785a580ec598f0cefe9f /src/interfaces/jdbc/postgresql/PreparedStatement.java | |
parent | 9142e54e7351c744e92b261f9d77c2d3b85c2653 (diff) |
From: Peter T Mount <patches@maidast.demon.co.uk>
Bug fixes:
PreparedStatement.setObject didn't handle short's
ResultSet.getDate() now handles null dates (returns null rather
than a NullPointerException)
ResultSetMetaData.getPrecision() now returns 0 for VARCHAR
New features:
Field now caches the typename->oid in a Hashtable to speed things
up. It removes the need for some unnecessary queries to the
backend.
PreparedStatement.toString() now returns the sql statement that
it will send to the backend. Before it did nothing.
DatabaseMetaData.getTypeInfo() now does something.
Diffstat (limited to 'src/interfaces/jdbc/postgresql/PreparedStatement.java')
-rw-r--r-- | src/interfaces/jdbc/postgresql/PreparedStatement.java | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/src/interfaces/jdbc/postgresql/PreparedStatement.java b/src/interfaces/jdbc/postgresql/PreparedStatement.java index 1f82314e115..86121c57347 100644 --- a/src/interfaces/jdbc/postgresql/PreparedStatement.java +++ b/src/interfaces/jdbc/postgresql/PreparedStatement.java @@ -492,13 +492,21 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta { setObject(parameterIndex, x, targetSqlType, 0); } - + + /** + * This stores an Object into a parameter. + * <p>New for 6.4, if the object is not recognised, but it is + * Serializable, then the object is serialised using the + * postgresql.util.Serialize class. + */ public void setObject(int parameterIndex, Object x) throws SQLException { if (x instanceof String) setString(parameterIndex, (String)x); else if (x instanceof BigDecimal) setBigDecimal(parameterIndex, (BigDecimal)x); + else if (x instanceof Short) + setShort(parameterIndex, ((Short)x).shortValue()); else if (x instanceof Integer) setInt(parameterIndex, ((Integer)x).intValue()); else if (x instanceof Long) @@ -520,7 +528,7 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta else if (x instanceof PGobject) setString(parameterIndex, ((PGobject)x).getValue()); else - throw new SQLException("Unknown object type"); + setLong(parameterIndex, connection.putObject(x)); } /** @@ -548,6 +556,26 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta return super.execute(s.toString()); // in Statement class } + /** + * Returns the SQL statement with the current template values + * substituted. + */ + public String toString() { + StringBuffer s = new StringBuffer(); + int i; + + for (i = 0 ; i < inStrings.length ; ++i) + { + if (inStrings[i] == null) + s.append( '?' ); + else + s.append (templateStrings[i]); + s.append (inStrings[i]); + } + s.append(templateStrings[inStrings.length]); + return s.toString(); + } + // ************************************************************** // END OF PUBLIC INTERFACE // ************************************************************** |