LibreOffice Module connectivity (master) 1
dbexception.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#ifndef INCLUDED_CONNECTIVITY_DBEXCEPTION_HXX
21#define INCLUDED_CONNECTIVITY_DBEXCEPTION_HXX
22
25#include <com/sun/star/uno/Reference.hxx>
26
27namespace com::sun::star
28{
29 namespace sdb
30 {
31 class SQLContext;
32 struct SQLErrorEvent;
33 }
34 namespace sdbc
35 {
36 class SQLWarning;
37 class SQLException;
38 }
39}
40
41namespace dbtools
42{
43
44
45//= Special exception if cancel is pressed in DBA UI
46
48{
50};
51
52
53//= SQLExceptionInfo - encapsulating the type info of an SQLException-derived class
54
55
57{
58public:
59 enum class TYPE { SQLException, SQLWarning, SQLContext, Undefined };
60
61private:
62 css::uno::Any m_aContent;
63 TYPE m_eType; // redundant (could be derived from m_aContent.getValueType())
64
65public:
67 SQLExceptionInfo(const css::sdbc::SQLException& _rError);
68 SQLExceptionInfo(const css::sdbc::SQLWarning& _rError);
69 SQLExceptionInfo(const css::sdb::SQLContext& _rError);
70
78 SQLExceptionInfo( const OUString& _rSimpleErrorMessage );
79
80 // use for events got via XSQLErrorListener::errorOccured
81 SQLExceptionInfo(const css::uno::Any& _rError);
82 // use with the Reason member of an SQLErrorEvent or with NextElement of an SQLException
83
88 void prepend( const OUString& _rErrorMessage );
89
101 void append( TYPE _eType, const OUString& _rErrorMessage, const OUString& _rSQLState = OUString(), const sal_Int32 _nErrorCode = 0 );
102
110 void doThrow();
111
112 SQLExceptionInfo& operator=(const css::sdbc::SQLException& _rError);
113 SQLExceptionInfo& operator=(const css::sdbc::SQLWarning& _rError);
114 SQLExceptionInfo& operator=(const css::sdb::SQLContext& _rError);
115 SQLExceptionInfo& operator=(const css::sdb::SQLErrorEvent& _rErrorEvent);
116 SQLExceptionInfo& operator=(const css::uno::Any& _rCaughtSQLException);
117
118 bool isKindOf(TYPE _eType) const;
119 // not just a simple comparison ! e.g. getType() == SQL_CONTEXT implies isKindOf(SQL_EXCEPTION) == sal_True !
120 bool isValid() const { return m_eType != TYPE::Undefined; }
121 TYPE getType() const { return m_eType; }
122
123 operator const css::sdbc::SQLException* () const;
124 operator const css::sdb::SQLContext* () const;
125
126 const css::uno::Any& get() const { return m_aContent; }
127
128 void clear()
129 {
130 m_aContent.clear();
131 m_eType = TYPE::Undefined;
132 }
133
134 // create an exception
135 static css::uno::Any createException(TYPE eType, const OUString& rErrorMessage, const OUString& rSQLState, const sal_Int32 nErrorCode);
136
137 // find the end of the exception chain
138 static css::sdbc::SQLException* getLastException(css::sdbc::SQLException* pLastException);
139
140private:
141 void implDetermineType();
142};
143
144
145//= SQLExceptionIteratorHelper - iterating through an SQLException chain
146
147
149{
150 const css::sdbc::SQLException* m_pCurrent;
152
153public:
160 SQLExceptionIteratorHelper( const css::sdbc::SQLException& _rChainStart );
161
168 SQLExceptionIteratorHelper( const SQLExceptionInfo& _rErrorInfo );
169
172 bool hasMoreElements() const { return ( m_pCurrent != nullptr ); }
173
180 void current( SQLExceptionInfo& _out_rInfo ) const;
181
186 const css::sdbc::SQLException* next();
187
193 void next( SQLExceptionInfo& _out_rInfo );
194};
195
196
197//= StandardExceptions
198
199
208
209
215 const OUString& _rFunctionName,
216 const css::uno::Reference< css::uno::XInterface >& _rxContext
217 );
218
221 const OUString& _rFunctionName,
222 const css::uno::Reference< css::uno::XInterface >& _rxContext
223 );
224
230 const css::uno::Reference< css::uno::XInterface >& Context,
231 const css::uno::Any& Next = css::uno::Any()
232 );
233
234
240 const css::uno::Reference< css::uno::XInterface >& Context,
241 const css::uno::Any& Next = css::uno::Any()
242 );
243
244
250 const OUString& _rMsg,
251 const css::uno::Reference< css::uno::XInterface >& _rxSource
252 );
253
254
260 const OUString& _rMsg,
261 const css::uno::Reference< css::uno::XInterface >& _rxSource,
262 const css::uno::Any& _rNextException
263 );
264
265
275 const OUString& _rFeatureName,
276 const css::uno::Reference< css::uno::XInterface >& _rxContext,
277 const css::uno::Any& _rNextException = css::uno::Any()
278 );
279
289 const OUString& _rFeatureName,
290 const css::uno::Reference< css::uno::XInterface >& _rxContext
291 );
292
301 const OUString& _rColumnName,
302 const css::uno::Reference< css::uno::XInterface >& _rxContext
303 );
304
305
309 const OUString& _rMessage,
310 const OUString& _rSQLState,
311 const css::uno::Reference< css::uno::XInterface >& _rxContext,
312 const sal_Int32 _nErrorCode
313 );
314
315
319 const OUString& _rMessage,
320 StandardSQLState _eSQLState,
321 const css::uno::Reference< css::uno::XInterface >& _rxContext,
322 const sal_Int32 _nErrorCode = 0
323 );
324
325
326} // namespace dbtools
327
328
329#endif // INCLUDED_CONNECTIVITY_DBEXCEPTION_HXX
330
331
332/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const css::uno::Any & get() const
bool hasMoreElements() const
determines whether there are more elements in the exception chain
const css::sdbc::SQLException * m_pCurrent
SQLExceptionInfo::TYPE m_eCurrentType
#define OOO_DLLPUBLIC_DBTOOLS
const EnumerationType m_eType
void throwFunctionSequenceException(const Reference< XInterface > &Context, const Any &Next)
void throwFeatureNotImplementedRuntimeException(const OUString &_rFeatureName, const Reference< XInterface > &_rxContext)
void throwInvalidIndexException(const css::uno::Reference< css::uno::XInterface > &Context, const css::uno::Any &Next)
throw an invalid index sqlexception
StandardSQLState
standard SQLStates to be used with an SQLException
void throwFunctionNotSupportedRuntimeException(const OUString &_rFunctionName, const css::uno::Reference< css::uno::XInterface > &_rxContext)
void throwFeatureNotImplementedSQLException(const OUString &_rFeatureName, const Reference< XInterface > &_rxContext, const Any &_rNextException)
void throwFunctionNotSupportedSQLException(const OUString &_rFunctionName, const css::uno::Reference< css::uno::XInterface > &_rxContext)
throws an exception with SQL state IM001, saying that a certain function is not supported
@ ParameterInteractionCancelled
Definition: dbexception.hxx:49
void throwSQLException(const OUString &_rMessage, const OUString &_rSQLState, const Reference< XInterface > &_rxContext, const sal_Int32 _nErrorCode)
void throwInvalidColumnException(const OUString &_rColumnName, const Reference< XInterface > &_rxContext)
OUString getStandardSQLState(StandardSQLState _eState)
returns a standard error string for a given SQLState
void throwGenericSQLException(const OUString &_rMsg, const css::uno::Reference< css::uno::XInterface > &_rxSource)
throw a generic SQLException, i.e.
::ucbhelper::Content m_aContent