File indexing completed on 2025-02-23 05:15:19
0001 // 0002 // Copyright (C) 2004-2007 Maciej Sobczak, Stephen Hutton 0003 // Distributed under the Boost Software License, Version 1.0. 0004 // (See accompanying file LICENSE_1_0.txt or copy at 0005 // http://www.boost.org/LICENSE_1_0.txt) 0006 // 0007 0008 #define SOCI_ORACLE_SOURCE 0009 #include "soci/oracle/soci-oracle.h" 0010 #include "error.h" 0011 #include <limits> 0012 #include <sstream> 0013 0014 #ifdef _MSC_VER 0015 #pragma warning(disable:4355) 0016 #endif 0017 0018 using namespace soci; 0019 using namespace soci::details; 0020 using namespace soci::details::oracle; 0021 0022 oracle_soci_error::oracle_soci_error(std::string const & msg, int errNum) 0023 : soci_error(msg), err_num_(errNum), cat_(unknown) 0024 { 0025 if (errNum == 3113 || 0026 errNum == 3114 || 0027 errNum == 12162 || 0028 errNum == 12541 || 0029 errNum == 25403) 0030 { 0031 cat_ = connection_error; 0032 } 0033 else if (errNum == 1400) 0034 { 0035 cat_ = constraint_violation; 0036 } 0037 else if (errNum == 1466 || 0038 errNum == 2055 || 0039 errNum == 2067 || 0040 errNum == 2091 || 0041 errNum == 2092 || 0042 errNum == 25401 || 0043 errNum == 25402 || 0044 errNum == 25405 || 0045 errNum == 25408 || 0046 errNum == 25409) 0047 { 0048 cat_ = unknown_transaction_state; 0049 } 0050 } 0051 0052 void soci::details::oracle::get_error_details(sword res, OCIError *errhp, 0053 std::string &msg, int &errNum) 0054 { 0055 text errbuf[512]; 0056 sb4 errcode; 0057 errNum = 0; 0058 0059 switch (res) 0060 { 0061 case OCI_NO_DATA: 0062 msg = "soci error: No data"; 0063 break; 0064 case OCI_ERROR: 0065 case OCI_SUCCESS_WITH_INFO: 0066 OCIErrorGet(errhp, 1, 0, &errcode, 0067 errbuf, sizeof(errbuf), OCI_HTYPE_ERROR); 0068 msg = reinterpret_cast<char*>(errbuf); 0069 errNum = static_cast<int>(errcode); 0070 break; 0071 case OCI_INVALID_HANDLE: 0072 msg = "soci error: Invalid handle"; 0073 break; 0074 default: 0075 msg = "soci error: Unknown error code"; 0076 } 0077 } 0078 0079 void soci::details::oracle::throw_oracle_soci_error(sword res, OCIError *errhp) 0080 { 0081 std::string msg; 0082 int errNum; 0083 0084 get_error_details(res, errhp, msg, errNum); 0085 throw oracle_soci_error(msg, errNum); 0086 }