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
39 #include <anna/core/DataBlock.hpp>
41 #include <anna/dbms/Data.hpp>
42 #include <anna/dbms/LongBlock.hpp>
44 #include <anna/dbms.oracle/BaseBind.hpp>
45 #include <anna/dbms.oracle/Database.hpp>
46 #include <anna/dbms.oracle/Connection.hpp>
47 #include <anna/dbms.oracle/ResultCode.hpp>
51 //----------------------------------------------------------------------------
52 // (1) Reserva 2 Kbytes para trabajar con el LOB.
53 //----------------------------------------------------------------------------
54 dbms::oracle::BaseBind::BaseBind(const dbms::Data& data) :
55 a_type(data.getType()),
58 case Data::Type::Float:
59 a_ofb = new anna::DataBlock(true);
60 a_ofb->allocate(FloatSize + 1);
62 case Data::Type::ShortBlock:
63 a_ofb = new anna::DataBlock(true);
64 a_ofb->allocate(data.getMaxSize() * 2 + 1);
66 case Data::Type::LongBlock:
67 a_ofb = new anna::DataBlock(true);
68 a_ofb->allocate(2048); // (1)
73 dbms::oracle::BaseBind::~BaseBind() {
78 // (1) Aunque sea un objeto de tipo Date lo define/trata como un tipo TimeStamp, porque de otro modo no se grabaria la
79 // informacion referente a la hora.
80 // (2) El Float hasta ahora se trataba como un tipo especial de cadena, pero no es un tratamiento indicado
81 // para todos los gestores de base de datos, as� que vamos a resumir en estas clases todos los detalles de
84 dbms::oracle::BaseBind::oci_param dbms::oracle::BaseBind::getOCIParam(dbms::oracle::Database& database, dbms::oracle::Connection* connection, dbms::Data& data)
85 throw(RuntimeException) {
89 case Data::Type::Integer:
90 ociparam.type = SQLT_INT;
91 ociparam.maxLength = data.getMaxSize();
92 ociparam.length = NULL;
93 ociparam.buffer = const_cast <dbms::Data&>(data).getBuffer();
95 case Data::Type::String:
96 ociparam.type = SQLT_STR;
97 ociparam.maxLength = data.getMaxSize() + 1;
98 ociparam.length = NULL;
99 ociparam.buffer = const_cast <dbms::Data&>(data).getBuffer();
101 case Data::Type::Float: // (2)
102 ociparam.type = SQLT_STR;
103 ociparam.maxLength = FloatSize + 1;
104 ociparam.length = NULL;
105 ociparam.buffer = const_cast <char*>(a_ofb->getData());
107 case Data::Type::ShortBlock:
108 ociparam.type = SQLT_STR;
109 ociparam.maxLength = data.getMaxSize() * 2 + 1;
110 ociparam.length = &a_length;
111 ociparam.buffer = const_cast <char*>(a_ofb->getData());
113 case Data::Type::LongBlock:
114 a_blob.allocate(database, connection, OCI_DTYPE_LOB);
115 ociparam.type = SQLT_BLOB;
116 ociparam.buffer = &a_blob.handle;
117 ociparam.length = NULL;
118 ociparam.maxLength = 0;
120 case Data::Type::Date: // (1)
121 case Data::Type::TimeStamp:
122 a_datetime.allocate(database, connection, OCI_DTYPE_TIMESTAMP);
123 ociparam.type = SQLT_TIMESTAMP;
124 ociparam.buffer = &a_datetime.handle;
125 ociparam.length = NULL;
126 ociparam.maxLength = 0;
129 throw RuntimeException(functions::asString("Unsupported data type %d", (int) a_type), ANNA_FILE_LOCATION);