Bruce,

Here are the patches. I haven't tested them personally, but I did build a jar 
for the guy who asked for it. He downloaded it, and said it worked. The jdbc1 
patch is completely untested. 

They are simple enough that they should work (The little guy on my left 
shoulder is saying sure, sure.... ;) 

Dave



Index: PreparedStatement.java
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/PreparedStatement.java,v
retrieving revision 1.14
diff -c -r1.14 PreparedStatement.java
*** PreparedStatement.java       2001/07/04 15:08:32     1.14
--- PreparedStatement.java       2001/07/12 00:28:30
***************
*** 267,273 ****
         {
          // if the passed string is null, then set this column to null
          if(x==null)
!           set(parameterIndex,"null");
          else {
              // use the shared buffer object. Should never clash but this makes
              // us thread safe!
--- 267,273 ----
         {
          // if the passed string is null, then set this column to null
          if(x==null)
!           setNull(parameterIndex,Types.OTHER);
          else {
              // use the shared buffer object. Should never clash but this makes
              // us thread safe!
***************
*** 323,336 ****
         */
         public void setDate(int parameterIndex, java.sql.Date x) throws SQLException
         {
!           SimpleDateFormat df = (SimpleDateFormat) tl_df.get();
!           if(df==null) {
!             df = new SimpleDateFormat("''yyyy-MM-dd''");
!             tl_df.set(df);
!           }
!
!         set(parameterIndex, df.format(x));

          // The above is how the date should be handled.
          //
          // However, in JDK's prior to 1.1.6 (confirmed with the
--- 323,339 ----
         */
         public void setDate(int parameterIndex, java.sql.Date x) throws SQLException
         {
!                if(null == x){
!                        setNull(parameterIndex,Types.OTHER);
!                }else{
!                SimpleDateFormat df = (SimpleDateFormat) tl_df.get();
!                if(df==null) {
!                df = new SimpleDateFormat("''yyyy-MM-dd''");
!                tl_df.set(df);
!                }

+                       set(parameterIndex, df.format(x));
+                }
          // The above is how the date should be handled.
          //
          // However, in JDK's prior to 1.1.6 (confirmed with the
***************
*** 353,359 ****
         */
         public void setTime(int parameterIndex, Time x) throws SQLException
         {
!                set(parameterIndex, "'" + x.toString() + "'");
         }

         /**
--- 356,366 ----
         */
         public void setTime(int parameterIndex, Time x) throws SQLException
         {
!                if (null == x){
!                        setNull(parameterIndex,Types.OTHER);
!                }else{
!                        set(parameterIndex, "'" + x.toString() + "'");
!                }
         }

         /**
***************
*** 365,371 ****
         * @exception SQLException if a database access error occurs
         */
         public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException
!         {
            SimpleDateFormat df = (SimpleDateFormat) tl_tsdf.get();
            if(df==null) {
              df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
--- 372,381 ----
         * @exception SQLException if a database access error occurs
         */
         public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException
!     {
!                if (null == x){
!                        setNull(parameterIndex,Types.OTHER);
!                }else{
            SimpleDateFormat df = (SimpleDateFormat) tl_tsdf.get();
            if(df==null) {
              df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
***************
*** 383,388 ****
--- 393,399 ----
            // The above works, but so does the following. I'm leaving the above in, but this seems
            // to be identical. Pays to read the docs ;-)
            //set(parameterIndex,"'"+x.toString()+"'");
+                }
         }

         /**
Index: PreparedStatement.java
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/PreparedStatement.java,v
retrieving revision 1.7
diff -c -r1.7 PreparedStatement.java
*** PreparedStatement.java	2001/06/11 22:11:59	1.7
--- PreparedStatement.java	2001/07/12 00:33:51
***************
*** 260,266 ****
  	{
  	  // if the passed string is null, then set this column to null
  	  if(x==null)
! 	    set(parameterIndex,"null");
  	  else {
  	    StringBuffer b = new StringBuffer();
  	    int i;
--- 260,266 ----
  	{
  	  // if the passed string is null, then set this column to null
  	  if(x==null)
! 	    setNull(parameterIndex,Types.OTHER);
  	  else {
  	    StringBuffer b = new StringBuffer();
  	    int i;
***************
*** 312,320 ****
  	 */
  	public void setDate(int parameterIndex, java.sql.Date x) throws SQLException
  	{
!           SimpleDateFormat df = new SimpleDateFormat("''yyyy-MM-dd''");
! 	  set(parameterIndex, df.format(x));
! 
  	  // The above is how the date should be handled.
  	  //
  	  // However, in JDK's prior to 1.1.6 (confirmed with the
--- 312,323 ----
  	 */
  	public void setDate(int parameterIndex, java.sql.Date x) throws SQLException
  	{
! 	  if (null == x){
! 		setNull(parameterIndex,Types.OTHER);
! 	  }else{
!             SimpleDateFormat df = new SimpleDateFormat("''yyyy-MM-dd''");
! 	    set(parameterIndex, df.format(x));
! 	  }
  	  // The above is how the date should be handled.
  	  //
  	  // However, in JDK's prior to 1.1.6 (confirmed with the
***************
*** 337,343 ****
--- 340,350 ----
  	 */
  	public void setTime(int parameterIndex, Time x) throws SQLException
  	{
+ 	  if (null == x){
+ 		setNull(parameterIndex,Types.OTHER);
+ 	  }else{
  		set(parameterIndex, "'" + x.toString() + "'");
+ 	  }
  	}
  
  	/**
***************
*** 350,360 ****
  	 */
  	public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException
          {
!           SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
!           df.setTimeZone(TimeZone.getTimeZone("GMT"));
!           StringBuffer strBuf = new StringBuffer("'");
!           strBuf.append(df.format(x)).append('.').append(x.getNanos()/10000000).append("+00'");
! 	  set(parameterIndex, strBuf.toString());
  	}
  
  	/**
--- 357,371 ----
  	 */
  	public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException
          {
! 	  if (null == x){
! 		setNull(parameterIndex,Types.OTHER);
! 	  }else{
!             SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
!             df.setTimeZone(TimeZone.getTimeZone("GMT"));
!             StringBuffer strBuf = new StringBuffer("'");
!             strBuf.append(df.format(x)).append('.').append(x.getNanos()/10000000).append("+00'");
! 	    set(parameterIndex, strBuf.toString());
! 	  }
  	}
  
  	/**

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://www.postgresql.org/search.mpl

Reply via email to