File indexing completed on 2025-02-23 05:15:16
0001 // 0002 // Copyright (C) 2004-2006 Maciej Sobczak, Stephen Hutton, Rafal Bobrowski 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_FIREBIRD_SOURCE 0009 #include "soci/firebird/soci-firebird.h" 0010 #include "firebird/error-firebird.h" 0011 0012 #include <cstdlib> 0013 #include <string> 0014 0015 namespace soci 0016 { 0017 0018 firebird_soci_error::firebird_soci_error(std::string const & msg, ISC_STATUS const * status) 0019 : soci_error(msg) 0020 { 0021 if (status != 0) 0022 { 0023 std::size_t i = 0; 0024 while (i < stat_size && status[i] != 0) 0025 { 0026 status_.push_back(status[i++]); 0027 } 0028 } 0029 } 0030 0031 namespace details 0032 { 0033 0034 namespace firebird 0035 { 0036 0037 void get_iscerror_details(ISC_STATUS * status_vector, std::string &msg) 0038 { 0039 char msg_buffer[SOCI_FIREBIRD_ERRMSG]; 0040 const ISC_STATUS *pvector = status_vector; 0041 0042 try 0043 { 0044 // fetching first error message 0045 fb_interpret(msg_buffer, SOCI_FIREBIRD_ERRMSG, &pvector); 0046 msg = msg_buffer; 0047 0048 // fetching next errors 0049 while (fb_interpret(msg_buffer, SOCI_FIREBIRD_ERRMSG, &pvector)) 0050 { 0051 msg += "\n"; 0052 msg += msg_buffer; 0053 } 0054 } 0055 catch (...) 0056 { 0057 throw firebird_soci_error("Exception caught while fetching error information"); 0058 } 0059 } 0060 0061 bool check_iscerror(ISC_STATUS const * status_vector, long errNum) 0062 { 0063 std::size_t i=0; 0064 while (status_vector[i] != 0) 0065 { 0066 if (status_vector[i] == 1 && status_vector[i+1] == errNum) 0067 { 0068 return true; 0069 } 0070 ++i; 0071 } 0072 0073 return false; 0074 } 0075 void throw_iscerror(ISC_STATUS * status_vector) 0076 { 0077 std::string msg; 0078 0079 get_iscerror_details(status_vector, msg); 0080 throw firebird_soci_error(msg, status_vector); 0081 } 0082 0083 } // namespace firebird 0084 0085 } // namespace details 0086 0087 } // namespace soci