Date: Wednesday, July 5, 2006 @ 09:26:05
  Author: gilles
    Path: /cvsroot/carob/carob

Modified: include/Connection.hpp (1.69 -> 1.70)
          include/DriverResultSet.hpp (1.42 -> 1.43) include/Statement.hpp
          (1.42 -> 1.43) src/Connection.cpp (1.78 -> 1.79)
          src/DriverResultSet.cpp (1.56 -> 1.57) src/Statement.cpp (1.29
          -> 1.30)

Throw exception when calling getWarning on closed Statement or ResultSet
Added Connection getWarnings() and clearWarnings() (new protocol 6.1)


-----------------------------+
 include/Connection.hpp      |   26 ++++++++++++++++++++++--
 include/DriverResultSet.hpp |    3 +-
 include/Statement.hpp       |    3 +-
 src/Connection.cpp          |   44 ++++++++++++++++++++++++++++++++++++++++++
 src/DriverResultSet.cpp     |    6 +++++
 src/Statement.cpp           |    9 ++++++++
 6 files changed, 87 insertions(+), 4 deletions(-)


Index: carob/include/Connection.hpp
diff -u carob/include/Connection.hpp:1.69 carob/include/Connection.hpp:1.70
--- carob/include/Connection.hpp:1.69   Wed Jun 28 17:54:48 2006
+++ carob/include/Connection.hpp        Wed Jul  5 09:26:05 2006
@@ -33,7 +33,7 @@
 
 namespace {
 const int32_t ProtocolVersion = (static_cast<int32_t>(6) /* major */ << 16)
-                                                    + 0 /* minor */;
+                                                    + 1 /* minor */;
 }
 
 namespace CarobNS {
@@ -74,6 +74,8 @@
 //#define ConnectionGetCatalogs                   37
 //#define ConnectionSetCatalog                    38
 //#define SetTransactionIsolation                 39
+#define ConnectionGetWarnings                   40
+#define ConnectionClearWarnings                 41
 //#define GetVirtualDatabaseName                  50
 //#define GetControllerVersionNumber              51
 //#define DatabaseMetaDataGetTables               52
@@ -342,12 +344,28 @@
    * the metadata).
    * @param sqlTemplate sql template of the PreparedStatement
    */
-  DriverResultSet*  preparedStatementGetMetaData(const std::wstring 
&sqlTemplate)
+  DriverResultSet*  preparedStatementGetMetaData(const std::wstring& 
sqlTemplate)
                           throw (SocketIOException, BackendException,
                           ProtocolException, ControllerException,
                           NotImplementedException, ConnectionException,
                           UnexpectedException);
   /**
+   * Returns the first warning reported by calls on this connection. Subsequent
+   * warnings will be chained to this SQLWarning<br>
+   * <B>Note: </B> If the 'persistent connections' option is set to false, this
+   * function will always return null.
+   * 
+   * @return the first SQLWarning or null
+   * @exception DriverException if a database access error occurs or this 
method is
+   *              called on a closed connection
+   */
+  SQLWarning*       getWarnings() throw (DriverException, UnexpectedException);
+  /**
+   * After this call, <code>getWarnings()</code> returns <code>null</code>
+   * until a new call to getWarnings() on this connection.
+   */
+  void              clearWarnings() throw (DriverException, 
UnexpectedException);
+  /**
    * Utility function to convert the given chain of backendException to a chain
    * of SQLWarnings
    * 
@@ -454,6 +472,8 @@
   int64_t             persistent_connection_id;
   /** True if the controller should retrieve SQL warnings */
   bool                retrieve_sql_warnings;
+  /** Pointer to the first warning attached to this connection */
+  SQLWarning*         first_warning;
   /** Controller connection policy used for this connection */
   AbstractControllerConnectPolicy* connect_policy_ptr;
   /** The parameters of this connection */
@@ -480,6 +500,8 @@
    */
   void                setConnectionParametersOnRequest(Request &request);
 
+  void                throwExceptionIfClosed(const std::wstring& msg)
+                          throw (DriverException, UnexpectedException);
   /**
    * Returns a boolean read from the stream or throws the CarobException
    * that came instead.
Index: carob/include/DriverResultSet.hpp
diff -u carob/include/DriverResultSet.hpp:1.42 
carob/include/DriverResultSet.hpp:1.43
--- carob/include/DriverResultSet.hpp:1.42      Wed Jun 28 17:54:48 2006
+++ carob/include/DriverResultSet.hpp   Wed Jul  5 09:26:05 2006
@@ -438,8 +438,9 @@
   /**
    * Gets the SQL warnings associated to this ResultSet
    * @return a SQL warning chain
+   * @throw DriverException if the ResultSet is closed
    */
