db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r414795 - in /db/derby/code/trunk/java: engine/org/apache/derby/iapi/sql/ engine/org/apache/derby/impl/jdbc/ engine/org/apache/derby/impl/sql/ engine/org/apache/derby/impl/sql/execute/ testing/org/apache/derbyTesting/functionTests/suites/
Date Fri, 16 Jun 2006 10:17:15 GMT
Author: kahatlen
Date: Fri Jun 16 03:17:14 2006
New Revision: 414795

URL: http://svn.apache.org/viewvc?rev=414795&view=rev
Log:
DERBY-501: Client and embedded drivers differ on invoking a procedure
that returns a single Dynamic resultSet using CallableStatement.executeQuery()

This patch modifies EmbedStatement.processDynamicResults() so that it
returns the number of dynamic results instead of a
boolean. EmbedStatement.executeStatement() uses this number to decide
whether an exception is to be raised. With this change, the
executeQuery and executeUpdate parameters are no longer needed in
GenericPreparedStatement.execute().

ProcedureTest.junit is now enabled in derbyall (all frameworks). Seven
of the test cases run in the embedded framework only, but I expect all
of them to succeed with the client driver after DERBY-1314 and
DERBY-1364 have been fixed.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/PreparedStatement.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedStatement.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/GenericPreparedStatement.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/GenericTriggerExecutor.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbcapi.runall

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/PreparedStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/PreparedStatement.java?rev=414795&r1=414794&r2=414795&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/PreparedStatement.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/PreparedStatement.java Fri Jun
16 03:17:14 2006
@@ -101,8 +101,6 @@
 	 *
 	 * @param activation The activation containing all the local state
 	 *		to execute the plan.
-	 * @param executeQuery		Whether or not called from a Statement.executeQuery()
-	 * @param executeUpdate	Whether or not called from a Statement.executeUpdate()
  	 * @param rollbackParentContext True if 1) the statement context is
 	 *  NOT a top-level context, AND 2) in the event of a statement-level
 	 *	 exception, the parent context needs to be rolled back, too.
@@ -116,8 +114,6 @@
 	 * @exception StandardException		Thrown on failure
 	 */
     ResultSet execute(Activation activation,
-                      boolean executeQuery,
-                      boolean executeUpdate,
                       boolean rollbackParentContext,
                       long timeoutMillis)
         throws StandardException;

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java?rev=414795&r1=414794&r2=414795&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java Fri Jun
16 03:17:14 2006
@@ -3485,7 +3485,7 @@
                 // Don't see any timeout when inserting rows (use 0)
                 //execute the insert
                 org.apache.derby.iapi.sql.ResultSet rs = 
-                        ps.execute(act, false, true, true, 0L); 
+                        ps.execute(act, true, 0L); 
                 rs.close();
                 rs.finish();
 
@@ -3556,7 +3556,8 @@
                     act.getParameterValueSet().getParameterForSet(paramPosition++).setValue(updateRow.getColumn(i));
             }
             // Don't set any timeout when updating rows (use 0)
