Add no-deprecated to warnings due to dynamic exceptions.
[anna.git] / source / dbms / ResultCode.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/functions.hpp>
10
11 #include <anna/dbms/ResultCode.hpp>
12
13 using namespace std;
14 using namespace anna::dbms;
15
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);
22   }
23
24   return a_errorDecoder->notFound(a_errorCode);
25 }
26
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);
33   }
34
35   return a_errorDecoder->successful(a_errorCode);
36 }
37
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);
44   }
45
46   return a_errorDecoder->locked(a_errorCode);
47 }
48
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);
55   }
56
57   return a_errorDecoder->lostConnection(a_errorCode);
58 }
59
60 //
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.
63 //
64 void ResultCode::copy(const char* text)
65 throw() {
66   if(text == NULL) {
67     if(a_errorText != NULL) {
68       free(a_errorText);
69       a_errorText = NULL;
70     }
71   } else {
72     char* aux;
73
74     if((aux = anna_strchr((char*) text, '\n')) != NULL)
75       * aux = 0;
76
77     const int textLen = anna_strlen(text);
78
79     if(a_errorText == NULL)
80       a_errorText = strdup(text);
81     else if(anna_strlen(a_errorText) >= textLen)
82       anna_strcpy(a_errorText, text);
83     else {
84       free(a_errorText);
85       a_errorText = strdup(text);
86     }
87   }
88 }
89
90 std::string ResultCode::asString() const
91 throw() {
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: ";
97
98   if(a_errorDecoder != NULL)
99     result += functions::asString(successful());
100   else
101     result += "<No ErrorDecoder>";
102
103   return result += " }";
104 }