Revert "Remove mysql and oracle resources for anna-ericsson project"
[anna.git] / source / dbms.oracle / Descriptor.cpp
diff --git a/source/dbms.oracle/Descriptor.cpp b/source/dbms.oracle/Descriptor.cpp
new file mode 100644 (file)
index 0000000..b7e5011
--- /dev/null
@@ -0,0 +1,39 @@
+// ANNA - Anna is Not Nothingness Anymore                                                         //
+//                                                                                                //
+// (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo                         //
+//                                                                                                //
+// See project site at http://redmine.teslayout.com/projects/anna-suite                           //
+// See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
+
+
+#include <oci.h>
+
+#include <anna/dbms.oracle/Descriptor.hpp>
+#include <anna/dbms.oracle/Database.hpp>
+#include <anna/dbms.oracle/Connection.hpp>
+#include <anna/dbms.oracle/ResultCode.hpp>
+
+using namespace anna;
+
+dbms::oracle::Descriptor::~Descriptor() {
+  if(*reference != NULL) {
+    OCIDescriptorFree(*reference, type);
+    *reference = NULL;
+  }
+}
+
+void dbms::oracle::Descriptor::allocate(dbms::oracle::Database& database, dbms::oracle::Connection* connection,  const int _type)
+throw(RuntimeException) {
+  if(*reference != NULL)
+    return;
+
+  env = database;
+  error = database.getErrorHandler();
+  context = *connection;                      // Invoca al operador de conversion
+
+  try {
+    anna_dbms_oracle_check(OCIDescriptorAlloc(env, reference, type = _type, 0, 0),  error);
+  } catch(DatabaseException& edb) {
+    throw RuntimeException(edb);
+  }
+}