1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_connectivity.hxx" 30*cdf0e10cSrcweir #include <connectivity/dbexception.hxx> 31*cdf0e10cSrcweir #include <comphelper/types.hxx> 32*cdf0e10cSrcweir #include <cppuhelper/exc_hlp.hxx> 33*cdf0e10cSrcweir #include <osl/diagnose.h> 34*cdf0e10cSrcweir #include <com/sun/star/sdb/SQLContext.hpp> 35*cdf0e10cSrcweir #include <com/sun/star/sdbc/SQLWarning.hpp> 36*cdf0e10cSrcweir #include <com/sun/star/sdb/SQLErrorEvent.hpp> 37*cdf0e10cSrcweir #include "TConnection.hxx" 38*cdf0e10cSrcweir #include "resource/common_res.hrc" 39*cdf0e10cSrcweir #include "resource/sharedresources.hxx" 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir //......................................................................... 42*cdf0e10cSrcweir namespace dbtools 43*cdf0e10cSrcweir { 44*cdf0e10cSrcweir //......................................................................... 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 47*cdf0e10cSrcweir using namespace ::com::sun::star::sdb; 48*cdf0e10cSrcweir using namespace ::com::sun::star::sdbc; 49*cdf0e10cSrcweir using namespace ::comphelper; 50*cdf0e10cSrcweir using namespace ::connectivity; 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir //============================================================================== 53*cdf0e10cSrcweir //= SQLExceptionInfo - encapsulating the type info of an SQLException-derived class 54*cdf0e10cSrcweir //============================================================================== 55*cdf0e10cSrcweir //------------------------------------------------------------------------------ 56*cdf0e10cSrcweir SQLExceptionInfo::SQLExceptionInfo() 57*cdf0e10cSrcweir :m_eType(UNDEFINED) 58*cdf0e10cSrcweir { 59*cdf0e10cSrcweir } 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir //------------------------------------------------------------------------------ 62*cdf0e10cSrcweir SQLExceptionInfo::SQLExceptionInfo(const ::com::sun::star::sdbc::SQLException& _rError) 63*cdf0e10cSrcweir { 64*cdf0e10cSrcweir m_aContent <<= _rError; 65*cdf0e10cSrcweir implDetermineType(); 66*cdf0e10cSrcweir } 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir //------------------------------------------------------------------------------ 69*cdf0e10cSrcweir SQLExceptionInfo::SQLExceptionInfo(const ::com::sun::star::sdbc::SQLWarning& _rError) 70*cdf0e10cSrcweir { 71*cdf0e10cSrcweir m_aContent <<= _rError; 72*cdf0e10cSrcweir implDetermineType(); 73*cdf0e10cSrcweir } 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir //------------------------------------------------------------------------------ 76*cdf0e10cSrcweir SQLExceptionInfo::SQLExceptionInfo(const ::com::sun::star::sdb::SQLContext& _rError) 77*cdf0e10cSrcweir { 78*cdf0e10cSrcweir m_aContent <<= _rError; 79*cdf0e10cSrcweir implDetermineType(); 80*cdf0e10cSrcweir } 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir //------------------------------------------------------------------------------ 83*cdf0e10cSrcweir SQLExceptionInfo::SQLExceptionInfo( const ::rtl::OUString& _rSimpleErrorMessage ) 84*cdf0e10cSrcweir { 85*cdf0e10cSrcweir SQLException aError; 86*cdf0e10cSrcweir aError.Message = _rSimpleErrorMessage; 87*cdf0e10cSrcweir m_aContent <<= aError; 88*cdf0e10cSrcweir implDetermineType(); 89*cdf0e10cSrcweir } 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir //------------------------------------------------------------------------------ 92*cdf0e10cSrcweir SQLExceptionInfo::SQLExceptionInfo(const SQLExceptionInfo& _rCopySource) 93*cdf0e10cSrcweir :m_aContent(_rCopySource.m_aContent) 94*cdf0e10cSrcweir ,m_eType(_rCopySource.m_eType) 95*cdf0e10cSrcweir { 96*cdf0e10cSrcweir } 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir //------------------------------------------------------------------------------ 99*cdf0e10cSrcweir const SQLExceptionInfo& SQLExceptionInfo::operator=(const ::com::sun::star::sdbc::SQLException& _rError) 100*cdf0e10cSrcweir { 101*cdf0e10cSrcweir m_aContent <<= _rError; 102*cdf0e10cSrcweir implDetermineType(); 103*cdf0e10cSrcweir return *this; 104*cdf0e10cSrcweir } 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir //------------------------------------------------------------------------------ 107*cdf0e10cSrcweir const SQLExceptionInfo& SQLExceptionInfo::operator=(const ::com::sun::star::sdbc::SQLWarning& _rError) 108*cdf0e10cSrcweir { 109*cdf0e10cSrcweir m_aContent <<= _rError; 110*cdf0e10cSrcweir implDetermineType(); 111*cdf0e10cSrcweir return *this; 112*cdf0e10cSrcweir } 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir //------------------------------------------------------------------------------ 115*cdf0e10cSrcweir const SQLExceptionInfo& SQLExceptionInfo::operator=(const ::com::sun::star::sdb::SQLContext& _rError) 116*cdf0e10cSrcweir { 117*cdf0e10cSrcweir m_aContent <<= _rError; 118*cdf0e10cSrcweir implDetermineType(); 119*cdf0e10cSrcweir return *this; 120*cdf0e10cSrcweir } 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir //------------------------------------------------------------------------------ 123*cdf0e10cSrcweir const SQLExceptionInfo& SQLExceptionInfo::operator=(const ::com::sun::star::sdb::SQLErrorEvent& _rErrorEvent) 124*cdf0e10cSrcweir { 125*cdf0e10cSrcweir m_aContent = _rErrorEvent.Reason; 126*cdf0e10cSrcweir implDetermineType(); 127*cdf0e10cSrcweir return *this; 128*cdf0e10cSrcweir } 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir //------------------------------------------------------------------------------ 131*cdf0e10cSrcweir const SQLExceptionInfo& SQLExceptionInfo::operator=(const ::com::sun::star::uno::Any& _rCaughtSQLException) 132*cdf0e10cSrcweir { 133*cdf0e10cSrcweir m_aContent = _rCaughtSQLException; 134*cdf0e10cSrcweir implDetermineType(); 135*cdf0e10cSrcweir return *this; 136*cdf0e10cSrcweir } 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir //------------------------------------------------------------------------------ 139*cdf0e10cSrcweir SQLExceptionInfo::SQLExceptionInfo(const ::com::sun::star::sdb::SQLErrorEvent& _rError) 140*cdf0e10cSrcweir { 141*cdf0e10cSrcweir m_aContent = _rError.Reason; 142*cdf0e10cSrcweir implDetermineType(); 143*cdf0e10cSrcweir } 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir //------------------------------------------------------------------------------ 146*cdf0e10cSrcweir SQLExceptionInfo::SQLExceptionInfo(const staruno::Any& _rError) 147*cdf0e10cSrcweir { 148*cdf0e10cSrcweir const staruno::Type& aSQLExceptionType = ::getCppuType(reinterpret_cast< ::com::sun::star::sdbc::SQLException*>(NULL)); 149*cdf0e10cSrcweir sal_Bool bValid = isAssignableFrom(aSQLExceptionType, _rError.getValueType()); 150*cdf0e10cSrcweir if (bValid) 151*cdf0e10cSrcweir m_aContent = _rError; 152*cdf0e10cSrcweir // no assertion here : if used with the NextException member of an SQLException bValid==sal_False is allowed. 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir implDetermineType(); 155*cdf0e10cSrcweir } 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir //------------------------------------------------------------------------------ 158*cdf0e10cSrcweir void SQLExceptionInfo::implDetermineType() 159*cdf0e10cSrcweir { 160*cdf0e10cSrcweir staruno::Type aContentType = m_aContent.getValueType(); 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir const Type& aSQLExceptionType = ::getCppuType( reinterpret_cast< SQLException* >( NULL ) ); 163*cdf0e10cSrcweir const Type& aSQLWarningType = ::getCppuType( reinterpret_cast< SQLWarning* >( NULL ) ); 164*cdf0e10cSrcweir const Type& aSQLContextType = ::getCppuType( reinterpret_cast< SQLContext* >( NULL ) ); 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir if ( isAssignableFrom( aSQLContextType, m_aContent.getValueType() ) ) 167*cdf0e10cSrcweir m_eType = SQL_CONTEXT; 168*cdf0e10cSrcweir else if ( isAssignableFrom( aSQLWarningType, m_aContent.getValueType() ) ) 169*cdf0e10cSrcweir m_eType = SQL_WARNING; 170*cdf0e10cSrcweir else if ( isAssignableFrom( aSQLExceptionType, m_aContent.getValueType() ) ) 171*cdf0e10cSrcweir m_eType = SQL_EXCEPTION; 172*cdf0e10cSrcweir else 173*cdf0e10cSrcweir { 174*cdf0e10cSrcweir m_eType = UNDEFINED; 175*cdf0e10cSrcweir m_aContent.clear(); 176*cdf0e10cSrcweir } 177*cdf0e10cSrcweir } 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir //------------------------------------------------------------------------------ 180*cdf0e10cSrcweir sal_Bool SQLExceptionInfo::isKindOf(TYPE _eType) const 181*cdf0e10cSrcweir { 182*cdf0e10cSrcweir switch (_eType) 183*cdf0e10cSrcweir { 184*cdf0e10cSrcweir case SQL_CONTEXT: 185*cdf0e10cSrcweir return (m_eType == SQL_CONTEXT); 186*cdf0e10cSrcweir case SQL_WARNING: 187*cdf0e10cSrcweir return (m_eType == SQL_CONTEXT) || (m_eType == SQL_WARNING); 188*cdf0e10cSrcweir case SQL_EXCEPTION: 189*cdf0e10cSrcweir return (m_eType == SQL_CONTEXT) || (m_eType == SQL_WARNING) || (m_eType == SQL_EXCEPTION); 190*cdf0e10cSrcweir case UNDEFINED: 191*cdf0e10cSrcweir return (m_eType == UNDEFINED); 192*cdf0e10cSrcweir } 193*cdf0e10cSrcweir return sal_False; 194*cdf0e10cSrcweir } 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir //------------------------------------------------------------------------------ 197*cdf0e10cSrcweir SQLExceptionInfo::operator const ::com::sun::star::sdbc::SQLException*() const 198*cdf0e10cSrcweir { 199*cdf0e10cSrcweir OSL_ENSURE(isKindOf(SQL_EXCEPTION), "SQLExceptionInfo::operator SQLException* : invalid call !"); 200*cdf0e10cSrcweir return reinterpret_cast<const ::com::sun::star::sdbc::SQLException*>(m_aContent.getValue()); 201*cdf0e10cSrcweir } 202*cdf0e10cSrcweir 203*cdf0e10cSrcweir //------------------------------------------------------------------------------ 204*cdf0e10cSrcweir SQLExceptionInfo::operator const ::com::sun::star::sdbc::SQLWarning*() const 205*cdf0e10cSrcweir { 206*cdf0e10cSrcweir OSL_ENSURE(isKindOf(SQL_WARNING), "SQLExceptionInfo::operator SQLException* : invalid call !"); 207*cdf0e10cSrcweir return reinterpret_cast<const ::com::sun::star::sdbc::SQLWarning*>(m_aContent.getValue()); 208*cdf0e10cSrcweir } 209*cdf0e10cSrcweir 210*cdf0e10cSrcweir //------------------------------------------------------------------------------ 211*cdf0e10cSrcweir SQLExceptionInfo::operator const ::com::sun::star::sdb::SQLContext*() const 212*cdf0e10cSrcweir { 213*cdf0e10cSrcweir OSL_ENSURE(isKindOf(SQL_CONTEXT), "SQLExceptionInfo::operator SQLException* : invalid call !"); 214*cdf0e10cSrcweir return reinterpret_cast<const ::com::sun::star::sdb::SQLContext*>(m_aContent.getValue()); 215*cdf0e10cSrcweir } 216*cdf0e10cSrcweir 217*cdf0e10cSrcweir //------------------------------------------------------------------------------ 218*cdf0e10cSrcweir void SQLExceptionInfo::prepend( const ::rtl::OUString& _rErrorMessage, const sal_Char* _pAsciiSQLState, const sal_Int32 _nErrorCode ) 219*cdf0e10cSrcweir { 220*cdf0e10cSrcweir SQLException aException; 221*cdf0e10cSrcweir aException.Message = _rErrorMessage; 222*cdf0e10cSrcweir aException.ErrorCode = _nErrorCode; 223*cdf0e10cSrcweir aException.SQLState = ::rtl::OUString::createFromAscii( _pAsciiSQLState ? _pAsciiSQLState : "S1000" ); 224*cdf0e10cSrcweir aException.NextException = m_aContent; 225*cdf0e10cSrcweir m_aContent <<= aException; 226*cdf0e10cSrcweir 227*cdf0e10cSrcweir m_eType = SQL_EXCEPTION; 228*cdf0e10cSrcweir } 229*cdf0e10cSrcweir 230*cdf0e10cSrcweir //------------------------------------------------------------------------------ 231*cdf0e10cSrcweir void SQLExceptionInfo::append( TYPE _eType, const ::rtl::OUString& _rErrorMessage, const sal_Char* _pAsciiSQLState, const sal_Int32 _nErrorCode ) 232*cdf0e10cSrcweir { 233*cdf0e10cSrcweir // create the to-be-appended exception 234*cdf0e10cSrcweir Any aAppend; 235*cdf0e10cSrcweir switch ( _eType ) 236*cdf0e10cSrcweir { 237*cdf0e10cSrcweir case SQL_EXCEPTION: aAppend <<= SQLException(); break; 238*cdf0e10cSrcweir case SQL_WARNING: aAppend <<= SQLWarning(); break; 239*cdf0e10cSrcweir case SQL_CONTEXT: aAppend <<= SQLContext(); break; 240*cdf0e10cSrcweir default: 241*cdf0e10cSrcweir OSL_ENSURE( false, "SQLExceptionInfo::append: invalid exception type: this will crash!" ); 242*cdf0e10cSrcweir break; 243*cdf0e10cSrcweir } 244*cdf0e10cSrcweir 245*cdf0e10cSrcweir SQLException* pAppendException( static_cast< SQLException* >( const_cast< void* >( aAppend.getValue() ) ) ); 246*cdf0e10cSrcweir pAppendException->Message = _rErrorMessage; 247*cdf0e10cSrcweir pAppendException->SQLState = ::rtl::OUString::createFromAscii( _pAsciiSQLState ); 248*cdf0e10cSrcweir pAppendException->ErrorCode = _nErrorCode; 249*cdf0e10cSrcweir 250*cdf0e10cSrcweir // find the end of the current chain 251*cdf0e10cSrcweir Any* pChainIterator = &m_aContent; 252*cdf0e10cSrcweir SQLException* pLastException = NULL; 253*cdf0e10cSrcweir const Type& aSQLExceptionType( ::getCppuType< SQLException >() ); 254*cdf0e10cSrcweir while ( pChainIterator ) 255*cdf0e10cSrcweir { 256*cdf0e10cSrcweir if ( !pChainIterator->hasValue() ) 257*cdf0e10cSrcweir break; 258*cdf0e10cSrcweir 259*cdf0e10cSrcweir if ( !isAssignableFrom( aSQLExceptionType, pChainIterator->getValueType() ) ) 260*cdf0e10cSrcweir break; 261*cdf0e10cSrcweir 262*cdf0e10cSrcweir pLastException = static_cast< SQLException* >( const_cast< void* >( pChainIterator->getValue() ) ); 263*cdf0e10cSrcweir pChainIterator = &pLastException->NextException; 264*cdf0e10cSrcweir } 265*cdf0e10cSrcweir 266*cdf0e10cSrcweir // append 267*cdf0e10cSrcweir if ( pLastException ) 268*cdf0e10cSrcweir pLastException->NextException = aAppend; 269*cdf0e10cSrcweir else 270*cdf0e10cSrcweir { 271*cdf0e10cSrcweir m_aContent = aAppend; 272*cdf0e10cSrcweir m_eType = _eType; 273*cdf0e10cSrcweir } 274*cdf0e10cSrcweir } 275*cdf0e10cSrcweir 276*cdf0e10cSrcweir //------------------------------------------------------------------------------ 277*cdf0e10cSrcweir void SQLExceptionInfo::doThrow() 278*cdf0e10cSrcweir { 279*cdf0e10cSrcweir if ( m_aContent.getValueTypeClass() == TypeClass_EXCEPTION ) 280*cdf0e10cSrcweir ::cppu::throwException( m_aContent ); 281*cdf0e10cSrcweir throw RuntimeException(); 282*cdf0e10cSrcweir } 283*cdf0e10cSrcweir 284*cdf0e10cSrcweir //============================================================================== 285*cdf0e10cSrcweir //= SQLExceptionIteratorHelper 286*cdf0e10cSrcweir //============================================================================== 287*cdf0e10cSrcweir 288*cdf0e10cSrcweir //------------------------------------------------------------------------------ 289*cdf0e10cSrcweir SQLExceptionIteratorHelper::SQLExceptionIteratorHelper( const SQLExceptionInfo& _rChainStart ) 290*cdf0e10cSrcweir :m_pCurrent( NULL ) 291*cdf0e10cSrcweir ,m_eCurrentType( SQLExceptionInfo::UNDEFINED ) 292*cdf0e10cSrcweir { 293*cdf0e10cSrcweir if ( _rChainStart.isValid() ) 294*cdf0e10cSrcweir { 295*cdf0e10cSrcweir m_pCurrent = (const SQLException*)_rChainStart; 296*cdf0e10cSrcweir m_eCurrentType = _rChainStart.getType(); 297*cdf0e10cSrcweir } 298*cdf0e10cSrcweir } 299*cdf0e10cSrcweir 300*cdf0e10cSrcweir //------------------------------------------------------------------------------ 301*cdf0e10cSrcweir SQLExceptionIteratorHelper::SQLExceptionIteratorHelper( const ::com::sun::star::sdbc::SQLException& _rChainStart ) 302*cdf0e10cSrcweir :m_pCurrent( &_rChainStart ) 303*cdf0e10cSrcweir ,m_eCurrentType( SQLExceptionInfo::SQL_EXCEPTION ) 304*cdf0e10cSrcweir { 305*cdf0e10cSrcweir } 306*cdf0e10cSrcweir 307*cdf0e10cSrcweir //------------------------------------------------------------------------------ 308*cdf0e10cSrcweir SQLExceptionIteratorHelper::SQLExceptionIteratorHelper( const ::com::sun::star::sdbc::SQLWarning& _rChainStart ) 309*cdf0e10cSrcweir :m_pCurrent( &_rChainStart ) 310*cdf0e10cSrcweir ,m_eCurrentType( SQLExceptionInfo::SQL_WARNING ) 311*cdf0e10cSrcweir { 312*cdf0e10cSrcweir } 313*cdf0e10cSrcweir 314*cdf0e10cSrcweir //------------------------------------------------------------------------------ 315*cdf0e10cSrcweir SQLExceptionIteratorHelper::SQLExceptionIteratorHelper( const ::com::sun::star::sdb::SQLContext& _rChainStart ) 316*cdf0e10cSrcweir :m_pCurrent( &_rChainStart ) 317*cdf0e10cSrcweir ,m_eCurrentType( SQLExceptionInfo::SQL_CONTEXT ) 318*cdf0e10cSrcweir { 319*cdf0e10cSrcweir } 320*cdf0e10cSrcweir 321*cdf0e10cSrcweir //------------------------------------------------------------------------------ 322*cdf0e10cSrcweir void SQLExceptionIteratorHelper::current( SQLExceptionInfo& _out_rInfo ) const 323*cdf0e10cSrcweir { 324*cdf0e10cSrcweir switch ( m_eCurrentType ) 325*cdf0e10cSrcweir { 326*cdf0e10cSrcweir case SQLExceptionInfo::SQL_EXCEPTION: 327*cdf0e10cSrcweir _out_rInfo = *m_pCurrent; 328*cdf0e10cSrcweir break; 329*cdf0e10cSrcweir 330*cdf0e10cSrcweir case SQLExceptionInfo::SQL_WARNING: 331*cdf0e10cSrcweir _out_rInfo = *static_cast< const SQLWarning* >( m_pCurrent ); 332*cdf0e10cSrcweir break; 333*cdf0e10cSrcweir 334*cdf0e10cSrcweir case SQLExceptionInfo::SQL_CONTEXT: 335*cdf0e10cSrcweir _out_rInfo = *static_cast< const SQLContext* >( m_pCurrent ); 336*cdf0e10cSrcweir break; 337*cdf0e10cSrcweir 338*cdf0e10cSrcweir default: 339*cdf0e10cSrcweir _out_rInfo = Any(); 340*cdf0e10cSrcweir break; 341*cdf0e10cSrcweir } 342*cdf0e10cSrcweir } 343*cdf0e10cSrcweir 344*cdf0e10cSrcweir //------------------------------------------------------------------------------ 345*cdf0e10cSrcweir const ::com::sun::star::sdbc::SQLException* SQLExceptionIteratorHelper::next() 346*cdf0e10cSrcweir { 347*cdf0e10cSrcweir OSL_ENSURE( hasMoreElements(), "SQLExceptionIteratorHelper::next : invalid call (please use hasMoreElements)!" ); 348*cdf0e10cSrcweir 349*cdf0e10cSrcweir const ::com::sun::star::sdbc::SQLException* pReturn = current(); 350*cdf0e10cSrcweir if ( !m_pCurrent ) 351*cdf0e10cSrcweir return pReturn; 352*cdf0e10cSrcweir 353*cdf0e10cSrcweir // check for the next element within the chain 354*cdf0e10cSrcweir const Type aTypeException( ::cppu::UnoType< SQLException >::get() ); 355*cdf0e10cSrcweir 356*cdf0e10cSrcweir Type aNextElementType = m_pCurrent->NextException.getValueType(); 357*cdf0e10cSrcweir if ( !isAssignableFrom( aTypeException, aNextElementType ) ) 358*cdf0e10cSrcweir { 359*cdf0e10cSrcweir // no SQLException at all in the next chain element 360*cdf0e10cSrcweir m_pCurrent = NULL; 361*cdf0e10cSrcweir m_eCurrentType = SQLExceptionInfo::UNDEFINED; 362*cdf0e10cSrcweir return pReturn; 363*cdf0e10cSrcweir } 364*cdf0e10cSrcweir 365*cdf0e10cSrcweir m_pCurrent = static_cast< const SQLException* >( m_pCurrent->NextException.getValue() ); 366*cdf0e10cSrcweir 367*cdf0e10cSrcweir // no finally determine the proper type of the exception 368*cdf0e10cSrcweir const Type aTypeContext( ::cppu::UnoType< SQLContext >::get() ); 369*cdf0e10cSrcweir if ( isAssignableFrom( aTypeContext, aNextElementType ) ) 370*cdf0e10cSrcweir { 371*cdf0e10cSrcweir m_eCurrentType = SQLExceptionInfo::SQL_CONTEXT; 372*cdf0e10cSrcweir return pReturn; 373*cdf0e10cSrcweir } 374*cdf0e10cSrcweir 375*cdf0e10cSrcweir const Type aTypeWarning( ::cppu::UnoType< SQLWarning >::get() ); 376*cdf0e10cSrcweir if ( isAssignableFrom( aTypeWarning, aNextElementType ) ) 377*cdf0e10cSrcweir { 378*cdf0e10cSrcweir m_eCurrentType = SQLExceptionInfo::SQL_WARNING; 379*cdf0e10cSrcweir return pReturn; 380*cdf0e10cSrcweir } 381*cdf0e10cSrcweir 382*cdf0e10cSrcweir // a simple SQLException 383*cdf0e10cSrcweir m_eCurrentType = SQLExceptionInfo::SQL_EXCEPTION; 384*cdf0e10cSrcweir return pReturn; 385*cdf0e10cSrcweir } 386*cdf0e10cSrcweir 387*cdf0e10cSrcweir //------------------------------------------------------------------------------ 388*cdf0e10cSrcweir void SQLExceptionIteratorHelper::next( SQLExceptionInfo& _out_rInfo ) 389*cdf0e10cSrcweir { 390*cdf0e10cSrcweir current( _out_rInfo ); 391*cdf0e10cSrcweir next(); 392*cdf0e10cSrcweir } 393*cdf0e10cSrcweir 394*cdf0e10cSrcweir //------------------------------------------------------------ 395*cdf0e10cSrcweir void throwFunctionSequenceException(const Reference< XInterface >& _Context, const Any& _Next) throw ( ::com::sun::star::sdbc::SQLException ) 396*cdf0e10cSrcweir { 397*cdf0e10cSrcweir ::connectivity::SharedResources aResources; 398*cdf0e10cSrcweir throw SQLException( 399*cdf0e10cSrcweir aResources.getResourceString(STR_ERRORMSG_SEQUENCE), 400*cdf0e10cSrcweir _Context, 401*cdf0e10cSrcweir getStandardSQLState( SQL_FUNCTION_SEQUENCE_ERROR ), 402*cdf0e10cSrcweir 0, 403*cdf0e10cSrcweir _Next 404*cdf0e10cSrcweir ); 405*cdf0e10cSrcweir } 406*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 407*cdf0e10cSrcweir void throwInvalidIndexException(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _Context, 408*cdf0e10cSrcweir const ::com::sun::star::uno::Any& _Next) throw ( ::com::sun::star::sdbc::SQLException ) 409*cdf0e10cSrcweir { 410*cdf0e10cSrcweir ::connectivity::SharedResources aResources; 411*cdf0e10cSrcweir throw SQLException( 412*cdf0e10cSrcweir aResources.getResourceString(STR_INVALID_INDEX), 413*cdf0e10cSrcweir _Context, 414*cdf0e10cSrcweir getStandardSQLState( SQL_INVALID_DESCRIPTOR_INDEX ), 415*cdf0e10cSrcweir 0, 416*cdf0e10cSrcweir _Next 417*cdf0e10cSrcweir ); 418*cdf0e10cSrcweir } 419*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 420*cdf0e10cSrcweir void throwFunctionNotSupportedException(const ::rtl::OUString& _rMsg, 421*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _Context, 422*cdf0e10cSrcweir const ::com::sun::star::uno::Any& _Next) throw ( ::com::sun::star::sdbc::SQLException ) 423*cdf0e10cSrcweir { 424*cdf0e10cSrcweir throw SQLException( 425*cdf0e10cSrcweir _rMsg, 426*cdf0e10cSrcweir _Context, 427*cdf0e10cSrcweir getStandardSQLState( SQL_FUNCTION_NOT_SUPPORTED ), 428*cdf0e10cSrcweir 0, 429*cdf0e10cSrcweir _Next 430*cdf0e10cSrcweir ); 431*cdf0e10cSrcweir } 432*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 433*cdf0e10cSrcweir void throwFunctionNotSupportedException( const sal_Char* _pAsciiFunctionName, const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxContext, 434*cdf0e10cSrcweir const ::com::sun::star::uno::Any* _pNextException ) throw ( ::com::sun::star::sdbc::SQLException ) 435*cdf0e10cSrcweir { 436*cdf0e10cSrcweir ::connectivity::SharedResources aResources; 437*cdf0e10cSrcweir const ::rtl::OUString sError( aResources.getResourceStringWithSubstitution( 438*cdf0e10cSrcweir STR_UNSUPPORTED_FUNCTION, 439*cdf0e10cSrcweir "$functionname$", ::rtl::OUString::createFromAscii( _pAsciiFunctionName ) 440*cdf0e10cSrcweir ) ); 441*cdf0e10cSrcweir throw SQLException( 442*cdf0e10cSrcweir sError, 443*cdf0e10cSrcweir _rxContext, 444*cdf0e10cSrcweir getStandardSQLState( SQL_FUNCTION_NOT_SUPPORTED ), 445*cdf0e10cSrcweir 0, 446*cdf0e10cSrcweir _pNextException ? *_pNextException : Any() 447*cdf0e10cSrcweir ); 448*cdf0e10cSrcweir } 449*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 450*cdf0e10cSrcweir void throwGenericSQLException(const ::rtl::OUString& _rMsg, const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxSource) 451*cdf0e10cSrcweir throw (::com::sun::star::sdbc::SQLException) 452*cdf0e10cSrcweir { 453*cdf0e10cSrcweir throwGenericSQLException(_rMsg, _rxSource, Any()); 454*cdf0e10cSrcweir } 455*cdf0e10cSrcweir 456*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 457*cdf0e10cSrcweir void throwGenericSQLException(const ::rtl::OUString& _rMsg, const Reference< XInterface >& _rxSource, const Any& _rNextException) 458*cdf0e10cSrcweir throw (SQLException) 459*cdf0e10cSrcweir { 460*cdf0e10cSrcweir throw SQLException( _rMsg, _rxSource, getStandardSQLState( SQL_GENERAL_ERROR ), 0, _rNextException); 461*cdf0e10cSrcweir } 462*cdf0e10cSrcweir 463*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 464*cdf0e10cSrcweir void throwFeatureNotImplementedException( const sal_Char* _pAsciiFeatureName, const Reference< XInterface >& _rxContext, const Any* _pNextException ) 465*cdf0e10cSrcweir throw (SQLException) 466*cdf0e10cSrcweir { 467*cdf0e10cSrcweir ::connectivity::SharedResources aResources; 468*cdf0e10cSrcweir const ::rtl::OUString sError( aResources.getResourceStringWithSubstitution( 469*cdf0e10cSrcweir STR_UNSUPPORTED_FEATURE, 470*cdf0e10cSrcweir "$featurename$", ::rtl::OUString::createFromAscii( _pAsciiFeatureName ) 471*cdf0e10cSrcweir ) ); 472*cdf0e10cSrcweir 473*cdf0e10cSrcweir throw SQLException( 474*cdf0e10cSrcweir sError, 475*cdf0e10cSrcweir _rxContext, 476*cdf0e10cSrcweir getStandardSQLState( SQL_FEATURE_NOT_IMPLEMENTED ), 477*cdf0e10cSrcweir 0, 478*cdf0e10cSrcweir _pNextException ? *_pNextException : Any() 479*cdf0e10cSrcweir ); 480*cdf0e10cSrcweir } 481*cdf0e10cSrcweir 482*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 483*cdf0e10cSrcweir void throwSQLException( const sal_Char* _pAsciiMessage, const sal_Char* _pAsciiState, 484*cdf0e10cSrcweir const Reference< XInterface >& _rxContext, const sal_Int32 _nErrorCode, const Any* _pNextException ) throw (SQLException) 485*cdf0e10cSrcweir { 486*cdf0e10cSrcweir throw SQLException( 487*cdf0e10cSrcweir ::rtl::OUString::createFromAscii( _pAsciiMessage ), 488*cdf0e10cSrcweir _rxContext, 489*cdf0e10cSrcweir ::rtl::OUString::createFromAscii( _pAsciiState ), 490*cdf0e10cSrcweir _nErrorCode, 491*cdf0e10cSrcweir _pNextException ? *_pNextException : Any() 492*cdf0e10cSrcweir ); 493*cdf0e10cSrcweir } 494*cdf0e10cSrcweir 495*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 496*cdf0e10cSrcweir void throwSQLException( const sal_Char* _pAsciiMessage, StandardSQLState _eSQLState, 497*cdf0e10cSrcweir const Reference< XInterface >& _rxContext, const sal_Int32 _nErrorCode, 498*cdf0e10cSrcweir const Any* _pNextException ) throw (SQLException) 499*cdf0e10cSrcweir { 500*cdf0e10cSrcweir throwSQLException( _pAsciiMessage, getStandardSQLStateAscii( _eSQLState ), _rxContext, _nErrorCode, _pNextException ); 501*cdf0e10cSrcweir } 502*cdf0e10cSrcweir 503*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 504*cdf0e10cSrcweir void throwSQLException( const ::rtl::OUString& _rMessage, StandardSQLState _eSQLState, 505*cdf0e10cSrcweir const Reference< XInterface >& _rxContext, const sal_Int32 _nErrorCode, 506*cdf0e10cSrcweir const Any* _pNextException ) throw (SQLException) 507*cdf0e10cSrcweir { 508*cdf0e10cSrcweir throw SQLException( 509*cdf0e10cSrcweir _rMessage, 510*cdf0e10cSrcweir _rxContext, 511*cdf0e10cSrcweir getStandardSQLState( _eSQLState ), 512*cdf0e10cSrcweir _nErrorCode, 513*cdf0e10cSrcweir _pNextException ? *_pNextException : Any() 514*cdf0e10cSrcweir ); 515*cdf0e10cSrcweir } 516*cdf0e10cSrcweir 517*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 518*cdf0e10cSrcweir const sal_Char* getStandardSQLStateAscii( StandardSQLState _eState ) 519*cdf0e10cSrcweir { 520*cdf0e10cSrcweir const sal_Char* pAsciiState = NULL; 521*cdf0e10cSrcweir switch ( _eState ) 522*cdf0e10cSrcweir { 523*cdf0e10cSrcweir case SQL_WRONG_PARAMETER_NUMBER: pAsciiState = "07001"; break; 524*cdf0e10cSrcweir case SQL_INVALID_DESCRIPTOR_INDEX: pAsciiState = "07009"; break; 525*cdf0e10cSrcweir case SQL_UNABLE_TO_CONNECT: pAsciiState = "08001"; break; 526*cdf0e10cSrcweir case SQL_NUMERIC_OUT_OF_RANGE: pAsciiState = "22003"; break; 527*cdf0e10cSrcweir case SQL_INVALID_DATE_TIME: pAsciiState = "22007"; break; 528*cdf0e10cSrcweir case SQL_INVALID_CURSOR_STATE: pAsciiState = "24000"; break; 529*cdf0e10cSrcweir case SQL_TABLE_OR_VIEW_EXISTS: pAsciiState = "42S01"; break; 530*cdf0e10cSrcweir case SQL_TABLE_OR_VIEW_NOT_FOUND: pAsciiState = "42S02"; break; 531*cdf0e10cSrcweir case SQL_INDEX_ESISTS: pAsciiState = "42S11"; break; 532*cdf0e10cSrcweir case SQL_INDEX_NOT_FOUND: pAsciiState = "42S12"; break; 533*cdf0e10cSrcweir case SQL_COLUMN_EXISTS: pAsciiState = "42S21"; break; 534*cdf0e10cSrcweir case SQL_COLUMN_NOT_FOUND: pAsciiState = "42S22"; break; 535*cdf0e10cSrcweir case SQL_GENERAL_ERROR: pAsciiState = "HY000"; break; 536*cdf0e10cSrcweir case SQL_INVALID_SQL_DATA_TYPE: pAsciiState = "HY004"; break; 537*cdf0e10cSrcweir case SQL_OPERATION_CANCELED: pAsciiState = "HY008"; break; 538*cdf0e10cSrcweir case SQL_FUNCTION_SEQUENCE_ERROR: pAsciiState = "HY010"; break; 539*cdf0e10cSrcweir case SQL_INVALID_CURSOR_POSITION: pAsciiState = "HY109"; break; 540*cdf0e10cSrcweir case SQL_INVALID_BOOKMARK_VALUE: pAsciiState = "HY111"; break; 541*cdf0e10cSrcweir case SQL_FEATURE_NOT_IMPLEMENTED: pAsciiState = "HYC00"; break; 542*cdf0e10cSrcweir case SQL_FUNCTION_NOT_SUPPORTED: pAsciiState = "IM001"; break; 543*cdf0e10cSrcweir case SQL_CONNECTION_DOES_NOT_EXIST: pAsciiState = "08003"; break; 544*cdf0e10cSrcweir 545*cdf0e10cSrcweir default: 546*cdf0e10cSrcweir break; 547*cdf0e10cSrcweir } 548*cdf0e10cSrcweir if ( !pAsciiState ) 549*cdf0e10cSrcweir throw RuntimeException(); 550*cdf0e10cSrcweir return pAsciiState; 551*cdf0e10cSrcweir } 552*cdf0e10cSrcweir 553*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 554*cdf0e10cSrcweir ::rtl::OUString getStandardSQLState( StandardSQLState _eState ) 555*cdf0e10cSrcweir { 556*cdf0e10cSrcweir return ::rtl::OUString::createFromAscii( getStandardSQLStateAscii( _eState ) ); 557*cdf0e10cSrcweir } 558*cdf0e10cSrcweir 559*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 560*cdf0e10cSrcweir //......................................................................... 561*cdf0e10cSrcweir } // namespace dbtools 562*cdf0e10cSrcweir //......................................................................... 563*cdf0e10cSrcweir 564*cdf0e10cSrcweir 565