db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From banda...@apache.org
Subject svn commit: r159445 - in incubator/derby/code/trunk/java: engine/org/apache/derby/iapi/types/SQLBlob.java engine/org/apache/derby/iapi/types/SQLTimestamp.java testing/org/apache/derbyTesting/functionTests/master/prepStmtNull.out testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/prepStmtNull.java
Date Tue, 29 Mar 2005 23:08:21 GMT
Author: bandaram
Date: Tue Mar 29 15:08:20 2005
New Revision: 159445

URL: http://svn.apache.org/viewcvs?view=rev&rev=159445
Log:
Derby-174 & Derby-175: Make setNull work with Timestamp and Blob datatypes.

Submitted by Shreyas Kaushik (Shreyas.Kaushik@Sun.COM)

Added:
    incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/prepStmtNull.out
  (with props)
    incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/prepStmtNull.java
  (with props)
Modified:
    incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLBlob.java
    incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLTimestamp.java

Modified: incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLBlob.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLBlob.java?view=diff&r1=159444&r2=159445
==============================================================================
--- incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLBlob.java (original)
+++ incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLBlob.java Tue Mar
29 15:08:20 2005
@@ -46,6 +46,7 @@
 import java.io.IOException;
 import java.sql.ResultSet;
 import java.sql.SQLException;
