24#include <com/sun/star/sdbc/SQLException.hpp>
25#include <com/sun/star/sdb/ErrorCondition.hpp>
29#include <osl/diagnose.h>
39 using ::com::sun::star::uno::Reference;
40 using ::com::sun::star::uno::Any;
41 using ::com::sun::star::uno::XInterface;
42 using ::com::sun::star::sdbc::SQLException;
43 using ::com::sun::star::uno::Type;
52 OUString
getErrorMessage(
const ErrorCondition _eCondition,
const std::optional<OUString>& _rParamValue1,
const std::optional<OUString>& _rParamValue2,
const std::optional<OUString>& _rParamValue3 )
const;
54 void raiseException(
const ErrorCondition _eCondition,
const Reference< XInterface >& _rxContext,
const std::optional<OUString>& _rParamValue1,
const std::optional<OUString>& _rParamValue2,
const std::optional<OUString>& _rParamValue3 );
55 void raiseException(
const ErrorCondition _eCondition,
const std::optional<OUString>& _rParamValue1,
const std::optional<OUString>& _rParamValue2,
const std::optional<OUString>& _rParamValue3 );
56 void raiseTypedException(
const ErrorCondition _eCondition,
const Reference< XInterface >& _rxContext,
const Type& _rExceptionType,
const std::optional<OUString>& _rParamValue1,
const std::optional<OUString>& _rParamValue2,
const std::optional<OUString>& _rParamValue3 );
57 SQLException
getSQLException(
const ErrorCondition _eCondition,
const Reference< XInterface >& _rxContext,
const std::optional<OUString>& _rParamValue1,
const std::optional<OUString>& _rParamValue2,
const std::optional<OUString>& _rParamValue3 );
70 const std::optional<OUString>& _rParamValue1,
const std::optional<OUString>& _rParamValue2,
const std::optional<OUString>& _rParamValue3 );
82 static const OUString s_sMessagePrefix(
"[OOoBase]" );
83 return s_sMessagePrefix;
91 void lcl_substitutePlaceholder(OUString& _rMessage,
const char* _pPlaceholder,
const std::optional<OUString>& rParamValue)
93 size_t nPlaceholderLen( strlen( _pPlaceholder ) );
94 sal_Int32
nIndex = _rMessage.indexOfAsciiL( _pPlaceholder, nPlaceholderLen );
96 bool bHasPlaceholder = (
nIndex != -1 );
97 bool bWantsPlaceholder = rParamValue.has_value();
98 OSL_ENSURE( bHasPlaceholder == bWantsPlaceholder,
"lcl_substitutePlaceholder: placeholder where none is expected, or no placeholder where one is needed!" );
100 if ( bHasPlaceholder && bWantsPlaceholder )
101 _rMessage = _rMessage.replaceAt( nIndex, nPlaceholderLen, *rParamValue );
108 case css::sdb::ErrorCondition::ROW_SET_OPERATION_VETOED:
109 return STR_ROW_SET_OPERATION_VETOED;
110 case css::sdb::ErrorCondition::PARSER_CYCLIC_SUB_QUERIES:
111 return STR_PARSER_CYCLIC_SUB_QUERIES;
112 case css::sdb::ErrorCondition::DB_OBJECT_NAME_WITH_SLASHES:
113 return STR_DB_OBJECT_NAME_WITH_SLASHES;
114 case css::sdb::ErrorCondition::DB_INVALID_SQL_NAME:
115 return STR_DB_INVALID_SQL_NAME;
116 case css::sdb::ErrorCondition::DB_QUERY_NAME_WITH_QUOTES:
117 return STR_DB_QUERY_NAME_WITH_QUOTES;
118 case css::sdb::ErrorCondition::DB_OBJECT_NAME_IS_USED:
119 return STR_DB_OBJECT_NAME_IS_USED;
120 case css::sdb::ErrorCondition::DB_NOT_CONNECTED:
121 return STR_DB_NOT_CONNECTED;
122 case css::sdb::ErrorCondition::AB_ADDRESSBOOK_NOT_FOUND:
123 return STR_AB_ADDRESSBOOK_NOT_FOUND;
124 case css::sdb::ErrorCondition::DATA_CANNOT_SELECT_UNFILTERED:
125 return STR_DATA_CANNOT_SELECT_UNFILTERED;
134 case css::sdb::ErrorCondition::DB_NOT_CONNECTED:
136 case css::sdb::ErrorCondition::DATA_CANNOT_SELECT_UNFILTERED:
147 lcl_substitutePlaceholder( sErrorMessage,
"$1$", _rParamValue1 );
148 lcl_substitutePlaceholder( sErrorMessage,
"$2$", _rParamValue2 );
149 lcl_substitutePlaceholder( sErrorMessage,
"$3$", _rParamValue3 );
151 return sErrorMessage;
157 return 0 - ::sal::static_int_cast< ErrorCode, ErrorCondition >( _eCondition );
161 void SQLError_Impl::raiseException(
const ErrorCondition _eCondition,
const Reference< XInterface >& _rxContext,
const std::optional<OUString>& _rParamValue1,
const std::optional<OUString>& _rParamValue2,
const std::optional<OUString>& _rParamValue3 )
187 const Type& _rExceptionType,
const std::optional<OUString>& _rParamValue1,
const std::optional<OUString>& _rParamValue2,
const std::optional<OUString>& _rParamValue3 )
190 throw std::bad_cast();
193 Any aException(
nullptr, _rExceptionType );
196 SQLException* pException =
static_cast< SQLException*
>( aException.pData );
197 *pException =
impl_buildSQLException( _eCondition, _rxContext, _rParamValue1, _rParamValue2, _rParamValue3 );
200 ::cppu::throwException( aException );
204 const std::optional<OUString>& _rParamValue1,
const std::optional<OUString>& _rParamValue2,
const std::optional<OUString>& _rParamValue3 )
210 const std::optional<OUString>& _rParamValue1,
const std::optional<OUString>& _rParamValue2,
const std::optional<OUString>& _rParamValue3 )
213 getErrorMessage( _eCondition, _rParamValue1, _rParamValue2, _rParamValue3 ),
224 OSL_ENSURE( !sResMessage.isEmpty(),
"SQLError_Impl::impl_getErrorMessage: illegal error condition, or invalid resource!" );
231 OUString sState = lcl_getResourceState(_eCondition);
232 if (sState.isEmpty())
256 return m_pImpl->getErrorMessage( _eCondition, std::optional<OUString>(), std::optional<OUString>(), std::optional<OUString>() );
266 void SQLError::raiseException(
const ErrorCondition _eCondition,
const Reference< XInterface >& _rxContext,
const std::optional<OUString>& _rParamValue1,
const std::optional<OUString>& _rParamValue2,
const std::optional<OUString>& _rParamValue3 )
const
268 m_pImpl->raiseException( _eCondition, _rxContext, _rParamValue1, _rParamValue2, _rParamValue3 );
274 m_pImpl->raiseException( _eCondition, std::optional<OUString>(), std::optional<OUString>(), std::optional<OUString>() );
279 const Type& _rExceptionType )
const
281 m_pImpl->raiseTypedException( _eCondition, _rxContext, _rExceptionType, std::optional<OUString>(), std::optional<OUString>(), std::optional<OUString>() );
286 const std::optional<OUString>& _rParamValue1,
const std::optional<OUString>& _rParamValue2,
const std::optional<OUString>& _rParamValue3 )
const
288 return m_pImpl->getSQLException( _eCondition, _rxContext, _rParamValue1, _rParamValue2, _rParamValue3 );
OUString impl_getErrorMessage(ErrorCondition _eCondition) const
returns the basic error message associated with the given error condition, without any parameter repl...
static OUString impl_getSQLState(ErrorCondition _eCondition)
returns the SQLState associated with the given error condition
void raiseException(const ErrorCondition _eCondition, const Reference< XInterface > &_rxContext, const std::optional< OUString > &_rParamValue1, const std::optional< OUString > &_rParamValue2, const std::optional< OUString > &_rParamValue3)
SQLException getSQLException(const ErrorCondition _eCondition, const Reference< XInterface > &_rxContext, const std::optional< OUString > &_rParamValue1, const std::optional< OUString > &_rParamValue2, const std::optional< OUString > &_rParamValue3)
SQLException impl_buildSQLException(const ErrorCondition _eCondition, const Reference< XInterface > &_rxContext, const std::optional< OUString > &_rParamValue1, const std::optional< OUString > &_rParamValue2, const std::optional< OUString > &_rParamValue3)
returns an SQLException describing the given error condition
OUString getErrorMessage(const ErrorCondition _eCondition, const std::optional< OUString > &_rParamValue1, const std::optional< OUString > &_rParamValue2, const std::optional< OUString > &_rParamValue3) const
void raiseTypedException(const ErrorCondition _eCondition, const Reference< XInterface > &_rxContext, const Type &_rExceptionType, const std::optional< OUString > &_rParamValue1, const std::optional< OUString > &_rParamValue2, const std::optional< OUString > &_rParamValue3)
static ErrorCode getErrorCode(const ErrorCondition _eCondition)
static const OUString & getMessagePrefix()
void raiseTypedException(const ErrorCondition _eCondition, const css::uno::Reference< css::uno::XInterface > &_rxContext, const css::uno::Type &_rExceptionType) const
raises a typed exception, that is, a UNO exception which is derived from css::sdbc::SQLException
static const OUString & getMessagePrefix()
returns the prefix which is used for OpenOffice.org Base's error messages
std::shared_ptr< SQLError_Impl > m_pImpl
void raiseException(const ErrorCondition _eCondition, const css::uno::Reference< css::uno::XInterface > &_rxContext, const std::optional< OUString > &_rParamValue1=std::nullopt, const std::optional< OUString > &_rParamValue2=std::nullopt, const std::optional< OUString > &_rParamValue3=std::nullopt) const
throws an SQLException describing the given error condition
static ErrorCode getErrorCode(const ErrorCondition _eCondition)
returns the error code associated with a given error condition
OUString getErrorMessage(const ErrorCondition _eCondition) const
returns the message associated with a given error condition, after (optionally) replacing a placehold...
css::sdbc::SQLException getSQLException(const ErrorCondition _eCondition, const css::uno::Reference< css::uno::XInterface > &_rxContext, const std::optional< OUString > &_rParamValue1=std::nullopt, const std::optional< OUString > &_rParamValue2=std::nullopt, const std::optional< OUString > &_rParamValue3=std::nullopt) const
retrieves an SQLException object which contains information about the given error condition
OUString get(TranslateId sContextAndId, const std::locale &loc)
bool isAssignableFrom(const Type &_rAssignable, const Type &_rFrom)
::sal_Int32 ErrorCondition
error condition values as defined in css::sdb::ErrorCondition
::sal_Int32 ErrorCode
the type of error codes to be used in SQLExceptions
std::shared_ptr< T > make_shared(Args &&... args)
constexpr OUStringLiteral STR_DATA_CANNOT_SELECT_UNFILTERED_STATE
constexpr OUStringLiteral STR_DB_NOT_CONNECTED_STATE