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