Tag: cws_src680_qiq User: fs Date: 06/05/19 02:46:44 Modified: /dba/connectivity/source/commontools/ dbexception.cxx
Log: some more constness for the SQLExceptionIteratorHelper File Changes: Directory: /dba/connectivity/source/commontools/ ================================================ File [changed]: dbexception.cxx Url: http://dba.openoffice.org/source/browse/dba/connectivity/source/commontools/dbexception.cxx?r1=1.15.56.3&r2=1.15.56.4 Delta lines: +109 -120 ----------------------- --- dbexception.cxx 18 May 2006 09:08:32 -0000 1.15.56.3 +++ dbexception.cxx 19 May 2006 09:46:41 -0000 1.15.56.4 @@ -4,9 +4,9 @@ * * $RCSfile: dbexception.cxx,v $ * - * $Revision: 1.15.56.3 $ + * $Revision: 1.15.56.4 $ * - * last change: $Author: fs $ $Date: 2006/05/18 09:08:32 $ + * last change: $Author: fs $ $Date: 2006/05/19 09:46:41 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -54,17 +54,17 @@ #ifndef CONNECTIVITY_CONNECTION_HXX #include "TConnection.hxx" #endif -using namespace comphelper; //......................................................................... namespace dbtools { //......................................................................... - using namespace ::connectivity; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::sdb; using namespace ::com::sun::star::sdbc; + using namespace ::comphelper; + using namespace ::connectivity; //============================================================================== //= SQLExceptionInfo - encapsulating the type info of an SQLException-derived class @@ -274,146 +274,115 @@ } //============================================================================== -//= SQLExceptionIteratorHelper - iterating through an SQLException chain +//= SQLExceptionIteratorHelper //============================================================================== //------------------------------------------------------------------------------ -SQLExceptionIteratorHelper::SQLExceptionIteratorHelper(const SQLExceptionInfo& _rStart, NODES_INCLUDED _eMask) - :m_pCurrent(NULL) - ,m_eCurrentType(SQLExceptionInfo::UNDEFINED) - // no other chance without RTTI - ,m_eMask(_eMask) +SQLExceptionIteratorHelper::SQLExceptionIteratorHelper( const SQLExceptionInfo& _rChainStart ) + :m_pCurrent( NULL ) + ,m_eCurrentType( SQLExceptionInfo::UNDEFINED ) { - if (_rStart.isValid()) + if ( _rChainStart.isValid() ) { - m_pCurrent = (const SQLException*)_rStart; - m_eCurrentType = _rStart.getType(); + m_pCurrent = (const SQLException*)_rChainStart; + m_eCurrentType = _rChainStart.getType(); } } //------------------------------------------------------------------------------ -SQLExceptionIteratorHelper::SQLExceptionIteratorHelper(const ::com::sun::star::sdbc::SQLException* _pStart, NODES_INCLUDED _eMask) - :m_pCurrent(_pStart) - ,m_eCurrentType(SQLExceptionInfo::SQL_EXCEPTION) - // no other chance without RTTI - ,m_eMask(_eMask) +SQLExceptionIteratorHelper::SQLExceptionIteratorHelper( const ::com::sun::star::sdbc::SQLException& _rChainStart ) + :m_pCurrent( &_rChainStart ) + ,m_eCurrentType( SQLExceptionInfo::SQL_EXCEPTION ) { - // initially check the start of the chain against the include mask - if (m_pCurrent && (m_eMask > NI_EXCEPTIONS)) - next(); } //------------------------------------------------------------------------------ -SQLExceptionIteratorHelper::SQLExceptionIteratorHelper(const ::com::sun::star::sdbc::SQLWarning* _pStart, NODES_INCLUDED _eMask) - :m_pCurrent(_pStart) - ,m_eCurrentType(SQLExceptionInfo::SQL_WARNING) - // no other chance without RTTI - ,m_eMask(_eMask) +SQLExceptionIteratorHelper::SQLExceptionIteratorHelper( const ::com::sun::star::sdbc::SQLWarning& _rChainStart ) + :m_pCurrent( &_rChainStart ) + ,m_eCurrentType( SQLExceptionInfo::SQL_WARNING ) { - // initially check the start of the chain against the include mask - if (m_pCurrent && (m_eMask > NI_WARNINGS)) - next(); } //------------------------------------------------------------------------------ -SQLExceptionIteratorHelper::SQLExceptionIteratorHelper(const ::com::sun::star::sdb::SQLContext* _pStart, NODES_INCLUDED _eMask) - :m_pCurrent(_pStart) - ,m_eCurrentType(SQLExceptionInfo::SQL_CONTEXT) - // no other chance without RTTI - ,m_eMask(_eMask) +SQLExceptionIteratorHelper::SQLExceptionIteratorHelper( const ::com::sun::star::sdb::SQLContext& _rChainStart ) + :m_pCurrent( &_rChainStart ) + ,m_eCurrentType( SQLExceptionInfo::SQL_CONTEXT ) { - // initially check the start of the chain against the include mask - if (m_pCurrent && (m_eMask > NI_CONTEXTINFOS)) - next(); } //------------------------------------------------------------------------------ -void SQLExceptionIteratorHelper::next(SQLExceptionInfo& _rOutInfo) +void SQLExceptionIteratorHelper::current( SQLExceptionInfo& _out_rInfo ) const { - SQLExceptionInfo::TYPE eType = m_eCurrentType; - const SQLException* pNext = next(); - switch (eType) + switch ( m_eCurrentType ) { case SQLExceptionInfo::SQL_EXCEPTION: - _rOutInfo = *pNext; + _out_rInfo = *m_pCurrent; break; + case SQLExceptionInfo::SQL_WARNING: - _rOutInfo = *static_cast<const SQLWarning*>(pNext); + _out_rInfo = *static_cast< const SQLWarning* >( m_pCurrent ); break; + case SQLExceptionInfo::SQL_CONTEXT: - _rOutInfo = *static_cast<const SQLContext*>(pNext); + _out_rInfo = *static_cast< const SQLContext* >( m_pCurrent ); break; + default: - OSL_ENSURE(sal_False, "SQLExceptionIteratorHelper::next: invalid type!"); + _out_rInfo = Any(); + break; } } //------------------------------------------------------------------------------ const ::com::sun::star::sdbc::SQLException* SQLExceptionIteratorHelper::next() { - OSL_ENSURE(hasMoreElements(), "SQLExceptionIteratorHelper::next : invalid call (please use hasMoreElements) !"); + OSL_ENSURE( hasMoreElements(), "SQLExceptionIteratorHelper::next : invalid call (please use hasMoreElements)!" ); - const ::com::sun::star::sdbc::SQLException* pReturn = m_pCurrent; - if (m_pCurrent) - { // check for the next element within the chain - const staruno::Type& aSqlExceptionCompare = ::getCppuType(reinterpret_cast< ::com::sun::star::sdbc::SQLException*>(NULL)); - const staruno::Type& aSqlWarningCompare = ::getCppuType(reinterpret_cast< ::com::sun::star::sdbc::SQLWarning*>(NULL)); - const staruno::Type& aSqlContextCompare = ::getCppuType(reinterpret_cast< ::com::sun::star::sdb::SQLContext*>(NULL)); + const ::com::sun::star::sdbc::SQLException* pReturn = current(); + if ( !m_pCurrent ) + return pReturn; - const ::com::sun::star::sdbc::SQLException* pSearch = m_pCurrent; - SQLExceptionInfo::TYPE eSearchType = m_eCurrentType; + // check for the next element within the chain + const Type aTypeException( ::cppu::UnoType< SQLException >::get() ); - sal_Bool bIncludeThis = sal_False; - while (pSearch && !bIncludeThis) + Type aNextElementType = m_pCurrent->NextException.getValueType(); + if ( !isAssignableFrom( aTypeException, aNextElementType ) ) { - if (!pSearch->NextException.hasValue()) - { // last chain element - pSearch = NULL; - break; - } - staruno::Type aNextElementType = pSearch->NextException.getValueType(); - if (!isAssignableFrom(aSqlExceptionCompare, aNextElementType)) - { - // the next chain element isn't an SQLException - OSL_ENSURE(sal_False, "SQLExceptionIteratorHelper::next : the exception chain is invalid !"); - pSearch = NULL; - break; + // no SQLException at all in the next chain element + m_pCurrent = NULL; + m_eCurrentType = SQLExceptionInfo::UNDEFINED; + return pReturn; } - // the next element - SQLExceptionInfo aInfo(pSearch->NextException); - eSearchType = aInfo.getType(); - switch (eSearchType) - { - case SQLExceptionInfo::SQL_CONTEXT: - pSearch = reinterpret_cast<const ::com::sun::star::sdb::SQLContext*>(pSearch->NextException.getValue()); - bIncludeThis = eSearchType >= NI_CONTEXTINFOS; - break; + m_pCurrent = static_cast< const SQLException* >( m_pCurrent->NextException.getValue() ); - case SQLExceptionInfo::SQL_WARNING: - pSearch = reinterpret_cast<const ::com::sun::star::sdbc::SQLWarning*>(pSearch->NextException.getValue()); - bIncludeThis = eSearchType >= NI_WARNINGS; - break; - - case SQLExceptionInfo::SQL_EXCEPTION: - pSearch = reinterpret_cast<const ::com::sun::star::sdbc::SQLException*>(pSearch->NextException.getValue()); - bIncludeThis = eSearchType >= NI_EXCEPTIONS; - break; - - default: - pSearch = NULL; - bIncludeThis = sal_False; - break; - } + // no finally determine the proper type of the exception + const Type aTypeContext( ::cppu::UnoType< SQLContext >::get() ); + if ( isAssignableFrom( aTypeContext, aNextElementType ) ) + { + m_eCurrentType = SQLExceptionInfo::SQL_CONTEXT; + return pReturn; } - m_pCurrent = pSearch; - m_eCurrentType = eSearchType; + const Type aTypeWarning( ::cppu::UnoType< SQLWarning >::get() ); + if ( isAssignableFrom( aTypeWarning, aNextElementType ) ) + { + m_eCurrentType = SQLExceptionInfo::SQL_WARNING; + return pReturn; } + // a simple SQLException + m_eCurrentType = SQLExceptionInfo::SQL_EXCEPTION; return pReturn; } -using namespace ::com::sun::star::uno; + +//------------------------------------------------------------------------------ +void SQLExceptionIteratorHelper::next( SQLExceptionInfo& _out_rInfo ) +{ + current( _out_rInfo ); + next(); +} + //------------------------------------------------------------ void throwFunctionSequenceException(const Reference< XInterface >& _Context, const Any& _Next) throw ( ::com::sun::star::sdbc::SQLException ) { @@ -423,16 +392,26 @@ void throwInvalidIndexException(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _Context, const ::com::sun::star::uno::Any& _Next) throw ( ::com::sun::star::sdbc::SQLException ) { - static ::rtl::OUString sStatus = ::rtl::OUString::createFromAscii("07009"); - throw SQLException(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_INVALID_INDEX),_Context,sStatus,0,_Next); + throw SQLException( + OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_INVALID_INDEX), + _Context, + getStandardSQLState( SQL_INVALID_DESCRIPTOR_INDEX ), + 0, + _Next + ); } // ----------------------------------------------------------------------------- void throwFunctionNotSupportedException(const ::rtl::OUString& _rMsg, const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _Context, const ::com::sun::star::uno::Any& _Next) throw ( ::com::sun::star::sdbc::SQLException ) { - static ::rtl::OUString sStatus = ::rtl::OUString::createFromAscii("IM001"); - throw SQLException(_rMsg,_Context,sStatus,0,_Next); + throw SQLException( + _rMsg, + _Context, + getStandardSQLState( SQL_FUNCTION_NOT_SUPPORTED ), + 0, + _Next + ); } // ----------------------------------------------------------------------------- void throwFunctionNotSupportedException( const sal_Char* _pAsciiFunctionName, const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxContext, @@ -440,8 +419,13 @@ { ::rtl::OUString sMessage = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ": Driver does not support this function: " ) ); sMessage += ::rtl::OUString::createFromAscii( _pAsciiFunctionName ); - ::rtl::OUString sState( RTL_CONSTASCII_USTRINGPARAM( "IM001" ) ); - throw SQLException( sMessage, _rxContext, sState, 0, _pNextException ? *_pNextException : Any() ); + throw SQLException( + sMessage, + _rxContext, + getStandardSQLState( SQL_FUNCTION_NOT_SUPPORTED ), + 0, + _pNextException ? *_pNextException : Any() + ); } // ----------------------------------------------------------------------------- void throwGenericSQLException(const ::rtl::OUString& _rMsg, const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxSource) @@ -463,8 +447,13 @@ throw (SQLException) { ::rtl::OUString sMessage = ::rtl::OUString::createFromAscii( _pAsciiFeatureName ) + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ": feature not implemented." ) ); - ::rtl::OUString sState( RTL_CONSTASCII_USTRINGPARAM( "HYC00" ) ); - throw SQLException( sMessage, _rxContext, sState, 0, _pNextException ? *_pNextException : Any() ); + throw SQLException( + sMessage, + _rxContext, + getStandardSQLState( SQL_FEATURE_NOT_IMPLEMENTED ), + 0, + _pNextException ? *_pNextException : Any() + ); } // ----------------------------------------------------------------------------- --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
