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