/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
SQLExceptionInfo::SQLExceptionInfo(const css::uno::Any& _rError)
{ const css::uno::Type& aSQLExceptionType = cppu::UnoType<css::sdbc::SQLException>::get(); bool bValid = isAssignableFrom(aSQLExceptionType, _rError.getValueType()); if (bValid)
m_aContent = _rError; // no assertion here : if used with the NextException member of an SQLException bValid==sal_False is allowed.
// create the to-be-appended exception
Any SQLExceptionInfo::createException(TYPE eType, const OUString& rErrorMessage, const OUString& rSQLState, const sal_Int32 nErrorCode)
{
Any aAppend; switch (eType)
{ case TYPE::SQLException:
aAppend <<= SQLException(rErrorMessage, {}, rSQLState, nErrorCode, {}); break; case TYPE::SQLWarning:
aAppend <<= SQLWarning(rErrorMessage, {}, rSQLState, nErrorCode, {}); break; case TYPE::SQLContext:
aAppend <<= SQLContext(rErrorMessage, {}, rSQLState, nErrorCode, {}, {}); break; default:
TOOLS_WARN_EXCEPTION("connectivity.commontools", "SQLExceptionInfo::createException: invalid exception type: this will crash!"); break;
}
return aAppend;
}
// find the end of the exception chain
SQLException* SQLExceptionInfo::getLastException(SQLException* pLastException)
{
SQLException* pException = pLastException; while (pException)
{
pException = const_cast<SQLException*>(o3tl::tryAccess<SQLException>(pException->NextException)); if (!pException) break;
pLastException = pException;
} return pLastException;
}
void SQLExceptionInfo::append( TYPE _eType, const OUString& _rErrorMessage, const OUString& _rSQLState, const sal_Int32 _nErrorCode )
{ // create the to-be-appended exception
Any aAppend = createException(_eType, _rErrorMessage, _rSQLState, _nErrorCode);
// find the end of the current chain
SQLException* pLastException = getLastException(const_cast<SQLException*>(o3tl::tryAccess<SQLException>(m_aContent)));
// check for the next element within the chain const Type aTypeException( ::cppu::UnoType< SQLException >::get() );
Type aNextElementType = m_pCurrent->NextException.getValueType(); if ( !isAssignableFrom( aTypeException, aNextElementType ) )
{ // no SQLException at all in the next chain element
m_pCurrent = nullptr;
m_eCurrentType = SQLExceptionInfo::TYPE::Undefined; return pReturn;
}
// no finally determine the proper type of the exception const Type aTypeContext( ::cppu::UnoType< SQLContext >::get() ); if ( isAssignableFrom( aTypeContext, aNextElementType ) )
{
m_eCurrentType = SQLExceptionInfo::TYPE::SQLContext; return pReturn;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.