X-Git-Url: https://git.teslayout.com/public/public/public/?a=blobdiff_plain;f=source%2Fdbms%2FSentence.cpp;fp=source%2Fdbms%2FSentence.cpp;h=34dfaf39a43657c0ff1c6a6ae9807a8444e5f8c0;hb=78be86969d2f26a9084b0c4af6ce43d5fa4ed3fd;hp=0000000000000000000000000000000000000000;hpb=a3b95648bd76140ef55e0b5941d423eee6c3856f;p=anna.git diff --git a/source/dbms/Sentence.cpp b/source/dbms/Sentence.cpp new file mode 100644 index 0000000..34dfaf3 --- /dev/null +++ b/source/dbms/Sentence.cpp @@ -0,0 +1,99 @@ +// ANNA - Anna is Not Nothingness Anymore // +// // +// (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo // +// // +// See project site at http://redmine.teslayout.com/projects/anna-suite // +// See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE // + + +#include +#include + +#include +#include +#include +#include + +using namespace std; +using namespace anna; + +const string& dbms::Sentence::getName() const +throw() { + static string empty; + return (a_dbStatement == NULL) ? empty : a_dbStatement->getName(); +} + +void dbms::Sentence::initialize(dbms::Database& database) +throw(RuntimeException) { + Guard guard(this, "anna::dbms::Sentence (initialize)"); + a_dbStatement = do_initialize(database); +} + +//------------------------------------------------------------------------------------- +// Ojo!! No activamos la seccion critica en este metodo porque debera estar +// activa externamente ... para recoger datos multiples, etc, etc. +//------------------------------------------------------------------------------------- +dbms::ResultCode dbms::Sentence::execute(dbms::Connection& connection, dbms::Statement* statement) +throw(RuntimeException) { + using namespace anna::dbms; + ResultCode result; + + try { + result = connection.execute(statement); + + if(result.successful() == false) { + if(a_mode == Mode::SilentWhenNotFound && result.notFound() == true) + return result; + + throw DatabaseException(result, ANNA_FILE_LOCATION); + } + } catch(DatabaseException& edb) { + string msg("Sentence: "); + msg += getName(); + msg += " | "; + msg += edb.getText(); + throw RuntimeException(msg, ANNA_FILE_LOCATION); + } + + return result; +} + +bool dbms::Sentence::fetch() +throw(RuntimeException) { + bool result = false; + + try { + result = a_dbStatement->fetch(); + } catch(dbms::DatabaseException& edb) { + throw RuntimeException(edb); + } + + return result; +} + +string dbms::Sentence::asString() const +/*virtual*/ +throw() { + string result("dbms::Sentence { Mode: "); + result += (a_mode == Mode::SilentWhenNotFound) ? "SilentWhenNotFound" : "ExceptionWhenNotFound"; + result += " | "; + + if(a_dbStatement != NULL) + result += a_dbStatement->asString(); + else + result += "dbms::Statement: "; + + return result += " }"; +} + +/*virtual*/ +xml::Node* dbms::Sentence::asXML(xml::Node* parent) const +throw() { + xml::Node* result = parent->createChild("dbms.Sentence"); + result->createAttribute("Mode", (a_mode == Mode::SilentWhenNotFound) ? "SilentWhenNotFound" : "ExceptionWhenNotFound"); + + if(a_dbStatement) + a_dbStatement->asXML(result); + + return result; +}