1 // ANNA - Anna is Not 'N' Anymore
3 // (c) Copyright 2005-2014 Eduardo Ramos Testillano & Francisco Ruiz Rayo
5 // https://bitbucket.org/testillano/anna
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions
11 // * Redistributions of source code must retain the above copyright
12 // notice, this list of conditions and the following disclaimer.
13 // * Redistributions in binary form must reproduce the above
14 // copyright notice, this list of conditions and the following disclaimer
15 // in the documentation and/or other materials provided with the
17 // * Neither the name of Google Inc. nor the names of its
18 // contributors may be used to endorse or promote products derived from
19 // this software without specific prior written permission.
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 // Authors: eduardo.ramos.testillano@gmail.com
34 // cisco.tierra@gmail.com
37 #ifndef anna_dbms_ResultCode_hpp
38 #define anna_dbms_ResultCode_hpp
46 #include <anna/config/defines.hpp>
47 #include <anna/core/RuntimeException.hpp>
54 Clase para acceder a la informacion devuelta por el gestor de base de datos
55 referente al ultimo comando realizado.
61 \warning Antes de usarse debe asignarse a algun otro ResultCode obtenido mediante la invocacion
62 a anna::dbms::Connection::execute.
64 ResultCode() : a_errorText(NULL), a_errorDecoder(NULL), a_errorCode(0) {;}
68 @param other Instancia de la que copiar los datos.
70 ResultCode(const ResultCode& other) :
72 a_errorDecoder(other.a_errorDecoder) {
73 set(other.a_errorCode, other.a_errorText);
79 virtual ~ResultCode() { if(a_errorText != NULL) free(a_errorText); }
82 Devuelve el codigo de error del ultimo comando ejecutado contra la base de datos.
83 @return El codigo de error del ultimo comando ejecutado contra la base de datos.
85 int getErrorCode() const throw() { return a_errorCode; }
88 Devuelve el texto del error del ultimo comando ejecutado contra la base de datos.
89 @return El texto del error del ultimo comando ejecutado contra la base de datos.
91 const char* getErrorText() const throw() { return (a_errorText != NULL) ? a_errorText : ""; }
96 @param resultCode Instancia a copiar.
97 @return Una instancia de si mismo.
99 ResultCode& operator = (const ResultCode& resultCode)
101 if(this != &resultCode) {
102 a_errorDecoder = resultCode.a_errorDecoder;
103 set(resultCode.a_errorCode, resultCode.a_errorText);
110 Devuelve \em true si las condiciones de busqueda de la ultimo operacion
111 no han sido satisfechas por ningun registro o \em false en otro caso.
112 @return \em true si las condiciones de busqueda de la ultimo operacion
113 no han sido satisfechas por ningun registro o \em false en otro caso.
115 bool notFound() const throw(anna::RuntimeException);
118 Devuelve \em true si la ultima operacion solicitada fue realizada correctamente
119 o \em false en otro caso.
120 @return \em true si la ultima operacion solicitada fue realizada correctamente
121 o \em false en otro caso.
123 bool successful() const throw(anna::RuntimeException);
126 Devuelve \em true Si el registro obtenenido en una sentencia de seleccion con indicador
127 de modo exclusivo ha sido bloqueada previamente por otro proceso y/o contexto de base de
128 datos o \em false en otro caso.
129 @return \em true Si el registro obtenenido en una sentencia de seleccion con indicador
130 de modo exclusivo ha sido bloqueada previamente por otro proceso y/o contexto de base de
131 datos o \em false en otro caso.
133 bool locked() const throw(anna::RuntimeException);
136 Devuelve \em true si se perdio la conexion la base de datos o \em false en otro caso.
137 @return \em true si se perdio la conexion la base de datos o \em false en otro caso.
139 bool lostConnection() const throw(anna::RuntimeException);
142 Devuelve una cadena con la informacion sobre esta clase.
143 \return Una cadena con la informacion sobre esta clase.
145 std::string asString() const throw();
148 static const int MaxErrorLen = 512;
151 Decodificador del error devuelto por el RDBMS concreto que estemos usando.
152 \warning Exclusivamente uso interno.
156 virtual bool notFound(const int errorCode) const throw() = 0;
157 virtual bool successful(const int errorCode) const throw() = 0;
158 virtual bool locked(const int errorCode) const throw() = 0;
159 virtual bool lostConnection(const int errorCode) const throw() = 0;
165 \param errorCode Codigo de error asociado a la ultima operacion realizada contra la base de datos.
166 \param errorText Texto asociado al error de ultima operacion realizada contra la base de datos. Puede ser
167 NULL si no hay ningun texto de error asociado al codigo recibido.
168 \param errorDecoder Decofidicador de errores.
170 ResultCode(const int errorCode, const char* errorText, const ErrorDecoder* errorDecoder) :
172 a_errorDecoder(errorDecoder) {
173 set(errorCode, errorText);
177 Establece el contenido de esta clase.
179 \param errorCode Codigo de error asociado a la ultima operacion realizada contra la base de datos.
180 \param errorText Texto asociado al error de ultima operacion realizada contra la base de datos.
182 void set(const int errorCode, const char* errorText)
184 a_errorCode = errorCode;
191 const ErrorDecoder* a_errorDecoder;
193 void copy(const char* text) throw();