00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __ODBCXX_ERRORHANDLER_H
00023 #define __ODBCXX_ERRORHANDLER_H
00024
00025 #include <odbc++/setup.h>
00026 #include <odbc++/types.h>
00027 #include <odbc++/threads.h>
00028
00029 namespace odbc {
00030
00032 class ODBCXX_EXPORT ErrorHandler {
00033 friend class DriverManager;
00034 friend class DataStreamBuf;
00035 friend class DataStream;
00036 private:
00037
00038 struct PD;
00039 PD* pd_;
00040
00041 WarningList* warnings_;
00042 bool collectWarnings_;
00043
00044
00045 enum {
00046 MAX_WARNINGS=128
00047 };
00048
00049 protected:
00050 void _postWarning(SQLWarning* w);
00051
00052
00053 #if ODBCVER < 0x0300
00054 void _checkErrorODBC2(SQLHENV henv,
00055 SQLHDBC hdbc,
00056 SQLHSTMT hstmt,
00057 SQLRETURN r,
00058 const ODBCXX_STRING& what);
00059 #else
00060
00061 void _checkErrorODBC3(SQLINTEGER handleType,
00062 SQLHANDLE h,
00063 SQLRETURN r, const ODBCXX_STRING& what);
00064 #endif //ODBCVER < 0x0300
00065
00066 void _checkStmtError(SQLHSTMT hstmt,
00067 SQLRETURN r, const ODBCXX_CHAR_TYPE* what=ODBCXX_STRING_CONST("")) {
00068
00069 if(r==SQL_SUCCESS_WITH_INFO || r==SQL_ERROR) {
00070 #if ODBCVER < 0x0300
00071
00072 this->_checkErrorODBC2(SQL_NULL_HENV, SQL_NULL_HDBC, hstmt,
00073 r,ODBCXX_STRING_C(what));
00074 #else
00075
00076 this->_checkErrorODBC3(SQL_HANDLE_STMT,hstmt,r,ODBCXX_STRING_C(what));
00077
00078 #endif
00079 }
00080 }
00081
00082 void _checkConError(SQLHDBC hdbc,
00083 SQLRETURN r,
00084 const ODBCXX_CHAR_TYPE* what=ODBCXX_STRING_CONST("")) {
00085 if(r==SQL_SUCCESS_WITH_INFO || r==SQL_ERROR) {
00086 #if ODBCVER < 0x0300
00087
00088 this->_checkErrorODBC2(SQL_NULL_HENV, hdbc, SQL_NULL_HSTMT, r,
00089 ODBCXX_STRING_C(what));
00090
00091 #else
00092
00093 this->_checkErrorODBC3(SQL_HANDLE_DBC, hdbc, r, ODBCXX_STRING_C(what));
00094
00095 #endif
00096 }
00097 }
00098
00099 void _checkEnvError(SQLHENV henv,
00100 SQLRETURN r,
00101 const ODBCXX_CHAR_TYPE* what=ODBCXX_STRING_CONST("")) {
00102 if(r==SQL_SUCCESS_WITH_INFO || r==SQL_ERROR) {
00103 #if ODBCVER < 0x0300
00104
00105 this->_checkErrorODBC2(henv,SQL_NULL_HDBC,SQL_NULL_HSTMT,r,
00106 ODBCXX_STRING_C(what));
00107
00108 #else
00109
00110 this->_checkErrorODBC3(SQL_HANDLE_ENV,henv,r,ODBCXX_STRING_C(what));
00111
00112 #endif
00113 }
00114 }
00115
00117 ErrorHandler(bool collectWarnings =true);
00118
00119 public:
00121 void clearWarnings();
00122
00127 WarningList* getWarnings();
00128
00130 virtual ~ErrorHandler();
00131 };
00132
00133
00134 }
00135
00136 #endif