libodbc++  0.2.5
errorhandler.h
1 /*
2  This file is part of libodbc++.
3 
4  Copyright (C) 1999-2000 Manush Dodunekov <manush@stendahls.net>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License as published by the Free Software Foundation; either
9  version 2 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Library General Public License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING. If not, write to
18  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  Boston, MA 02111-1307, USA.
20 */
21 
22 #ifndef __ODBCXX_ERRORHANDLER_H
23 #define __ODBCXX_ERRORHANDLER_H
24 
25 #include <odbc++/setup.h>
26 #include <odbc++/types.h>
27 #include <odbc++/threads.h>
28 
29 namespace odbc {
30 
32  class ODBCXX_EXPORT ErrorHandler {
33  friend class DriverManager;
34  friend class DataStreamBuf;
35  friend class DataStream;
36  private:
37  // private data
38  struct PD;
39  PD* pd_;
40 
41  WarningList* warnings_;
42  bool collectWarnings_;
43 
44  //the maxumum number of warnings to contain at a time
45  enum {
46  MAX_WARNINGS=128
47  };
48 
49  protected:
50  void _postWarning(SQLWarning* w);
51 
52 
53 #if ODBCVER < 0x0300
54  void _checkErrorODBC2(SQLHENV henv,
55  SQLHDBC hdbc,
56  SQLHSTMT hstmt,
57  SQLRETURN r,
58  const ODBCXX_STRING& what,
59  const ODBCXX_STRING& sqlstate = ODBCXX_STRING("HY000"));
60 #else
61 
62  void _checkErrorODBC3(SQLINTEGER handleType,
63  SQLHANDLE h,
64  SQLRETURN r, const ODBCXX_STRING& what,
65  const ODBCXX_STRING& sqlstate = SQLException::ssDEFSQLSTATE);
66 #endif //ODBCVER < 0x0300
67 
68  void _checkStmtError(SQLHSTMT hstmt,
69  SQLRETURN r, const ODBCXX_CHAR_TYPE* what=ODBCXX_STRING_CONST(""),
70  const ODBCXX_CHAR_TYPE* sqlstate=SQLException::scDEFSQLSTATE) {
71 
72  if(r==SQL_SUCCESS_WITH_INFO || r==SQL_ERROR) {
73 #if ODBCVER < 0x0300
74 
75  this->_checkErrorODBC2(SQL_NULL_HENV, SQL_NULL_HDBC, hstmt,
76  r,ODBCXX_STRING_C(what), ODBCXX_STRING_C(sqlstate));
77 #else
78 
79  this->_checkErrorODBC3(SQL_HANDLE_STMT,hstmt,r,ODBCXX_STRING_C(what), ODBCXX_STRING_C(sqlstate));
80 
81 #endif
82  }
83  }
84 
85  void _checkConError(SQLHDBC hdbc,
86  SQLRETURN r,
87  const ODBCXX_CHAR_TYPE* what=ODBCXX_STRING_CONST(""),
88  const ODBCXX_CHAR_TYPE* sqlstate=SQLException::scDEFSQLSTATE) {
89  if(r==SQL_SUCCESS_WITH_INFO || r==SQL_ERROR) {
90 #if ODBCVER < 0x0300
91 
92  this->_checkErrorODBC2(SQL_NULL_HENV, hdbc, SQL_NULL_HSTMT, r,
93  ODBCXX_STRING_C(what), ODBCXX_STRING_C(sqlstate));
94 
95 #else
96 
97  this->_checkErrorODBC3(SQL_HANDLE_DBC, hdbc, r, ODBCXX_STRING_C(what), ODBCXX_STRING_C(sqlstate));
98 
99 #endif
100  }
101  }
102 
103  void _checkEnvError(SQLHENV henv,
104  SQLRETURN r,
105  const ODBCXX_CHAR_TYPE* what=ODBCXX_STRING_CONST(""),
106  const ODBCXX_CHAR_TYPE* sqlstate=SQLException::scDEFSQLSTATE) {
107  if(r==SQL_SUCCESS_WITH_INFO || r==SQL_ERROR) {
108 #if ODBCVER < 0x0300
109 
110  this->_checkErrorODBC2(henv,SQL_NULL_HDBC,SQL_NULL_HSTMT,r,
111  ODBCXX_STRING_C(what), ODBCXX_STRING_C(sqlstate));
112 
113 #else
114 
115  this->_checkErrorODBC3(SQL_HANDLE_ENV,henv,r,ODBCXX_STRING_C(what), ODBCXX_STRING_C(sqlstate));
116 
117 #endif
118  }
119  }
120 
122  ErrorHandler(bool collectWarnings =true);
123 
124  public:
126  void clearWarnings();
127 
132  WarningList* getWarnings();
133 
135  virtual ~ErrorHandler();
136  };
137 
138 
139 } // namespace odbc
140 
141 #endif

Go back to the libodbc++ homepage