bump product version to 6.3.0.0.beta1
[LibreOffice.git] / include / connectivity / dbexception.hxx
blobe1335591fc947bea3688aa214d40205937b8e946
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_CONNECTIVITY_DBEXCEPTION_HXX
21 #define INCLUDED_CONNECTIVITY_DBEXCEPTION_HXX
23 #include <connectivity/standardsqlstate.hxx>
24 #include <connectivity/dbtoolsdllapi.hxx>
25 #include <com/sun/star/uno/Reference.hxx>
27 namespace com
29 namespace sun
31 namespace star
33 namespace sdb
35 class SQLContext;
36 struct SQLErrorEvent;
38 namespace sdbc
40 class SQLWarning;
41 class SQLException;
47 namespace dbtools
51 //= Special exception if cancel is pressed in DBA UI
53 enum OOoBaseErrorCode
55 ParameterInteractionCancelled = 1
59 //= SQLExceptionInfo - encapsulating the type info of an SQLException-derived class
62 class OOO_DLLPUBLIC_DBTOOLS SQLExceptionInfo final
64 public:
65 enum class TYPE { SQLException, SQLWarning, SQLContext, Undefined };
67 private:
68 css::uno::Any m_aContent;
69 TYPE m_eType; // redundant (could be derived from m_aContent.getValueType())
71 public:
72 SQLExceptionInfo();
73 SQLExceptionInfo(const css::sdbc::SQLException& _rError);
74 SQLExceptionInfo(const css::sdbc::SQLWarning& _rError);
75 SQLExceptionInfo(const css::sdb::SQLContext& _rError);
77 /** convenience constructor
79 If your error processing relies on SQLExceptions, and SQLExceptionInfos, you still may
80 need to display an error which consists of a simple message string only.
81 In those cases, you can use this constructor, which behaves as if you would have used
82 an SQLException containing exactly the given error message.
84 SQLExceptionInfo( const OUString& _rSimpleErrorMessage );
86 // use for events got via XSQLErrorListener::errorOccured
87 SQLExceptionInfo(const css::uno::Any& _rError);
88 // use with the Reason member of an SQLErrorEvent or with NextElement of an SQLException
90 /** prepends a plain error message to the chain of exceptions
91 @param _rSimpleErrorMessage
92 the error message to prepend
94 void prepend( const OUString& _rErrorMessage );
96 /** appends a plain message to the chain of exceptions
97 @param _eType
98 the type of exception to append. Must be SQL_EXCEPTION, SQL_WARNING, SQL_CONTEXT, for all other
99 values, the behavior is undefined.
100 @param _rErrorMessage
101 the message to append
102 @param _rSQLState
103 the SQLState of the exception to append
104 @param _nErrorCode
105 the error code of the exception to append
107 void append( TYPE _eType, const OUString& _rErrorMessage, const OUString& _rSQLState = OUString(), const sal_Int32 _nErrorCode = 0 );
109 /** throws (properly typed) the exception contained in the object
110 @precond
111 isValid() returns <TRUE/>
112 @throws SQLException
113 @throws RuntimeException
114 if the instance does not contain an SQLException
116 void doThrow();
118 SQLExceptionInfo& operator=(const css::sdbc::SQLException& _rError);
119 SQLExceptionInfo& operator=(const css::sdbc::SQLWarning& _rError);
120 SQLExceptionInfo& operator=(const css::sdb::SQLContext& _rError);
121 SQLExceptionInfo& operator=(const css::sdb::SQLErrorEvent& _rErrorEvent);
122 SQLExceptionInfo& operator=(const css::uno::Any& _rCaughtSQLException);
124 bool isKindOf(TYPE _eType) const;
125 // not just a simple comparison ! e.g. getType() == SQL_CONTEXT implies isKindOf(SQL_EXCEPTION) == sal_True !
126 bool isValid() const { return m_eType != TYPE::Undefined; }
127 TYPE getType() const { return m_eType; }
129 operator const css::sdbc::SQLException* () const;
130 operator const css::sdb::SQLContext* () const;
132 const css::uno::Any& get() const { return m_aContent; }
134 void clear()
136 m_aContent.clear();
137 m_eType = TYPE::Undefined;
140 private:
141 void implDetermineType();
145 //= SQLExceptionIteratorHelper - iterating through an SQLException chain
148 class OOO_DLLPUBLIC_DBTOOLS SQLExceptionIteratorHelper final
150 const css::sdbc::SQLException* m_pCurrent;
151 SQLExceptionInfo::TYPE m_eCurrentType;
153 public:
154 /** constructs an iterator instance from an SQLException
156 @param _rChainStart
157 the start of the exception chain to iterate. Must live as long as the iterator
158 instances lives, at least.
160 SQLExceptionIteratorHelper( const css::sdbc::SQLException& _rChainStart );
162 /** constructs an iterator instance from an SQLExceptionInfo
164 @param _rErrorInfo
165 the start of the exception chain to iterate. Must live as long as the iterator
166 instances lives, at least.
168 SQLExceptionIteratorHelper( const SQLExceptionInfo& _rErrorInfo );
170 /** determines whether there are more elements in the exception chain
172 bool hasMoreElements() const { return ( m_pCurrent != nullptr ); }
174 /** retrieves the current element in the chain, or <NULL/> if the chain has been completely
175 traveled.
177 In opposite to the second <member>current</member>, this version allows typed access to
178 the respective SQLException.
180 void current( SQLExceptionInfo& _out_rInfo ) const;
182 /** proceeds to the next element in the chain
184 @return the current element in the chain, as <b>before</em> the chain move.
186 const css::sdbc::SQLException* next();
188 /** proceeds to the next element in the chain
190 In opposite to the second <member>current</member>, this version allows typed access to
191 the respective SQLException.
193 void next( SQLExceptionInfo& _out_rInfo );
197 //= StandardExceptions
200 /** returns a standard error string for a given SQLState
202 @param _eState
203 describes the state whose description is to retrieve. Must not be SQL_ERROR_UNSPECIFIED.
204 @throws RuntimeException
205 in case of an internal error
207 OOO_DLLPUBLIC_DBTOOLS OUString getStandardSQLState( StandardSQLState _eState );
210 /** throws an exception with SQL state IM001, saying that a certain function is not supported
212 @throws css::sdbc::SQLException
214 OOO_DLLPUBLIC_DBTOOLS void throwFunctionNotSupportedSQLException(
215 const OUString& _rFunctionName,
216 const css::uno::Reference< css::uno::XInterface >& _rxContext
219 /// @throws css::uno::RuntimeException
220 OOO_DLLPUBLIC_DBTOOLS void throwFunctionNotSupportedRuntimeException(
221 const OUString& _rFunctionName,
222 const css::uno::Reference< css::uno::XInterface >& _rxContext
225 /** throws a function sequence (HY010) exception
227 @throws css::sdbc::SQLException
229 OOO_DLLPUBLIC_DBTOOLS void throwFunctionSequenceException(
230 const css::uno::Reference< css::uno::XInterface >& Context,
231 const css::uno::Any& Next = css::uno::Any()
235 /** throw a invalid index sqlexception
237 @throws css::sdbc::SQLException
239 OOO_DLLPUBLIC_DBTOOLS void throwInvalidIndexException(
240 const css::uno::Reference< css::uno::XInterface >& Context,
241 const css::uno::Any& Next = css::uno::Any()
245 /** throw a generic SQLException, i.e. one with an SQLState of HY000, an ErrorCode of 0 and no NextException
247 @throws css::sdbc::SQLException
249 OOO_DLLPUBLIC_DBTOOLS void throwGenericSQLException(
250 const OUString& _rMsg,
251 const css::uno::Reference< css::uno::XInterface >& _rxSource
255 /** throw a generic SQLException, i.e. one with an SQLState of HY000, an ErrorCode of 0 and no NextException
257 @throws css::sdbc::SQLException
259 OOO_DLLPUBLIC_DBTOOLS void throwGenericSQLException(
260 const OUString& _rMsg,
261 const css::uno::Reference< css::uno::XInterface >& _rxSource,
262 const css::uno::Any& _rNextException
266 /** throw a SQLException with SQLState HYC00 (Optional feature not implemented)
267 @param _rFeatureName
268 a description of the feature which is not implemented. It's recommended that the feature
269 name is built from the name of the interface plus its method, for instance "XParameters::updateBinaryStream"
270 @param _rxContext
271 the context of the exception
272 @throws css::sdbc::SQLException
274 OOO_DLLPUBLIC_DBTOOLS void throwFeatureNotImplementedSQLException(
275 const OUString& _rFeatureName,
276 const css::uno::Reference< css::uno::XInterface >& _rxContext,
277 const css::uno::Any& _rNextException = css::uno::Any()
280 /** throw a RuntimeException (Optional feature not implemented)
281 @param _rFeatureName
282 a description of the feature which is not implemented. It's recommended that the feature
283 name is built from the name of the interface plus its method, for instance "XParameters::updateBinaryStream"
284 @param _rxContext
285 the context of the exception
286 @throws css::uno::RuntimeException
288 OOO_DLLPUBLIC_DBTOOLS void throwFeatureNotImplementedRuntimeException(
289 const OUString& _rFeatureName,
290 const css::uno::Reference< css::uno::XInterface >& _rxContext
293 /** throw a SQLException with SQLState 42S22 (Column Not Found)
294 @param _rColumnNameName
295 The column that couldn't be found.
296 @param _rxContext
297 the context of the exception
298 @throws css::sdbc::SQLException
300 OOO_DLLPUBLIC_DBTOOLS void throwInvalidColumnException(
301 const OUString& _rColumnName,
302 const css::uno::Reference< css::uno::XInterface >& _rxContext
306 /** @throws css::sdbc::SQLException
308 OOO_DLLPUBLIC_DBTOOLS void throwSQLException(
309 const OUString& _rMessage,
310 const OUString& _rSQLState,
311 const css::uno::Reference< css::uno::XInterface >& _rxContext,
312 const sal_Int32 _nErrorCode
316 /** @throws css::sdbc::SQLException
318 OOO_DLLPUBLIC_DBTOOLS void throwSQLException(
319 const OUString& _rMessage,
320 StandardSQLState _eSQLState,
321 const css::uno::Reference< css::uno::XInterface >& _rxContext,
322 const sal_Int32 _nErrorCode = 0
326 } // namespace dbtools
329 #endif // INCLUDED_CONNECTIVITY_DBEXCEPTION_HXX
332 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */