File indexing completed on 2025-02-23 05:15:18
0001 // 0002 // Copyright (C) 2004-2006 Maciej Sobczak, Stephen Hutton, David Courtney 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 #ifndef SOCI_UTILITY_H_INCLUDED 0009 #define SOCI_UTILITY_H_INCLUDED 0010 0011 #include "soci-backend.h" 0012 #include <sstream> 0013 0014 namespace soci 0015 { 0016 0017 inline void throw_odbc_error(SQLSMALLINT htype, SQLHANDLE hndl, char const * msg) 0018 { 0019 SQLCHAR message[SQL_MAX_MESSAGE_LENGTH + 1]; 0020 SQLCHAR sqlstate[SQL_SQLSTATE_SIZE + 1]; 0021 SQLINTEGER sqlcode; 0022 SQLSMALLINT length, i; 0023 0024 std::stringstream ss; 0025 0026 i = 1; 0027 0028 /* get multiple field settings of diagnostic record */ 0029 while (SQLGetDiagRecA(htype, 0030 hndl, 0031 i, 0032 sqlstate, 0033 &sqlcode, 0034 message, 0035 SQL_MAX_MESSAGE_LENGTH + 1, 0036 &length) == SQL_SUCCESS) 0037 { 0038 ss << std::endl << "SOCI ODBC Error: " << msg << std::endl 0039 << "SQLSTATE = " << sqlstate << std::endl 0040 << "Native Error Code = " << sqlcode << std::endl 0041 << message << std::endl; 0042 ++i; 0043 } 0044 0045 throw soci_error(ss.str()); 0046 } 0047 0048 inline bool is_odbc_error(SQLRETURN rc) 0049 { 0050 if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) 0051 { 0052 return true; 0053 } 0054 else 0055 { 0056 return false; 0057 } 0058 } 0059 0060 } 0061 0062 #endif // SOCI_UTILITY_H_INCLUDED