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 <mysql/mysql.h>
10 #include <mysql/mysqld_error.h>
11 #include <mysql/errmsg.h>
13 #include <anna/config/defines.hpp>
14 #include <anna/core/tracing/Logger.hpp>
16 #include <anna/dbms.mysql/ResultCode.hpp>
19 using namespace anna::dbms;
21 mysql::ResultCode::ErrorDecoder mysql::ResultCode::st_errorDecoder;
23 mysql::ResultCode::ResultCode(st_mysql* _mysql) :
24 dbms::ResultCode(0, NULL, &st_errorDecoder) {
25 int errorCode = mysql_errno(_mysql);
28 dbms::ResultCode::set(errorCode, mysql_error(_mysql));
31 mysql::ResultCode::ResultCode(st_mysql_stmt* stmt) :
32 dbms::ResultCode(0, NULL, &st_errorDecoder) {
33 int errorCode = mysql_stmt_errno(stmt);
36 dbms::ResultCode::set(errorCode, mysql_stmt_error(stmt));
40 * Códigos de error obtenidos de:
41 * http://dev.mysql.com/doc/refman/4.1/en/error-messages-client.html
44 bool mysql::ResultCode::ErrorDecoder::notFound(const int errorCode) const
46 return errorCode == CR_NO_DATA;
49 bool mysql::ResultCode::ErrorDecoder::successful(const int errorCode) const
51 return errorCode == 0;
54 bool mysql::ResultCode::ErrorDecoder::locked(const int errorCode) const
56 return false; // No parece que haya un código de error en MySQL para identificar esta situación ¿?¿?
59 bool mysql::ResultCode::ErrorDecoder::lostConnection(const int errorCode) const
61 return errorCode == CR_INVALID_CONN_HANDLE || errorCode == CR_SHARED_MEMORY_CONNECT_REQUEST_ERROR || errorCode == CR_SHARED_MEMORY_CONNECT_ANSWER_ERROR ||
62 errorCode == CR_SHARED_MEMORY_CONNECT_MAP_ERROR || errorCode == CR_SHARED_MEMORY_CONNECT_SET_ERROR;