00001 // 00002 // File: include/odbcpp/diagnostic.h 00003 // Object: Define the diagnostic objects of the odbcpp library 00004 // Project: http://www.m2osw.com/odbcpp 00005 // Author: alexis_wilke@sourceforge.net 00006 // 00007 // Copyright (C) 2008 Made to Order Software Corp. 00008 // 00009 // This program is free software: you can redistribute it and/or modify 00010 // it under the terms of the GNU General Public License as published by 00011 // the Free Software Foundation, either version 3 of the License, or 00012 // (at your option) any later version. 00013 // 00014 // This program is distributed in the hope that it will be useful, 00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 // GNU General Public License for more details. 00018 // 00019 // You should have received a copy of the GNU General Public License 00020 // along with this program. If not, see <http://www.gnu.org/licenses/> 00021 // or <http://gpl3.m2osw.com/>. 00022 // 00023 00024 #ifndef ODBCPP_DIAG 00025 #define ODBCPP_DIAG 00026 00027 #include "odbcpp_config.h" 00028 #include <sql.h> 00029 #include <string> 00030 #include <vector> 00031 00032 namespace odbcpp 00033 { 00034 00035 class diag_t 00036 { 00037 public: 00038 diag_t(); 00039 00040 std::string msg() const; 00041 00042 std::string f_server; 00043 std::string f_connection; 00044 std::string f_message; 00045 std::string f_odbc_state; 00046 SQLINTEGER f_native_errno; 00047 }; 00049 typedef std::vector<diag_t> diag_vector_t; 00050 00051 00052 class handle; 00053 00054 00055 class diagnostic 00056 { 00057 public: 00058 diagnostic() {} 00059 diagnostic(SQLINTEGER odbcpp_errno, const std::string& message); 00060 diagnostic(SQLSMALLINT handle_type, SQLHANDLE hdl, handle *parent = 0); 00061 00062 void set(SQLSMALLINT handle_type, SQLHANDLE handle); 00063 std::string msg() const; 00064 00065 SQLLEN get_affected_rows() const { return f_affected_rows; } 00066 SQLSMALLINT size() const { return static_cast<SQLSMALLINT>(f_diag.size()); } 00067 diag_t get(SQLSMALLINT record) const { return f_diag[static_cast<int>(record) - 1]; } 00068 diag_t operator [] (int record) const { return f_diag[record - 1]; } 00069 00070 static bool get_string(SQLSMALLINT handle_type, SQLHANDLE handle, SQLSMALLINT record, SQLSMALLINT identifier, std::string& string); 00071 static bool get_integer(SQLSMALLINT handle_type, SQLHANDLE handle, SQLSMALLINT record, SQLSMALLINT identifier, SQLINTEGER& integer); 00072 static bool get_length(SQLSMALLINT handle_type, SQLHANDLE handle, SQLSMALLINT record, SQLSMALLINT identifier, SQLLEN& length); 00073 00074 private: 00075 SQLLEN f_affected_rows; 00076 diag_vector_t f_diag; 00077 }; 00078 00079 00080 00081 } // namespace odbcpp 00082 00083 00084 #endif // #ifndef ODBCPP_DIAG