Add no-deprecated to warnings due to dynamic exceptions.
[anna.git] / source / dbms.mysql / 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 <mysql/mysql.h>
10 #include <mysql/mysqld_error.h>
11 #include <mysql/errmsg.h>
12
13 #include <anna/config/defines.hpp>
14 #include <anna/core/tracing/Logger.hpp>
15
16 #include <anna/dbms.mysql/ResultCode.hpp>
17
18 using namespace anna;
19 using namespace anna::dbms;
20
21 mysql::ResultCode::ErrorDecoder mysql::ResultCode::st_errorDecoder;
22
23 mysql::ResultCode::ResultCode(st_mysql* _mysql) :
24   dbms::ResultCode(0, NULL, &st_errorDecoder) {
25   int errorCode = mysql_errno(_mysql);
26
27   if(errorCode != 0)
28     dbms::ResultCode::set(errorCode, mysql_error(_mysql));
29 }
30
31 mysql::ResultCode::ResultCode(st_mysql_stmt* stmt) :
32   dbms::ResultCode(0, NULL, &st_errorDecoder) {
33   int errorCode = mysql_stmt_errno(stmt);
34
35   if(errorCode != 0)
36     dbms::ResultCode::set(errorCode, mysql_stmt_error(stmt));
37 }
38
39 /*
40  * Códigos de error obtenidos de:
41  * http://dev.mysql.com/doc/refman/4.1/en/error-messages-client.html
42  */
43
44 bool mysql::ResultCode::ErrorDecoder::notFound(const int errorCode) const
45 throw() {
46   return errorCode == CR_NO_DATA;
47 }
48
49 bool mysql::ResultCode::ErrorDecoder::successful(const int errorCode) const
50 throw() {
51   return errorCode == 0;
52 }
53
54 bool mysql::ResultCode::ErrorDecoder::locked(const int errorCode) const
55 throw() {
56   return false; // No parece que haya un código de error en MySQL para identificar esta situación Â¿?¿?
57 }
58
59 bool mysql::ResultCode::ErrorDecoder::lostConnection(const int errorCode) const
60 throw() {
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;
63 }