xref: /trunk/main/connectivity/inc/connectivity/dbtools.hxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _CONNECTIVITY_DBTOOLS_HXX_
25 #define _CONNECTIVITY_DBTOOLS_HXX_
26 
27 #include <connectivity/dbexception.hxx>
28 #include <comphelper/types.hxx>
29 #include <com/sun/star/sdbc/DataType.hpp>
30 #include <comphelper/stl_types.hxx>
31 #include <unotools/sharedunocomponent.hxx>
32 #include "connectivity/dbtoolsdllapi.hxx"
33 #include "connectivity/FValue.hxx"
34 
35 namespace com { namespace sun { namespace star {
36 
37 namespace sdb {
38     class XSingleSelectQueryComposer;
39     class SQLContext;
40 }
41 namespace sdbcx {
42     class XTablesSupplier;
43 }
44 namespace sdbc {
45     class XConnection;
46     class XDatabaseMetaData;
47     class XRowSet;
48     class XDataSource;
49     class SQLException;
50     class XParameters;
51     class XRowUpdate;
52 }
53 namespace beans {
54     class XPropertySet;
55 }
56 namespace awt {
57     class XWindow;
58 }
59 namespace lang {
60     struct Locale;
61     class XMultiServiceFactory;
62     class WrappedTargetException;
63 }
64 namespace container {
65     class XNameAccess;
66 }
67 
68 namespace util {
69     class XNumberFormatTypes;
70     class XNumberFormatsSupplier;
71 }
72 namespace task {
73     class XInteractionHandler;
74 }
75 
76 } } }
77 
78 namespace rtl
79 {
80     class OUStringBuffer;
81 }
82 
83 //.........................................................................
84 namespace dbtools
85 {
86     class ISQLStatementHelper;
87     typedef ::utl::SharedUNOComponent< ::com::sun::star::sdbc::XConnection > SharedConnection;
88 
89     enum EComposeRule
90     {
91         eInTableDefinitions,
92         eInIndexDefinitions,
93         eInDataManipulation,
94         eInProcedureCalls,
95         eInPrivilegeDefinitions,
96         eComplete
97     };
98 //=========================================================================
99     // date conversion
100 
101     // calculates the default numberformat for a given datatype and a give language
102     OOO_DLLPUBLIC_DBTOOLS
103     sal_Int32 getDefaultNumberFormat(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _xColumn,
104                                      const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatTypes >& _xTypes,
105                                      const ::com::sun::star::lang::Locale& _rLocale);
106 
107     // calculates the default numberformat for a given datatype and a give language
108     // @param  _nDataType @see com.sun.star.sdbc.DataType
109     // @param _nScale       can be zero
110     OOO_DLLPUBLIC_DBTOOLS
111     sal_Int32 getDefaultNumberFormat(sal_Int32 _nDataType,
112                                      sal_Int32 _nScale,
113                                      sal_Bool _bIsCurrency,
114                                      const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatTypes >& _xTypes,
115                                      const ::com::sun::star::lang::Locale& _rLocale);
116 
117 //=========================================================================
118 
119     /** creates a connection which can be used for the rowset given
120 
121         The function tries to obtain a connection for the row set with the following
122         steps (in this order):
123         <nl>
124             <li>If the rowset already has an ActiveConnection (means a non-<NULL/> value vor this property),
125                 this one is used.</li>
126             <li>If row set is part of a database form document (see ->isEmbeddedInDatabase),
127                 a connection for the respective database is used.</li>
128             <li>If in the parent hierarchy of the row set, there is an object supporting
129                 the XConnection interface, this one is returned.</li>
130             <li>If the DataSourceName property of the row set is not empty, a connection for this
131                 data source is retrieved.</li>
132             <li>If the URL property of the row set is not empty, an connection for this URL is
133                 retrieved from the driver manager.
134         </nl>
135 
136         @param _rxRowSet
137             the row set
138 
139         @param _rxFactory
140             a service factory, which can be used to create data sources, interaction handler etc (the usual stuff)
141 
142         @param _bSetAsActiveConnection
143             If <TRUE/>, the calculated connection is set as ActiveConnection property on the rowset.
144 
145             If the connection was newly created by the method, and this parameter is <TRUE/>, then
146             the ownership of the connection is delivered to a temporary object, which observes the
147             row set: As soon as a connection-relevant property of the row set changes, or as soon
148             as somebody else sets another ActiveConnection at the row set, the original
149             connection (the one which this function calculated) is disposed and discarded. At this
150             very moment, also the temporary observer object dies. This way, it is ensured that
151             there's no resource leak from an un-owned connection object.
152     */
153     OOO_DLLPUBLIC_DBTOOLS
154     ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection> connectRowset(
155         const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowSet>& _rxRowSet,
156         const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory>& _rxFactory,
157         sal_Bool _bSetAsActiveConnection
158     );
159 
160     /** ensures that a row set has a valid ActiveConnection, if possible
161 
162         This function does nearly the same as ->connectRowset. In fact, it is to be preferred over
163         ->connectRowset, if possible.
164 
165         There are a few differences:
166         <ul><li>If a connection could be determined for the given RowSet, it is always
167                 set as ActiveConnection.</li>
168             <li>Definition of the ownership of the created connection allows for more scenarios:
169                 <ul><li>If the connection was not newly created, the returned ->SharedConnection
170                         instance will not have the ownership, since in this case it's assumed
171                         that there already is an instance which has the ownership.</li>
172                     <li>If the connection was newly created, and ->_bUseAutoConnectionDisposer
173                         is <TRUE/>, then the returned SharedConnection instance will <em>not</em>
174                         be the owner of the connection. Instead, the ownership will be delivered
175                         to a temporary object as described for connectRowset.</li>
176                     <li>If the connection was newly created, and ->_bUseAutoConnectionDisposer
177                         is <FALSE/>, then the returned SharedConnection instance will have the
178                         ownership of the XConnection.</li>
179                 </ul>
180             </li>
181         </ul>
182     */
183     OOO_DLLPUBLIC_DBTOOLS SharedConnection    ensureRowSetConnection(
184         const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowSet>& _rxRowSet,
185         const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory>& _rxFactory,
186         bool _bUseAutoConnectionDisposer
187     );
188 
189     /** returns the connection the RowSet is currently working with (which is the ActiveConnection property)
190     */
191     OOO_DLLPUBLIC_DBTOOLS ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection> getConnection(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowSet>& _rxRowSet);
192     OOO_DLLPUBLIC_DBTOOLS ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection> getConnection(
193             const ::rtl::OUString& _rsTitleOrPath,
194             const ::rtl::OUString& _rsUser,
195             const ::rtl::OUString& _rsPwd,
196             const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory>& _rxFactory);
197 
198     OOO_DLLPUBLIC_DBTOOLS ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection> getConnection_withFeedback(
199             const ::rtl::OUString& _rDataSourceName,
200             const ::rtl::OUString& _rUser,
201             const ::rtl::OUString& _rPwd,
202             const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory>& _rxFactory);
203 
204 
205     /** determines whether the given component is part of a document which is an embedded database
206         document (such as a form)
207     */
208     OOO_DLLPUBLIC_DBTOOLS bool    isEmbeddedInDatabase(
209                 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxComponent,
210                 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxActualConnection
211             );
212 
213     /** returns the columns of the named table of the given connection
214     */
215     OOO_DLLPUBLIC_DBTOOLS ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess> getTableFields(
216         const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _rxConn,
217         const ::rtl::OUString& _rName
218     );
219 
220     /** returns the primary key columns of the table
221     */
222     OOO_DLLPUBLIC_DBTOOLS ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess> getPrimaryKeyColumns_throw(
223         const ::com::sun::star::uno::Any& i_aTable
224     );
225     OOO_DLLPUBLIC_DBTOOLS ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess> getPrimaryKeyColumns_throw(
226         const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& i_xTable
227     );
228 
229     /** get fields for a result set given by a "command descriptor"
230 
231         <p>A command descriptor here means:
232         <ul><li>a SDB-level connection (<type scope="com.sun.star.sdb">Connection</type></li>
233             <li>a string specifying the name of an object relative to the connection</li>
234             <li>a <type scope="com.sun.star.sdb">CommandType</type> value specifying the type
235                 of the object</type></li>
236         </ul>
237         </p>
238 
239         @param _rxConnection
240             the connection relative to which the to-be-examined object exists
241 
242         @param _nCommandType
243             the type of the object
244 
245         @param _rCommand
246             the object. This may be a table name, a query name, or an SQL statement, depending on the value
247             of <arg>_nCommandType</arg>
248 
249         @param _rxCollectionOner
250             If (and only if) <arg>CommandType</arg> is CommandType.COMMAND, the fields collection which is returned
251             by this function here is a temporary object. It is kept alive by another object, which is to be
252             created temporarily, too. To ensure that the fields you get are valid as long as you need them,
253             the owner which controls their life time is transferred to this parameter upon return.<br/>
254 
255             Your fields live as long as this component lives.<br/>
256 
257             Additionally, you are encouraged to dispose this component as soon as you don't need the fields anymore.
258             It depends on the connection's implementation if this is necessary, but the is no guarantee, so to
259             be on the safe side with respect to resource leaks, you should dispose the component.
260 
261         @param _pErrorInfo
262             If not <NULL/>, then upon return from the function the instance pointed to by this argument will
263             contain any available error information in case something went wrong.
264 
265         @return
266             the container of the columns (aka fields) of the object
267     */
268     OOO_DLLPUBLIC_DBTOOLS
269     ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >
270         getFieldsByCommandDescriptor(
271             const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConnection,
272             const sal_Int32 _nCommandType,
273             const ::rtl::OUString& _rCommand,
274             ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& _rxKeepFieldsAlive,
275             SQLExceptionInfo* _pErrorInfo = NULL
276         )   SAL_THROW( ( ) );
277 
278 
279     /** get fields for a result set given by a "command descriptor"
280 
281         <p>A command descriptor here means:
282         <ul><li>a SDB-level connection (<type scope="com.sun.star.sdb">Connection</type></li>
283             <li>a string specifying the name of an object relative to the connection</li>
284             <li>a <type scope="com.sun.star.sdb">CommandType</type> value specifying the type
285                 of the object</type></li>
286         </ul>
287         </p>
288 
289         @param _rxConnection
290             the connection relative to which the to-be-examined object exists
291 
292         @param _nCommandType
293             the type of the object
294 
295         @param _rCommand
296             the object. This may be a table name, a query name, or an SQL statement, depending on the value
297             of <arg>_nCommandType</arg>
298 
299         @param _pErrorInfo
300             If not <NULL/>, then upon return from the function the instance pointed to by this argument will
301             contain any available error information in case something went wrong.
302 
303         @return
304             an array of strings containing the names of the columns (aka fields) of the object
305     */
306     OOO_DLLPUBLIC_DBTOOLS ::com::sun::star::uno::Sequence< ::rtl::OUString >
307         getFieldNamesByCommandDescriptor(
308             const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConnection,
309             const sal_Int32 _nCommandType,
310             const ::rtl::OUString& _rCommand,
311             SQLExceptionInfo* _pErrorInfo = NULL
312         )   SAL_THROW( ( ) );
313 
314 
315     /** create a new ::com::sun::star::sdbc::SQLContext, fill it with the given descriptions and the given source,
316         and <i>append</i> _rException (i.e. put it into the NextException member of the SQLContext).
317     */
318     OOO_DLLPUBLIC_DBTOOLS ::com::sun::star::sdb::SQLContext prependContextInfo(const ::com::sun::star::sdbc::SQLException& _rException, const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxContext, const ::rtl::OUString& _rContextDescription, const ::rtl::OUString& _rContextDetails );
319 
320     OOO_DLLPUBLIC_DBTOOLS
321     ::com::sun::star::sdbc::SQLException prependErrorInfo(
322         const ::com::sun::star::sdbc::SQLException& _rChainedException,
323         const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxContext,
324         const ::rtl::OUString& _rAdditionalError,
325         const StandardSQLState _eSQLState = SQL_ERROR_UNSPECIFIED,
326         const sal_Int32 _nErrorCode = 0);
327 
328     /** search the parent hierarchy for a data source.
329     */
330     OOO_DLLPUBLIC_DBTOOLS ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDataSource> findDataSource(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xParent);
331 
332     /** determines the value of a boolean data source setting, given by ASCII name
333 
334         @param _rxConnection
335             the connection belonging to the data source whose setting is to be retrieved
336         @param _pAsciiSettingName
337             the ASCII name of the setting
338     */
339     OOO_DLLPUBLIC_DBTOOLS bool getBooleanDataSourceSetting(
340             const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConnection,
341             const sal_Char* _pAsciiSettingName
342         );
343 
344     /** check if a specific property is enabled in the info sequence
345         @deprecated
346             Use getBooleanDataSourceSetting instead, which cares for the default of the property itself,
347             instead of spreading this knowledge through all callers.
348     */
349     OOO_DLLPUBLIC_DBTOOLS
350     sal_Bool isDataSourcePropertyEnabled(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>& _xProp
351                                         ,const ::rtl::OUString& _sProperty,
352                                         sal_Bool _bDefault = sal_False);
353 
354     /** retrieves a particular indirect data source setting
355 
356         @param _rxDataSource
357             a data source component
358         @param _pAsciiSettingsName
359             the ASCII name of the setting to obtain
360         @param _rSettingsValue
361             the value of the setting, upon successful return
362 
363         @return
364             <FALSE/> if the setting is not present in the <member scope="com::sun::star::sdb">DataSource::Info</member>
365             member of the data source
366             <TRUE/> otherwise
367     */
368     OOO_DLLPUBLIC_DBTOOLS
369     bool    getDataSourceSetting(
370         const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxDataSource,
371         const sal_Char* _pAsciiSettingsName,
372         ::com::sun::star::uno::Any& /* [out] */ _rSettingsValue
373     );
374     OOO_DLLPUBLIC_DBTOOLS
375     bool    getDataSourceSetting(
376         const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxDataSource,
377         const ::rtl::OUString& _sSettingsName,
378         ::com::sun::star::uno::Any& /* [out] */ _rSettingsValue
379     );
380 
381     OOO_DLLPUBLIC_DBTOOLS ::rtl::OUString getDefaultReportEngineServiceName(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory>& _rxFactory);
382 
383     /** quote the given name with the given quote string.
384     */
385     OOO_DLLPUBLIC_DBTOOLS ::rtl::OUString quoteName(const ::rtl::OUString& _rQuote, const ::rtl::OUString& _rName);
386 
387     /** quote the given table name (which may contain a catalog and a schema) according to the rules provided by the meta data
388     */
389     OOO_DLLPUBLIC_DBTOOLS
390     ::rtl::OUString quoteTableName(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData>& _rxMeta
391                                     , const ::rtl::OUString& _rName
392                                     ,EComposeRule _eComposeRule);
393 
394     /** split a fully qualified table name (including catalog and schema, if appliable) into it's component parts.
395         @param  _rxConnMetaData     meta data describing the connection where you got the table name from
396         @param  _rQualifiedName     fully qualified table name
397         @param  _rCatalog           (out parameter) upon return, contains the catalog name
398         @param  _rSchema            (out parameter) upon return, contains the schema name
399         @param  _rName              (out parameter) upon return, contains the table name
400         @param  _eComposeRule       where do you need the name for
401     */
402     OOO_DLLPUBLIC_DBTOOLS void qualifiedNameComponents(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData >& _rxConnMetaData,
403         const ::rtl::OUString& _rQualifiedName, ::rtl::OUString& _rCatalog, ::rtl::OUString& _rSchema, ::rtl::OUString& _rName,EComposeRule _eComposeRule);
404 
405     /** calculate a NumberFormatsSupplier for use with an given connection
406         @param      _rxConn         the connection for which the formatter is requested
407         @param      _bAllowDefault  if the connection (and related components, such as it's parent) cannot supply
408                                     a formatter, we can ask the DatabaseEnvironment for a default one. This parameter
409                                     states if this is allowed.
410         @param      _rxFactory      required (only of _bAllowDefault is sal_True) for creating the DatabaseEnvironment.
411         @return     the formatter all object related to the given connection should work with.
412     */
413     OOO_DLLPUBLIC_DBTOOLS ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatsSupplier> getNumberFormats(
414         const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _rxConn,
415         sal_Bool _bAllowDefault = sal_False,
416         const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory>& _rxFactory = ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory>()
417     );
418 
419     /** returns the statement which is composed from the current settings of a row set
420 
421         If the row set is currently not connected, it is attempted to do so with it's current settings.
422         (TODO: isn't this a resource leak? Do we really need this behaviour?).
423 
424         @param _rxRowSet
425             the row set whose settings should be examined. Must not be <NULL/>
426         @param _rxFactory
427             a service factory which may be needed to connect the row set
428         @param _bUseRowSetFilter
429             If <TRUE/>, the <b>Filter</b> property of the row set will also be examined. In case it is
430             not empty, and <b>ApplyFilter</b> is <TRUE/>, it will also be added to the composed statement.
431         @param _bUseRowSetOrder
432             If <TRUE/>, the <b>Order</b> property of the row set will also be examined. In case it is
433             not empty, it will also be added to the composed statement.
434     */
435     OOO_DLLPUBLIC_DBTOOLS ::rtl::OUString getComposedRowSetStatement(
436             const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxRowSet,
437             const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory>& _rxFactory,
438             sal_Bool _bUseRowSetFilter = sal_True,
439             sal_Bool _bUseRowSetOrder = sal_True
440     );
441 
442     /** create an <type scope="com::sun::star::sdb">XSingleSelectQueryComposer</type> which represents
443         the current settings (Command/CommandType/Filter/Order) of the given rowset.
444 
445         As such an instance can be obtained from a <type scope="com::sun::star::sdb">Connection</type>
446         only the function searches for the connection the RowSet is using via connectRowset.
447         This implies that a connection will be set on the RowSet if needed.
448         (need to changes this sometimes ...)
449     */
450     OOO_DLLPUBLIC_DBTOOLS ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XSingleSelectQueryComposer > getCurrentSettingsComposer(
451         const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _rxRowSetProps,
452         const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory>& _rxFactory
453     );
454 
455     /** transfer and translate properties between two FormComponents
456         @param      _rxOld      the source property set
457         @param      _rxNew      the destination property set
458         @param      _rLocale    the locale for converting number related properties
459     */
460     OOO_DLLPUBLIC_DBTOOLS void TransferFormComponentProperties(
461         const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _rxOld,
462         const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _rxNew,
463         const ::com::sun::star::lang::Locale& _rLocale
464         );
465 
466     /** check if the property "Privileges" supports ::com::sun::star::sdbcx::Privilege::INSERT
467         @param      _rxCursorSet    the property set
468     */
469     OOO_DLLPUBLIC_DBTOOLS sal_Bool canInsert(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _rxCursorSet);
470     /** check if the property "Privileges" supports ::com::sun::star::sdbcx::Privilege::UPDATE
471         @param      _rxCursorSet    the property set
472     */
473     OOO_DLLPUBLIC_DBTOOLS sal_Bool canUpdate(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _rxCursorSet);
474     /** check if the property "Privileges" supports ::com::sun::star::sdbcx::Privilege::DELETE
475         @param      _rxCursorSet    the property set
476     */
477     OOO_DLLPUBLIC_DBTOOLS sal_Bool canDelete(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _rxCursorSet);
478 
479     //----------------------------------------------------------------------------------
480     /** compose a complete table name from it's up to three parts, regarding to the database meta data composing rules
481     */
482     OOO_DLLPUBLIC_DBTOOLS ::rtl::OUString composeTableName( const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData >& _rxMetaData,
483                             const ::rtl::OUString& _rCatalog,
484                             const ::rtl::OUString& _rSchema,
485                             const ::rtl::OUString& _rName,
486                             sal_Bool _bQuote,
487                             EComposeRule _eComposeRule);
488 
489     /** composes a table name for usage in a SELECT statement
490 
491         This includes quoting of the table as indicated by the connection's meta data, plus respecting
492         the settings "UseCatalogInSelect" and "UseSchemaInSelect", which might be present
493         in the data source which the connection belongs to.
494     */
495     OOO_DLLPUBLIC_DBTOOLS ::rtl::OUString composeTableNameForSelect(
496                             const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConnection,
497                             const ::rtl::OUString& _rCatalog,
498                             const ::rtl::OUString& _rSchema,
499                             const ::rtl::OUString& _rName );
500 
501     /** composes a table name for usage in a SELECT statement
502 
503         This includes quoting of the table as indicated by the connection's meta data, plus respecting
504         the settings "UseCatalogInSelect" and "UseSchemaInSelect", which might be present
505         in the data source which the connection belongs to.
506     */
507     OOO_DLLPUBLIC_DBTOOLS ::rtl::OUString composeTableNameForSelect(
508                             const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConnection,
509                             const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _xTable );
510     //----------------------------------------------------------------------------------
511     /** compose the table name out of the property set which must support the properties from the service <member scope= "com::sun::star::sdbcx">table</member>
512         @param  _xMetaData
513             The metadata from the connection.
514         @param  _xTable
515             The table.
516     */
517     OOO_DLLPUBLIC_DBTOOLS ::rtl::OUString composeTableName(
518         const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData>& _xMetaData,
519         const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _xTable,
520         EComposeRule _eComposeRule,
521         bool _bSuppressCatalogName,
522         bool _bSuppressSchemaName,
523         bool _bQuote);
524 
525     //----------------------------------------------------------------------------------
526     OOO_DLLPUBLIC_DBTOOLS sal_Int32 getSearchColumnFlag( const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _rxConn,
527                                     sal_Int32 _nDataType);
528     // return the datasource for the given datasource name
529     OOO_DLLPUBLIC_DBTOOLS ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDataSource> getDataSource(const ::rtl::OUString& _rsDataSourceName,
530                         const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory>& _rxFactory);
531 
532     /** search for a name that is NOT in the NameAcces
533         @param  _rxContainer
534             the NameAccess container to search in
535         @param  _rBaseName
536             the base name that should be used to create the new name
537         @param  _bStartWithNumber
538             When <TRUE/> the name ends with number even when the name itself doesn't occur in the collection.
539         @return
540             A name which doesn't exist in the collection.
541     */
542     OOO_DLLPUBLIC_DBTOOLS
543     ::rtl::OUString createUniqueName(const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess>& _rxContainer,
544                                      const ::rtl::OUString& _rBaseName,
545                                      sal_Bool _bStartWithNumber = sal_True);
546 
547     /** creates a unique name which is not already used in the given name array
548     */
549     OOO_DLLPUBLIC_DBTOOLS ::rtl::OUString createUniqueName(
550         const ::com::sun::star::uno::Sequence< ::rtl::OUString >& _rNames,
551         const ::rtl::OUString& _rBaseName,
552         sal_Bool _bStartWithNumber = sal_True
553     );
554 
555     /** create a name which is a valid SQL 92 identifier name
556         @param      _rName          the string which should be converted
557         @param      _rSpecials      @see com.sun.star.sdbc.XDatabaseMetaData.getExtraNameCharacters
558 
559         @see isValidSQLName
560     */
561     OOO_DLLPUBLIC_DBTOOLS ::rtl::OUString convertName2SQLName(const ::rtl::OUString& _rName,const ::rtl::OUString& _rSpecials);
562 
563     /** checks whether the given name is a valid SQL name
564 
565         @param      _rName          the string which should be converted
566         @param      _rSpecials      @see com.sun.star.sdbc.XDatabaseMetaData.getExtraNameCharacters
567 
568         @see convertName2SQLName
569     */
570     OOO_DLLPUBLIC_DBTOOLS sal_Bool isValidSQLName( const ::rtl::OUString& _rName, const ::rtl::OUString& _rSpecials );
571 
572     OOO_DLLPUBLIC_DBTOOLS
573     void showError( const SQLExceptionInfo& _rInfo,
574                     const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow>& _pParent,
575                     const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory>& _rxFactory);
576 
577     /** implements <method scope="com.sun.star.sdb">XRowUpdate::updateObject</method>
578         <p>The object which is to be set is analyzed, and in case it is a simlpe scalar type for which there
579         is another updateXXX method, this other method is used.</p>
580         @param _rxUpdatedObject
581             the interface to forward all updateXXX calls to (except updateObject)
582         @param _nColumnIndex
583             the column index to update
584         @param _rValue
585             the value to update
586         @return
587             <TRUE/> if the update request was successfully re-routed to one of the other updateXXX methods
588     */
589     OOO_DLLPUBLIC_DBTOOLS
590     sal_Bool implUpdateObject(  const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowUpdate >& _rxUpdatedObject,
591                                 const sal_Int32 _nColumnIndex,
592                                 const ::com::sun::star::uno::Any& _rValue);
593 
594 
595 
596     /** ask the user for parameters if the prepared statement needs some and sets them in the prepared statement
597         @param _xConnection     the connection must be able to create <type scope="com::sun::star::sdb">SingleSelectQueryComposer</type>s
598         @param _xPreparedStmt   the prepared statement where the parameters could be set when needed
599         @param _aParametersSet  contains which parameters have to asked for and which already have set.
600     */
601     OOO_DLLPUBLIC_DBTOOLS
602     void askForParameters(  const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XSingleSelectQueryComposer >& _xComposer,
603                             const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XParameters>& _xParameters,
604                             const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _xConnection,
605                             const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& _rxHandler,
606                             const ::std::bit_vector& _aParametersSet = ::std::bit_vector());
607 
608     /** call the appropriate set method for the specific sql type @see com::sun::star::sdbc::DataType
609         @param  _xParams        the parameters where to set the value
610         @param  parameterIndex  the index of the parameter, 1 based
611         @param  x               the value to set
612         @param  sqlType         the corresponding sql type @see com::sun::star::sdbc::DataType
613         @param  scale           the scale of the sql type can be 0
614     */
615     OOO_DLLPUBLIC_DBTOOLS
616     void setObjectWithInfo( const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XParameters>& _xParameters,
617                             sal_Int32 parameterIndex,
618                             const ::com::sun::star::uno::Any& x,
619                             sal_Int32 sqlType,
620                             sal_Int32 scale=0);
621 
622     /** call the appropriate set method for the specific sql type @see com::sun::star::sdbc::DataType
623         @param  _xParams        the parameters where to set the value
624         @param  parameterIndex  the index of the parameter, 1 based
625         @param  x               the value to set
626         @param  sqlType         the corresponding sql type @see com::sun::star::sdbc::DataType
627         @param  scale           the scale of the sql type can be 0
628     */
629     OOO_DLLPUBLIC_DBTOOLS
630     void setObjectWithInfo( const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XParameters>& _xParameters,
631                             sal_Int32 parameterIndex,
632                             const ::connectivity::ORowSetValue& x,
633                             sal_Int32 sqlType,
634                             sal_Int32 scale=0);
635 
636 
637     /** implements <method scope="com.sun.star.sdb">XParameters::setObject</method>
638         <p>The object which is to be set is analyzed, and in case it is a simlpe scalar type for which there
639         is another setXXX method, this other method is used.</p>
640         @param _rxParameters
641             the interface to forward all setXXX calls to (except setObject)
642         @param _nColumnIndex
643             the column index to update
644         @param _rValue
645             the value to update
646         @return
647             <TRUE/> if the update request was successfully re-routed to one of the other updateXXX methods
648     */
649     OOO_DLLPUBLIC_DBTOOLS
650     sal_Bool implSetObject( const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XParameters>& _rxParameters,
651                             const sal_Int32 _nColumnIndex,
652                             const ::com::sun::star::uno::Any& _rValue);
653 
654     /** creates the standard sql create table statement without the key part.
655         @param  descriptor
656             The descriptor of the new table.
657         @param  _xConnection
658             The connection.
659         @param  _bAddScale
660             The scale will also be added when the value is 0.
661     */
662     OOO_DLLPUBLIC_DBTOOLS
663     ::rtl::OUString createStandardCreateStatement(  const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& descriptor,
664                                                     const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _xConnection,
665                                                     ISQLStatementHelper* _pHelper,
666                                                     const ::rtl::OUString& _sCreatePattern = ::rtl::OUString());
667 
668     /** creates the standard sql statement for the key part of a create table statement.
669         @param  descriptor
670             The descriptor of the new table.
671         @param  _xConnection
672             The connection.
673     */
674     OOO_DLLPUBLIC_DBTOOLS
675     ::rtl::OUString createStandardKeyStatement( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& descriptor,
676                                                 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _xConnection);
677 
678     /** creates the standard sql statement for the column part of a create table statement.
679         @param  _pHelper
680             Allow to add special SQL constructs.
681         @param  descriptor
682             The descriptor of the column.
683         @param  _xConnection
684             The connection.
685         @param  _pHelper
686             Allow to add special SQL constructs.
687     */
688     OOO_DLLPUBLIC_DBTOOLS
689     ::rtl::OUString createStandardColumnPart(   const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& descriptor
690                                                 ,const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _xConnection
691                                                 ,ISQLStatementHelper* _pHelper = NULL
692                                                 ,const ::rtl::OUString& _sCreatePattern = ::rtl::OUString());
693 
694     /** creates a SQL CREATE TABLE statement
695 
696         @param  descriptor
697             The descriptor of the new table.
698         @param  _xConnection
699             The connection.
700         @param  _pHelper
701             Allow to add special SQL constructs.
702         @param  _sCreatePattern
703 
704         @return
705             The CREATE TABLE statement.
706     */
707     OOO_DLLPUBLIC_DBTOOLS
708     ::rtl::OUString createSqlCreateTableStatement(  const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& descriptor
709                                                     ,const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _xConnection
710                                                     ,ISQLStatementHelper* _pHelper = NULL
711                                                     ,const ::rtl::OUString& _sCreatePattern = ::rtl::OUString());
712 
713     /** creates a SDBC column with the help of getColumns.
714         @param  _xTable
715             The table.
716         @param  _rName
717             The name of the column.
718         @param  _bCase
719             Is the column case sensitive.
720         @param  _bQueryForInfo
721             If <TRUE/> the autoincrement and currency field will be read from the meta data, otherwise the following parameters will be used instead
722         @param  _bIsAutoIncrement
723             <TRUE/> if the column is an autoincrement.
724         @param  _bIsCurrency
725             <TRUE/> if the column is a currency field.
726         @param  _nDataType
727             The data type of the column.
728     */
729     OOO_DLLPUBLIC_DBTOOLS
730     ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>
731             createSDBCXColumn(  const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _xTable,
732                                 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _xConnection,
733                                 const ::rtl::OUString& _rName,
734                                 sal_Bool _bCase,
735                                 sal_Bool _bQueryForInfo = sal_True,
736                                 sal_Bool _bIsAutoIncrement = sal_False,
737                                 sal_Bool _bIsCurrency = sal_False,
738                                 sal_Int32 _nDataType = com::sun::star::sdbc::DataType::OTHER);
739 
740     /** tries to locate the corresponding DataDefinitionSupplier for the given url and connection
741         @param  _rsUrl
742             The URL used to connect to the database.
743         @param  _xConnection
744             The connection used to find the correct driver.
745         @param  _rxFactory
746             Used to create the drivermanager.
747         @return
748             The datadefintion object.
749     */
750     OOO_DLLPUBLIC_DBTOOLS ::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XTablesSupplier> getDataDefinitionByURLAndConnection(
751             const ::rtl::OUString& _rsUrl,
752             const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _xConnection,
753             const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory>& _rxFactory);
754 
755     /** returns the table privileges to the given parameters
756         @param  _xMetaData
757             The meta data.
758         @param  _sCatalog
759             contains the catalog name
760         @param  _sSchema
761             contains the schema name
762         @param  _sTable
763             contains the table name
764     */
765     OOO_DLLPUBLIC_DBTOOLS
766     sal_Int32 getTablePrivileges(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData>& _xMetaData,
767                                  const ::rtl::OUString& _sCatalog,
768                                  const ::rtl::OUString& _sSchema,
769                                  const ::rtl::OUString& _sTable);
770 
771     typedef ::std::pair<sal_Bool,sal_Bool> TBoolPair;
772     typedef ::std::pair< TBoolPair,sal_Int32 > ColumnInformation;
773     typedef ::std::multimap< ::rtl::OUString, ColumnInformation, ::comphelper::UStringMixLess> ColumnInformationMap;
774     /** collects the information about auto increment, currency and data type for the given column name.
775         The column must be quoted, * is also valid.
776         @param  _xConnection
777             The connection.
778         @param  _sComposedTableName
779             The quoted table name. ccc.sss.ttt
780         @param  _sName
781             The name of the column, or *
782         @param  _rInfo
783             The information about the column(s).
784     */
785     OOO_DLLPUBLIC_DBTOOLS
786     void collectColumnInformation(  const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _xConnection,
787                                     const ::rtl::OUString& _sComposedTableName,
788                                     const ::rtl::OUString& _rName,
789                                     ColumnInformationMap& _rInfo);
790 
791 
792     /** adds a boolean comparison clause to the given SQL predicate
793 
794         @param _rExpression
795             the expression which is to be compared with a boolean value
796         @param _bValue
797             the boolean value which the expression is to be compared with
798         @param _nBooleanComparisonMode
799             the boolean comparison mode to be used. Usually obtained from
800             a css.sdb.DataSource's Settings member.
801         @param _out_rSQLPredicate
802             the buffer to which the comparison predicate will be appended
803     */
804     OOO_DLLPUBLIC_DBTOOLS void getBoleanComparisonPredicate(
805             const ::rtl::OUString& _rExpression,
806             const sal_Bool  _bValue,
807             const sal_Int32 _nBooleanComparisonMode,
808             ::rtl::OUStringBuffer& _out_rSQLPredicate
809         );
810 
811 //.........................................................................
812 }   // namespace dbtools
813 //.........................................................................
814 
815 #endif // _CONNECTIVITY_DBTOOLS_HXX_
816