Remove warnings
[anna.git] / source / dbms.oracle / 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 <stdlib.h>
10 #include <stdio.h>
11
12 #include <oci.h>
13
14 #include <anna/config/defines.hpp>
15 #include <anna/core/tracing/Logger.hpp>
16
17 #include <anna/dbms.oracle/ResultCode.hpp>
18
19 using namespace anna;
20 using namespace anna::dbms;
21
22 oracle::ResultCode::ErrorDecoder oracle::ResultCode::st_errorDecoder;
23
24 oracle::ResultCode::ResultCode(const int status, OCIError* error) :
25   dbms::ResultCode(0, NULL, &st_errorDecoder) {
26   char errorText [dbms::ResultCode::MaxErrorLen];
27   int errorCode = status;
28
29   if(status == OCI_SUCCESS) {
30     dbms::ResultCode::set(OCI_SUCCESS, NULL);
31     return;
32   } else if(status == OCI_SUCCESS_WITH_INFO) {
33     OCIErrorGet(error, (ub4) 1, (text*) 0, &errorCode, (unsigned char*) errorText, (ub4) sizeof(errorText), OCI_HTYPE_ERROR);
34     dbms::ResultCode::set(OCI_SUCCESS, errorText);
35     LOGINFORMATION(Logger::information(asString(), ANNA_FILE_LOCATION));
36     return;
37   }
38
39   switch(status) {
40   case OCI_ERROR:
41     OCIErrorGet(error, (ub4) 1, (text*) 0, &errorCode, (unsigned char*) errorText, (ub4) sizeof(errorText), OCI_HTYPE_ERROR);
42     break;
43   case OCI_NEED_DATA: anna_strcpy(errorText, "OCI | Need data"); break;
44   case OCI_NO_DATA: anna_strcpy(errorText, "OCI | Data not found"); break;
45   case OCI_INVALID_HANDLE: anna_strcpy(errorText, "OCI | Invalid handle"); break;
46   default: sprintf(errorText, "OCI | Error code: %d", status); break;
47   }
48
49   dbms::ResultCode::set(errorCode, errorText);
50 }
51
52 bool oracle::ResultCode::ErrorDecoder::notFound(const int errorCode) const
53 throw() {
54   return errorCode == OCI_NO_DATA;
55 }
56
57 bool oracle::ResultCode::ErrorDecoder::successful(const int errorCode) const
58 throw() {
59   return errorCode == OCI_SUCCESS;
60 }
61
62 bool oracle::ResultCode::ErrorDecoder::lostConnection(const int errorCode) const
63 throw() {
64   return errorCode == 28 || errorCode == 3113 || errorCode == 3114 || errorCode == 1012 || errorCode == 12570 || errorCode == 12571;
65 }