SQLException.hh

00001 //********************************************************************
00002 //*** ResourcePool/SQL/SQLException.hh
00003 //*** Copyright (c) 2003-2009 by Markus Winand <mws@fatalmind.com>
00004 //*** $Id: SQLException.hh,v 1.13 2009-05-04 13:20:43 mws Exp $
00005 //********************************************************************
00006 /*
00007 This file is part of ResourcePool.
00008 
00009 ResourcePool is free software; you can redistribute it
00010 and/or modify it under the terms of the GNU General Public License
00011 as published by the Free Software Foundation; either version 2 of 
00012 the License, or (at your option) any later version.
00013 
00014 ResourcePool is distributed in the hope that it will be
00015 useful, but WITHOUT ANY WARRANTY; without even the implied warranty
00016 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 GNU General Public License for more details.
00018 
00019 You should have received a copy of the GNU General Public License
00020 along with ResourcePool; if not, write to the Free Software
00021 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00022 02111-1307  USA */
00023 
00024 #ifndef RESOURCEPOOL_SQL_SQLException_HH
00025 #define RESOURCEPOOL_SQL_SQLException_HH
00026 
00027 #ifndef INCLUDED_EXCEPTIONS_HH
00028 #include "Exceptions/Exception.hh"
00029 #endif
00030 
00031 #include "SQLStatement.hh"
00032 
00033 namespace fatalmind {
00034 namespace SQL {
00035 
00039 class SQLException: virtual public Exception {
00040     public:
00041         SQLException(const std::string& msg
00042             , const std::string&  sqlstate // confirming to X/Open
00043             , const std::string&  sql
00044             , const bool          failover // Should this exception cause an failover in ResourcPool?
00045         ):Exception(getFullMessage(msg, sql))
00046         , _sqlstate(sqlstate)
00047         , _sql(sql)
00048         , _failover(failover)
00049         {
00050         }
00051 
00052         SQLException(const std::string& msg
00053             , const std::string&  sqlstate // confirming to X/Open
00054             , const SQLStatement& sqlstm   // the SQL statement which caused the exception
00055             , const bool          failover // Should this exception cause an failover in ResourcPool?
00056         ):Exception(getFullMessage(msg, sqlstm.getSQL()))
00057         , _sqlstate(sqlstate)
00058         , _sql(sqlstm.getSQL())
00059         , _failover(failover)
00060         {
00061         }
00062 
00063         static std::string getFullMessage(const std::string& message, const std::string& sql) {
00064             std::string rv(message);
00065             rv += " with SQL: " + sql; // ref or getSQL is ok here
00066             return rv;
00067         }
00068 
00069         const std::string& getSQL() const throw() {
00070             return _sql;
00071         }
00072 
00073         bool isFailover() const throw() {
00074             return _failover;
00075         }
00076 
00077         const std::string& getSQLState() const throw() {
00078             return _sqlstate;
00079         }
00080         
00081         bool isSQLState(const char* const c) const {
00082             return !_sqlstate.compare(c);
00083         }
00084 
00085         const std::string getSQLStateClass() const {
00086             return _sqlstate.substr(0,2);
00087         }
00088 
00089         bool isSQLStateClass(const std::string& c) const {
00090             return !_sqlstate.compare(0, 2, c, 0, 2);
00091         }
00092             
00093         bool isSQLStateClass(const char* const c) const {
00094             return !_sqlstate.compare(0, 2, c, 0, 2);
00095         }
00096 
00097     private:
00098         const std::string  _sqlstate;
00099         const std::string  _sql;
00100         const bool         _failover;
00101 }; // class SQLException
00102 
00103 } // namespace SQL
00104 } // namespace fatalmind
00105 
00106 #endif

Generated on Mon Nov 9 16:21:24 2009 for ResourcePool by  doxygen 1.5.3