db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r586607 - in /db/derby/code/branches/10.3/java: client/org/apache/derby/client/am/PreparedStatement.java testing/org/apache/derbyTesting/functionTests/tests/derbynet/PrepareStatementTest.java
Date Fri, 19 Oct 2007 20:52:05 GMT
Author: mamta
Date: Fri Oct 19 13:52:05 2007
New Revision: 586607

URL: http://svn.apache.org/viewvc?rev=586607&view=rev
Log:
Migrating changes from trunk(586596) for DERBY-3046 into 10.3 codeline with this commit. The
commit changes for trunk were as follows


This commit fixes the null pointer exception by making sure that we do not try to access the
object's elements if the object is null. I have also added a test case for this fix.

Additionally, while working on this, I found that we return different sql state for parameter
being out of range for PreparedStatment.setObject and Preparedstatement.setXXX calls in Network
Server. I have entered a Jira entry for that issue DERBY-3139.


Modified:
    db/derby/code/branches/10.3/java/client/org/apache/derby/client/am/PreparedStatement.java
    db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/PrepareStatementTest.java

Modified: db/derby/code/branches/10.3/java/client/org/apache/derby/client/am/PreparedStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/client/org/apache/derby/client/am/PreparedStatement.java?rev=586607&r1=586606&r2=586607&view=diff
==============================================================================
--- db/derby/code/branches/10.3/java/client/org/apache/derby/client/am/PreparedStatement.java
(original)
+++ db/derby/code/branches/10.3/java/client/org/apache/derby/client/am/PreparedStatement.java
Fri Oct 19 13:52:05 2007
@@ -2410,10 +2410,16 @@
 
     void checkForValidParameterIndex(int parameterIndex) throws SqlException {
         if (parameterMetaData_ == null || parameterIndex < 1 || parameterIndex > parameterMetaData_.columns_)
{
+        	int totalParameters = 0;
+            if (parameterMetaData_ != null)
+            	//Load totalParmeters with correct number of parameters if 
+            	//ParameterMetaData_ is not null. We will need that in the error
+            	//message.
+            	totalParameters = parameterMetaData_.columns_;
             throw new SqlException(agent_.logWriter_, 
                 new ClientMessageId(SQLState.LANG_INVALID_PARAM_POSITION),
                 new Integer(parameterIndex), 
-                new Integer(parameterMetaData_.columns_));
+                new Integer(totalParameters));
         }
     }
 

Modified: db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/PrepareStatementTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/PrepareStatementTest.java?rev=586607&r1=586606&r2=586607&view=diff
==============================================================================
--- db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/PrepareStatementTest.java
(original)
+++ db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/PrepareStatementTest.java
Fri Oct 19 13:52:05 2007
@@ -1104,6 +1104,57 @@
         st.close();
     }
 
+    /**
+     * A test case for DERBY-3046
+     * We were running into null pointer exception if the parameter count
+     * for PreparedStatement was 0 and the user tried doing setObject
+     * 
+     * @throws Exception
+     */
+    public void testVariationOfSetObject() throws Exception
+    {
+        Statement stmt = createStatement();
+        String createString = "CREATE TABLE WISH_LIST  "
+        	+  "(WISH_ID INT NOT NULL GENERATED ALWAYS AS IDENTITY " 
+        	+  "   CONSTRAINT WISH_PK PRIMARY KEY, " 
+        	+  " ENTRY_DATE TIMESTAMP DEFAULT CURRENT_TIMESTAMP, "
+        	+  " WISH_ITEM VARCHAR(32) NOT NULL) " ;
+        
+        stmt.executeUpdate(createString);
+        PreparedStatement ps = prepareStatement("insert into WISH_LIST(WISH_ITEM) values
(?)");
+        //this won't raise any errors because there is one parameter in ps
+        ps.setString(1, "aaa");
+        ps.executeUpdate();
+        
+        //Negative test case. There are no parameter in the following ps
+        ps = prepareStatement("insert into WISH_LIST(WISH_ITEM) values ('bb')");
+        //Try setString when no parameters in ps
+        try {
+        	ps.setString(1, "aaa");
+            fail("Exception expected above!");
+        } catch (SQLException e)  {  
+        	if (usingDerbyNetClient())
+        		//note that SQLState is XCL14. For setObject below, the 
+        		//SQLState is XCL13. I have entered DERBY-3139 for this
+        		//difference in SQLState.
+        		assertSQLState("XCL14", e);
+        	else
+        		assertSQLState("07009", e);
+        }
+        //Try setObject when no parameters in ps
+        try {
+        	ps.setObject(1,"cc",java.sql.Types.VARCHAR); 
+            fail("Exception expected above!");
+        } catch (SQLException e)  {   
+        	if (usingDerbyNetClient())
+        		//note that SQLState is XCL13. For setString above, the 
+        		//SQLState is XCL14. I have entered DERBY-3139 for this
+        		//difference in SQLState.
+        		assertSQLState("XCL13", e);
+        	else
+        		assertSQLState("07009", e);
+        }
+    }
 
     /**
      * Test two different bugs regarding the handling of large



Mime
View raw message