Problem:
- Error if user attempts to call:
1. setObject(x,y,java.sql.types.Timestamp) if y is a Date
2. setObject(x,y,java.sql.types.Time) if y is a Timestamp
3. setObject(x,y,java.sql.types.Date) if y is a Timestamp
4. setObject(x,y,java.sql.types.Date/Timestamp/Time) if y is a string
with valid date/timestamp/time format
1 - 3 are causing failures in the JDBC CTS.
Fix:
1. adds 00:00:00.0 as time portion of timestamp
2. substring() to remove date
3. substring() to remove time
4. check for instance of java.sql.types.date/time/timestamp and use
valueOf if necessary
Cheers,
Kim
Index: org/postgresql/jdbc1/AbstractJdbc1Statement.java
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java,v
retrieving revision 1.24
diff -c -p -c -p -r1.24 AbstractJdbc1Statement.java
*** org/postgresql/jdbc1/AbstractJdbc1Statement.java 29 May 2003 04:52:44 -0000 1.24
--- org/postgresql/jdbc1/AbstractJdbc1Statement.java 17 Jun 2003 16:22:27 -0000
*************** public abstract class AbstractJdbc1State
*** 1459,1464 ****
--- 1459,1465 ----
setNull(parameterIndex, targetSqlType);
return ;
}
+ String dateString;
switch (targetSqlType)
{
case Types.INTEGER:
*************** public abstract class AbstractJdbc1State
*** 1483,1494 ****
--- 1484,1501 ----
setString(parameterIndex, x.toString());
break;
case Types.DATE:
+ dateString = (x instanceof java.sql.Timestamp) ? x.toString().substring(0,x.toString().indexOf(" ")) : x.toString();
+ x = (x instanceof java.sql.Date) ? x : java.sql.Date.valueOf(dateString);
setDate(parameterIndex, (java.sql.Date)x);
break;
case Types.TIME:
+ dateString = (x instanceof java.sql.Timestamp) ? x.toString().substring(x.toString().indexOf(" ")+1,x.toString().indexOf(".")) : x.toString();
+ x = (x instanceof java.sql.Time) ? x : java.sql.Time.valueOf(dateString);
setTime(parameterIndex, (Time)x);
break;
case Types.TIMESTAMP:
+ dateString = (x instanceof java.sql.Date) ? x.toString()+" 00:00:00.0" : x.toString();
+ x = (x instanceof java.sql.Timestamp) ? x : java.sql.Timestamp.valueOf(dateString);
setTimestamp(parameterIndex, (Timestamp)x);
break;
case Types.BIT:
---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend