Date: Wednesday, March 22, 2006 @ 15:35:04
  Author: marc
    Path: /cvsroot/carob/odbsequoia/src

Modified: connect.cpp (1.14 -> 1.15)

Now throwing a proper exception when DATABASE parameter is missing from .ini 
file


-------------+
 connect.cpp |   18 +++++++++++++-----
 1 files changed, 13 insertions(+), 5 deletions(-)


Index: odbsequoia/src/connect.cpp
diff -u odbsequoia/src/connect.cpp:1.14 odbsequoia/src/connect.cpp:1.15
--- odbsequoia/src/connect.cpp:1.14     Fri Feb 24 15:55:45 2006
+++ odbsequoia/src/connect.cpp  Wed Mar 22 15:35:04 2006
@@ -22,12 +22,13 @@
 
 #include "stmt.hpp"
 #include "util.hpp"
+#include "odbc_exception.hpp"
 #include "inst.hpp"
 
 #include "Connection.hpp"
 #include "ConnectionParameters.hpp"
-#include "CarobException.hpp"
 #include "StringCodecs.hpp"
+#include "Common.hpp" // setLogLevel()
 
 #include <odbcinst.h>
 
@@ -87,20 +88,27 @@
     LPCSTR cdsn = narrow_dsn.c_str();
 #endif
 
+    // The trick: providing a zero-length default value is like
+    // providing NO default value. Now we can throw an SQL_ERROR
+    // when we require the user to provide a value.
+
+    // TODO: call SQLInstallerError() to throw better diags
+
     // Slurp DSN information from odbc.ini into ConnectionParameters
     if (!SQLGetPrivateProfileString(cdsn, SERVER_INI, "localhost",
        temp, MAX_VALUE_LEN, ODBC_INI))
-        return SQL_ERROR; // TODO: diags
+        return SQL_ERROR; // TODO: diags. On the other hand it can hardly fail.
     std::wstring serverhost = fromString(std::string(temp));
 
     if (!SQLGetPrivateProfileString(cdsn, PORT_INI, "25322",
        temp, MAX_VALUE_LEN, ODBC_INI))
-        return SQL_ERROR; // TODO: diags
+        return SQL_ERROR; // TODO: diags. On the other hand it can hardly fail.
     in_port_t port = atoi(temp);
 
     if (!SQLGetPrivateProfileString(cdsn, DATABASE_INI, "",
        temp, MAX_VALUE_LEN, ODBC_INI))
-        return SQL_ERROR; // TODO: diags
+        throw ODBSeqException(L"???", L"'" WIDENMACRO(DATABASE_INI) L"'"
+                              L" parameter not found in .ini file");
     std::wstring vdbname = fromString(std::string(temp));
 
     if (!SQLGetPrivateProfileString(cdsn, BACKEND_IDS_INI, 
DEFAULT_BACKEND_IDS_INI,
@@ -109,7 +117,7 @@
     this->backend_diagids = fromString(std::string(temp));
 
 
-#if 0    
+#if 0 // see above
     delete[] cdsn;
 #endif
 

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

Reply via email to