diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2011-11-20 13:30:43 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2011-11-20 13:30:43 +0200 |
commit | 16283f61ddd0525b08e615fac6148f544973ac82 (patch) | |
tree | 04d2a2116ea9c6ee87bf441ca22df6e7f7e6572b | |
parent | 0362bba70741404fb5dca7f0bb7aa4c484f307cc (diff) |
Handle error conditions that are indicated via return code
-rw-r--r-- | odb/mssql/connection.cxx | 4 | ||||
-rw-r--r-- | odb/mssql/database.cxx | 4 | ||||
-rw-r--r-- | odb/mssql/error.cxx | 48 | ||||
-rw-r--r-- | odb/mssql/error.hxx | 8 | ||||
-rw-r--r-- | odb/mssql/mssql-fwd.hxx | 2 |
5 files changed, 51 insertions, 15 deletions
diff --git a/odb/mssql/connection.cxx b/odb/mssql/connection.cxx index 50bc8db..788fecb 100644 --- a/odb/mssql/connection.cxx +++ b/odb/mssql/connection.cxx @@ -37,7 +37,7 @@ namespace odb r = SQLAllocHandle (SQL_HANDLE_DBC, db_.environment (), &h); if (!SQL_SUCCEEDED (r)) - translate_error (db_.environment (), SQL_HANDLE_ENV); + translate_error (r, db_.environment (), SQL_HANDLE_ENV); handle_.reset (h); } @@ -59,7 +59,7 @@ namespace odb // Still use the handle version of translate_error since there // is no connection. // - translate_error (handle_, SQL_HANDLE_DBC); + translate_error (r, handle_, SQL_HANDLE_DBC); state_ = state_connected; } diff --git a/odb/mssql/database.cxx b/odb/mssql/database.cxx index bafe176..1d02afc 100644 --- a/odb/mssql/database.cxx +++ b/odb/mssql/database.cxx @@ -264,7 +264,7 @@ namespace odb 0); if (!SQL_SUCCEEDED (r)) - translate_error (environment_, SQL_HANDLE_ENV); + translate_error (r, environment_, SQL_HANDLE_ENV); } // Build the connection string. @@ -292,7 +292,7 @@ namespace odb if (r == SQL_NO_DATA) break; else if (!SQL_SUCCEEDED (r)) - translate_error (environment_, SQL_HANDLE_ENV); + translate_error (r, environment_, SQL_HANDLE_ENV); // Native Client 9.0 (first version). // diff --git a/odb/mssql/error.cxx b/odb/mssql/error.cxx index b405db7..b659bd6 100644 --- a/odb/mssql/error.cxx +++ b/odb/mssql/error.cxx @@ -17,10 +17,40 @@ namespace odb namespace mssql { static void - translate_error (SQLHANDLE h, SQLSMALLINT htype, connection* conn) + translate_error (SQLRETURN r, + SQLHANDLE h, + SQLSMALLINT htype, + connection* conn) { - SQLRETURN r; + // First see if we have one of the errors indicated via the + // return error code. + // + switch (r) + { + case SQL_STILL_EXECUTING: + { + throw database_exception (0, "?????", "statement still executing"); + break; + } + case SQL_NEED_DATA: + case SQL_NO_DATA: +#if ODBCVER >= 0x0380 + case SQL_PARAM_DATA_AVAILABLE: +#endif + { + throw database_exception ( + 0, "?????", "unhandled SQL_*_DATA condition"); + break; + } + case SQL_INVALID_HANDLE: + { + throw database_exception (0, "?????", "invalid handle"); + break; + } + } + // Otherwise the diagnostics is stored in the handle. + // char sqlstate[SQL_SQLSTATE_SIZE + 1]; SQLINTEGER native_code; // Will be 0 if no natve code. char msg[512]; // Will be truncated if doesn't fit. @@ -161,21 +191,23 @@ namespace odb } void - translate_error (connection& c) + translate_error (SQLRETURN r, connection& c) { - translate_error (c.handle (), SQL_HANDLE_DBC, &c); + translate_error (r, c.handle (), SQL_HANDLE_DBC, &c); } void - translate_error (connection& c, const auto_handle<SQL_HANDLE_STMT>& h) + translate_error (SQLRETURN r, + connection& c, + const auto_handle<SQL_HANDLE_STMT>& h) { - translate_error (h, SQL_HANDLE_STMT, &c); + translate_error (r, h, SQL_HANDLE_STMT, &c); } void - translate_error (SQLHANDLE h, SQLSMALLINT htype) + translate_error (SQLRETURN r, SQLHANDLE h, SQLSMALLINT htype) { - translate_error (h, htype, 0); + translate_error (r, h, htype, 0); } } } diff --git a/odb/mssql/error.hxx b/odb/mssql/error.hxx index 6208103..f160514 100644 --- a/odb/mssql/error.hxx +++ b/odb/mssql/error.hxx @@ -20,13 +20,15 @@ namespace odb namespace mssql { LIBODB_MSSQL_EXPORT void - translate_error (connection&); + translate_error (SQLRETURN, connection&); LIBODB_MSSQL_EXPORT void - translate_error (connection&, const auto_handle<SQL_HANDLE_STMT>&); + translate_error (SQLRETURN, + connection&, + const auto_handle<SQL_HANDLE_STMT>&); LIBODB_MSSQL_EXPORT void - translate_error (SQLHANDLE, SQLSMALLINT htype); + translate_error (SQLRETURN, SQLHANDLE, SQLSMALLINT htype); } } diff --git a/odb/mssql/mssql-fwd.hxx b/odb/mssql/mssql-fwd.hxx index bee639b..b4afbb6 100644 --- a/odb/mssql/mssql-fwd.hxx +++ b/odb/mssql/mssql-fwd.hxx @@ -20,6 +20,8 @@ typedef unsigned long SQLUINTEGER; typedef short SQLSMALLINT; typedef unsigned short SQLUSMALLINT; +typedef SQLSMALLINT SQLRETURN; + typedef void* SQLHANDLE; typedef SQLHANDLE SQLHENV; typedef SQLHANDLE SQLHDBC; |