-  SQLWarning*                 getWarnings() {return warningsPtr;}
+  SQLWarning*                 getWarnings() throw (DriverException, 
UnexpectedException);
   /**
    * Sets the owning statement warnings. Only fills statementWarnings field, 
    * does *not* set the owningStatement->warnings
Index: carob/include/Statement.hpp
diff -u carob/include/Statement.hpp:1.42 carob/include/Statement.hpp:1.43
--- carob/include/Statement.hpp:1.42    Wed Jun 21 14:56:22 2006
+++ carob/include/Statement.hpp Wed Jul  5 09:26:05 2006
@@ -304,7 +304,8 @@
    * Gets the SQL warnings associated to this statement
    * @return a SQL warning chain
    */
-  SQLWarning*             getWarnings() {return warningsPtr;}
+  SQLWarning*             getWarnings()  throw (DriverException,
+                              UnexpectedException);
 protected:
   /** Original, untouched request (only trimmed) */
   std::wstring            sql_request;
Index: carob/src/Connection.cpp
diff -u carob/src/Connection.cpp:1.78 carob/src/Connection.cpp:1.79
--- carob/src/Connection.cpp:1.78       Wed Jun 28 17:54:48 2006
+++ carob/src/Connection.cpp    Wed Jul  5 09:26:05 2006
@@ -75,6 +75,7 @@
   mustBeginTransaction(false),
   persistent_connection(false),
   retrieve_sql_warnings(false),
+  first_warning(NULL),
   connect_policy_ptr(NULL),
   parameters(prms)
 {
@@ -1017,6 +1018,42 @@
   return convertToSQLWarnings(e);
 }
 
+SQLWarning* Connection::getWarnings() throw (DriverException,
+    UnexpectedException)
+{
+  wstring fctName(L"Connection::getWarnings");
+
+  throwExceptionIfClosed(L"Cannot getWarnings() on a closed connection");
+  if (!persistent_connection || !retrieve_sql_warnings)
+    return first_warning;
+  // else...
+  FO_TRY_NTIMES(RECONNECT_RETRIES)
+    if (isDebugEnabled())
+      logDebug(fctName, L"Getting persistent connection warnings");
+    sendCommand(*driverSocketPtr, ConnectionGetWarnings);
+    *driverSocketPtr << persistent_connection_id;
+    return receiveSQLWarnings();
+  FO_CATCH_NTIMES
+  return NULL; //avoid compiler warning
+}
+
+void Connection::clearWarnings() throw (DriverException,
+    UnexpectedException)
+{
+  wstring fctName(L"Connection::clearWarnings");
+
+  if (!persistent_connection || !retrieve_sql_warnings)
+    return;
+  // else...
+  FO_TRY_NTIMES(RECONNECT_RETRIES)
+    if (isDebugEnabled())
+      logDebug(fctName, L"Getting persistent connection warnings");
+    sendCommand(*driverSocketPtr, ConnectionClearWarnings);
+    *driverSocketPtr << persistent_connection_id;
+    receiveBoolOrException();
+  FO_CATCH_NTIMES
+}
+
 SQLWarning* Connection::convertToSQLWarnings(BackendException* bde)
 {
   if (bde == NULL)
@@ -1028,6 +1065,13 @@
   return sqlw;
 }
 
+void Connection::throwExceptionIfClosed(const wstring& msg)
+    throw (DriverException, UnexpectedException)
+{
+  if (isClosed)
+    throw DriverException(msg);
+}
+
 void Connection::receiveException() throw (SocketIOException,
                                            BackendException,
                                            ControllerException,
Index: carob/src/DriverResultSet.cpp
diff -u carob/src/DriverResultSet.cpp:1.56 carob/src/DriverResultSet.cpp:1.57
--- carob/src/DriverResultSet.cpp:1.56  Wed Jun 28 17:54:48 2006
+++ carob/src/DriverResultSet.cpp       Wed Jul  5 09:26:05 2006
@@ -992,6 +992,12 @@
   return answer;
 }
 
+SQLWarning* DriverResultSet::getWarnings() throw (DriverException, 
UnexpectedException)
+{
+  checkIfClosed();
+  return warningsPtr;
+}
+  
 void DriverResultSet::checkRowAndColPosAndSetNullFlag(int columnIndex)
     throw (DriverException, UnexpectedException)
 {
Index: carob/src/Statement.cpp
diff -u carob/src/Statement.cpp:1.29 carob/src/Statement.cpp:1.30
--- carob/src/Statement.cpp:1.29        Wed Jun 21 14:56:22 2006
+++ carob/src/Statement.cpp     Wed Jul  5 09:26:05 2006
@@ -310,3 +310,12 @@
   }
   return rs_metadata_ptr;
 }
+
+SQLWarning* Statement::getWarnings() throw (DriverException, 
UnexpectedException)
+{
+  if (isClosed())
+  {
+    throw DriverException(L"Unable to get warnings on a closed statement");
+  }
+  return warningsPtr;
+}

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

Reply via email to