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_VIRTUAL_DBTOOLS_HXX 25 #define CONNECTIVITY_VIRTUAL_DBTOOLS_HXX 26 27 #include <rtl/ref.hxx> 28 #include <rtl/ustring.hxx> 29 #include <com/sun/star/uno/Reference.hxx> 30 #include <com/sun/star/util/Date.hpp> 31 #include <com/sun/star/sdbc/SQLException.hpp> 32 #include <com/sun/star/uno/Sequence.hxx> 33 34 #include <vector> 35 #include <memory> 36 #include "connectivity/dbtoolsdllapi.hxx" 37 38 //======================================================================== 39 //= forward declarations 40 //======================================================================== 41 namespace com { 42 namespace sun { 43 namespace star { 44 namespace util { 45 class XNumberFormatter; 46 class XNumberFormatTypes; 47 class XNumberFormatsSupplier; 48 } 49 namespace beans { 50 class XPropertySet; 51 } 52 namespace lang { 53 class XMultiServiceFactory; 54 class XComponent; 55 class WrappedTargetException; 56 struct Locale; 57 } 58 namespace sdbc { 59 class XDatabaseMetaData; 60 class XConnection; 61 class XRowSet; 62 class XDataSource; 63 } 64 namespace sdb { 65 class XColumn; 66 class SQLContext; 67 } 68 namespace container { 69 class XNameAccess; 70 } 71 } 72 } 73 } 74 75 namespace dbtools { 76 class SQLExceptionInfo; 77 class FormattedColumnValue; 78 } 79 80 namespace comphelper { 81 class ComponentContext; 82 } 83 84 //======================================================================== 85 //= entry into this library 86 //======================================================================== 87 /** this is the entry point for the load-on-call usage of the DBTOOLS 88 library. 89 <p>When you need one of the simple objects in this library, load the lib 90 and call this method. The returned pointer is a pointer to an IDataAccessToolsFactory 91 instance, which is acquired <em>once</em>.</p> 92 @return 93 a pointer to an object implementing the IDataAccessToolsFactory interface, 94 aquired exactly <em>once</em>. 95 */ 96 extern "C" OOO_DLLPUBLIC_DBTOOLS void* SAL_CALL createDataAccessToolsFactory(); 97 98 //======================================================================== 99 //= 100 //======================================================================== 101 //........................................................................ 102 namespace connectivity 103 { 104 //........................................................................ 105 106 class IParseContext; 107 //.................................................................... 108 namespace simple 109 { 110 //.................................................................... 111 112 typedef void* (SAL_CALL * createDataAccessToolsFactoryFunction)( ); 113 114 //================================================================ 115 //= IDataAccessTools 116 //================================================================ 117 class OOO_DLLPUBLIC_DBTOOLS IDataAccessTools : public ::rtl::IReference 118 { 119 public: 120 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection> getConnection_withFeedback( 121 const ::rtl::OUString& _rDataSourceName, 122 const ::rtl::OUString& _rUser, 123 const ::rtl::OUString& _rPwd, 124 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory>& _rxFactory 125 ) const SAL_THROW ( (::com::sun::star::sdbc::SQLException) ) = 0; 126 127 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection> connectRowset( 128 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowSet>& _rxRowSet, 129 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory>& _rxFactory, 130 sal_Bool _bSetAsActiveConnection 131 ) const SAL_THROW ( ( ::com::sun::star::sdbc::SQLException 132 , ::com::sun::star::lang::WrappedTargetException 133 , ::com::sun::star::uno::RuntimeException ) ) = 0; 134 135 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection> getRowSetConnection( 136 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowSet>& _rxRowSet) 137 const SAL_THROW ( (::com::sun::star::uno::RuntimeException) ) = 0; 138 139 virtual ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatsSupplier> getNumberFormats( 140 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _rxConn, 141 sal_Bool _bAllowDefault 142 ) const = 0; 143 144 virtual sal_Int32 getDefaultNumberFormat( 145 const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxColumn, 146 const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatTypes >& _rxTypes, 147 const ::com::sun::star::lang::Locale& _rLocale 148 ) const = 0; 149 150 virtual void TransferFormComponentProperties( 151 const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _rxOld, 152 const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _rxNew, 153 const ::com::sun::star::lang::Locale& _rLocale 154 ) const = 0; 155 156 virtual ::rtl::OUString quoteName( 157 const ::rtl::OUString& _rQuote, 158 const ::rtl::OUString& _rName 159 ) const = 0; 160 161 virtual ::rtl::OUString composeTableNameForSelect( 162 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConnection, 163 const ::rtl::OUString& _rCatalog, 164 const ::rtl::OUString& _rSchema, 165 const ::rtl::OUString& _rName 166 ) const = 0; 167 168 virtual ::rtl::OUString composeTableNameForSelect( 169 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConnection, 170 const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _xTable 171 ) const = 0; 172 173 virtual ::com::sun::star::sdb::SQLContext prependContextInfo( 174 ::com::sun::star::sdbc::SQLException& _rException, 175 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxContext, 176 const ::rtl::OUString& _rContextDescription, 177 const ::rtl::OUString& _rContextDetails 178 ) const = 0; 179 180 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDataSource > getDataSource( 181 const ::rtl::OUString& _rsRegisteredName, 182 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory>& _rxFactory 183 ) const = 0; 184 185 virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > 186 getFieldsByCommandDescriptor( 187 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConnection, 188 const sal_Int32 _nCommandType, 189 const ::rtl::OUString& _rCommand, 190 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& _rxKeepFieldsAlive, 191 ::dbtools::SQLExceptionInfo* _pErrorInfo = NULL 192 ) SAL_THROW( ( ) ) = 0; 193 194 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > 195 getFieldNamesByCommandDescriptor( 196 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConnection, 197 const sal_Int32 _nCommandType, 198 const ::rtl::OUString& _rCommand, 199 ::dbtools::SQLExceptionInfo* _pErrorInfo = NULL 200 ) SAL_THROW( ( ) ) = 0; 201 202 /** check if the property "Privileges" supports ::com::sun::star::sdbcx::Privilege::INSERT 203 @param _rxCursorSet the property set 204 */ 205 virtual sal_Bool canInsert(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _rxCursorSet) const = 0; 206 207 /** check if the property "Privileges" supports ::com::sun::star::sdbcx::Privilege::UPDATE 208 @param _rxCursorSet the property set 209 */ 210 virtual sal_Bool canUpdate(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _rxCursorSet) const = 0; 211 212 /** check if the property "Privileges" supports ::com::sun::star::sdbcx::Privilege::DELETE 213 @param _rxCursorSet the property set 214 */ 215 virtual sal_Bool canDelete(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _rxCursorSet) const = 0; 216 217 /** determines whether the given component is part of a document which is an embedded database 218 document (such as a form) 219 */ 220 virtual bool isEmbeddedInDatabase( 221 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxComponent, 222 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxActualConnection 223 ) = 0; 224 }; 225 226 //================================================================ 227 //= IDataAccessCharSet 228 //================================================================ 229 /** simple wrapper for the <type>OCharsetMap</type> 230 */ 231 class OOO_DLLPUBLIC_DBTOOLS IDataAccessCharSet : 232 public ::rtl::IReference 233 { 234 // to be extended if necessary .... 235 public: 236 /** enumerates all supported char sets 237 @return the number of charsets supported 238 */ 239 virtual sal_Int32 getSupportedTextEncodings( 240 ::std::vector< rtl_TextEncoding >& /* [out] */ _rEncs 241 ) const = 0; 242 }; 243 244 //================================================================ 245 //= IDataAccessTypeConversion 246 //================================================================ 247 class OOO_DLLPUBLIC_DBTOOLS IDataAccessTypeConversion : 248 public ::rtl::IReference 249 { 250 public: 251 virtual ::com::sun::star::util::Date getStandardDate() const = 0; 252 253 virtual double getValue( 254 const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XColumn>& _rxVariant, 255 const ::com::sun::star::util::Date& rNullDate ) const = 0; 256 257 virtual ::rtl::OUString getFormattedValue( 258 const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XColumn >& _rxColumn, 259 const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter >& _rxFormatter, 260 const ::com::sun::star::util::Date& _rNullDate, 261 sal_Int32 _nKey, 262 sal_Int16 _nKeyType) const = 0; 263 264 virtual ::rtl::OUString getFormattedValue( 265 const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _rxColumn, 266 const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter>& _rxFormatter, 267 const ::com::sun::star::lang::Locale& _rLocale, 268 const ::com::sun::star::util::Date& _rNullDate 269 ) const = 0; 270 }; 271 272 //================================================================ 273 //= ISQLParseNode 274 //================================================================ 275 /** a simple version of the OSQLParseNode, with all methods beeing virtual 276 */ 277 class OOO_DLLPUBLIC_DBTOOLS ISQLParseNode : public ::rtl::IReference 278 { 279 public: 280 virtual void parseNodeToStr(::rtl::OUString& _rString, 281 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConnection, 282 const IParseContext* _pContext 283 ) const = 0; 284 285 virtual void parseNodeToPredicateStr(::rtl::OUString& _rString, 286 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConnection, 287 const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter >& _rxFormatter, 288 const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxField, 289 const ::com::sun::star::lang::Locale& _rIntl, 290 const sal_Char _cDecSeparator, 291 const IParseContext* _pContext 292 ) const = 0; 293 }; 294 295 //================================================================ 296 //= ISQLParser 297 //================================================================ 298 /** a simple version of the OSQLParser, with all methods beeing virtual 299 */ 300 class OOO_DLLPUBLIC_DBTOOLS ISQLParser : public ::rtl::IReference 301 { 302 public: 303 virtual ::rtl::Reference< ISQLParseNode > predicateTree( 304 ::rtl::OUString& rErrorMessage, 305 const ::rtl::OUString& rStatement, 306 const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter >& _rxFormatter, 307 const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxField 308 ) const = 0; 309 310 virtual const IParseContext& getContext() const = 0; 311 }; 312 313 //================================================================ 314 //= IDataAccessToolsFactory 315 //================================================================ 316 /** the main factory for runtime-loadable tools in the DBTOOLS library 317 */ 318 class OOO_DLLPUBLIC_DBTOOLS IDataAccessToolsFactory : 319 public ::rtl::IReference 320 { 321 public: 322 /// creates a simple version of the class OSQLParser 323 virtual ::rtl::Reference< ISQLParser > createSQLParser( 324 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxServiceFactory, 325 const IParseContext* _pContext 326 ) const = 0; 327 328 /// creates a helper for charset related functionality (<type>OCharsetMap</type>) 329 virtual ::rtl::Reference< IDataAccessCharSet > createCharsetHelper( ) const = 0; 330 331 /// creates a simple version of the DBTypeConversion helper 332 virtual ::rtl::Reference< IDataAccessTypeConversion > getTypeConversionHelper() = 0; 333 334 /// creates a helper which can be used to access the static methods in dbtools.hxx 335 virtual ::rtl::Reference< IDataAccessTools > getDataAccessTools() = 0; 336 337 virtual ::std::auto_ptr< ::dbtools::FormattedColumnValue > createFormattedColumnValue( 338 const ::comphelper::ComponentContext& _rContext, 339 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowSet >& _rxRowSet, 340 const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxColumn 341 ) = 0; 342 }; 343 344 //.................................................................... 345 } // namespace simple 346 //.................................................................... 347 348 //........................................................................ 349 } // namespace connectivity 350 //........................................................................ 351 352 #endif // CONNECTIVITY_VIRTUAL_DBTOOLS_HXX 353 354