-            org.apache.derby.iapi.sql.ResultSet rs = ps.execute(act, false, true, true, 0L);
//execute the update where current of sql
+            // Execute the update where current of sql.
+            org.apache.derby.iapi.sql.ResultSet rs = ps.execute(act, true, 0L);
             SQLWarning w = act.getWarnings();
             if (w != null) {
                 addWarning(w);
@@ -3616,7 +3617,7 @@
                 // Don't set any timeout when deleting rows (use 0)
                 //execute delete where current of sql
                 org.apache.derby.iapi.sql.ResultSet rs = 
-                        ps.execute(act, false, true, true, 0L);
+                        ps.execute(act, true, 0L);
                 SQLWarning w = act.getWarnings();
                 if (w != null) {
                     addWarning(w);

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedStatement.java?rev=414795&r1=414794&r2=414795&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedStatement.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedStatement.java Fri Jun
16 03:17:14 2006
@@ -1179,14 +1179,20 @@
 				a.setMaxRows(maxRows);
                 long timeoutMillis = (long)timeoutSeconds * 1000L;
                 ResultSet resultsToWrap = ps.execute(a,
-                                                     executeQuery,
-                                                     executeUpdate,
                                                      false,
                                                      timeoutMillis);
 				addWarning(a.getWarnings());
 
 
 				if (resultsToWrap.returnsRows()) {
+
+                    // The statement returns rows, so calling it with
+                    // executeUpdate() is not allowed.
+                    if (executeUpdate) {
+                        throw StandardException.newException(
+                                SQLState.LANG_INVALID_CALL_TO_EXECUTE_UPDATE);
+                    }
+
 					EmbedResultSet lresults = factory.newEmbedResultSet(getEmbedConnection(), resultsToWrap,
forMetaData, this, ps.isAtomic());
 					results = lresults;
 
@@ -1217,12 +1223,28 @@
 					resultsToWrap.finish();	// Don't need the result set any more
 					results = null; // note that we have none.
 
-					boolean haveDynamicResults = false;
+                    int dynamicResultCount = 0;
 					if (a.getDynamicResults() != null) {
-						haveDynamicResults = processDynamicResults(a.getDynamicResults(), a.getMaxDynamicResults());
+                        dynamicResultCount =
+                            processDynamicResults(a.getDynamicResults(),
+                                                  a.getMaxDynamicResults());
 					}
+
+                    // executeQuery() is not allowed if the statement
+                    // doesn't return exactly one ResultSet.
+                    if (executeQuery && dynamicResultCount != 1) {
+                        throw StandardException.newException(
+                                SQLState.LANG_INVALID_CALL_TO_EXECUTE_QUERY);
+                    }
+
+                    // executeUpdate() is not allowed if the statement
+                    // returns ResultSets.
+                    if (executeUpdate && dynamicResultCount > 0) {
+                        throw StandardException.newException(
+                                SQLState.LANG_INVALID_CALL_TO_EXECUTE_UPDATE);
+                    }
 					
-					if (!haveDynamicResults) {
+                    if (dynamicResultCount == 0) {
 						if (a.isSingleExecution()) {
 							a.close();
 						}
@@ -1240,7 +1262,7 @@
 						}
 					}
 
-					retval = haveDynamicResults;
+                    retval = (dynamicResultCount > 0);
 				}
 	        } catch (Throwable t) {
 				if (a.isSingleExecution()) {
@@ -1446,7 +1468,22 @@
 
 	private EmbedResultSet[] dynamicResults;
 	private int currentDynamicResultSet;
-	private boolean processDynamicResults(java.sql.ResultSet[][] holder, int maxDynamicResultSets)
throws SQLException {
+
+    /**
+     * Go through a holder of dynamic result sets, remove those that
+     * should not be returned, and sort the result sets according to
+     * their creation.
+     *
+     * @param holder a holder of dynamic result sets
+     * @param maxDynamicResultSets the maximum number of result sets
+     * to be returned
+     * @return the actual number of result sets
+     * @exception SQLException if an error occurs
+     */
+    private int processDynamicResults(java.sql.ResultSet[][] holder,
+                                      int maxDynamicResultSets)
+        throws SQLException
+    {
 
 		EmbedResultSet[] sorted = new EmbedResultSet[holder.length];
 
@@ -1505,12 +1542,10 @@
 
 			// 0100C is not returned for procedures written in Java, from the SQL2003 spec.
 			// getWarnings(StandardException.newWarning(SQLState.LANG_DYNAMIC_RESULTS_RETURNED));
-
-			return true;
 		}
 
 
-		return false;
+		return actualCount;
 	}
 
 	/**

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/GenericPreparedStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/GenericPreparedStatement.java?rev=414795&r1=414794&r2=414795&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/GenericPreparedStatement.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/GenericPreparedStatement.java
Fri Jun 16 03:17:14 2006
@@ -237,15 +237,13 @@
 	{
 		Activation a = getActivation(lcc, false);
 		a.setSingleExecution();
-		return execute(a, false, false, rollbackParentContext, timeoutMillis);
+		return execute(a, rollbackParentContext, timeoutMillis);
 	}
 
 	/**
 	  *	The guts of execution.
 	  *
 	  *	@param	activation					the activation to run.
-	  * @param	executeQuery				Called via executeQuery
-	  * @param	executeUpdate				Called via executeUpdate
 	  * @param rollbackParentContext True if 1) the statement context is
 	  *  NOT a top-level context, AND 2) in the event of a statement-level
 	  *	 exception, the parent context needs to be rolled back, too.
@@ -256,8 +254,6 @@
 	  */
 
     public ResultSet execute(Activation activation,
-                             boolean executeQuery,
-                             boolean executeUpdate,
                              boolean rollbackParentContext,
                              long timeoutMillis)
         throws
@@ -388,24 +384,6 @@
 				activation.close();
 			}
 
-
-			/* executeQuery() not allowed on statements
-			 * that return a row count,
-			 * executeUpdate() not allowed on statements
-			 * that return a ResultSet.
-			 * We need to do the test here so that any
-			 * exeception will rollback to the statement
-			 * savepoint.
-			 */
-			if ( (! resultSet.returnsRows()) && executeQuery)
-			{
-				throw StandardException.newException(SQLState.LANG_INVALID_CALL_TO_EXECUTE_QUERY);
-			}
-
-			if ( resultSet.returnsRows() && executeUpdate)
-			{
-				throw StandardException.newException(SQLState.LANG_INVALID_CALL_TO_EXECUTE_UPDATE);
-			}
 			return resultSet;
 			
 		}

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/GenericTriggerExecutor.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/GenericTriggerExecutor.java?rev=414795&r1=414794&r2=414795&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/GenericTriggerExecutor.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/GenericTriggerExecutor.java
Fri Jun 16 03:17:14 2006
@@ -166,7 +166,7 @@
                 // This is a substatement; for now, we do not set any timeout
                 // for it. We might change this behaviour later, by linking
                 // timeout to its parent statement's timeout settings.
-				ResultSet rs = ps.execute(spsActivation, false, false, false, 0L);
+                ResultSet rs = ps.execute(spsActivation, false, 0L);
                 if( rs.returnsRows())
                 {
                     // Fetch all the data to ensure that functions in the select list or
values statement will

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbcapi.runall
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbcapi.runall?rev=414795&r1=414794&r2=414795&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbcapi.runall
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbcapi.runall
Fri Jun 16 03:17:14 2006
@@ -15,6 +15,7 @@
 jdbcapi/LOBTest.java
 jdbcapi/blobclob4BLOB.java
 jdbcapi/parameterMapping.java
+jdbcapi/ProcedureTest.junit
 jdbcapi/setTransactionIsolation.java
 jdbcapi/SetQueryTimeoutTest.java
 jdbcapi/prepStmtNull.java



Mime
View raw message