X-Git-Url: https://git.teslayout.com/public/public/public/?a=blobdiff_plain;f=source%2Fdbms%2FResultCode.cpp;fp=source%2Fdbms%2FResultCode.cpp;h=453f78bb1759e950b79e91655cd9d4653cc0995e;hb=78be86969d2f26a9084b0c4af6ce43d5fa4ed3fd;hp=0000000000000000000000000000000000000000;hpb=a3b95648bd76140ef55e0b5941d423eee6c3856f;p=anna.git diff --git a/source/dbms/ResultCode.cpp b/source/dbms/ResultCode.cpp new file mode 100644 index 0000000..453f78b --- /dev/null +++ b/source/dbms/ResultCode.cpp @@ -0,0 +1,104 @@ +// 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 + +using namespace std; +using namespace anna::dbms; + +bool ResultCode::notFound() const +throw(anna::RuntimeException) { + if(a_errorDecoder == NULL) { + string msg(asString()); + msg += " | Has no decoder for associated error"; + throw anna::RuntimeException(msg, ANNA_FILE_LOCATION); + } + + return a_errorDecoder->notFound(a_errorCode); +} + +bool ResultCode::successful() const +throw(anna::RuntimeException) { + if(a_errorDecoder == NULL) { + string msg(asString()); + msg += " | Has no decoder for associated error"; + throw anna::RuntimeException(msg, ANNA_FILE_LOCATION); + } + + return a_errorDecoder->successful(a_errorCode); +} + +bool ResultCode::locked() const +throw(anna::RuntimeException) { + if(a_errorDecoder == NULL) { + string msg(asString()); + msg += " | Has no decoder for associated error"; + throw anna::RuntimeException(msg, ANNA_FILE_LOCATION); + } + + return a_errorDecoder->locked(a_errorCode); +} + +bool ResultCode::lostConnection() const +throw(anna::RuntimeException) { + if(a_errorDecoder == NULL) { + string msg(asString()); + msg += " | Has no decoder for associated error"; + throw anna::RuntimeException(msg, ANNA_FILE_LOCATION); + } + + return a_errorDecoder->lostConnection(a_errorCode); +} + +// +// No usamos la std::string porque la gran mayoría de las veces la ejecución de las sentencias SQL será +// correcta => no hará falta reservar ninguna memoria. +// +void ResultCode::copy(const char* text) +throw() { + if(text == NULL) { + if(a_errorText != NULL) { + free(a_errorText); + a_errorText = NULL; + } + } else { + char* aux; + + if((aux = anna_strchr((char*) text, '\n')) != NULL) + * aux = 0; + + const int textLen = anna_strlen(text); + + if(a_errorText == NULL) + a_errorText = strdup(text); + else if(anna_strlen(a_errorText) >= textLen) + anna_strcpy(a_errorText, text); + else { + free(a_errorText); + a_errorText = strdup(text); + } + } +} + +std::string ResultCode::asString() const +throw() { + std::string result("dbms::ResultCode { Error: "); + result += functions::asString(a_errorCode); + result += " | Error: "; + result += (a_errorText == NULL) ? "(null)" : a_errorText; + result += " | Correct: "; + + if(a_errorDecoder != NULL) + result += functions::asString(successful()); + else + result += ""; + + return result += " }"; +}