aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2011-11-16 12:14:57 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2011-11-16 12:14:57 +0200
commitbc85d6a1c8d5296428c121cd1b51d470d5c0e963 (patch)
tree4c7c95c245fd7d025181b5758ca7c500439097a5
parent90e5bee516554805707436ccf9cb2b2e7d2c207a (diff)
Add initial translate_error() implementation
-rw-r--r--odb/mssql/error.cxx71
-rw-r--r--odb/mssql/error.hxx30
-rw-r--r--odb/mssql/makefile1
3 files changed, 102 insertions, 0 deletions
diff --git a/odb/mssql/error.cxx b/odb/mssql/error.cxx
new file mode 100644
index 0000000..f2e172b
--- /dev/null
+++ b/odb/mssql/error.cxx
@@ -0,0 +1,71 @@
+// file : odb/mssql/error.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2005-2011 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#include <odb/mssql/odbc.hxx>
+#include <odb/mssql/error.hxx>
+//#include <odb/mssql/connection.hxx>
+#include <odb/mssql/exceptions.hxx>
+
+using namespace std;
+
+namespace odb
+{
+ namespace mssql
+ {
+ static void
+ translate_error (SQLHANDLE h, SQLSMALLINT htype, connection* /*conn*/)
+ {
+ 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.
+ SQLSMALLINT msg_size;
+
+ database_exception e;
+
+ for (SQLSMALLINT i (1);; ++i)
+ {
+ SQLRETURN r (SQLGetDiagRec (htype,
+ h,
+ i,
+ (SQLCHAR*) sqlstate,
+ &native_code,
+ (SQLCHAR*) msg,
+ sizeof (msg),
+ &msg_size));
+
+ if (r == SQL_NO_DATA)
+ break;
+ else if (r == SQL_SUCCESS || r == SQL_SUCCESS_WITH_INFO)
+ {
+ //@@ TODO: translate timeout, connection_lost exceptions
+ //@@ TODO: if conn != 0, mark it as failed for certain errors
+
+ e.append (native_code, sqlstate, msg);
+ }
+ else
+ e.append (0, "?????", "unable to extract information for this "
+ "diagnostic record");
+ }
+
+ if (e.size () == 0)
+ e.append (0, "?????", "no diagnostic record (using wrong handle?)");
+
+ throw e;
+ }
+
+ void
+ translate_error (const auto_handle<SQL_HANDLE_ENV>& h)
+ {
+ translate_error (h, SQL_HANDLE_ENV, 0);
+ }
+
+ void
+ translate_error (connection& /*c*/)
+ {
+ //@@ TODO enable (also header inclusion)
+ // translate_error (c.handle (), SQL_HANDLE_DBC, &c);
+ }
+ }
+}
diff --git a/odb/mssql/error.hxx b/odb/mssql/error.hxx
new file mode 100644
index 0000000..2cbea5c
--- /dev/null
+++ b/odb/mssql/error.hxx
@@ -0,0 +1,30 @@
+// file : odb/mssql/error.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2005-2011 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef ODB_MSSQL_ERROR_HXX
+#define ODB_MSSQL_ERROR_HXX
+
+#include <odb/pre.hxx>
+
+#include <odb/mssql/version.hxx>
+#include <odb/mssql/forward.hxx> // connection
+#include <odb/mssql/auto-handle.hxx>
+#include <odb/mssql/details/export.hxx>
+
+namespace odb
+{
+ namespace mssql
+ {
+ LIBODB_MSSQL_EXPORT void
+ translate_error (const auto_handle<SQL_HANDLE_ENV>&);
+
+ LIBODB_MSSQL_EXPORT void
+ translate_error (connection&);
+ }
+}
+
+#include <odb/post.hxx>
+
+#endif // ODB_MSSQL_ERROR_HXX
diff --git a/odb/mssql/makefile b/odb/mssql/makefile
index 00342f1..fbe46f4 100644
--- a/odb/mssql/makefile
+++ b/odb/mssql/makefile
@@ -8,6 +8,7 @@ include $(dir $(lastword $(MAKEFILE_LIST)))../../build/bootstrap.make
cxx := \
auto-handle.cxx \
+error.cxx \
exceptions.cxx