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_DBTOOLS_HXX
21 #define INCLUDED_CONNECTIVITY_DBTOOLS_HXX
23 #include <connectivity/dbexception.hxx>
24 #include <comphelper/stl_types.hxx>
25 #include <unotools/sharedunocomponent.hxx>
26 #include <connectivity/dbtoolsdllapi.hxx>
27 #include <connectivity/FValue.hxx>
29 namespace com
{ namespace sun
{ namespace star
{
32 class XSingleSelectQueryComposer
;
35 class XTablesSupplier
;
39 class XDatabaseMetaData
;
59 class XComponentContext
;
62 class XNumberFormatTypes
;
63 class XNumberFormatsSupplier
;
66 class XInteractionHandler
;
75 class ISQLStatementHelper
;
76 typedef ::utl::SharedUNOComponent
< css::sdbc::XConnection
> SharedConnection
;
78 enum class EComposeRule
84 InPrivilegeDefinitions
,
90 // calculates the default numberformat for a given datatype and a give language
92 sal_Int32
getDefaultNumberFormat(const css::uno::Reference
< css::beans::XPropertySet
>& _xColumn
,
93 const css::uno::Reference
< css::util::XNumberFormatTypes
>& _xTypes
,
94 const css::lang::Locale
& _rLocale
);
96 // calculates the default numberformat for a given datatype and a give language
97 // @param _nDataType @see com.sun.star.sdbc.DataType
98 // @param _nScale can be zero
100 sal_Int32
getDefaultNumberFormat(sal_Int32 _nDataType
,
103 const css::uno::Reference
< css::util::XNumberFormatTypes
>& _xTypes
,
104 const css::lang::Locale
& _rLocale
);
107 /** creates a connection which can be used for the rowset given
109 The function tries to obtain a connection for the row set with the following
110 steps (in this order):
112 <li>If the rowset already has an ActiveConnection (means a non-<NULL/> value for this property),
113 this one is used.</li>
114 <li>If row set is part of a database form document (see ->isEmbeddedInDatabase),
115 a connection for the respective database is used.</li>
116 <li>If in the parent hierarchy of the row set, there is an object supporting
117 the XConnection interface, this one is returned.</li>
118 <li>If the DataSourceName property of the row set is not empty, a connection for this
119 data source is retrieved.</li>
120 <li>If the URL property of the row set is not empty, an connection for this URL is
121 retrieved from the driver manager.
124 The calculated connection is set as ActiveConnection property on the rowset.
126 If the connection was newly created by the method, then
127 the ownership of the connection is delivered to a temporary object, which observes the
128 row set: As soon as a connection-relevant property of the row set changes, or as soon
129 as somebody else sets another ActiveConnection at the row set, the original
130 connection (the one which this function calculated) is disposed and discarded. At this
131 very moment, also the temporary observer object dies. This way, it is ensured that
132 there's no resource leak from an un-owned connection object.
138 a service factory, which can be used to create data sources, interaction handler etc (the usual stuff)
141 OOO_DLLPUBLIC_DBTOOLS
142 css::uno::Reference
< css::sdbc::XConnection
> connectRowset(
143 const css::uno::Reference
< css::sdbc::XRowSet
>& _rxRowSet
,
144 const css::uno::Reference
< css::uno::XComponentContext
>& _rxContext
147 /** ensures that a row set has a valid ActiveConnection, if possible
149 This function does nearly the same as ->connectRowset. In fact, it is to be preferred over
150 ->connectRowset, if possible.
152 There are a few differences:
153 <ul><li>If a connection could be determined for the given RowSet, it is always
154 set as ActiveConnection.</li>
155 <li>Definition of the ownership of the created connection allows for more scenarios:
156 <ul><li>If the connection was not newly created, the returned ->SharedConnection
157 instance will not have the ownership, since in this case it's assumed
158 that there already is an instance which has the ownership.</li>
159 <li>If the connection was newly created, then the returned SharedConnection
160 instance will have the ownership of the XConnection.</li>
165 OOO_DLLPUBLIC_DBTOOLS SharedConnection
ensureRowSetConnection(
166 const css::uno::Reference
< css::sdbc::XRowSet
>& _rxRowSet
,
167 const css::uno::Reference
< css::uno::XComponentContext
>& _rxContext
170 /** returns the connection the RowSet is currently working with (which is the ActiveConnection property)
172 @throws css::uno::RuntimeException
174 OOO_DLLPUBLIC_DBTOOLS
css::uno::Reference
< css::sdbc::XConnection
> getConnection(const css::uno::Reference
< css::sdbc::XRowSet
>& _rxRowSet
);
175 OOO_DLLPUBLIC_DBTOOLS
css::uno::Reference
< css::sdbc::XConnection
> getConnection_withFeedback(
176 const OUString
& _rDataSourceName
,
177 const OUString
& _rUser
,
178 const OUString
& _rPwd
,
179 const css::uno::Reference
< css::uno::XComponentContext
>& _rxContext
);
182 /** determines whether the given component is part of a document which is an embedded database
183 document (such as a form)
185 OOO_DLLPUBLIC_DBTOOLS
bool isEmbeddedInDatabase(
186 const css::uno::Reference
< css::uno::XInterface
>& _rxComponent
,
187 css::uno::Reference
< css::sdbc::XConnection
>& _rxActualConnection
190 /** returns the columns of the named table of the given connection
192 OOO_DLLPUBLIC_DBTOOLS
css::uno::Reference
< css::container::XNameAccess
> getTableFields(
193 const css::uno::Reference
< css::sdbc::XConnection
>& _rxConn
,
194 const OUString
& _rName
197 /** returns the primary key columns of the table
199 OOO_DLLPUBLIC_DBTOOLS
css::uno::Reference
< css::container::XNameAccess
> getPrimaryKeyColumns_throw(
200 const css::uno::Any
& i_aTable
202 OOO_DLLPUBLIC_DBTOOLS
css::uno::Reference
< css::container::XNameAccess
> getPrimaryKeyColumns_throw(
203 const css::uno::Reference
< css::beans::XPropertySet
>& i_xTable
206 /** get fields for a result set given by a "command descriptor"
208 <p>A command descriptor here means:
209 <ul><li>a SDB-level connection (com.sun.star.sdb::Connection</li>
210 <li>a string specifying the name of an object relative to the connection</li>
211 <li>a com.sun.star.sdb::CommandType value specifying the type
212 of the object</type></li>
217 the connection relative to which the to-be-examined object exists
220 the type of the object
223 the object. This may be a table name, a query name, or an SQL statement, depending on the value
224 of <arg>_nCommandType</arg>
226 @param _rxCollectionOner
227 If (and only if) <arg>CommandType</arg> is CommandType.COMMAND, the fields collection which is returned
228 by this function here is a temporary object. It is kept alive by another object, which is to be
229 created temporarily, too. To ensure that the fields you get are valid as long as you need them,
230 the owner which controls their life time is transferred to this parameter upon return.<br/>
232 Your fields live as long as this component lives.<br/>
234 Additionally, you are encouraged to dispose this component as soon as you don't need the fields anymore.
235 It depends on the connection's implementation if this is necessary, but the is no guarantee, so to
236 be on the safe side with respect to resource leaks, you should dispose the component.
239 If not <NULL/>, then upon return from the function the instance pointed to by this argument will
240 contain any available error information in case something went wrong.
243 the container of the columns (aka fields) of the object
245 OOO_DLLPUBLIC_DBTOOLS
246 css::uno::Reference
< css::container::XNameAccess
>
247 getFieldsByCommandDescriptor(
248 const css::uno::Reference
< css::sdbc::XConnection
>& _rxConnection
,
249 const sal_Int32 _nCommandType
,
250 const OUString
& _rCommand
,
251 css::uno::Reference
< css::lang::XComponent
>& _rxKeepFieldsAlive
,
252 SQLExceptionInfo
* _pErrorInfo
= nullptr
256 /** get fields for a result set given by a "command descriptor"
258 <p>A command descriptor here means:
259 <ul><li>a SDB-level connection (com.sun.star.sdb::Connection</li>
260 <li>a string specifying the name of an object relative to the connection</li>
261 <li>a com.sun.star.sdb::CommandType value specifying the type
262 of the object</type></li>
267 the connection relative to which the to-be-examined object exists
270 the type of the object
273 the object. This may be a table name, a query name, or an SQL statement, depending on the value
274 of <arg>_nCommandType</arg>
277 If not <NULL/>, then upon return from the function the instance pointed to by this argument will
278 contain any available error information in case something went wrong.
281 an array of strings containing the names of the columns (aka fields) of the object
283 OOO_DLLPUBLIC_DBTOOLS
css::uno::Sequence
< OUString
>
284 getFieldNamesByCommandDescriptor(
285 const css::uno::Reference
< css::sdbc::XConnection
>& _rxConnection
,
286 const sal_Int32 _nCommandType
,
287 const OUString
& _rCommand
,
288 SQLExceptionInfo
* _pErrorInfo
= nullptr
292 /** create a new css::sdbc::SQLContext, fill it with the given descriptions and the given source,
293 and <i>append</i> _rException (i.e. put it into the NextException member of the SQLContext).
295 OOO_DLLPUBLIC_DBTOOLS
296 css::sdbc::SQLException
prependErrorInfo(
297 const css::sdbc::SQLException
& _rChainedException
,
298 const css::uno::Reference
< css::uno::XInterface
>& _rxContext
,
299 const OUString
& _rAdditionalError
,
300 const StandardSQLState _eSQLState
= StandardSQLState::ERROR_UNSPECIFIED
);
302 /** search the parent hierarchy for a data source.
304 OOO_DLLPUBLIC_DBTOOLS
css::uno::Reference
< css::sdbc::XDataSource
> findDataSource(const css::uno::Reference
< css::uno::XInterface
>& _xParent
);
306 /** determines the value of a boolean data source setting, given by ASCII name
309 the connection belonging to the data source whose setting is to be retrieved
310 @param _pAsciiSettingName
311 the ASCII name of the setting
313 OOO_DLLPUBLIC_DBTOOLS
bool getBooleanDataSourceSetting(
314 const css::uno::Reference
< css::sdbc::XConnection
>& _rxConnection
,
315 const sal_Char
* _pAsciiSettingName
318 /** check if a specific property is enabled in the info sequence
320 Use getBooleanDataSourceSetting instead, which cares for the default of the property itself,
321 instead of spreading this knowledge through all callers.
323 OOO_DLLPUBLIC_DBTOOLS
324 bool isDataSourcePropertyEnabled(const css::uno::Reference
< css::uno::XInterface
>& _xProp
,
325 const OUString
& _sProperty
,
328 /** retrieves a particular indirect data source setting
331 a data source component
332 @param _pAsciiSettingsName
333 the ASCII name of the setting to obtain
334 @param _rSettingsValue
335 the value of the setting, upon successful return
338 <FALSE/> if the setting is not present in the <member scope="css::sdb">DataSource::Info</member>
339 member of the data source
342 OOO_DLLPUBLIC_DBTOOLS
343 bool getDataSourceSetting(
344 const css::uno::Reference
< css::uno::XInterface
>& _rxDataSource
,
345 const sal_Char
* _pAsciiSettingsName
,
346 css::uno::Any
& /* [out] */ _rSettingsValue
348 OOO_DLLPUBLIC_DBTOOLS
349 bool getDataSourceSetting(
350 const css::uno::Reference
< css::uno::XInterface
>& _rxDataSource
,
351 const OUString
& _sSettingsName
,
352 css::uno::Any
& /* [out] */ _rSettingsValue
355 OOO_DLLPUBLIC_DBTOOLS OUString
getDefaultReportEngineServiceName(const css::uno::Reference
< css::uno::XComponentContext
>& _rxFactory
);
357 /** quote the given name with the given quote string.
359 OOO_DLLPUBLIC_DBTOOLS OUString
quoteName(const OUString
& _rQuote
, const OUString
& _rName
);
361 /** quote the given table name (which may contain a catalog and a schema) according to the rules provided by the meta data
363 OOO_DLLPUBLIC_DBTOOLS
364 OUString
quoteTableName(const css::uno::Reference
< css::sdbc::XDatabaseMetaData
>& _rxMeta
365 , const OUString
& _rName
366 ,EComposeRule _eComposeRule
);
368 /** split a fully qualified table name (including catalog and schema, if applicable) into its component parts.
369 @param _rxConnMetaData meta data describing the connection where you got the table name from
370 @param _rQualifiedName fully qualified table name
371 @param _rCatalog (out parameter) upon return, contains the catalog name
372 @param _rSchema (out parameter) upon return, contains the schema name
373 @param _rName (out parameter) upon return, contains the table name
374 @param _eComposeRule where do you need the name for
376 OOO_DLLPUBLIC_DBTOOLS
void qualifiedNameComponents(const css::uno::Reference
< css::sdbc::XDatabaseMetaData
>& _rxConnMetaData
,
377 const OUString
& _rQualifiedName
, OUString
& _rCatalog
, OUString
& _rSchema
, OUString
& _rName
,EComposeRule _eComposeRule
);
379 /** calculate a NumberFormatsSupplier for use with an given connection
380 @param _rxConn the connection for which the formatter is requested
381 @param _bAllowDefault if the connection (and related components, such as its parent) cannot supply
382 a formatter, we can ask the DatabaseEnvironment for a default one. This parameter
383 states if this is allowed.
384 @param _rxFactory required (only of _bAllowDefault is sal_True) for creating the DatabaseEnvironment.
385 @return the formatter all object related to the given connection should work with.
387 OOO_DLLPUBLIC_DBTOOLS
css::uno::Reference
< css::util::XNumberFormatsSupplier
> getNumberFormats(
388 const css::uno::Reference
< css::sdbc::XConnection
>& _rxConn
,
389 bool _bAllowDefault
= false,
390 const css::uno::Reference
< css::uno::XComponentContext
>& _rxContext
= css::uno::Reference
< css::uno::XComponentContext
>()
393 /** create an css::sdb::XSingleSelectQueryComposer which represents
394 the current settings (Command/CommandType/Filter/Order) of the given rowset.
396 As such an instance can be obtained from a css::sdb::Connection
397 only the function searches for the connection the RowSet is using via connectRowset.
398 This implies that a connection will be set on the RowSet if needed.
399 (need to changes this sometimes ...)
401 OOO_DLLPUBLIC_DBTOOLS
css::uno::Reference
< css::sdb::XSingleSelectQueryComposer
> getCurrentSettingsComposer(
402 const css::uno::Reference
< css::beans::XPropertySet
>& _rxRowSetProps
,
403 const css::uno::Reference
< css::uno::XComponentContext
>& _rxContext
406 /** transfer and translate properties between two FormComponents
407 @param _rxOld the source property set
408 @param _rxNew the destination property set
409 @param _rLocale the locale for converting number related properties
411 OOO_DLLPUBLIC_DBTOOLS
void TransferFormComponentProperties(
412 const css::uno::Reference
< css::beans::XPropertySet
>& _rxOld
,
413 const css::uno::Reference
< css::beans::XPropertySet
>& _rxNew
,
414 const css::lang::Locale
& _rLocale
417 /** check if the property "Privileges" supports css::sdbcx::Privilege::INSERT
418 @param _rxCursorSet the property set
420 OOO_DLLPUBLIC_DBTOOLS
bool canInsert(const css::uno::Reference
< css::beans::XPropertySet
>& _rxCursorSet
);
421 /** check if the property "Privileges" supports css::sdbcx::Privilege::UPDATE
422 @param _rxCursorSet the property set
424 OOO_DLLPUBLIC_DBTOOLS
bool canUpdate(const css::uno::Reference
< css::beans::XPropertySet
>& _rxCursorSet
);
425 /** check if the property "Privileges" supports css::sdbcx::Privilege::DELETE
426 @param _rxCursorSet the property set
428 OOO_DLLPUBLIC_DBTOOLS
bool canDelete(const css::uno::Reference
< css::beans::XPropertySet
>& _rxCursorSet
);
431 /** compose a complete table name from its up to three parts, regarding to the database meta data composing rules
433 OOO_DLLPUBLIC_DBTOOLS OUString
composeTableName( const css::uno::Reference
< css::sdbc::XDatabaseMetaData
>& _rxMetaData
,
434 const OUString
& _rCatalog
,
435 const OUString
& _rSchema
,
436 const OUString
& _rName
,
438 EComposeRule _eComposeRule
);
440 /** composes a table name for usage in a SELECT statement
442 This includes quoting of the table as indicated by the connection's meta data, plus respecting
443 the settings "UseCatalogInSelect" and "UseSchemaInSelect", which might be present
444 in the data source which the connection belongs to.
446 OOO_DLLPUBLIC_DBTOOLS OUString
composeTableNameForSelect(
447 const css::uno::Reference
< css::sdbc::XConnection
>& _rxConnection
,
448 const OUString
& _rCatalog
,
449 const OUString
& _rSchema
,
450 const OUString
& _rName
);
452 /** composes a table name for usage in a SELECT statement
454 This includes quoting of the table as indicated by the connection's meta data, plus respecting
455 the settings "UseCatalogInSelect" and "UseSchemaInSelect", which might be present
456 in the data source which the connection belongs to.
458 OOO_DLLPUBLIC_DBTOOLS OUString
composeTableNameForSelect(
459 const css::uno::Reference
< css::sdbc::XConnection
>& _rxConnection
,
460 const css::uno::Reference
< css::beans::XPropertySet
>& _xTable
);
462 /** compose the table name out of the property set which must support the properties from the service <member scope= "css::sdbcx">table</member>
464 The metadata from the connection.
468 OOO_DLLPUBLIC_DBTOOLS OUString
composeTableName(
469 const css::uno::Reference
< css::sdbc::XDatabaseMetaData
>& _xMetaData
,
470 const css::uno::Reference
< css::beans::XPropertySet
>& _xTable
,
471 EComposeRule _eComposeRule
,
475 OOO_DLLPUBLIC_DBTOOLS sal_Int32
getSearchColumnFlag( const css::uno::Reference
< css::sdbc::XConnection
>& _rxConn
,
476 sal_Int32 _nDataType
);
477 // return the datasource for the given datasource name
478 OOO_DLLPUBLIC_DBTOOLS
css::uno::Reference
< css::sdbc::XDataSource
> getDataSource(const OUString
& _rsDataSourceName
,
479 const css::uno::Reference
< css::uno::XComponentContext
>& _rxContext
);
481 /** search for a name that is NOT in the NameAcces
483 the NameAccess container to search in
485 the base name that should be used to create the new name
486 @param _bStartWithNumber
487 When <TRUE/> the name ends with number even when the name itself doesn't occur in the collection.
489 A name which doesn't exist in the collection.
491 OOO_DLLPUBLIC_DBTOOLS
492 OUString
createUniqueName(const css::uno::Reference
< css::container::XNameAccess
>& _rxContainer
,
493 const OUString
& _rBaseName
,
494 bool _bStartWithNumber
= true);
496 /** creates a unique name which is not already used in the given name array
498 OOO_DLLPUBLIC_DBTOOLS OUString
createUniqueName(
499 const css::uno::Sequence
< OUString
>& _rNames
,
500 const OUString
& _rBaseName
,
501 bool _bStartWithNumber
504 /** create a name which is a valid SQL 92 identifier name
505 @param _rName the string which should be converted
506 @param _rSpecials @see com.sun.star.sdbc.XDatabaseMetaData.getExtraNameCharacters
510 OOO_DLLPUBLIC_DBTOOLS OUString
convertName2SQLName(const OUString
& _rName
,const OUString
& _rSpecials
);
512 /** checks whether the given name is a valid SQL name
514 @param _rName the string which should be converted
515 @param _rSpecials @see com.sun.star.sdbc.XDatabaseMetaData.getExtraNameCharacters
517 @see convertName2SQLName
519 OOO_DLLPUBLIC_DBTOOLS
bool isValidSQLName( const OUString
& _rName
, const OUString
& _rSpecials
);
521 OOO_DLLPUBLIC_DBTOOLS
522 void showError( const SQLExceptionInfo
& _rInfo
,
523 const css::uno::Reference
< css::awt::XWindow
>& _pParent
,
524 const css::uno::Reference
< css::uno::XComponentContext
>& _rxContext
);
526 /** implements <method scope="com.sun.star.sdb">XRowUpdate::updateObject</method>
527 <p>The object which is to be set is analyzed, and in case it is a simlpe scalar type for which there
528 is another updateXXX method, this other method is used.</p>
529 @param _rxUpdatedObject
530 the interface to forward all updateXXX calls to (except updateObject)
532 the column index to update
536 <TRUE/> if the update request was successfully re-routed to one of the other updateXXX methods
538 OOO_DLLPUBLIC_DBTOOLS
539 bool implUpdateObject( const css::uno::Reference
< css::sdbc::XRowUpdate
>& _rxUpdatedObject
,
540 const sal_Int32 _nColumnIndex
,
541 const css::uno::Any
& _rValue
);
544 /** ask the user for parameters if the prepared statement needs some and sets them in the prepared statement
545 @param _xConnection the connection must be able to create css::sdb::SingleSelectQueryComposers
546 @param _xPreparedStmt the prepared statement where the parameters could be set when needed
547 @param _aParametersSet contains which parameters have to asked for and which already have set.
549 OOO_DLLPUBLIC_DBTOOLS
550 void askForParameters( const css::uno::Reference
< css::sdb::XSingleSelectQueryComposer
>& _xComposer
,
551 const css::uno::Reference
< css::sdbc::XParameters
>& _xParameters
,
552 const css::uno::Reference
< css::sdbc::XConnection
>& _xConnection
,
553 const css::uno::Reference
< css::task::XInteractionHandler
>& _rxHandler
,
554 const ::std::vector
<bool, std::allocator
<bool> >& _aParametersSet
= ::std::vector
<bool, std::allocator
<bool> >());
556 /** call the appropriate set method for the specific sql type @see css::sdbc::DataType
557 @param _xParams the parameters where to set the value
558 @param parameterIndex the index of the parameter, 1 based
559 @param x the value to set
560 @param sqlType the corresponding sql type @see css::sdbc::DataType
561 @param scale the scale of the sql type can be 0
562 @throws css::sdbc::SQLException
563 @throws css::uno::RuntimeException
565 OOO_DLLPUBLIC_DBTOOLS
566 void setObjectWithInfo( const css::uno::Reference
< css::sdbc::XParameters
>& _xParameters
,
567 sal_Int32 parameterIndex
,
568 const css::uno::Any
& x
,
572 /** call the appropriate set method for the specific sql type @see css::sdbc::DataType
573 @param _xParams the parameters where to set the value
574 @param parameterIndex the index of the parameter, 1 based
575 @param x the value to set
576 @param sqlType the corresponding sql type @see css::sdbc::DataType
577 @param scale the scale of the sql type can be 0
578 @throws css::sdbc::SQLException
579 @throws css::uno::RuntimeException
581 OOO_DLLPUBLIC_DBTOOLS
582 void setObjectWithInfo( const css::uno::Reference
< css::sdbc::XParameters
>& _xParameters
,
583 sal_Int32 parameterIndex
,
584 const ::connectivity::ORowSetValue
& x
,
589 /** implements <method scope="com.sun.star.sdb">XParameters::setObject</method>
590 <p>The object which is to be set is analyzed, and in case it is a simlpe scalar type for which there
591 is another setXXX method, this other method is used.</p>
593 the interface to forward all setXXX calls to (except setObject)
595 the column index to update
599 <TRUE/> if the update request was successfully re-routed to one of the other updateXXX methods
601 OOO_DLLPUBLIC_DBTOOLS
602 bool implSetObject( const css::uno::Reference
< css::sdbc::XParameters
>& _rxParameters
,
603 const sal_Int32 _nColumnIndex
,
604 const css::uno::Any
& _rValue
);
606 /** creates the standard sql create table statement without the key part.
608 The descriptor of the new table.
612 The scale will also be added when the value is 0.
614 OOO_DLLPUBLIC_DBTOOLS
615 OUString
createStandardCreateStatement( const css::uno::Reference
< css::beans::XPropertySet
>& descriptor
,
616 const css::uno::Reference
< css::sdbc::XConnection
>& _xConnection
,
617 ISQLStatementHelper
* _pHelper
,
618 const OUString
& _sCreatePattern
);
620 /** creates the standard sql statement for the key part of a create table statement.
622 The descriptor of the new table.
626 OOO_DLLPUBLIC_DBTOOLS
627 OUString
createStandardKeyStatement( const css::uno::Reference
< css::beans::XPropertySet
>& descriptor
,
628 const css::uno::Reference
< css::sdbc::XConnection
>& _xConnection
);
630 /** creates the standard sql statement for the type part of a create or alter table statement.
632 Allow to add special SQL constructs.
634 The descriptor of the column.
638 OOO_DLLPUBLIC_DBTOOLS
639 OUString
createStandardTypePart( const css::uno::Reference
< css::beans::XPropertySet
>& descriptor
640 ,const css::uno::Reference
< css::sdbc::XConnection
>& _xConnection
641 ,const OUString
& _sCreatePattern
= OUString());
643 /** creates the standard sql statement for the column part of a create table statement.
645 Allow to add special SQL constructs.
647 The descriptor of the column.
651 Allow to add special SQL constructs.
653 OOO_DLLPUBLIC_DBTOOLS
654 OUString
createStandardColumnPart( const css::uno::Reference
< css::beans::XPropertySet
>& descriptor
655 ,const css::uno::Reference
< css::sdbc::XConnection
>& _xConnection
656 ,ISQLStatementHelper
* _pHelper
= nullptr
657 ,const OUString
& _sCreatePattern
= OUString());
659 /** creates a SQL CREATE TABLE statement
662 The descriptor of the new table.
667 The CREATE TABLE statement.
669 OOO_DLLPUBLIC_DBTOOLS
670 OUString
createSqlCreateTableStatement( const css::uno::Reference
< css::beans::XPropertySet
>& descriptor
671 ,const css::uno::Reference
< css::sdbc::XConnection
>& _xConnection
);
673 /** creates a SDBC column with the help of getColumns.
677 The name of the column.
679 Is the column case sensitive.
680 @param _bQueryForInfo
681 If <TRUE/> the autoincrement and currency field will be read from the meta data, otherwise the following parameters will be used instead
682 @param _bIsAutoIncrement
683 <TRUE/> if the column is an autoincrement.
685 <TRUE/> if the column is a currency field.
687 The data type of the column.
689 OOO_DLLPUBLIC_DBTOOLS
690 css::uno::Reference
< css::beans::XPropertySet
>
691 createSDBCXColumn( const css::uno::Reference
< css::beans::XPropertySet
>& _xTable
,
692 const css::uno::Reference
< css::sdbc::XConnection
>& _xConnection
,
693 const OUString
& _rName
,
696 bool _bIsAutoIncrement
,
698 sal_Int32 _nDataType
);
700 /** tries to locate the corresponding DataDefinitionSupplier for the given url and connection
702 The URL used to connect to the database.
704 The connection used to find the correct driver.
706 Used to create the drivermanager.
708 The datadefinition object.
710 OOO_DLLPUBLIC_DBTOOLS
css::uno::Reference
< css::sdbcx::XTablesSupplier
> getDataDefinitionByURLAndConnection(
711 const OUString
& _rsUrl
,
712 const css::uno::Reference
< css::sdbc::XConnection
>& _xConnection
,
713 const css::uno::Reference
< css::uno::XComponentContext
>& _rxContext
);
715 /** returns the table privileges to the given parameters
719 contains the catalog name
721 contains the schema name
723 contains the table name
725 OOO_DLLPUBLIC_DBTOOLS
726 sal_Int32
getTablePrivileges(const css::uno::Reference
< css::sdbc::XDatabaseMetaData
>& _xMetaData
,
727 const OUString
& _sCatalog
,
728 const OUString
& _sSchema
,
729 const OUString
& _sTable
);
731 typedef ::std::pair
<bool,bool> TBoolPair
;
732 typedef ::std::pair
< TBoolPair
,sal_Int32
> ColumnInformation
;
733 typedef ::std::multimap
< OUString
, ColumnInformation
, ::comphelper::UStringMixLess
> ColumnInformationMap
;
734 /** collects the information about auto increment, currency and data type for the given column name.
735 The column must be quoted, * is also valid.
738 @param _sComposedTableName
739 The quoted table name. ccc.sss.ttt
741 The name of the column, or *
743 The information about the column(s).
745 OOO_DLLPUBLIC_DBTOOLS
746 void collectColumnInformation( const css::uno::Reference
< css::sdbc::XConnection
>& _xConnection
,
747 const OUString
& _sComposedTableName
,
748 const OUString
& _rName
,
749 ColumnInformationMap
& _rInfo
);
752 /** adds a boolean comparison clause to the given SQL predicate
755 the expression which is to be compared with a boolean value
757 the boolean value which the expression is to be compared with
758 @param _nBooleanComparisonMode
759 the boolean comparison mode to be used. Usually obtained from
760 a css.sdb.DataSource's Settings member.
761 @param _out_rSQLPredicate
762 the buffer to which the comparison predicate will be appended
764 OOO_DLLPUBLIC_DBTOOLS
void getBooleanComparisonPredicate(
765 const OUString
& _rExpression
,
767 const sal_Int32 _nBooleanComparisonMode
,
768 OUStringBuffer
& _out_rSQLPredicate
771 /** is this field an aggregate?
774 a query composer that knows the field by name
778 OOO_DLLPUBLIC_DBTOOLS
bool isAggregateColumn(
779 const css::uno::Reference
< css::sdb::XSingleSelectQueryComposer
> &_xComposer
,
780 const css::uno::Reference
< css::beans::XPropertySet
> &_xField
783 /** is this column an aggregate?
785 @param _xColumns collection of columns
786 look for column sName in there
790 OOO_DLLPUBLIC_DBTOOLS
bool isAggregateColumn(
791 const css::uno::Reference
< css::container::XNameAccess
> &_xColumns
,
792 const OUString
&_sName
795 /** is this column an aggregate?
799 OOO_DLLPUBLIC_DBTOOLS
bool isAggregateColumn(
800 const css::uno::Reference
< css::beans::XPropertySet
> &_xColumn
803 } // namespace dbtools
805 namespace connectivity
809 enum DBFType
{ dBaseIII
= 0x03,
813 VisualFoxProAuto
= 0x31, // Visual FoxPro with AutoIncrement field
818 dBaseIVMemoSQL
= 0x8E,
822 /** decode a DBase file's codepage byte to a RTL charset
824 in case of success, the decoded RTL charset is written there.
825 else, this is not written to.
829 the file's codepage byte
831 true if a RTL charset was successfully decoded and written to _out_nCharset
832 false if nothing was written to _out_nCharset
834 OOO_DLLPUBLIC_DBTOOLS
bool dbfDecodeCharset(rtl_TextEncoding
&_out_nCharset
, sal_uInt8 nType
, sal_uInt8 nCodepage
);
836 /** decode a DBase file's codepage byte to a RTL charset
838 in case of success, the decoded RTL charset is written there.
839 else, this is not written to.
841 pointer to a SvStream encapsulating the DBase file.
842 The stream will be rewinded and read from.
843 No guarantee is made on its position afterwards. Caller must reposition it itself.
845 true if a RTL charset was successfully decoded and written to _out_nCharset
846 false if nothing was written to _out_nCharset
848 OOO_DLLPUBLIC_DBTOOLS
bool dbfReadCharset(rtl_TextEncoding
&nCharSet
, SvStream
* dbf_Stream
);
850 } // namespace connectivity::dbase
851 } // namespace connectivity
853 #endif // INCLUDED_CONNECTIVITY_DBTOOLS_HXX
855 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */