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/core/functions.hpp>
11 #include <anna/dbms/ResultCode.hpp>
14 using namespace anna::dbms;
16 bool ResultCode::notFound() const
17 throw(anna::RuntimeException) {
18 if(a_errorDecoder == NULL) {
19 string msg(asString());
20 msg += " | Has no decoder for associated error";
21 throw anna::RuntimeException(msg, ANNA_FILE_LOCATION);
24 return a_errorDecoder->notFound(a_errorCode);
27 bool ResultCode::successful() const
28 throw(anna::RuntimeException) {
29 if(a_errorDecoder == NULL) {
30 string msg(asString());
31 msg += " | Has no decoder for associated error";
32 throw anna::RuntimeException(msg, ANNA_FILE_LOCATION);
35 return a_errorDecoder->successful(a_errorCode);
38 bool ResultCode::locked() const
39 throw(anna::RuntimeException) {
40 if(a_errorDecoder == NULL) {
41 string msg(asString());
42 msg += " | Has no decoder for associated error";
43 throw anna::RuntimeException(msg, ANNA_FILE_LOCATION);
46 return a_errorDecoder->locked(a_errorCode);
49 bool ResultCode::lostConnection() const
50 throw(anna::RuntimeException) {
51 if(a_errorDecoder == NULL) {
52 string msg(asString());
53 msg += " | Has no decoder for associated error";
54 throw anna::RuntimeException(msg, ANNA_FILE_LOCATION);
57 return a_errorDecoder->lostConnection(a_errorCode);
61 // No usamos la std::string porque la gran mayoría de las veces la ejecución de las sentencias SQL será
62 // correcta => no hará falta reservar ninguna memoria.
64 void ResultCode::copy(const char* text)
67 if(a_errorText != NULL) {
74 if((aux = anna_strchr((char*) text, '\n')) != NULL)
77 const int textLen = anna_strlen(text);
79 if(a_errorText == NULL)
80 a_errorText = strdup(text);
81 else if(anna_strlen(a_errorText) >= textLen)
82 anna_strcpy(a_errorText, text);
85 a_errorText = strdup(text);
90 std::string ResultCode::asString() const
92 std::string result("dbms::ResultCode { Error: ");
93 result += functions::asString(a_errorCode);
94 result += " | Error: ";
95 result += (a_errorText == NULL) ? "(null)" : a_errorText;
96 result += " | Correct: ";
98 if(a_errorDecoder != NULL)
99 result += functions::asString(successful());
101 result += "<No ErrorDecoder>";
103 return result += " }";