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 <mysql/mysql.h>
41 #include <anna/config/defines.hpp>
42 #include <anna/core/functions.hpp>
43 #include <anna/core/DataBlock.hpp>
44 #include <anna/core/tracing/Logger.hpp>
46 #include <anna/dbms/String.hpp>
47 #include <anna/dbms/ShortBlock.hpp>
48 #include <anna/dbms/Date.hpp>
49 #include <anna/dbms/TimeStamp.hpp>
50 #include <anna/dbms/LongBlock.hpp>
52 #include <anna/dbms.mysql/mysql.hpp>
57 InputBind::InputBind(const char* name, dbms::Data& data) :
58 dbms::InputBind(name, data),
62 InputBind::~InputBind() {
66 * Completa la informacion establececida por el setupBind.
68 void InputBind::prepare(anna::dbms::Statement* dbmsStmt, anna::dbms::Connection*, const int pos)
69 throw(RuntimeException) {
70 st_mysql_bind* bind = static_cast <dbms::mysql::Statement*>(dbmsStmt)->getBindParams() + pos;
71 Data& data = anna::dbms::Bind::getData();
72 BaseBind::setupBind(*bind, data);
74 if(data.getType() == Data::Type::LongBlock) {
75 DataBlock& dataBlock = static_cast <dbms::LongBlock&>(data).getValue();
76 bind->buffer_type = MYSQL_TYPE_BLOB;
77 bind->buffer_length = dataBlock.getSize();
78 bind->buffer = (char*) dataBlock.getData();
79 bind->length = &a_length;
84 * Se invoca desde anna::dbms::mysql::Statement::execute.
85 * Codificar� la informaci�n C++ de forma que encaje en las estructuras requeridas por el API de MySQL.
87 void InputBind::code() const
88 throw(RuntimeException) {
89 InputBind* _this = const_cast <InputBind*>(this);
90 Data& data = _this->getData();
92 if((_this->a_nullIndicator = data.isNull() ? true : false) == true)
95 switch(data.getType()) {
96 case Data::Type::String:
97 _this->a_length = anna_strlen((char*)(static_cast <dbms::String&>(data).getBuffer()));
99 case Data::Type::Date:
100 case Data::Type::TimeStamp:
101 _this->codeDate(data);
107 * El bind.buffer ha sido asociado a una estructura de tipo MYSQL_TIME (a_time), cuyos valores vamos
108 * a establecer en �ste m�todo.
110 void InputBind::codeDate(dbms::Data& data)
112 dbms::Date& date = static_cast <dbms::Date&>(data);
114 if(data.getType() == Data::Type::TimeStamp) {
115 a_time->second_part = static_cast <dbms::TimeStamp&>(data).getFractionalSecond();
118 a_time->year = date.getYear();
119 a_time->month = date.getMonth();
120 a_time->day = date.getDay();
121 a_time->hour = date.getHour();
122 a_time->minute = date.getMinute();
123 a_time->second = date.getSecond();