![]() |
Shadowrun: Awakened 29 September 2011 - Build 871
|
00001 /* 00002 Copyright 2007 - 2008 MySQL AB, 2008 - 2009 Sun Microsystems, Inc. All rights reserved. 00003 00004 The MySQL Connector/C++ is licensed under the terms of the GPL 00005 <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most 00006 MySQL Connectors. There are special exceptions to the terms and 00007 conditions of the GPL as it is applied to this software, see the 00008 FLOSS License Exception 00009 <http://www.mysql.com/about/legal/licensing/foss-exception.html>. 00010 */ 00011 00012 #ifndef _SQL_EXCEPTION_H_ 00013 #define _SQL_EXCEPTION_H_ 00014 00015 #include "build_config.h" 00016 #include <stdexcept> 00017 #include <string> 00018 #include <memory> 00019 00020 namespace sql 00021 { 00022 00023 #define MEMORY_ALLOC_OPERATORS(Class) \ 00024 void* operator new(size_t size) throw (std::bad_alloc) { return ::operator new(size); } \ 00025 void* operator new(size_t, void*) throw(); \ 00026 void* operator new(size_t, const std::nothrow_t&) throw(); \ 00027 void* operator new[](size_t) throw (std::bad_alloc); \ 00028 void* operator new[](size_t, void*) throw(); \ 00029 void* operator new[](size_t, const std::nothrow_t&) throw(); \ 00030 void* operator new(size_t N, std::allocator<Class>&); \ 00031 virtual SQLException* copy() { return new Class(*this); } 00032 00033 #ifdef _WIN32 00034 #pragma warning (disable : 4290) 00035 //warning C4290: C++ exception specification ignored except to indicate a function is not __declspec(nothrow) 00036 00037 00038 #pragma warning(push) 00039 #pragma warning(disable: 4275) 00040 #endif 00041 class CPPCONN_PUBLIC_FUNC SQLException : public std::runtime_error 00042 { 00043 #ifdef _WIN32 00044 #pragma warning(pop) 00045 #endif 00046 protected: 00047 const std::string sql_state; 00048 const int errNo; 00049 00050 public: 00051 SQLException(const SQLException& e) : std::runtime_error(e.what()), sql_state(e.sql_state), errNo(e.errNo) {} 00052 00053 SQLException(const std::string& reason, const std::string& SQLState, int vendorCode) : 00054 std::runtime_error (reason ), 00055 sql_state (SQLState ), 00056 errNo (vendorCode) 00057 {} 00058 00059 SQLException(const std::string& reason, const std::string& SQLState) : std::runtime_error(reason), sql_state(SQLState), errNo(0) {} 00060 00061 SQLException(const std::string& reason) : std::runtime_error(reason), sql_state("HY000"), errNo(0) {} 00062 00063 SQLException() : std::runtime_error(""), sql_state("HY000"), errNo(0) {} 00064 00065 const char * getSQLState() const 00066 { 00067 return sql_state.c_str(); 00068 } 00069 00070 int getErrorCode() const 00071 { 00072 return errNo; 00073 } 00074 00075 virtual ~SQLException() throw () {}; 00076 00077 protected: 00078 MEMORY_ALLOC_OPERATORS(SQLException) 00079 }; 00080 00081 struct CPPCONN_PUBLIC_FUNC MethodNotImplementedException : public SQLException 00082 { 00083 MethodNotImplementedException(const MethodNotImplementedException& e) : SQLException(e.what(), e.sql_state, e.errNo) { } 00084 MethodNotImplementedException(const std::string& reason) : SQLException(reason, "", 0) {} 00085 00086 private: 00087 virtual SQLException* copy() { return new MethodNotImplementedException(*this); } 00088 }; 00089 00090 struct CPPCONN_PUBLIC_FUNC InvalidArgumentException : public SQLException 00091 { 00092 InvalidArgumentException(const InvalidArgumentException& e) : SQLException(e.what(), e.sql_state, e.errNo) { } 00093 InvalidArgumentException(const std::string& reason) : SQLException(reason, "", 0) {} 00094 00095 private: 00096 virtual SQLException* copy() { return new InvalidArgumentException(*this); } 00097 }; 00098 00099 struct CPPCONN_PUBLIC_FUNC InvalidInstanceException : public SQLException 00100 { 00101 InvalidInstanceException(const InvalidInstanceException& e) : SQLException(e.what(), e.sql_state, e.errNo) { } 00102 InvalidInstanceException(const std::string& reason) : SQLException(reason, "", 0) {} 00103 00104 private: 00105 virtual SQLException* copy() { return new InvalidInstanceException(*this); } 00106 }; 00107 00108 00109 struct CPPCONN_PUBLIC_FUNC NonScrollableException : public SQLException 00110 { 00111 NonScrollableException(const NonScrollableException& e) : SQLException(e.what(), e.sql_state, e.errNo) { } 00112 NonScrollableException(const std::string& reason) : SQLException(reason, "", 0) {} 00113 00114 private: 00115 virtual SQLException* copy() { return new NonScrollableException(*this); } 00116 }; 00117 00118 } /* namespace sql */ 00119 00120 #endif /* _SQL_EXCEPTION_H_ */
Copyright © 2007-2010 by The Shadowrun: Awakened Team. This work is licensed under the GNU Lesser General Public License 3.