db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r1448278 - in /db/derby/code/trunk/java: client/org/apache/derby/client/am/Utils42.java engine/org/apache/derby/impl/jdbc/Util42.java testing/org/apache/derbyTesting/functionTests/tests/jdbc4/PreparedStatementTest42.java
Date Wed, 20 Feb 2013 16:24:09 GMT
Author: kahatlen
Date: Wed Feb 20 16:24:09 2013
New Revision: 1448278

URL: http://svn.apache.org/r1448278
Log:
DERBY-6081: JDBC 4.2 setObject() and updateObject() methods throw NPE when type is null

Modified:
    db/derby/code/trunk/java/client/org/apache/derby/client/am/Utils42.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/Util42.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/PreparedStatementTest42.java

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/Utils42.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/Utils42.java?rev=1448278&r1=1448277&r2=1448278&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/Utils42.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/Utils42.java Wed Feb 20 16:24:09
2013
@@ -52,7 +52,7 @@ public final class Utils42
             (
              agent.logWriter_,
              new ClientMessageId(SQLState.DATA_TYPE_NOT_SUPPORTED),
-             sqlType.toString()
+             sqlType
              ).getSQLException();
     }
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/Util42.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/Util42.java?rev=1448278&r1=1448277&r2=1448278&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/Util42.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/Util42.java Wed Feb 20 16:24:09
2013
@@ -54,7 +54,7 @@ public class Util42
         }
 
         throw connChild.newSQLException
-            ( SQLState.DATA_TYPE_NOT_SUPPORTED, sqlType.toString() );
+            ( SQLState.DATA_TYPE_NOT_SUPPORTED, sqlType );
     }
     
 }    

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/PreparedStatementTest42.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/PreparedStatementTest42.java?rev=1448278&r1=1448277&r2=1448278&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/PreparedStatementTest42.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/PreparedStatementTest42.java
Wed Feb 20 16:24:09 2013
@@ -21,7 +21,6 @@
 package org.apache.derbyTesting.functionTests.tests.jdbc4;
 
 import java.math.BigDecimal;
-import java.io.Serializable;
 import java.sql.Blob;
 import java.sql.CallableStatement;
 import java.sql.Clob;
@@ -31,6 +30,8 @@ import java.sql.JDBCType;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
+import java.sql.Statement;
 import java.sql.Time;
 import java.sql.Timestamp;
 
@@ -42,6 +43,7 @@ import org.apache.derby.iapi.types.Harmo
 import org.apache.derbyTesting.junit.BaseJDBCTestCase;
 import org.apache.derbyTesting.junit.TestConfiguration;
 import org.apache.derbyTesting.functionTests.tests.lang.Price;
+import org.apache.derbyTesting.junit.JDBC;
 
 /**
  * Tests for new methods added for PreparedStatement in JDBC 4.2.
@@ -231,7 +233,7 @@ public class PreparedStatementTest42 ext
             }
             catch (SQLException se)
             {
-                assertSQLState( "0A000", se );
+                assertSQLState( UNIMPLEMENTED_FEATURE, se );
             }
         }
 
@@ -638,6 +640,73 @@ public class PreparedStatementTest42 ext
         }
     }
 
+    /**
+     * DERBY-6081: Verify that an SQLException is raised if the supplied
+     * SQLType argument is null. It used to fail with a NullPointerException.
+     */
+    public void test_04_targetTypeIsNull() throws SQLException {
+        setAutoCommit(false);
+
+        // Test PreparedStatement.setObject() with targetType == null.
+
+        PreparedStatement ps = prepareStatement("values cast(? as int)");
+
+        try {
+            ps.setObject(1, 1, null);
+            fail("setObject should fail when type is null");
+        } catch (SQLFeatureNotSupportedException se) {
+            assertSQLState(UNIMPLEMENTED_FEATURE, se);
+        }
+
+        try {
+            ps.setObject(1, 1, null, 1);
+            fail("setObject should fail when type is null");
+        } catch (SQLFeatureNotSupportedException se) {
+            assertSQLState(UNIMPLEMENTED_FEATURE, se);
+        }
+
+        // Test ResultSet.updateObject() with targetType == null.
+
+        Statement s = createStatement(
+                ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
+        s.execute("create table t(x int)");
+        s.execute("insert into t values 1");
+
+        ResultSet rs = s.executeQuery("select * from t");
+        assertTrue(rs.next());
+
+        try {
+            rs.updateObject("x", 1, null);
+            fail("updateObject should fail when type is null");
+        } catch (SQLFeatureNotSupportedException se) {
+            assertSQLState(UNIMPLEMENTED_FEATURE, se);
+        }
+
+        try {
+            rs.updateObject(1, 1, null);
+            fail("updateObject should fail when type is null");
+        } catch (SQLFeatureNotSupportedException se) {
+            assertSQLState(UNIMPLEMENTED_FEATURE, se);
+        }
+
+        try {
+            rs.updateObject("x", 1, null, 1);
+            fail("updateObject should fail when type is null");
+        } catch (SQLFeatureNotSupportedException se) {
+            assertSQLState(UNIMPLEMENTED_FEATURE, se);
+        }
+
+        try {
+            rs.updateObject(1, 1, null, 1);
+            fail("updateObject should fail when type is null");
+        } catch (SQLFeatureNotSupportedException se) {
+            assertSQLState(UNIMPLEMENTED_FEATURE, se);
+        }
+
+        // There should be no more rows.
+        JDBC.assertEmpty(rs);
+    }
+
     //////////////////////////////////////////////////////////
     //
     // SQL ROUTINES



Mime
View raw message