aboutsummaryrefslogtreecommitdiff
path: root/odb/oracle/error.cxx
diff options
context:
space:
mode:
authorConstantin Michael <constantin@codesynthesis.com>2011-09-05 11:55:41 +0200
committerConstantin Michael <constantin@codesynthesis.com>2011-09-05 11:55:41 +0200
commit6eed6c47b07371349bd4c30daf2b305ff7f5b1d3 (patch)
treea9e63048560e301a1415c8d9821d2715423a94aa /odb/oracle/error.cxx
parentf024d16b9c78d683baa5d87b6e92b3d79a1f3300 (diff)
Add exceptions and error translation
Diffstat (limited to 'odb/oracle/error.cxx')
-rw-r--r--odb/oracle/error.cxx63
1 files changed, 63 insertions, 0 deletions
diff --git a/odb/oracle/error.cxx b/odb/oracle/error.cxx
new file mode 100644
index 0000000..900e3d9
--- /dev/null
+++ b/odb/oracle/error.cxx
@@ -0,0 +1,63 @@
+// file : odb/oracle/errors.cxx
+// author : Constantin Michael <constantin@codesynthesis.com>
+// copyright : Copyright (c) 2005-2011 Code Synthesis Tools CC
+// license : ODB NCUEL; see accompanying LICENSE file
+
+#include <cassert>
+
+#include <odb/details/buffer.hxx>
+
+#include <odb/oracle/error.hxx>
+#include <odb/oracle/exceptions.hxx>
+
+using namespace std;
+
+namespace odb
+{
+ namespace oracle
+ {
+ void
+ translate_error (void* h, ub4 t, sword s)
+ {
+ assert (s == OCI_ERROR || s == OCI_INVALID_HANDLE);
+
+ if (s == OCI_INVALID_HANDLE)
+ throw invalid_oci_handle ();
+
+ sb4 e;
+ details::buffer b;
+ b.capacity (128);
+
+ bool trunc (true);
+ while (trunc)
+ {
+ trunc = OCIErrorGet (h,
+ 1,
+ 0,
+ &e,
+ reinterpret_cast<text*> (b.data ()),
+ b.capacity (),
+ t) == OCI_ERROR;
+
+ if (trunc)
+ b.capacity (b.capacity () * 2);
+ }
+
+ // @@ Need to find a source of OCI specific codes.
+ //
+ // There are no symbolic definitions for error codes in the OCI
+ // header files.
+ //
+ switch (e)
+ {
+ case 60:
+ throw deadlock ();
+ case 3135:
+ case 3136:
+ throw connection_lost ();
+ default:
+ throw database_exception (e, b.data ());
+ }
+ }
+ }
+}