1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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_SQLERROR_HXX
21 #define INCLUDED_CONNECTIVITY_SQLERROR_HXX
23 #include <config_options.h>
24 #include <com/sun/star/sdbc/SQLException.hpp>
25 #include <connectivity/dbtoolsdllapi.hxx>
29 namespace connectivity
35 /** the type of error codes to be used in SQLExceptions
37 @see css::sdbc::SQLException::ErrorCode
39 typedef ::sal_Int32 ErrorCode
;
41 /** error condition values as defined in css::sdb::ErrorCondition
43 typedef ::sal_Int32 ErrorCondition
;
50 /** a class which provides helpers for working with SQLErrors
52 In particular, this class provides vendor-specific error codes (where
53 the vendor is OpenOffice.org Base), which can be used in OOo's various
54 database drivers, and checked in application-level code, to properly
55 recognize highly specific error conditions.
57 @see css::sdb::ErrorCondition
59 class UNLESS_MERGELIBS_MORE(OOO_DLLPUBLIC_DBTOOLS
) SQLError
65 /** returns the message associated with a given error condition, after (optionally) replacing
66 a placeholder with a given string
68 Some error messages need to contain references to runtime-dependent data (say, the
69 name of a concrete table in the database), which in the resource file's strings are
70 represented by a placeholder, namely $1$, $2, and so on. This method allows to
71 retrieve such an error message, and replace up to 3 placeholders with their concrete
74 In a non-product build, assertions will fire if the number of placeholders in the
75 message's resource string does not match the number of passed parameter values.
77 As specified in the css::sdb::ErrorCondition type,
78 error messages thrown by core components of OpenOffice.org Base will contain
79 a standardized prefix "[OOoBase]" in every message.
81 @see css::sdb::ErrorCondition
83 OUString
getErrorMessage(
84 const ErrorCondition _eCondition
87 /** returns the error code associated with a given error condition
90 @see css::sdb::ErrorCondition
91 @see css::sdbc::SQLException::ErrorCode
94 getErrorCode( const ErrorCondition _eCondition
);
96 /** returns the prefix which is used for OpenOffice.org Base's error messages
98 As specified in the css::sdb::ErrorCondition type,
99 error messages thrown by core components of OpenOffice.org Base will
100 contain a standardized prefix in every message. <code>getBaseErrorMessagePrefix</code>
101 returns this prefix, so clients of such error messages might decide to strip this
102 prefix before presenting the message to the user, or use it to determine
103 whether a concrete error has been raised by a OpenOffice.org core component.
105 static const OUString
&
109 /** throws an SQLException describing the given error condition
111 The thrown SQLException will contain the OOo-specific error code which derives
112 from the given error condition, and the error message associated with that condition.
115 the ErrorCondition which hit you
118 the context in which the error occurred. This will be filled in as
119 <member scope="css::uno">Exception::Context</member> member.
122 a runtime-dependent value which should be filled into the error message
123 which is associated with <arg>_eCondition</arg>, replacing the first placeholder
127 a runtime-dependent value which should be filled into the error message
128 which is associated with <arg>_eCondition</arg>, replacing the second placeholder
132 a runtime-dependent value which should be filled into the error message
133 which is associated with <arg>_eCondition</arg>, replacing the third placeholder
140 const ErrorCondition _eCondition
,
141 const css::uno::Reference
< css::uno::XInterface
>& _rxContext
,
142 const std::optional
<OUString
>& _rParamValue1
= std::nullopt
,
143 const std::optional
<OUString
>& _rParamValue2
= std::nullopt
,
144 const std::optional
<OUString
>& _rParamValue3
= std::nullopt
147 /** throws an SQLException describing the given error condition
149 The thrown SQLException will contain the OOo-specific error code which derives
150 from the given error condition, and the error message associated with that condition.
152 Note: You should prefer the version of raiseException which takes
153 an additional Context parameter, since this allows clients of your
154 exception to examine where the error occurred.
157 the ErrorCondition which hit you
163 const ErrorCondition _eCondition
166 /** raises a typed exception, that is, a UNO exception which is derived from
167 css::sdbc::SQLException
170 the ErrorCondition which hit you
173 the context in which the error occurred. This will be filled in as
174 <member scope="css::uno">Exception::Context</member> member.
176 @param _rExceptionType
177 the type of the exception to throw. This type <em>must</em> specify
178 an exception class derived from css::sdbc::SQLException.
180 @throws ::std::bad_cast
181 if <arg>_rExceptionType</arg> does not specify an exception class derived from
182 css::sdbc::SQLException.
187 void raiseTypedException(
188 const ErrorCondition _eCondition
,
189 const css::uno::Reference
< css::uno::XInterface
>& _rxContext
,
190 const css::uno::Type
& _rExceptionType
193 /** retrieves an <code>SQLException</code> object which contains information about
194 the given error condition
197 the ErrorCondition which hit you
200 the context in which the error occurred. This will be filled in as
201 <member scope="css::uno">Exception::Context</member> member.
204 a runtime-dependent value which should be filled into the error message
205 which is associated with <arg>_eCondition</arg>, replacing the first placeholder
209 a runtime-dependent value which should be filled into the error message
210 which is associated with <arg>_eCondition</arg>, replacing the second placeholder
214 a runtime-dependent value which should be filled into the error message
215 which is associated with <arg>_eCondition</arg>, replacing the third placeholder
221 css::sdbc::SQLException
223 const ErrorCondition _eCondition
,
224 const css::uno::Reference
< css::uno::XInterface
>& _rxContext
,
225 const std::optional
<OUString
>& _rParamValue1
= std::nullopt
,
226 const std::optional
<OUString
>& _rParamValue2
= std::nullopt
,
227 const std::optional
<OUString
>& _rParamValue3
= std::nullopt
231 std::shared_ptr
< SQLError_Impl
> m_pImpl
;
235 } // namespace connectivity
238 #endif // INCLUDED_CONNECTIVITY_SQLERROR_HXX
240 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */