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 //
11 #include <mysql/mysql.h>
13 #include <anna/config/defines.hpp>
14 #include <anna/core/functions.hpp>
15 #include <anna/core/DataBlock.hpp>
16 #include <anna/core/tracing/Logger.hpp>
18 #include <anna/dbms/String.hpp>
19 #include <anna/dbms/ShortBlock.hpp>
20 #include <anna/dbms/Date.hpp>
21 #include <anna/dbms/TimeStamp.hpp>
22 #include <anna/dbms/LongBlock.hpp>
24 #include <anna/dbms.mysql/mysql.hpp>
29 InputBind::InputBind(const char* name, dbms::Data& data) :
30 dbms::InputBind(name, data),
34 InputBind::~InputBind() {
38 * Completa la informacion establececida por el setupBind.
40 void InputBind::prepare(anna::dbms::Statement* dbmsStmt, anna::dbms::Connection*, const int pos)
41 throw(RuntimeException) {
42 st_mysql_bind* bind = static_cast <dbms::mysql::Statement*>(dbmsStmt)->getBindParams() + pos;
43 Data& data = anna::dbms::Bind::getData();
44 BaseBind::setupBind(*bind, data);
46 if(data.getType() == Data::Type::LongBlock) {
47 DataBlock& dataBlock = static_cast <dbms::LongBlock&>(data).getValue();
48 bind->buffer_type = MYSQL_TYPE_BLOB;
49 bind->buffer_length = dataBlock.getSize();
50 bind->buffer = (char*) dataBlock.getData();
51 bind->length = &a_length;
56 * Se invoca desde anna::dbms::mysql::Statement::execute.
57 * Codificar� la informaci�n C++ de forma que encaje en las estructuras requeridas por el API de MySQL.
59 void InputBind::code() const
60 throw(RuntimeException) {
61 InputBind* _this = const_cast <InputBind*>(this);
62 Data& data = _this->getData();
64 if((_this->a_nullIndicator = data.isNull() ? true : false) == true)
67 switch(data.getType()) {
68 case Data::Type::String:
69 _this->a_length = anna_strlen((char*)(static_cast <dbms::String&>(data).getBuffer()));
71 case Data::Type::Date:
72 case Data::Type::TimeStamp:
73 _this->codeDate(data);
75 case Data::Type::Integer:
76 throw RuntimeException("anna::dbms::mysql::InputBind::code not implemented for Data::Type::Integer", ANNA_FILE_LOCATION);
78 case Data::Type::Float:
79 throw RuntimeException("anna::dbms::mysql::InputBind::code not implemented for Data::Type::Float", ANNA_FILE_LOCATION);
81 case Data::Type::ShortBlock:
82 throw RuntimeException("anna::dbms::mysql::InputBind::code not implemented for Data::Type::ShortBlock", ANNA_FILE_LOCATION);
84 case Data::Type::LongBlock:
85 throw RuntimeException("anna::dbms::mysql::InputBind::code not implemented for Data::Type::LongBlock", ANNA_FILE_LOCATION);
92 * El bind.buffer ha sido asociado a una estructura de tipo MYSQL_TIME (a_time), cuyos valores vamos
93 * a establecer en �ste m�todo.
95 void InputBind::codeDate(dbms::Data& data)
97 dbms::Date& date = static_cast <dbms::Date&>(data);
99 if(data.getType() == Data::Type::TimeStamp) {
100 a_time->second_part = static_cast <dbms::TimeStamp&>(data).getFractionalSecond();
103 a_time->year = date.getYear();
104 a_time->month = date.getMonth();
105 a_time->day = date.getDay();
106 a_time->hour = date.getHour();
107 a_time->minute = date.getMinute();
108 a_time->second = date.getSecond();