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 acquired 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 = 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 = 0; 132 133 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection> getRowSetConnection( 134 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowSet>& _rxRowSet) 135 const = 0; 136 137 virtual ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatsSupplier> getNumberFormats( 138 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _rxConn, 139 sal_Bool _bAllowDefault 140 ) const = 0; 141 142 virtual sal_Int32 getDefaultNumberFormat( 143 const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxColumn, 144 const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatTypes >& _rxTypes, 145 const ::com::sun::star::lang::Locale& _rLocale 146 ) const = 0; 147 148 virtual void TransferFormComponentProperties( 149 const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _rxOld, 150 const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _rxNew, 151 const ::com::sun::star::lang::Locale& _rLocale 152 ) const = 0; 153 154 virtual ::rtl::OUString quoteName( 155 const ::rtl::OUString& _rQuote, 156 const ::rtl::OUString& _rName 157 ) const = 0; 158 159 virtual ::rtl::OUString composeTableNameForSelect( 160 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConnection, 161 const ::rtl::OUString& _rCatalog, 162 const ::rtl::OUString& _rSchema, 163 const ::rtl::OUString& _rName 164 ) const = 0; 165 166 virtual ::rtl::OUString composeTableNameForSelect( 167 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConnection, 168 const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _xTable 169 ) const = 0; 170 171 virtual ::com::sun::star::sdb::SQLContext prependContextInfo( 172 ::com::sun::star::sdbc::SQLException& _rException, 173 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxContext, 174 const ::rtl::OUString& _rContextDescription, 175 const ::rtl::OUString& _rContextDetails 176 ) const = 0; 177 178 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDataSource > getDataSource( 179 const ::rtl::OUString& _rsRegisteredName, 180 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory>& _rxFactory 181 ) const = 0; 182 183 virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > 184 getFieldsByCommandDescriptor( 185 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConnection, 186 const sal_Int32 _nCommandType, 187 const ::rtl::OUString& _rCommand, 188 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& _rxKeepFieldsAlive, 189 ::dbtools::SQLExceptionInfo* _pErrorInfo = NULL 190 ) SAL_THROW( ( ) ) = 0; 191 192 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > 193 getFieldNamesByCommandDescriptor( 194 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConnection, 195 const sal_Int32 _nCommandType, 196 const ::rtl::OUString& _rCommand, 197 ::dbtools::SQLExceptionInfo* _pErrorInfo = NULL 198 ) SAL_THROW( ( ) ) = 0; 199 200 /** check if the property "Privileges" supports ::com::sun::star::sdbcx::Privilege::INSERT 201 @param _rxCursorSet the property set 202 */ 203 virtual sal_Bool canInsert(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _rxCursorSet) const = 0; 204 205 /** check if the property "Privileges" supports ::com::sun::star::sdbcx::Privilege::UPDATE 206 @param _rxCursorSet the property set 207 */ 208 virtual sal_Bool canUpdate(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _rxCursorSet) const = 0; 209 210 /** check if the property "Privileges" supports ::com::sun::star::sdbcx::Privilege::DELETE 211 @param _rxCursorSet the property set 212 */ 213 virtual sal_Bool canDelete(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _rxCursorSet) const = 0; 214 215 /** determines whether the given component is part of a document which is an embedded database 216 document (such as a form) 217 */ 218 virtual bool isEmbeddedInDatabase( 219 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxComponent, 220 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxActualConnection 221 ) = 0; 222 }; 223 224 //================================================================ 225 //= IDataAccessCharSet 226 //================================================================ 227 /** simple wrapper for the <type>OCharsetMap</type> 228 */ 229 class OOO_DLLPUBLIC_DBTOOLS IDataAccessCharSet : 230 public ::rtl::IReference 231 { 232 // to be extended if necessary .... 233 public: 234 /** enumerates all supported char sets 235 @return the number of charsets supported 236 */ 237 virtual sal_Int32 getSupportedTextEncodings( 238 ::std::vector< rtl_TextEncoding >& /* [out] */ _rEncs 239 ) const = 0; 240 }; 241 242 //================================================================ 243 //= IDataAccessTypeConversion 244 //================================================================ 245 class OOO_DLLPUBLIC_DBTOOLS IDataAccessTypeConversion : 246 public ::rtl::IReference 247 { 248 public: 249 virtual ::com::sun::star::util::Date getStandardDate() const = 0; 250 251 virtual double getValue( 252 const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XColumn>& _rxVariant, 253 const ::com::sun::star::util::Date& rNullDate ) const = 0; 254 255 virtual ::rtl::OUString getFormattedValue( 256 const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XColumn >& _rxColumn, 257 const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter >& _rxFormatter, 258 const ::com::sun::star::util::Date& _rNullDate, 259 sal_Int32 _nKey, 260 sal_Int16 _nKeyType) const = 0; 261 262 virtual ::rtl::OUString getFormattedValue( 263 const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _rxColumn, 264 const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter>& _rxFormatter, 265 const ::com::sun::star::lang::Locale& _rLocale, 266 const ::com::sun::star::util::Date& _rNullDate 267 ) const = 0; 268 }; 269 270 //================================================================ 271 //= ISQLParseNode 272 //================================================================ 273 /** a simple version of the OSQLParseNode, with all methods being virtual 274 */ 275 class OOO_DLLPUBLIC_DBTOOLS ISQLParseNode : public ::rtl::IReference 276 { 277 public: 278 virtual void parseNodeToStr(::rtl::OUString& _rString, 279 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConnection, 280 const IParseContext* _pContext 281 ) const = 0; 282 283 virtual void parseNodeToPredicateStr(::rtl::OUString& _rString, 284 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConnection, 285 const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter >& _rxFormatter, 286 const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxField, 287 const ::com::sun::star::lang::Locale& _rIntl, 288 const sal_Char _cDecSeparator, 289 const IParseContext* _pContext 290 ) const = 0; 291 }; 292 293 //================================================================ 294 //= ISQLParser 295 //================================================================ 296 /** a simple version of the OSQLParser, with all methods being virtual 297 */ 298 class OOO_DLLPUBLIC_DBTOOLS ISQLParser : public ::rtl::IReference 299 { 300 public: 301 virtual ::rtl::Reference< ISQLParseNode > predicateTree( 302 ::rtl::OUString& rErrorMessage, 303 const ::rtl::OUString& rStatement, 304 const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter >& _rxFormatter, 305 const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxField 306 ) const = 0; 307 308 virtual const IParseContext& getContext() const = 0; 309 }; 310 311 //================================================================ 312 //= IDataAccessToolsFactory 313 //================================================================ 314 /** the main factory for runtime-loadable tools in the DBTOOLS library 315 */ 316 class OOO_DLLPUBLIC_DBTOOLS IDataAccessToolsFactory : 317 public ::rtl::IReference 318 { 319 public: 320 /// creates a simple version of the class OSQLParser 321 virtual ::rtl::Reference< ISQLParser > createSQLParser( 322 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxServiceFactory, 323 const IParseContext* _pContext 324 ) const = 0; 325 326 /// creates a helper for charset related functionality (<type>OCharsetMap</type>) 327 virtual ::rtl::Reference< IDataAccessCharSet > createCharsetHelper( ) const = 0; 328 329 /// creates a simple version of the DBTypeConversion helper 330 virtual ::rtl::Reference< IDataAccessTypeConversion > getTypeConversionHelper() = 0; 331 332 /// creates a helper which can be used to access the static methods in dbtools.hxx 333 virtual ::rtl::Reference< IDataAccessTools > getDataAccessTools() = 0; 334 335 virtual ::std::auto_ptr< ::dbtools::FormattedColumnValue > createFormattedColumnValue( 336 const ::comphelper::ComponentContext& _rContext, 337 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowSet >& _rxRowSet, 338 const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxColumn 339 ) = 0; 340 }; 341 342 //.................................................................... 343 } // namespace simple 344 //.................................................................... 345 346 //........................................................................ 347 } // namespace connectivity 348 //........................................................................ 349 350 #endif // CONNECTIVITY_VIRTUAL_DBTOOLS_HXX 351