+import java.sql.PreparedStatement;
 
 /**
  * SQLBlob satisfies the DataValueDescriptor,
@@ -186,4 +187,9 @@
 			return TypeId.BLOB_PRECEDENCE; // not really used
 		}
 
-	}
+    public void setInto(PreparedStatement ps, int position) throws SQLException, StandardException
{
+        ps.setBlob(position,null);    
+    }
+}
+
+

Modified: incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLTimestamp.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLTimestamp.java?view=diff&r1=159444&r2=159445
==============================================================================
--- incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLTimestamp.java (original)
+++ incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLTimestamp.java Tue
Mar 29 15:08:20 2005
@@ -45,12 +45,15 @@
 import org.apache.derby.iapi.types.SQLDouble;
 import org.apache.derby.iapi.types.SQLTime;
 
+
+
 import java.sql.Date;
 import java.sql.Time;
 import java.sql.Timestamp;
 import java.sql.Types;
 import java.sql.ResultSet;
 import java.sql.SQLException;
+import java.sql.PreparedStatement;
 
 import java.util.Calendar;
 import java.util.GregorianCalendar;
@@ -65,7 +68,7 @@
 /**
  * This contains an instance of a SQL Timestamp object.
  * <p>
- * SQLTimestamp is stored in 3 ints - an encoded date, an encoded time and 
+ * SQLTimestamp is stored in 3 ints - an encoded date, an encoded time and
  *		nanoseconds
  * encodedDate = 0 indicates a null WSCTimestamp
  *
@@ -989,5 +992,12 @@
 		currentCal.setTime(value);
 		return SQLTime.computeEncodedTime(currentCal);
 	}
+
+    
+    public void setInto(PreparedStatement ps, int position) throws SQLException, StandardException
{
+
+                  ps.setTimestamp(position, getTimestamp((Calendar) null));
+     }
 }
+
 

Added: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/prepStmtNull.out
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/prepStmtNull.out?view=auto&rev=159445
==============================================================================
--- incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/prepStmtNull.out
(added)
+++ incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/prepStmtNull.out
Tue Mar 29 15:08:20 2005
@@ -0,0 +1,6 @@
+Test prepStmtNull starting
+ResultSet is: work
+ResultSet is: null
+Test prepStmtNull starting
+ResultSet is: blob
+ResultSet is: null

Propchange: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/prepStmtNull.out
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/prepStmtNull.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/prepStmtNull.java?view=auto&rev=159445
==============================================================================
--- incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/prepStmtNull.java
(added)
+++ incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/prepStmtNull.java
Tue Mar 29 15:08:20 2005
@@ -0,0 +1,119 @@
+package org.apache.derbyTesting.functionTests.tests.jdbcapi;
+
+
+import java.sql.*;
+
+import org.apache.derby.tools.ij;
+import org.apache.derby.tools.JDBCDisplayUtil;
+
+public class prepStmtNull {
+
+    public static void main(String[] args) {
+        test1(args);
+        test2(args);
+    }
+    
+        public static void test1(String []args) {   
+                Connection con;
+                ResultSet rs;
+                PreparedStatement stmt = null;
+                PreparedStatement pStmt = null;
+                Statement stmt1 = null;
+
+                System.out.println("Test prepStmtNull starting");
+
+                try
+                {
+                        // use the ij utility to read the property file and
+                        // make the initial connection.
+                        ij.getPropertyArg(args);
+                        con = ij.startJBMS();
+					
+			con.setAutoCommit(false);                        			              
+                        
+                        stmt = con.prepareStatement("create table nullTS(name varchar(10),
ts timestamp)");
+   			stmt.executeUpdate();
+   			con.commit();
+   			
+   			pStmt = con.prepareStatement("insert into nullTS values (?,?)");
+   			   			
+   			pStmt.setString(1,"work");
+			pStmt.setNull(2,java.sql.Types.TIMESTAMP);
+			pStmt.addBatch();
+
+		
+			pStmt.executeBatch();
+			con.commit();
+
+			stmt1 = con.createStatement();
+		        rs = stmt1.executeQuery("select * from nullTS");
+			while(rs.next()) {
+			   System.out.println("ResultSet is: "+rs.getObject(1));
+			   System.out.println("ResultSet is: "+rs.getObject(2));
+			}
+ 		} catch(SQLException sqle) {
+ 		   dumpSQLExceptions(sqle);
+ 		   sqle.printStackTrace();
+ 		} catch(Throwable e) {
+ 		   System.out.println("FAIL -- unexpected exception: "+e);
+                   e.printStackTrace();
+
+ 		}
+     }
+     
+     public static void test2(String []args) {   
+                Connection con;
+                ResultSet rs;
+                PreparedStatement stmt = null;
+                PreparedStatement pStmt = null;
+                Statement stmt1 = null;
+
+                System.out.println("Test prepStmtNull starting");
+
+                try
+                {
+                        // use the ij utility to read the property file and
+                        // make the initial connection.
+                        ij.getPropertyArg(args);
+                        con = ij.startJBMS();
+					
+			con.setAutoCommit(false);                        			              
+                        
+                        stmt = con.prepareStatement("create table nullBlob(name varchar(10),
bval blob(16K))");
+   			stmt.executeUpdate();
+   			con.commit();
+   			
+   			pStmt = con.prepareStatement("insert into nullBlob values (?,?)");
+   			   			
+   			pStmt.setString(1,"blob");
+			pStmt.setNull(2,java.sql.Types.BLOB);
+			pStmt.addBatch();
+
+		
+			pStmt.executeBatch();
+			con.commit();
+
+			stmt1 = con.createStatement();
+		        rs = stmt1.executeQuery("select * from nullBlob");
+			while(rs.next()) {
+			   System.out.println("ResultSet is: "+rs.getObject(1));
+			   System.out.println("ResultSet is: "+rs.getObject(2));
+			}
+ 		} catch(SQLException sqle) {
+ 		   dumpSQLExceptions(sqle);
+ 		   sqle.printStackTrace();
+ 		} catch(Throwable e) {
+ 		   System.out.println("FAIL -- unexpected exception: "+e);
+                   e.printStackTrace();
+
+ 		}
+     }
+     
+     static private void dumpSQLExceptions (SQLException se) {
+                System.out.println("FAIL -- unexpected exception");
+                while (se != null) {
+                        System.out.println("SQLSTATE("+se.getSQLState()+"): "+se);
+                        se = se.getNextException();
+                }
+        }
+}     

Propchange: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/prepStmtNull.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message