Fix bug in json to xml convert library
[anna.git] / source / dbms / Statement.cpp
1 // ANNA - Anna is Not Nothingness Anymore                                                         //
2 //                                                                                                //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo                         //
4 //                                                                                                //
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 //
7
8
9 #include <anna/core/tracing/TraceMethod.hpp>
10
11 #include <anna/xml/Node.hpp>
12 #include <anna/xml/Attribute.hpp>
13
14 #include <anna/dbms/Statement.hpp>
15 #include <anna/dbms/InputBind.hpp>
16 #include <anna/dbms/OutputBind.hpp>
17 #include <anna/dbms/Database.hpp>
18
19 using namespace std;
20 using namespace anna;
21 using namespace anna::dbms;
22
23 Statement::~Statement() {
24   InputBind* ibind;
25   OutputBind* obind;
26
27   for(input_iterator ii = input_begin(), maxii = input_end(); ii != maxii; ii ++) {
28     ibind = inputBind(ii);
29     ibind->release(this);
30     a_database.deallocate(ibind);
31   }
32
33   for(output_iterator ii = output_begin(), maxii = output_end(); ii != maxii; ii ++) {
34     obind = outputBind(ii);
35     obind->release(this);
36     a_database.deallocate(obind);
37   }
38 }
39
40 string Statement::asString() const
41 throw() {
42   string result("dbms::Statement { Nombre: ");
43   result += a_name;
44   result += functions::asText(" | Var.Entrada: ", input_size());
45   result += functions::asText(" | Var.Salida: ",  output_size());
46   result += " | ";
47   result += a_measureTiming.asString();
48   result += " | Expresion: ";
49   result += a_expression;
50   return result += " }";
51 }
52
53 xml::Node* dbms::Statement::asXML(xml::Node* parent) const
54 throw() {
55   xml::Node* result = parent->createChild("dbms.Statement");
56   result->createAttribute("Name", a_name);
57   xml::Node* node = result->createChild("Timing");
58   node->createAttribute("N", a_measureTiming.size());
59   node->createAttribute("Accumulator", a_measureTiming.getAccumulator());
60   node->createAttribute("Timing", a_measureTiming.asString());
61   result->createChild("Expression")->createText(a_expression);
62   return result;
63 }
64
65 void Statement::bindInput(const char* name, Data& data)
66 throw() {
67   a_inputBinds.push_back(a_database.allocateInputBind(name, data));
68 }
69
70 const OutputBind* Statement::bindOutput(const char* name, Data& i)
71 throw() {
72   OutputBind* result = a_database.allocateOutputBind(name, i);
73   a_outputBinds.push_back(result);
74   return result;
75 }
76
77 Data& Statement::input(input_iterator& ii)
78 throw() {
79   return (*ii)->getData();
80 }
81
82 Data& Statement::output(output_iterator& ii)
83 throw() {
84   return (*ii)->getData();
85 }
86