1 // ANNA - Anna is Not Nothingness Anymore //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
13 #include <anna/core/tracing/Logger.hpp>
14 #include <anna/core/tracing/TraceMethod.hpp>
16 #include <anna/dbms.oracle/oracle.hpp>
17 #include <anna/dbms.oracle/internal/sccs.hpp>
21 using namespace anna::dbms;
23 char oracle::Database::st_decimalPoint = 0;
25 oracle::Database::Database(const char* dbmsName) :
26 dbms::Database(getClassName(), dbmsName),
29 oracle::sccs::activate();
32 oracle::Database::Database(const char* componentName, const char* dbmsName) :
33 dbms::Database(componentName, dbmsName),
36 oracle::sccs::activate();
39 void oracle::Database::do_initialize()
40 throw(RuntimeException) {
41 LOGMETHOD(TraceMethod tm("anna::dbms::oracle::Database", "do_initialize", ANNA_FILE_LOCATION));
44 Logger::write(Logger::Warning, asString(), "Already initialized", ANNA_FILE_LOCATION);
48 if(OCIInitialize(OCI_DEFAULT, 0, 0, 0, 0) != OCI_SUCCESS) {
49 string msg(asString());
50 msg += " | Cannot initialize Oracle access system";
51 throw RuntimeException(msg, ANNA_FILE_LOCATION);
54 if(OCIEnvInit(&a_env, OCI_DEFAULT, 0, 0) != OCI_SUCCESS) {
55 string msg(asString());
56 msg += " | Cannot create database environment";
57 throw RuntimeException(msg, ANNA_FILE_LOCATION);
60 if(OCIHandleAlloc(a_env, (void**) &a_error, OCI_HTYPE_ERROR, 0, 0) != OCI_SUCCESS) {
61 string msg(asString());
62 msg += " | Cannot create database error handler";
63 throw RuntimeException(msg, ANNA_FILE_LOCATION);
67 OCIThreadProcessInit();
68 anna_dbms_oracle_check(OCIThreadInit(a_env, a_error), a_error);
70 initializeDecimalPoint();
71 dbms::Database::do_initialize();
74 //----------------------------------------------------------------------------------
75 // Libera todos los manejadores asociados a �te entorno.
76 //----------------------------------------------------------------------------------
77 oracle::Database::~Database() {
78 LOGMETHOD(TraceMethod tm("anna::dbms::oracle::Database", "~Database", ANNA_FILE_LOCATION));
81 OCIHandleFree(a_env, OCI_HTYPE_ERROR);
86 OCIHandleFree(a_env, OCI_HTYPE_ENV);
91 dbms::Connection* oracle::Database::allocateConnection(const std::string& name, const char* user, const char* password)
92 throw(RuntimeException) {
93 return new Connection(*this, name, user, password);
96 dbms::Statement* oracle::Database::allocateStatement(const char* name, const std::string& expression, const bool isCritical)
97 throw(RuntimeException) {
98 return new Statement(*this, name, expression, isCritical);
101 dbms::InputBind* oracle::Database::allocateInputBind(const char* name, Data& data)
102 throw(RuntimeException) {
103 return new InputBind(name, data);
106 void oracle::Database::deallocate(dbms::InputBind* inputBind)
108 delete(InputBind*) inputBind;
111 dbms::OutputBind* oracle::Database::allocateOutputBind(const char* name, Data& data)
112 throw(RuntimeException) {
113 return new OutputBind(name, data);
116 void oracle::Database::deallocate(dbms::OutputBind* outputBind)
118 delete(OutputBind*) outputBind;
122 * Ojo no se activa el uso de forma definitiva porque afectaría a todo el programa, cualquier
123 * conversion texto -> float/double que se hiciera se vería afectado por este cambio, que sólo debería
124 * aplicar a temas relaciones con la base de datos.
126 * Carga el valor del LC_NUMERIC de la correspondiente variable del entorno y luego repone el
127 * usado por defecto en las librerias del core de C.
130 void oracle::Database::initializeDecimalPoint()
131 throw(RuntimeException) {
132 setlocale(LC_NUMERIC, "");
133 struct lconv *locale = localeconv();
135 if(*locale->decimal_point != '.')
136 st_decimalPoint = *locale->decimal_point;
138 setlocale(LC_NUMERIC, "C");