Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members  

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 char* what="") {
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, SQLRETURN r, const char* what="") {
00083       if(r==SQL_SUCCESS_WITH_INFO || r==SQL_ERROR) {
00084 #if ODBCVER < 0x0300
00085         
00086         this->_checkErrorODBC2(SQL_NULL_HENV, hdbc, SQL_NULL_HSTMT, r, 
00087                                ODBCXX_STRING_C(what));
00088         
00089 #else
00090         
00091         this->_checkErrorODBC3(SQL_HANDLE_DBC, hdbc, r, ODBCXX_STRING_C(what));
00092 
00093 #endif
00094       }
00095     }
00096 
00097     void _checkEnvError(SQLHENV henv, SQLRETURN r, const char* what="") {
00098       if(r==SQL_SUCCESS_WITH_INFO || r==SQL_ERROR) {
00099 #if ODBCVER < 0x0300
00100         
00101         this->_checkErrorODBC2(henv,SQL_NULL_HDBC,SQL_NULL_HSTMT,r,
00102                                ODBCXX_STRING_C(what));
00103         
00104 #else
00105         
00106         this->_checkErrorODBC3(SQL_HANDLE_ENV,henv,r,ODBCXX_STRING_C(what));
00107         
00108 #endif
00109       }
00110     }
00111 
00113     ErrorHandler(bool collectWarnings =true);
00114 
00115   public:
00117     void clearWarnings();
00118 
00123     WarningList* getWarnings();
00124 
00126     virtual ~ErrorHandler();
00127   };
00128 
00129   
00130 }; // namespace odbc
00131 
00132 #endif

Go back to the freeodbc++ homepage