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 <anna/xml/Node.hpp>
10 #include <anna/xml/Attribute.hpp>
12 #include <anna/dbms/Database.hpp>
13 #include <anna/dbms/Connection.hpp>
14 #include <anna/dbms/Sentence.hpp>
15 #include <anna/dbms/Statement.hpp>
20 const string& dbms::Sentence::getName() const
23 return (a_dbStatement == NULL) ? empty : a_dbStatement->getName();
26 void dbms::Sentence::initialize(dbms::Database& database)
27 throw(RuntimeException) {
28 Guard guard(this, "anna::dbms::Sentence (initialize)");
29 a_dbStatement = do_initialize(database);
32 //-------------------------------------------------------------------------------------
33 // Ojo!! No activamos la seccion critica en este metodo porque debera estar
34 // activa externamente ... para recoger datos multiples, etc, etc.
35 //-------------------------------------------------------------------------------------
36 dbms::ResultCode dbms::Sentence::execute(dbms::Connection& connection, dbms::Statement* statement)
37 throw(RuntimeException) {
38 using namespace anna::dbms;
42 result = connection.execute(statement);
44 if(result.successful() == false) {
45 if(a_mode == Mode::SilentWhenNotFound && result.notFound() == true)
48 throw DatabaseException(result, ANNA_FILE_LOCATION);
50 } catch(DatabaseException& edb) {
51 string msg("Sentence: ");
55 throw RuntimeException(msg, ANNA_FILE_LOCATION);
61 bool dbms::Sentence::fetch()
62 throw(RuntimeException) {
66 result = a_dbStatement->fetch();
67 } catch(dbms::DatabaseException& edb) {
68 throw RuntimeException(edb);
74 string dbms::Sentence::asString() const
77 string result("dbms::Sentence { Mode: ");
78 result += (a_mode == Mode::SilentWhenNotFound) ? "SilentWhenNotFound" : "ExceptionWhenNotFound";
81 if(a_dbStatement != NULL)
82 result += a_dbStatement->asString();
84 result += "dbms::Statement: <null>";
86 return result += " }";
90 xml::Node* dbms::Sentence::asXML(xml::Node* parent) const
92 xml::Node* result = parent->createChild("dbms.Sentence");
93 result->createAttribute("Mode", (a_mode == Mode::SilentWhenNotFound) ? "SilentWhenNotFound" : "ExceptionWhenNotFound");
96 a_dbStatement->asXML(result);