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)
74 dbms::oracle::BaseBind::~BaseBind() {
79 // (1) Aunque sea un objeto de tipo Date lo define/trata como un tipo TimeStamp, porque de otro modo no se grabaria la
80 // informacion referente a la hora.
81 // (2) El Float hasta ahora se trataba como un tipo especial de cadena, pero no es un tratamiento indicado
82 // para todos los gestores de base de datos, as� que vamos a resumir en estas clases todos los detalles de
85 dbms::oracle::BaseBind::oci_param dbms::oracle::BaseBind::getOCIParam(dbms::oracle::Database& database, dbms::oracle::Connection* connection, dbms::Data& data)
86 throw(RuntimeException) {
90 case Data::Type::Integer:
91 ociparam.type = SQLT_INT;
92 ociparam.maxLength = data.getMaxSize();
93 ociparam.length = NULL;
94 ociparam.buffer = const_cast <dbms::Data&>(data).getBuffer();
96 case Data::Type::String:
97 ociparam.type = SQLT_STR;
98 ociparam.maxLength = data.getMaxSize() + 1;
99 ociparam.length = NULL;
100 ociparam.buffer = const_cast <dbms::Data&>(data).getBuffer();
102 case Data::Type::Float: // (2)
103 ociparam.type = SQLT_STR;
104 ociparam.maxLength = FloatSize + 1;
105 ociparam.length = NULL;
106 ociparam.buffer = const_cast <char*>(a_ofb->getData());
108 case Data::Type::ShortBlock:
109 ociparam.type = SQLT_STR;
110 ociparam.maxLength = data.getMaxSize() * 2 + 1;
111 ociparam.length = &a_length;
112 ociparam.buffer = const_cast <char*>(a_ofb->getData());
114 case Data::Type::LongBlock:
115 a_blob.allocate(database, connection, OCI_DTYPE_LOB);
116 ociparam.type = SQLT_BLOB;
117 ociparam.buffer = &a_blob.handle;
118 ociparam.length = NULL;
119 ociparam.maxLength = 0;
121 case Data::Type::Date: // (1)
122 case Data::Type::TimeStamp:
123 a_datetime.allocate(database, connection, OCI_DTYPE_TIMESTAMP);
124 ociparam.type = SQLT_TIMESTAMP;
125 ociparam.buffer = &a_datetime.handle;
126 ociparam.length = NULL;
127 ociparam.maxLength = 0;
130 throw RuntimeException(functions::asString("Unsupported data type %d", (int) a_type), ANNA_FILE_LOCATION);