Author: cbegin
Date: Sun Oct 2 18:43:20 2005
New Revision: 293201
URL: http://svn.apache.org/viewcvs?rev=293201view=rev
Log:
Fixed IBATIS-173 Incorrect resultset retrieve when calling stored procedure
Modified:
ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/execution/SqlExecutor.java
Modified:
ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/execution/SqlExecutor.java
URL:
http://svn.apache.org/viewcvs/ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/execution/SqlExecutor.java?rev=293201r1=293200r2=293201view=diff
==
---
ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/execution/SqlExecutor.java
(original)
+++
ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/execution/SqlExecutor.java
Sun Oct 2 18:43:20 2005
@@ -41,7 +41,7 @@
* Constant to let us know not to skip anything
*/
public static final int NO_SKIPPED_RESULTS = 0;
-
+
/**
* Constant to let us know to include all records
*/
@@ -53,14 +53,14 @@
/**
* Execute an update
- *
+ *
* @param request - the request scope
* @param conn - the database connection
* @param sql - the sql statement to execute
* @param parameters - the parameters for the sql statement
- *
+ *
* @return - the number of records changed
- *
+ *
* @throws SQLException - if the update fails
*/
public int executeUpdate(RequestScope request, Connection conn, String sql,
Object[] parameters)
@@ -93,12 +93,12 @@
/**
* Adds a statement to a batch
- *
+ *
* @param request - the request scope
* @param conn - the database connection
* @param sql - the sql statement
* @param parameters - the parameters for the statement
- *
+ *
* @throws SQLException - if the statement fails
*/
public void addBatch(RequestScope request, Connection conn, String sql,
Object[] parameters)
@@ -113,11 +113,11 @@
/**
* Execute a batch of statements
- *
+ *
* @param session - the session scope
- *
+ *
* @return - the number of rows impacted by the batch
- *
+ *
* @throws SQLException - if a statement fails
*/
public int executeBatch(SessionScope session)
@@ -136,7 +136,7 @@
/**
* Long form of the method to execute a query
- *
+ *
* @param request - the request scope
* @param conn - the database connection
* @param sql - the SQL statement to execute
@@ -144,7 +144,7 @@
* @param skipResults - the number of results to skip
* @param maxResults - the maximum number of results to return
* @param callback - the row handler for the query
- *
+ *
* @throws SQLException - if the query fails
*/
public void executeQuery(RequestScope request, Connection conn, String sql,
Object[] parameters,
@@ -178,7 +178,7 @@
errorContext.setMoreInfo(Check the statement (query failed).);
ps.execute();
- rs = ps.getResultSet();
+ rs = getFirstResultSet(ps);
errorContext.setMoreInfo(Check the results (failed to retrieve
results).);
handleResults(request, rs, skipResults, maxResults, callback);
@@ -198,14 +198,14 @@
/**
* Execute a stored procedure that updates data
- *
+ *
* @param request - the request scope
* @param conn - the database connection
* @param sql - the SQL to call the procedure
* @param parameters - the parameters for the procedure
- *
+ *
* @return - the rows impacted by the procedure
- *
+ *
* @throws SQLException - if the procedure fails
*/
public int executeUpdateProcedure(RequestScope request, Connection conn,
String sql, Object[] parameters)
@@ -247,7 +247,7 @@
/**
* Execute a stored procedure
- *
+ *
* @param request - the request scope
* @param conn - the database connection
* @param sql - the sql to call the procedure
@@ -255,7 +255,7 @@
* @param skipResults - the number of results to skip
* @param maxResults - the maximum number of results to return
* @param callback - a row handler for processing the results
- *
+ *
* @throws SQLException - if the procedure fails
*/
public void executeQueryProcedure(RequestScope request, Connection conn,
String sql, Object[] parameters,
@@ -285,7 +285,7 @@
errorContext.setMoreInfo(Check the statement (update procedure
failed).);
cs.execute();
- rs = cs.getResultSet();
+ rs = getFirstResultSet(cs);
errorContext.setMoreInfo(Check the results (failed to retrieve
results).);
handleResults(request, rs, skipResults, maxResults, callback);
@@ -306,9 +306,29 @@
}
+ private ResultSet getFirstResultSet(Statement stmt) throws SQLException {
+ResultSet rs = null;
+boolean hasMoreResults = true;
+while (hasMoreResults) {
+ rs = stmt.getResultSet();
+ if (rs != null) {
+break;
+ }
+