odbc++/errorhandler.h

00001 /*
00002    This file is part of libodbc++.
00003 
00004    Copyright (C) 1999-2000 Manush Dodunekov <manush@stendahls.net>
00005 
00006    This library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Library General Public
00008    License as published by the Free Software Foundation; either
00009    version 2 of the License, or (at your option) any later version.
00010 
00011    This library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Library General Public License for more details.
00015 
00016    You should have received a copy of the GNU Library General Public License
00017    along with this library; see the file COPYING.  If not, write to
00018    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00019    Boston, MA 02111-1307, USA.
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     // private data
00038     struct PD;
00039     PD* pd_;
00040 
00041     WarningList* warnings_;
00042     bool collectWarnings_;
00043 
00044     //the maxumum number of warnings to contain at a time
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 } // namespace odbc
00135 
00136 #endif

Go back to the libodbc++ homepage