Date: Friday, March 31, 2006 @ 00:45:32
  Author: marc
    Path: /cvsroot/carob/odbsequoia/src

Modified: explicit_type.cpp (1.9 -> 1.10)

Implemented bullet-proof exception catcher & converter in SQLAllocHandle()


-------------------+
 explicit_type.cpp |   46 +++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 45 insertions(+), 1 deletion(-)


Index: odbsequoia/src/explicit_type.cpp
diff -u odbsequoia/src/explicit_type.cpp:1.9 
odbsequoia/src/explicit_type.cpp:1.10
--- odbsequoia/src/explicit_type.cpp:1.9        Thu Mar 30 23:03:19 2006
+++ odbsequoia/src/explicit_type.cpp    Fri Mar 31 00:45:32 2006
@@ -28,6 +28,7 @@
 #include "stmt.hpp"
 #include "connect.hpp"
 #include "env.hpp"
+#include "odbc_exception.hpp"
 
 using namespace ODBSeqNS;
 
@@ -61,13 +62,17 @@
     if (SQL_HANDLE_ENV != HandleType)
         objectify(HandleType, InputHandle)->clear_diags();
 
+    // zero so we can detect if it was allocated in catch below
+    * OutputHandle = 0;
+
+    try {
+
     switch (HandleType)
     {
     case SQL_HANDLE_ENV: {
         ODBCEnv & newEnv = * new ODBCEnv;
         *OutputHandle = & newEnv;
 
-        // TODO: catch & convert exceptions
         return newEnv.init();
     }
     case SQL_HANDLE_DBC: {
@@ -85,6 +90,45 @@
         return SQL_INVALID_HANDLE; // TODO: need to push_diags sthing?
     }
 
+    // see also _PROTECT_SQLRETURN macro in abstract_item.hpp
+    } catch (CarobNS::CarobException& ce) {
+
+        SQLHANDLE report_handle;
+
+        if (SQL_HANDLE_ENV == HandleType) {
+            report_handle = * OutputHandle;
+        } else {
+            report_handle = InputHandle;
+            // delete target if exception occured AFTER ctor
+            if (* OutputHandle)
+                delete static_cast<ODBCItem *>(* OutputHandle);
+        }
+
+        if (0 == * OutputHandle) // error in ctor: must fix *OutputHandle
+            switch (HandleType) {
+            case(SQL_HANDLE_ENV):
+                * OutputHandle = SQL_NULL_HENV;
+                break;
+            case(SQL_HANDLE_DBC):
+                * OutputHandle = SQL_NULL_HDBC;
+                break;
+            case(SQL_HANDLE_STMT):
+                * OutputHandle = SQL_NULL_HSTMT;
+                break;
+            case(SQL_HANDLE_DESC):
+                * OutputHandle = SQL_NULL_HDESC;
+                break;
+            }
+
+        if (0 == report_handle) // no handle available (error in ODBCEnv ctor)
+            return SQL_ERROR;
+
+        ODBCItem & report_item = * static_cast<ODBCItem *>(report_handle);
+        report_item.push_diag_chain(ce);
+        return SQL_ERROR;
+
+    }
+
 }
 
 

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

Reply via email to