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 //
9 #include <mysql/mysql.h>
11 #include <anna/core/DataBlock.hpp>
13 #include <anna/dbms/Data.hpp>
14 #include <anna/dbms/LongBlock.hpp>
16 #include <anna/dbms.mysql/BaseBind.hpp>
21 //----------------------------------------------------------------------------
22 // (1) Reserva 2 Kbytes para trabajar con el LOB.
23 //----------------------------------------------------------------------------
24 dbms::mysql::BaseBind::BaseBind(const dbms::Data& data) :
25 a_type(data.getType()),
28 case Data::Type::ShortBlock:
29 case Data::Type::LongBlock:
31 case Data::Type::Date: // (1)
32 case Data::Type::TimeStamp:
33 a_time = new MYSQL_TIME;
39 dbms::mysql::BaseBind::~BaseBind() {
44 * SegĂșn http://dev.mysql.com/doc/refman/4.1/en/c-api-prepared-statement-datatypes.html
45 * y el truco para recoger BLOB's http://dev.mysql.com/doc/refman/4.1/en/mysql-stmt-fetch.html.
47 void dbms::mysql::BaseBind::setupBind(st_mysql_bind& bind, dbms::Data& data)
48 throw(RuntimeException) {
49 anna_memset(&bind, 0, sizeof(bind));
50 bind.is_null = &a_nullIndicator;
54 case Data::Type::Integer:
55 bind.buffer_type = MYSQL_TYPE_LONG;
56 bind.buffer_length = data.getMaxSize();
57 bind.length = &a_length;
58 bind.buffer = const_cast <dbms::Data&>(data).getBuffer();
59 bind.is_unsigned = false;
61 case Data::Type::String:
62 bind.buffer_type = MYSQL_TYPE_STRING;
63 bind.buffer_length = data.getMaxSize();
64 bind.length = &a_length;
65 bind.buffer = const_cast <dbms::Data&>(data).getBuffer();
67 case Data::Type::Float:
68 bind.buffer_type = MYSQL_TYPE_FLOAT;
69 bind.buffer_length = data.getMaxSize();
70 bind.length = &a_length;
71 bind.buffer = const_cast <dbms::Data&>(data).getBuffer();
73 case Data::Type::Date: // (1)
74 bind.buffer_type = MYSQL_TYPE_DATE;
75 bind.buffer_length = sizeof(MYSQL_TIME);
76 bind.length = &a_length;
77 bind.buffer = (char*) a_time;
79 case Data::Type::TimeStamp:
80 bind.buffer_type = MYSQL_TYPE_DATETIME;
81 bind.buffer_length = sizeof(MYSQL_TIME);
82 bind.length = &a_length;
83 bind.buffer = (char*) a_time;
85 case Data::Type::ShortBlock:
87 if((bind.buffer_length = data.getMaxSize()) < MaxBlobSize) {
88 bind.buffer_type = MYSQL_TYPE_BLOB;
89 bind.length = &a_length;
90 bind.buffer = const_cast <dbms::Data&>(data).getBuffer();
92 string msg(data.asString());
93 msg += functions::asString(" | Over maximum size: %d/%d", data.getMaxSize(), MaxBlobSize);
94 throw RuntimeException(msg, ANNA_FILE_LOCATION);
98 case Data::Type::LongBlock:
100 * El tratamiento particular se realiza en las clases InputBind y OutputBind.
104 throw RuntimeException(functions::asString("Unsupported data type %d", (int) a_type), ANNA_FILE_LOCATION);