1 // ANNA - Anna is Not Nothingness Anymore
3 // (c) Copyright 2005-2014 Eduardo Ramos Testillano & Francisco Ruiz Rayo
5 // http://redmine.teslayout.com/projects/anna-suite
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions
11 // * Redistributions of source code must retain the above copyright
12 // notice, this list of conditions and the following disclaimer.
13 // * Redistributions in binary form must reproduce the above
14 // copyright notice, this list of conditions and the following disclaimer
15 // in the documentation and/or other materials provided with the
17 // * Neither the name of the copyright holder nor the names of its
18 // contributors may be used to endorse or promote products derived from
19 // this software without specific prior written permission.
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 // Authors: eduardo.ramos.testillano@gmail.com
34 // cisco.tierra@gmail.com
41 #include <anna/core/tracing/Logger.hpp>
42 #include <anna/core/tracing/TraceMethod.hpp>
44 #include <anna/dbms.oracle/oracle.hpp>
45 #include <anna/dbms.oracle/internal/sccs.hpp>
49 using namespace anna::dbms;
51 char oracle::Database::st_decimalPoint = 0;
53 oracle::Database::Database(const char* dbmsName) :
54 dbms::Database(getClassName(), dbmsName),
57 oracle::sccs::activate();
60 oracle::Database::Database(const char* componentName, const char* dbmsName) :
61 dbms::Database(componentName, dbmsName),
64 oracle::sccs::activate();
67 void oracle::Database::do_initialize()
68 throw(RuntimeException) {
69 LOGMETHOD(TraceMethod tm("anna::dbms::oracle::Database", "do_initialize", ANNA_FILE_LOCATION));
73 Logger::write(Logger::Warning, asString(), "Already initialized", ANNA_FILE_LOCATION);
77 if(OCIInitialize(OCI_DEFAULT, 0, 0, 0, 0) != OCI_SUCCESS) {
78 string msg(asString());
79 msg += " | Cannot initialize Oracle access system";
80 throw RuntimeException(msg, ANNA_FILE_LOCATION);
83 if(OCIEnvInit(&a_env, OCI_DEFAULT, 0, 0) != OCI_SUCCESS) {
84 string msg(asString());
85 msg += " | Cannot create database environment";
86 throw RuntimeException(msg, ANNA_FILE_LOCATION);
89 if(OCIHandleAlloc(a_env, (void**) &a_error, OCI_HTYPE_ERROR, 0, 0) != OCI_SUCCESS) {
90 string msg(asString());
91 msg += " | Cannot create database error handler";
92 throw RuntimeException(msg, ANNA_FILE_LOCATION);
96 OCIThreadProcessInit();
97 anna_dbms_oracle_check(OCIThreadInit(a_env, a_error), a_error);
99 initializeDecimalPoint();
100 dbms::Database::do_initialize();
103 //----------------------------------------------------------------------------------
104 // Libera todos los manejadores asociados a �te entorno.
105 //----------------------------------------------------------------------------------
106 oracle::Database::~Database() {
107 LOGMETHOD(TraceMethod tm("anna::dbms::oracle::Database", "~Database", ANNA_FILE_LOCATION));
110 OCIHandleFree(a_env, OCI_HTYPE_ERROR);
115 OCIHandleFree(a_env, OCI_HTYPE_ENV);
120 dbms::Connection* oracle::Database::allocateConnection(const std::string& name, const char* user, const char* password)
121 throw(RuntimeException) {
122 return new Connection(*this, name, user, password);
125 dbms::Statement* oracle::Database::allocateStatement(const char* name, const std::string& expression, const bool isCritical)
126 throw(RuntimeException) {
127 return new Statement(*this, name, expression, isCritical);
130 dbms::InputBind* oracle::Database::allocateInputBind(const char* name, Data& data)
131 throw(RuntimeException) {
132 return new InputBind(name, data);
135 void oracle::Database::deallocate(dbms::InputBind* inputBind)
137 delete(InputBind*) inputBind;
140 dbms::OutputBind* oracle::Database::allocateOutputBind(const char* name, Data& data)
141 throw(RuntimeException) {
142 return new OutputBind(name, data);
145 void oracle::Database::deallocate(dbms::OutputBind* outputBind)
147 delete(OutputBind*) outputBind;
151 * Ojo no se activa el uso de forma definitiva porque afectaría a todo el programa, cualquier
152 * conversion texto -> float/double que se hiciera se vería afectado por este cambio, que sólo debería
153 * aplicar a temas relaciones con la base de datos.
155 * Carga el valor del LC_NUMERIC de la correspondiente variable del entorno y luego repone el
156 * usado por defecto en las librerias del core de C.
159 void oracle::Database::initializeDecimalPoint()
160 throw(RuntimeException) {
161 setlocale(LC_NUMERIC, "");
162 struct lconv *locale = localeconv();
164 if(*locale->decimal_point != '.')
165 st_decimalPoint = *locale->decimal_point;
167 setlocale(LC_NUMERIC, "C");