Date: Wednesday, November 30, 2005 @ 15:06:40
  Author: gilles
    Path: /cvsroot/carob/carob

Modified: include/Statement.hpp (1.7 -> 1.8) src/Statement.cpp (1.8 ->
          1.9)

Mirrored implementation of JDBC 3.0 getMoreResults(int) as requested in 
SEQUOIA-227
Fixed cleaning of opened results to not fail on ResultSet closing
Minor javadoc fixes


-----------------------+
 include/Statement.hpp |   49 ++++++++++++++++++++++++++++++++++++++++++
 src/Statement.cpp     |   55 ++++++++++++++++++++++++++++++++++++++++++++----
 2 files changed, 100 insertions(+), 4 deletions(-)


Index: carob/include/Statement.hpp
diff -u carob/include/Statement.hpp:1.7 carob/include/Statement.hpp:1.8
--- carob/include/Statement.hpp:1.7     Fri Nov 25 15:44:03 2005
+++ carob/include/Statement.hpp Wed Nov 30 15:06:40 2005
@@ -27,6 +27,25 @@
 #include "DriverResultSet.hpp"
 #include "RequestWithResultSetParameters.hpp"
 
+/** 
+ * The constant indicating that the current <code>ResultSet</code> object 
+ * should be closed when calling <code>getMoreResults</code>.
+ */
+#define CLOSE_CURRENT_RESULT          1
+
+/**
+ * The constant indicating that the current <code>ResultSet</code> object
+ * should not be closed when calling <code>getMoreResults</code>.
+ */
+#define KEEP_CURRENT_RESULT           2
+
+/**
+ * The constant indicating that all <code>ResultSet</code> objects that
+ * have previously been kept open should be closed when calling
+ * <code>getMoreResults</code>.
+ */
+#define CLOSE_ALL_RESULTS             3
+
 class Connection;
 
 /**
@@ -95,6 +114,29 @@
    */
   bool                    getMoreResults() throw (DriverException, 
SQLException,
                               UnexpectedException);
+  /**
+   * Moves to this <code>Statement</code> object's next result, deals with any
+   * current <code>ResultSet</code> object(s) according to the instructions
+   * specified by the given flag, and returns <code>true</code> if the next
+   * result is a <code>ResultSet</code> object.
+   * <p>
+   * There are no more results when the following is <code>true</code>:
+   * 
+   * <pre>(!getMoreResults() &amp;&amp; (getUpdateCount() == -1)</pre>
+   * 
+   * @param current one of the following <code>Statement</code> constants
+   *          indicating what should happen to current <code>ResultSet</code>
+   *          objects obtained using the method
+   *          <code>getResultSet</code>: <code>CLOSE_CURRENT_RESULT</code>,
+   *          <code>KEEP_CURRENT_RESULT</code>, or 
<code>CLOSE_ALL_RESULTS</code>
+   * @return <code>true</code> if the next result is a <code>ResultSet</code>
+   *         object; <code>false</code> if it is an update count or there are
+   *         no more results
+   * @exception SQLException if a database access error occurs
+   * @see #execute(std::wstring)
+   */
+  bool                    getMoreResults(int current) throw (DriverException,
+                              SQLException, UnexpectedException);
   // GETTERS AND SETTERS
   /**
    * Returns the current result as an update count, if the result is a
@@ -199,6 +241,13 @@
    */
   void                    setEscapeProcessing(bool enable)
                               { escapeProcessing = enable; }
+  /**
+   * In many cases, it is desirable to immediately release a Statement's
+   * database and JDBC resources instead of waiting for this to happen when it
+   * is automatically closed. The close method provides this immediate release.
+   * <p>
+   */
+  void                    close();
 protected:
   /**
    * Constructs a Statement with the given connection. Protected access so that
Index: carob/src/Statement.cpp
diff -u carob/src/Statement.cpp:1.8 carob/src/Statement.cpp:1.9
--- carob/src/Statement.cpp:1.8 Thu Nov 24 15:54:46 2005
+++ carob/src/Statement.cpp     Wed Nov 30 15:06:40 2005
@@ -102,12 +102,46 @@
 bool Statement::getMoreResults() throw (DriverException, SQLException,
     UnexpectedException)
 {
-  if (resultPtr != NULL)
+  return getMoreResults(CLOSE_CURRENT_RESULT);
+}
+
+/**
+ * Moves to this <code>Statement</code> object's next result, deals with any
+ * current <code>ResultSet</code> object(s) according to the instructions
+ * specified by the given flag, and returns <code>true</code> if the next
+ * result is a <code>ResultSet</code> object.
+ * <p>
+ * There are no more results when the following is <code>true</code>:
+ * 
+ * <pre>(!getMoreResults() &amp;&amp; (getUpdateCount() == -1)</pre>
+ * 
+ * @param current one of the following <code>Statement</code> constants
+ *          indicating what should happen to current <code>ResultSet</code>
+ *          objects obtained using the method
+ *          <code>getResultSet</code: <code>CLOSE_CURRENT_RESULT</code>,
+ *          <code>KEEP_CURRENT_RESULT</code>, or <code>CLOSE_ALL_RESULTS</code>
+ * @return <code>true</code> if the next result is a <code>ResultSet</code>
+ *         object; <code>false</code> if it is an update count or there are
+ *         no more results
+ * @exception SQLException if a database access error occurs
+ * @since JDK 1.4
+ * @see #execute(String)
+ */
+bool Statement::getMoreResults(int current) throw (DriverException, 
SQLException,
+    UnexpectedException)
+{
+  if (current != KEEP_CURRENT_RESULT)
   {
-    resultPtr->close();
-    resultPtr = NULL;
+    if (resultPtr != NULL)
+      try
+      {
+        resultPtr->close();
+        resultPtr = NULL;
+      }
+      catch (...) {} //ignore
   }
   updateCount = -1;
+
   ResultSetOrUpdateCount nextResult;
   if (resultListIterator == resultList.end())
   {
@@ -116,7 +150,6 @@
   }
   nextResult = *resultListIterator;
   resultListIterator++;
-
   if (nextResult.isResultSet)
   {
     resultPtr = nextResult.value.resultSetPtr;
@@ -175,3 +208,17 @@
   // this may break fetchSize <= maxRows
   maxRows = max;
 }
+
+void Statement::close()
+{
+  // Force the ResultSet to close
+  if (resultPtr != NULL)
+  {
+    try
+    {
+      resultPtr->close();
+      resultPtr = NULL;
+    }
+    catch (...) {} //ignore
+  }
+}

_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits

Reply via email to