1*9b5730f6SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*9b5730f6SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*9b5730f6SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*9b5730f6SAndrew Rist * distributed with this work for additional information 6*9b5730f6SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*9b5730f6SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*9b5730f6SAndrew Rist * "License"); you may not use this file except in compliance 9*9b5730f6SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*9b5730f6SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*9b5730f6SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*9b5730f6SAndrew Rist * software distributed under the License is distributed on an 15*9b5730f6SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*9b5730f6SAndrew Rist * KIND, either express or implied. See the License for the 17*9b5730f6SAndrew Rist * specific language governing permissions and limitations 18*9b5730f6SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*9b5730f6SAndrew Rist *************************************************************/ 21*9b5730f6SAndrew Rist 22*9b5730f6SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_connectivity.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "connectivity/CommonTools.hxx" 28cdf0e10cSrcweir #include "diagnose_ex.h" 29cdf0e10cSrcweir #include "TConnection.hxx" 30cdf0e10cSrcweir #include "connectivity/ParameterCont.hxx" 31cdf0e10cSrcweir 32cdf0e10cSrcweir /** === begin UNO includes === **/ 33cdf0e10cSrcweir #include <com/sun/star/awt/XWindow.hpp> 34cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp> 35cdf0e10cSrcweir #include <com/sun/star/container/XChild.hpp> 36cdf0e10cSrcweir #include <com/sun/star/form/FormComponentType.hpp> 37cdf0e10cSrcweir #include <com/sun/star/io/XInputStream.hpp> 38cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp> 39cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp> 40cdf0e10cSrcweir #include <com/sun/star/sdb/BooleanComparisonMode.hpp> 41cdf0e10cSrcweir #include <com/sun/star/sdb/CommandType.hpp> 42cdf0e10cSrcweir #include <com/sun/star/sdb/ParametersRequest.hpp> 43cdf0e10cSrcweir #include <com/sun/star/sdb/RowSetVetoException.hpp> 44cdf0e10cSrcweir #include <com/sun/star/sdb/SQLContext.hpp> 45cdf0e10cSrcweir #include <com/sun/star/sdb/XCompletedConnection.hpp> 46cdf0e10cSrcweir #include <com/sun/star/sdb/XInteractionSupplyParameters.hpp> 47cdf0e10cSrcweir #include <com/sun/star/sdb/XOfficeDatabaseDocument.hpp> 48cdf0e10cSrcweir #include <com/sun/star/sdb/XParametersSupplier.hpp> 49cdf0e10cSrcweir #include <com/sun/star/sdb/XQueriesSupplier.hpp> 50cdf0e10cSrcweir #include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp> 51cdf0e10cSrcweir #include <com/sun/star/sdbc/DataType.hpp> 52cdf0e10cSrcweir #include <com/sun/star/sdbc/XConnection.hpp> 53cdf0e10cSrcweir #include <com/sun/star/sdbc/XDataSource.hpp> 54cdf0e10cSrcweir #include <com/sun/star/sdbc/XDriverManager.hpp> 55cdf0e10cSrcweir #include <com/sun/star/sdbc/XParameters.hpp> 56cdf0e10cSrcweir #include <com/sun/star/sdbc/XRow.hpp> 57cdf0e10cSrcweir #include <com/sun/star/sdbc/XRowSet.hpp> 58cdf0e10cSrcweir #include <com/sun/star/sdbc/XRowUpdate.hpp> 59cdf0e10cSrcweir #include <com/sun/star/sdbcx/KeyType.hpp> 60cdf0e10cSrcweir #include <com/sun/star/sdbcx/Privilege.hpp> 61cdf0e10cSrcweir #include <com/sun/star/sdbcx/XColumnsSupplier.hpp> 62cdf0e10cSrcweir #include <com/sun/star/sdbcx/XKeysSupplier.hpp> 63cdf0e10cSrcweir #include <com/sun/star/sdbcx/XTablesSupplier.hpp> 64cdf0e10cSrcweir #include <com/sun/star/task/XInteractionHandler.hpp> 65cdf0e10cSrcweir #include <com/sun/star/task/XInteractionRequest.hpp> 66cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp> 67cdf0e10cSrcweir #include <com/sun/star/uno/XNamingService.hpp> 68cdf0e10cSrcweir #include <com/sun/star/util/NumberFormat.hpp> 69cdf0e10cSrcweir #include <com/sun/star/util/XNumberFormatsSupplier.hpp> 70cdf0e10cSrcweir #include <com/sun/star/util/XNumberFormatTypes.hpp> 71cdf0e10cSrcweir /** === end UNO includes === **/ 72cdf0e10cSrcweir 73cdf0e10cSrcweir #include <comphelper/extract.hxx> 74cdf0e10cSrcweir #include <comphelper/interaction.hxx> 75cdf0e10cSrcweir #include <comphelper/property.hxx> 76cdf0e10cSrcweir #include <connectivity/conncleanup.hxx> 77cdf0e10cSrcweir #include <connectivity/dbconversion.hxx> 78cdf0e10cSrcweir #include <connectivity/dbexception.hxx> 79cdf0e10cSrcweir #include <connectivity/dbtools.hxx> 80cdf0e10cSrcweir #include <connectivity/statementcomposer.hxx> 81cdf0e10cSrcweir #include <osl/diagnose.h> 82cdf0e10cSrcweir #include <rtl/ustrbuf.hxx> 83cdf0e10cSrcweir #include <tools/diagnose_ex.h> 84cdf0e10cSrcweir 85cdf0e10cSrcweir #include "resource/common_res.hrc" 86cdf0e10cSrcweir #include "resource/sharedresources.hxx" 87cdf0e10cSrcweir #include "OSubComponent.hxx" 88cdf0e10cSrcweir 89cdf0e10cSrcweir #include <algorithm> 90cdf0e10cSrcweir 91cdf0e10cSrcweir using namespace ::comphelper; 92cdf0e10cSrcweir using namespace ::com::sun::star::uno; 93cdf0e10cSrcweir using namespace ::com::sun::star::io; 94cdf0e10cSrcweir using namespace ::com::sun::star::awt; 95cdf0e10cSrcweir using namespace ::com::sun::star::ui::dialogs; 96cdf0e10cSrcweir using namespace ::com::sun::star::util; 97cdf0e10cSrcweir using namespace ::com::sun::star::lang; 98cdf0e10cSrcweir using namespace ::com::sun::star::beans; 99cdf0e10cSrcweir using namespace ::com::sun::star::container; 100cdf0e10cSrcweir using namespace ::com::sun::star::sdb; 101cdf0e10cSrcweir using namespace ::com::sun::star::sdbc; 102cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx; 103cdf0e10cSrcweir using namespace ::com::sun::star::form; 104cdf0e10cSrcweir using namespace connectivity; 105cdf0e10cSrcweir 106cdf0e10cSrcweir //......................................................................... 107cdf0e10cSrcweir namespace dbtools 108cdf0e10cSrcweir { 109cdf0e10cSrcweir //......................................................................... 110cdf0e10cSrcweir 111cdf0e10cSrcweir using namespace ::com::sun::star::uno; 112cdf0e10cSrcweir using namespace ::com::sun::star::beans; 113cdf0e10cSrcweir using namespace ::com::sun::star::util; 114cdf0e10cSrcweir using namespace ::com::sun::star::task; 115cdf0e10cSrcweir using namespace ::com::sun::star::uno; 116cdf0e10cSrcweir using namespace ::com::sun::star::lang; 117cdf0e10cSrcweir using namespace ::com::sun::star::sdbc; 118cdf0e10cSrcweir using namespace ::com::sun::star::task; 119cdf0e10cSrcweir // using namespace cppu; 120cdf0e10cSrcweir // using namespace osl; 121cdf0e10cSrcweir 122cdf0e10cSrcweir //============================================================================== 123cdf0e10cSrcweir //============================================================================== 124cdf0e10cSrcweir namespace 125cdf0e10cSrcweir { 126cdf0e10cSrcweir typedef sal_Bool (SAL_CALL XDatabaseMetaData::*FMetaDataSupport)(); 127cdf0e10cSrcweir } 128cdf0e10cSrcweir //============================================================================== 129cdf0e10cSrcweir //============================================================================== 130cdf0e10cSrcweir sal_Int32 getDefaultNumberFormat(const Reference< XPropertySet >& _xColumn, 131cdf0e10cSrcweir const Reference< XNumberFormatTypes >& _xTypes, 132cdf0e10cSrcweir const Locale& _rLocale) 133cdf0e10cSrcweir { 134cdf0e10cSrcweir OSL_ENSURE(_xTypes.is() && _xColumn.is(), "dbtools::getDefaultNumberFormat: invalid arg !"); 135cdf0e10cSrcweir if (!_xTypes.is() || !_xColumn.is()) 136cdf0e10cSrcweir return NumberFormat::UNDEFINED; 137cdf0e10cSrcweir 138cdf0e10cSrcweir sal_Int32 nDataType = 0; 139cdf0e10cSrcweir sal_Int32 nScale = 0; 140cdf0e10cSrcweir try 141cdf0e10cSrcweir { 142cdf0e10cSrcweir // determine the datatype of the column 143cdf0e10cSrcweir _xColumn->getPropertyValue(::rtl::OUString::createFromAscii("Type")) >>= nDataType; 144cdf0e10cSrcweir 145cdf0e10cSrcweir if (DataType::NUMERIC == nDataType || DataType::DECIMAL == nDataType) 146cdf0e10cSrcweir _xColumn->getPropertyValue(::rtl::OUString::createFromAscii("Scale")) >>= nScale; 147cdf0e10cSrcweir } 148cdf0e10cSrcweir catch (Exception&) 149cdf0e10cSrcweir { 150cdf0e10cSrcweir return NumberFormat::UNDEFINED; 151cdf0e10cSrcweir } 152cdf0e10cSrcweir return getDefaultNumberFormat(nDataType, 153cdf0e10cSrcweir nScale, 154cdf0e10cSrcweir ::cppu::any2bool(_xColumn->getPropertyValue(::rtl::OUString::createFromAscii("IsCurrency"))), 155cdf0e10cSrcweir _xTypes, 156cdf0e10cSrcweir _rLocale); 157cdf0e10cSrcweir } 158cdf0e10cSrcweir 159cdf0e10cSrcweir //------------------------------------------------------------------ 160cdf0e10cSrcweir sal_Int32 getDefaultNumberFormat(sal_Int32 _nDataType, 161cdf0e10cSrcweir sal_Int32 _nScale, 162cdf0e10cSrcweir sal_Bool _bIsCurrency, 163cdf0e10cSrcweir const Reference< XNumberFormatTypes >& _xTypes, 164cdf0e10cSrcweir const Locale& _rLocale) 165cdf0e10cSrcweir { 166cdf0e10cSrcweir OSL_ENSURE(_xTypes.is() , "dbtools::getDefaultNumberFormat: invalid arg !"); 167cdf0e10cSrcweir if (!_xTypes.is()) 168cdf0e10cSrcweir return NumberFormat::UNDEFINED; 169cdf0e10cSrcweir 170cdf0e10cSrcweir sal_Int32 nFormat = 0; 171cdf0e10cSrcweir sal_Int32 nNumberType = _bIsCurrency ? NumberFormat::CURRENCY : NumberFormat::NUMBER; 172cdf0e10cSrcweir switch (_nDataType) 173cdf0e10cSrcweir { 174cdf0e10cSrcweir case DataType::BIT: 175cdf0e10cSrcweir case DataType::BOOLEAN: 176cdf0e10cSrcweir nFormat = _xTypes->getStandardFormat(NumberFormat::LOGICAL, _rLocale); 177cdf0e10cSrcweir break; 178cdf0e10cSrcweir case DataType::TINYINT: 179cdf0e10cSrcweir case DataType::SMALLINT: 180cdf0e10cSrcweir case DataType::INTEGER: 181cdf0e10cSrcweir case DataType::BIGINT: 182cdf0e10cSrcweir case DataType::FLOAT: 183cdf0e10cSrcweir case DataType::REAL: 184cdf0e10cSrcweir case DataType::DOUBLE: 185cdf0e10cSrcweir case DataType::NUMERIC: 186cdf0e10cSrcweir case DataType::DECIMAL: 187cdf0e10cSrcweir { 188cdf0e10cSrcweir try 189cdf0e10cSrcweir { 190cdf0e10cSrcweir nFormat = _xTypes->getStandardFormat((sal_Int16)nNumberType, _rLocale); 191cdf0e10cSrcweir if(_nScale > 0) 192cdf0e10cSrcweir { 193cdf0e10cSrcweir // generate a new format if necessary 194cdf0e10cSrcweir Reference< XNumberFormats > xFormats(_xTypes, UNO_QUERY); 195cdf0e10cSrcweir ::rtl::OUString sNewFormat = xFormats->generateFormat( 0L, _rLocale, sal_False, sal_False, (sal_Int16)_nScale, sal_True); 196cdf0e10cSrcweir 197cdf0e10cSrcweir // and add it to the formatter if necessary 198cdf0e10cSrcweir nFormat = xFormats->queryKey(sNewFormat, _rLocale, sal_False); 199cdf0e10cSrcweir if (nFormat == (sal_Int32)-1) 200cdf0e10cSrcweir nFormat = xFormats->addNew(sNewFormat, _rLocale); 201cdf0e10cSrcweir } 202cdf0e10cSrcweir } 203cdf0e10cSrcweir catch (Exception&) 204cdf0e10cSrcweir { 205cdf0e10cSrcweir nFormat = _xTypes->getStandardFormat((sal_Int16)nNumberType, _rLocale); 206cdf0e10cSrcweir } 207cdf0e10cSrcweir } break; 208cdf0e10cSrcweir case DataType::CHAR: 209cdf0e10cSrcweir case DataType::VARCHAR: 210cdf0e10cSrcweir case DataType::LONGVARCHAR: 211cdf0e10cSrcweir case DataType::CLOB: 212cdf0e10cSrcweir nFormat = _xTypes->getStandardFormat(NumberFormat::TEXT, _rLocale); 213cdf0e10cSrcweir break; 214cdf0e10cSrcweir case DataType::DATE: 215cdf0e10cSrcweir nFormat = _xTypes->getStandardFormat(NumberFormat::DATE, _rLocale); 216cdf0e10cSrcweir break; 217cdf0e10cSrcweir case DataType::TIME: 218cdf0e10cSrcweir nFormat = _xTypes->getStandardFormat(NumberFormat::TIME, _rLocale); 219cdf0e10cSrcweir break; 220cdf0e10cSrcweir case DataType::TIMESTAMP: 221cdf0e10cSrcweir nFormat = _xTypes->getStandardFormat(NumberFormat::DATETIME, _rLocale); 222cdf0e10cSrcweir break; 223cdf0e10cSrcweir case DataType::BINARY: 224cdf0e10cSrcweir case DataType::VARBINARY: 225cdf0e10cSrcweir case DataType::LONGVARBINARY: 226cdf0e10cSrcweir case DataType::SQLNULL: 227cdf0e10cSrcweir case DataType::OTHER: 228cdf0e10cSrcweir case DataType::OBJECT: 229cdf0e10cSrcweir case DataType::DISTINCT: 230cdf0e10cSrcweir case DataType::STRUCT: 231cdf0e10cSrcweir case DataType::ARRAY: 232cdf0e10cSrcweir case DataType::BLOB: 233cdf0e10cSrcweir case DataType::REF: 234cdf0e10cSrcweir default: 235cdf0e10cSrcweir nFormat = _xTypes->getStandardFormat(NumberFormat::UNDEFINED, _rLocale); 236cdf0e10cSrcweir //nFormat = NumberFormat::UNDEFINED; 237cdf0e10cSrcweir } 238cdf0e10cSrcweir return nFormat; 239cdf0e10cSrcweir } 240cdf0e10cSrcweir 241cdf0e10cSrcweir //============================================================================== 242cdf0e10cSrcweir //------------------------------------------------------------------------------ 243cdf0e10cSrcweir Reference< XConnection> findConnection(const Reference< XInterface >& xParent) 244cdf0e10cSrcweir { 245cdf0e10cSrcweir Reference< XConnection> xConnection(xParent, UNO_QUERY); 246cdf0e10cSrcweir if (!xConnection.is()) 247cdf0e10cSrcweir { 248cdf0e10cSrcweir Reference< XChild> xChild(xParent, UNO_QUERY); 249cdf0e10cSrcweir if (xChild.is()) 250cdf0e10cSrcweir xConnection = findConnection(xChild->getParent()); 251cdf0e10cSrcweir } 252cdf0e10cSrcweir return xConnection; 253cdf0e10cSrcweir } 254cdf0e10cSrcweir 255cdf0e10cSrcweir //------------------------------------------------------------------------------ 256cdf0e10cSrcweir Reference< XDataSource> getDataSource_allowException( 257cdf0e10cSrcweir const ::rtl::OUString& _rsTitleOrPath, 258cdf0e10cSrcweir const Reference< XMultiServiceFactory >& _rxFactory ) 259cdf0e10cSrcweir { 260cdf0e10cSrcweir ENSURE_OR_RETURN( _rsTitleOrPath.getLength(), "getDataSource_allowException: invalid arg !", NULL ); 261cdf0e10cSrcweir 262cdf0e10cSrcweir Reference< XNameAccess> xDatabaseContext( 263cdf0e10cSrcweir _rxFactory->createInstance( 264cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "com.sun.star.sdb.DatabaseContext" ) ),UNO_QUERY ); 265cdf0e10cSrcweir OSL_ENSURE( xDatabaseContext.is(), "getDataSource_allowException: could not obtain the database context!" ); 266cdf0e10cSrcweir 267cdf0e10cSrcweir return Reference< XDataSource >( xDatabaseContext->getByName( _rsTitleOrPath ), UNO_QUERY ); 268cdf0e10cSrcweir } 269cdf0e10cSrcweir 270cdf0e10cSrcweir //------------------------------------------------------------------------------ 271cdf0e10cSrcweir Reference< XDataSource > getDataSource( 272cdf0e10cSrcweir const ::rtl::OUString& _rsTitleOrPath, 273cdf0e10cSrcweir const Reference< XMultiServiceFactory >& _rxFactory ) 274cdf0e10cSrcweir { 275cdf0e10cSrcweir Reference< XDataSource > xDS; 276cdf0e10cSrcweir try 277cdf0e10cSrcweir { 278cdf0e10cSrcweir xDS = getDataSource_allowException( _rsTitleOrPath, _rxFactory ); 279cdf0e10cSrcweir } 280cdf0e10cSrcweir catch( const Exception& ) 281cdf0e10cSrcweir { 282cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 283cdf0e10cSrcweir } 284cdf0e10cSrcweir 285cdf0e10cSrcweir return xDS; 286cdf0e10cSrcweir } 287cdf0e10cSrcweir 288cdf0e10cSrcweir //------------------------------------------------------------------------------ 289cdf0e10cSrcweir Reference< XConnection > getConnection_allowException( 290cdf0e10cSrcweir const ::rtl::OUString& _rsTitleOrPath, 291cdf0e10cSrcweir const ::rtl::OUString& _rsUser, 292cdf0e10cSrcweir const ::rtl::OUString& _rsPwd, 293cdf0e10cSrcweir const Reference< XMultiServiceFactory>& _rxFactory) 294cdf0e10cSrcweir { 295cdf0e10cSrcweir Reference< XDataSource> xDataSource( getDataSource_allowException(_rsTitleOrPath, _rxFactory) ); 296cdf0e10cSrcweir Reference<XConnection> xConnection; 297cdf0e10cSrcweir if (xDataSource.is()) 298cdf0e10cSrcweir { 299cdf0e10cSrcweir // do it with interaction handler 300cdf0e10cSrcweir if(!_rsUser.getLength() || !_rsPwd.getLength()) 301cdf0e10cSrcweir { 302cdf0e10cSrcweir Reference<XPropertySet> xProp(xDataSource,UNO_QUERY); 303cdf0e10cSrcweir ::rtl::OUString sPwd, sUser; 304cdf0e10cSrcweir sal_Bool bPwdReq = sal_False; 305cdf0e10cSrcweir try 306cdf0e10cSrcweir { 307cdf0e10cSrcweir xProp->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PASSWORD)) >>= sPwd; 308cdf0e10cSrcweir bPwdReq = ::cppu::any2bool(xProp->getPropertyValue(::rtl::OUString::createFromAscii("IsPasswordRequired"))); 309cdf0e10cSrcweir xProp->getPropertyValue(::rtl::OUString::createFromAscii("User")) >>= sUser; 310cdf0e10cSrcweir } 311cdf0e10cSrcweir catch(Exception&) 312cdf0e10cSrcweir { 313cdf0e10cSrcweir OSL_ENSURE(sal_False, "dbtools::getConnection: error while retrieving data source properties!"); 314cdf0e10cSrcweir } 315cdf0e10cSrcweir if(bPwdReq && !sPwd.getLength()) 316cdf0e10cSrcweir { // password required, but empty -> connect using an interaction handler 317cdf0e10cSrcweir Reference<XCompletedConnection> xConnectionCompletion(xProp, UNO_QUERY); 318cdf0e10cSrcweir if (xConnectionCompletion.is()) 319cdf0e10cSrcweir { // instantiate the default SDB interaction handler 320cdf0e10cSrcweir Reference< XInteractionHandler > xHandler(_rxFactory->createInstance(::rtl::OUString::createFromAscii("com.sun.star.task.InteractionHandler")), UNO_QUERY); 321cdf0e10cSrcweir OSL_ENSURE(xHandler.is(), "dbtools::getConnection service com.sun.star.task.InteractionHandler not available!"); 322cdf0e10cSrcweir if (xHandler.is()) 323cdf0e10cSrcweir { 324cdf0e10cSrcweir xConnection = xConnectionCompletion->connectWithCompletion(xHandler); 325cdf0e10cSrcweir } 326cdf0e10cSrcweir } 327cdf0e10cSrcweir } 328cdf0e10cSrcweir else 329cdf0e10cSrcweir xConnection = xDataSource->getConnection(sUser, sPwd); 330cdf0e10cSrcweir } 331cdf0e10cSrcweir if(!xConnection.is()) // try to get one if not already have one, just to make sure 332cdf0e10cSrcweir xConnection = xDataSource->getConnection(_rsUser, _rsPwd); 333cdf0e10cSrcweir } 334cdf0e10cSrcweir return xConnection; 335cdf0e10cSrcweir } 336cdf0e10cSrcweir 337cdf0e10cSrcweir //------------------------------------------------------------------------------ 338cdf0e10cSrcweir Reference< XConnection> getConnection_withFeedback(const ::rtl::OUString& _rDataSourceName, 339cdf0e10cSrcweir const ::rtl::OUString& _rUser, const ::rtl::OUString& _rPwd, const Reference< XMultiServiceFactory>& _rxFactory) 340cdf0e10cSrcweir SAL_THROW ( (SQLException) ) 341cdf0e10cSrcweir { 342cdf0e10cSrcweir Reference< XConnection > xReturn; 343cdf0e10cSrcweir try 344cdf0e10cSrcweir { 345cdf0e10cSrcweir xReturn = getConnection_allowException(_rDataSourceName, _rUser, _rPwd, _rxFactory); 346cdf0e10cSrcweir } 347cdf0e10cSrcweir catch(SQLException&) 348cdf0e10cSrcweir { 349cdf0e10cSrcweir // allowed to pass 350cdf0e10cSrcweir throw; 351cdf0e10cSrcweir } 352cdf0e10cSrcweir catch(Exception&) 353cdf0e10cSrcweir { 354cdf0e10cSrcweir OSL_ENSURE(sal_False, "::dbtools::getConnection_withFeedback: unexpected (non-SQL) exception caught!"); 355cdf0e10cSrcweir } 356cdf0e10cSrcweir return xReturn; 357cdf0e10cSrcweir } 358cdf0e10cSrcweir 359cdf0e10cSrcweir //------------------------------------------------------------------------------ 360cdf0e10cSrcweir Reference< XConnection> getConnection( 361cdf0e10cSrcweir const ::rtl::OUString& _rsTitleOrPath, 362cdf0e10cSrcweir const ::rtl::OUString& _rsUser, 363cdf0e10cSrcweir const ::rtl::OUString& _rsPwd, 364cdf0e10cSrcweir const Reference< XMultiServiceFactory>& _rxFactory) 365cdf0e10cSrcweir { 366cdf0e10cSrcweir Reference< XConnection > xReturn; 367cdf0e10cSrcweir try 368cdf0e10cSrcweir { 369cdf0e10cSrcweir xReturn = getConnection_allowException(_rsTitleOrPath, _rsUser, _rsPwd, _rxFactory); 370cdf0e10cSrcweir } 371cdf0e10cSrcweir catch(Exception&) 372cdf0e10cSrcweir { 373cdf0e10cSrcweir } 374cdf0e10cSrcweir 375cdf0e10cSrcweir // TODO: if there were not dozens of places which rely on getConnection not throwing an exception .... 376cdf0e10cSrcweir // I would change this ... 377cdf0e10cSrcweir 378cdf0e10cSrcweir return xReturn; 379cdf0e10cSrcweir } 380cdf0e10cSrcweir 381cdf0e10cSrcweir //------------------------------------------------------------------------------ 382cdf0e10cSrcweir Reference< XConnection> getConnection(const Reference< XRowSet>& _rxRowSet) throw (RuntimeException) 383cdf0e10cSrcweir { 384cdf0e10cSrcweir Reference< XConnection> xReturn; 385cdf0e10cSrcweir Reference< XPropertySet> xRowSetProps(_rxRowSet, UNO_QUERY); 386cdf0e10cSrcweir if (xRowSetProps.is()) 387cdf0e10cSrcweir xRowSetProps->getPropertyValue(::rtl::OUString::createFromAscii("ActiveConnection")) >>= xReturn; 388cdf0e10cSrcweir return xReturn; 389cdf0e10cSrcweir } 390cdf0e10cSrcweir 391cdf0e10cSrcweir //------------------------------------------------------------------------------ 392cdf0e10cSrcweir // helper function which allows to implement both the connectRowset and the ensureRowSetConnection semantics 393cdf0e10cSrcweir // if connectRowset (which is deprecated) is removed, this function and one of its parameters are 394cdf0e10cSrcweir // not needed anymore, the whole implementation can be moved into ensureRowSetConnection then) 395cdf0e10cSrcweir SharedConnection lcl_connectRowSet(const Reference< XRowSet>& _rxRowSet, const Reference< XMultiServiceFactory>& _rxFactory, 396cdf0e10cSrcweir bool _bSetAsActiveConnection, bool _bAttachAutoDisposer ) 397cdf0e10cSrcweir SAL_THROW ( ( SQLException, WrappedTargetException, RuntimeException ) ) 398cdf0e10cSrcweir { 399cdf0e10cSrcweir SharedConnection xConnection; 400cdf0e10cSrcweir 401cdf0e10cSrcweir do 402cdf0e10cSrcweir { 403cdf0e10cSrcweir Reference< XPropertySet> xRowSetProps(_rxRowSet, UNO_QUERY); 404cdf0e10cSrcweir if ( !xRowSetProps.is() ) 405cdf0e10cSrcweir break; 406cdf0e10cSrcweir 407cdf0e10cSrcweir // 1. already connected? 408cdf0e10cSrcweir Reference< XConnection > xExistingConn( 409cdf0e10cSrcweir xRowSetProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ActiveConnection" ) ) ), 410cdf0e10cSrcweir UNO_QUERY ); 411cdf0e10cSrcweir 412cdf0e10cSrcweir if ( xExistingConn.is() 413cdf0e10cSrcweir // 2. embedded in a database? 414cdf0e10cSrcweir || isEmbeddedInDatabase( _rxRowSet, xExistingConn ) 415cdf0e10cSrcweir // 3. is there a connection in the parent hierarchy? 416cdf0e10cSrcweir || ( xExistingConn = findConnection( _rxRowSet ) ).is() 417cdf0e10cSrcweir ) 418cdf0e10cSrcweir { 419cdf0e10cSrcweir if ( _bSetAsActiveConnection ) 420cdf0e10cSrcweir { 421cdf0e10cSrcweir xRowSetProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ActiveConnection" ) ), makeAny( xExistingConn ) ); 422cdf0e10cSrcweir // no auto disposer needed, since we did not create the connection 423cdf0e10cSrcweir } 424cdf0e10cSrcweir 425cdf0e10cSrcweir xConnection.reset( xExistingConn, SharedConnection::NoTakeOwnership ); 426cdf0e10cSrcweir break; 427cdf0e10cSrcweir } 428cdf0e10cSrcweir 429cdf0e10cSrcweir // build a connection with it's current settings (4. data source name, or 5. URL) 430cdf0e10cSrcweir 431cdf0e10cSrcweir const ::rtl::OUString sUserProp = ::rtl::OUString::createFromAscii("User"); 432cdf0e10cSrcweir ::rtl::OUString sDataSourceName; 433cdf0e10cSrcweir xRowSetProps->getPropertyValue(::rtl::OUString::createFromAscii("DataSourceName")) >>= sDataSourceName; 434cdf0e10cSrcweir ::rtl::OUString sURL; 435cdf0e10cSrcweir xRowSetProps->getPropertyValue(::rtl::OUString::createFromAscii("URL")) >>= sURL; 436cdf0e10cSrcweir 437cdf0e10cSrcweir Reference< XConnection > xPureConnection; 438cdf0e10cSrcweir if (sDataSourceName.getLength()) 439cdf0e10cSrcweir { // the row set's data source property is set 440cdf0e10cSrcweir // -> try to connect, get user and pwd setting for that 441cdf0e10cSrcweir ::rtl::OUString sUser, sPwd; 442cdf0e10cSrcweir 443cdf0e10cSrcweir if (hasProperty(sUserProp, xRowSetProps)) 444cdf0e10cSrcweir xRowSetProps->getPropertyValue(sUserProp) >>= sUser; 445cdf0e10cSrcweir if (hasProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PASSWORD), xRowSetProps)) 446cdf0e10cSrcweir xRowSetProps->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PASSWORD)) >>= sPwd; 447cdf0e10cSrcweir 448cdf0e10cSrcweir xPureConnection = getConnection_allowException( sDataSourceName, sUser, sPwd, _rxFactory ); 449cdf0e10cSrcweir } 450cdf0e10cSrcweir else if (sURL.getLength()) 451cdf0e10cSrcweir { // the row set has no data source, but a connection url set 452cdf0e10cSrcweir // -> try to connection with that url 453cdf0e10cSrcweir Reference< XDriverManager > xDriverManager( 454cdf0e10cSrcweir _rxFactory->createInstance( ::rtl::OUString::createFromAscii("com.sun.star.sdbc.ConnectionPool")), UNO_QUERY); 455cdf0e10cSrcweir if (xDriverManager.is()) 456cdf0e10cSrcweir { 457cdf0e10cSrcweir ::rtl::OUString sUser, sPwd; 458cdf0e10cSrcweir if (hasProperty(sUserProp, xRowSetProps)) 459cdf0e10cSrcweir xRowSetProps->getPropertyValue(sUserProp) >>= sUser; 460cdf0e10cSrcweir if (hasProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PASSWORD), xRowSetProps)) 461cdf0e10cSrcweir xRowSetProps->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PASSWORD)) >>= sPwd; 462cdf0e10cSrcweir if (sUser.getLength()) 463cdf0e10cSrcweir { // use user and pwd together with the url 464cdf0e10cSrcweir Sequence< PropertyValue> aInfo(2); 465cdf0e10cSrcweir aInfo.getArray()[0].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("user")); 466cdf0e10cSrcweir aInfo.getArray()[0].Value <<= sUser; 467cdf0e10cSrcweir aInfo.getArray()[1].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("password")); 468cdf0e10cSrcweir aInfo.getArray()[1].Value <<= sPwd; 469cdf0e10cSrcweir xPureConnection = xDriverManager->getConnectionWithInfo( sURL, aInfo ); 470cdf0e10cSrcweir } 471cdf0e10cSrcweir else 472cdf0e10cSrcweir // just use the url 473cdf0e10cSrcweir xPureConnection = xDriverManager->getConnection( sURL ); 474cdf0e10cSrcweir } 475cdf0e10cSrcweir } 476cdf0e10cSrcweir xConnection.reset( 477cdf0e10cSrcweir xPureConnection, 478cdf0e10cSrcweir _bAttachAutoDisposer ? SharedConnection::NoTakeOwnership : SharedConnection::TakeOwnership 479cdf0e10cSrcweir /* take ownership if and only if we're *not* going to auto-dispose the connection */ 480cdf0e10cSrcweir ); 481cdf0e10cSrcweir 482cdf0e10cSrcweir // now if we created a connection, forward it to the row set 483cdf0e10cSrcweir if ( xConnection.is() && _bSetAsActiveConnection ) 484cdf0e10cSrcweir { 485cdf0e10cSrcweir try 486cdf0e10cSrcweir { 487cdf0e10cSrcweir if ( _bAttachAutoDisposer ) 488cdf0e10cSrcweir { 489cdf0e10cSrcweir OAutoConnectionDisposer* pAutoDispose = new OAutoConnectionDisposer( _rxRowSet, xConnection ); 490cdf0e10cSrcweir Reference< XPropertyChangeListener > xEnsureDelete(pAutoDispose); 491cdf0e10cSrcweir } 492cdf0e10cSrcweir else 493cdf0e10cSrcweir xRowSetProps->setPropertyValue( 494cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ActiveConnection" ) ), 495cdf0e10cSrcweir makeAny( xConnection.getTyped() ) 496cdf0e10cSrcweir ); 497cdf0e10cSrcweir } 498cdf0e10cSrcweir catch(Exception&) 499cdf0e10cSrcweir { 500cdf0e10cSrcweir OSL_ENSURE(0,"EXception when we set the new active connection!"); 501cdf0e10cSrcweir } 502cdf0e10cSrcweir } 503cdf0e10cSrcweir } 504cdf0e10cSrcweir while ( false ); 505cdf0e10cSrcweir 506cdf0e10cSrcweir return xConnection; 507cdf0e10cSrcweir } 508cdf0e10cSrcweir 509cdf0e10cSrcweir //------------------------------------------------------------------------------ 510cdf0e10cSrcweir Reference< XConnection> connectRowset(const Reference< XRowSet>& _rxRowSet, const Reference< XMultiServiceFactory>& _rxFactory, 511cdf0e10cSrcweir sal_Bool _bSetAsActiveConnection ) SAL_THROW ( ( SQLException, WrappedTargetException, RuntimeException ) ) 512cdf0e10cSrcweir { 513cdf0e10cSrcweir SharedConnection xConnection = lcl_connectRowSet( _rxRowSet, _rxFactory, _bSetAsActiveConnection, true ); 514cdf0e10cSrcweir return xConnection.getTyped(); 515cdf0e10cSrcweir } 516cdf0e10cSrcweir 517cdf0e10cSrcweir //------------------------------------------------------------------------------ 518cdf0e10cSrcweir SharedConnection ensureRowSetConnection(const Reference< XRowSet>& _rxRowSet, const Reference< XMultiServiceFactory>& _rxFactory, 519cdf0e10cSrcweir bool _bUseAutoConnectionDisposer ) SAL_THROW ( ( SQLException, WrappedTargetException, RuntimeException ) ) 520cdf0e10cSrcweir { 521cdf0e10cSrcweir return lcl_connectRowSet( _rxRowSet, _rxFactory, true, _bUseAutoConnectionDisposer ); 522cdf0e10cSrcweir } 523cdf0e10cSrcweir 524cdf0e10cSrcweir //------------------------------------------------------------------------------ 525cdf0e10cSrcweir Reference< XNameAccess> getTableFields(const Reference< XConnection>& _rxConn,const ::rtl::OUString& _rName) 526cdf0e10cSrcweir { 527cdf0e10cSrcweir Reference< XComponent > xDummy; 528cdf0e10cSrcweir return getFieldsByCommandDescriptor( _rxConn, CommandType::TABLE, _rName, xDummy ); 529cdf0e10cSrcweir } 530cdf0e10cSrcweir //------------------------------------------------------------------------------ 531cdf0e10cSrcweir Reference< XNameAccess> getPrimaryKeyColumns_throw(const Any& i_aTable) 532cdf0e10cSrcweir { 533cdf0e10cSrcweir const Reference< XPropertySet > xTable(i_aTable,UNO_QUERY_THROW); 534cdf0e10cSrcweir return getPrimaryKeyColumns_throw(xTable); 535cdf0e10cSrcweir } 536cdf0e10cSrcweir //------------------------------------------------------------------------------ 537cdf0e10cSrcweir Reference< XNameAccess> getPrimaryKeyColumns_throw(const Reference< XPropertySet >& i_xTable) 538cdf0e10cSrcweir { 539cdf0e10cSrcweir Reference<XNameAccess> xKeyColumns; 540cdf0e10cSrcweir const Reference<XKeysSupplier> xKeySup(i_xTable,UNO_QUERY); 541cdf0e10cSrcweir if ( xKeySup.is() ) 542cdf0e10cSrcweir { 543cdf0e10cSrcweir const Reference<XIndexAccess> xKeys = xKeySup->getKeys(); 544cdf0e10cSrcweir if ( xKeys.is() ) 545cdf0e10cSrcweir { 546cdf0e10cSrcweir ::dbtools::OPropertyMap& rPropMap = OMetaConnection::getPropMap(); 547cdf0e10cSrcweir const ::rtl::OUString sPropName = rPropMap.getNameByIndex(PROPERTY_ID_TYPE); 548cdf0e10cSrcweir Reference<XPropertySet> xProp; 549cdf0e10cSrcweir const sal_Int32 nCount = xKeys->getCount(); 550cdf0e10cSrcweir for(sal_Int32 i = 0;i< nCount;++i) 551cdf0e10cSrcweir { 552cdf0e10cSrcweir xProp.set(xKeys->getByIndex(i),UNO_QUERY_THROW); 553cdf0e10cSrcweir if ( xProp.is() ) 554cdf0e10cSrcweir { 555cdf0e10cSrcweir sal_Int32 nKeyType = 0; 556cdf0e10cSrcweir xProp->getPropertyValue(sPropName) >>= nKeyType; 557cdf0e10cSrcweir if(KeyType::PRIMARY == nKeyType) 558cdf0e10cSrcweir { 559cdf0e10cSrcweir const Reference<XColumnsSupplier> xKeyColsSup(xProp,UNO_QUERY_THROW); 560cdf0e10cSrcweir xKeyColumns = xKeyColsSup->getColumns(); 561cdf0e10cSrcweir break; 562cdf0e10cSrcweir } 563cdf0e10cSrcweir } 564cdf0e10cSrcweir } 565cdf0e10cSrcweir } 566cdf0e10cSrcweir } 567cdf0e10cSrcweir 568cdf0e10cSrcweir return xKeyColumns; 569cdf0e10cSrcweir } 570cdf0e10cSrcweir 571cdf0e10cSrcweir //------------------------------------------------------------------------------ 572cdf0e10cSrcweir namespace 573cdf0e10cSrcweir { 574cdf0e10cSrcweir enum FieldLookupState 575cdf0e10cSrcweir { 576cdf0e10cSrcweir HANDLE_TABLE, HANDLE_QUERY, HANDLE_SQL, RETRIEVE_OBJECT, RETRIEVE_COLUMNS, DONE, FAILED 577cdf0e10cSrcweir }; 578cdf0e10cSrcweir } 579cdf0e10cSrcweir 580cdf0e10cSrcweir //------------------------------------------------------------------------------ 581cdf0e10cSrcweir Reference< XNameAccess > getFieldsByCommandDescriptor( const Reference< XConnection >& _rxConnection, 582cdf0e10cSrcweir const sal_Int32 _nCommandType, const ::rtl::OUString& _rCommand, 583cdf0e10cSrcweir Reference< XComponent >& _rxKeepFieldsAlive, SQLExceptionInfo* _pErrorInfo ) SAL_THROW( ( ) ) 584cdf0e10cSrcweir { 585cdf0e10cSrcweir OSL_PRECOND( _rxConnection.is(), "::dbtools::getFieldsByCommandDescriptor: invalid connection!" ); 586cdf0e10cSrcweir OSL_PRECOND( ( CommandType::TABLE == _nCommandType ) || ( CommandType::QUERY == _nCommandType ) || ( CommandType::COMMAND == _nCommandType ), 587cdf0e10cSrcweir "::dbtools::getFieldsByCommandDescriptor: invalid command type!" ); 588cdf0e10cSrcweir OSL_PRECOND( _rCommand.getLength(), "::dbtools::getFieldsByCommandDescriptor: invalid command (empty)!" ); 589cdf0e10cSrcweir 590cdf0e10cSrcweir Reference< XNameAccess > xFields; 591cdf0e10cSrcweir 592cdf0e10cSrcweir // reset the error 593cdf0e10cSrcweir if ( _pErrorInfo ) 594cdf0e10cSrcweir *_pErrorInfo = SQLExceptionInfo(); 595cdf0e10cSrcweir // reset the ownership holder 596cdf0e10cSrcweir _rxKeepFieldsAlive.clear(); 597cdf0e10cSrcweir 598cdf0e10cSrcweir // go for the fields 599cdf0e10cSrcweir try 600cdf0e10cSrcweir { 601cdf0e10cSrcweir // some kind of state machine to ease the sharing of code 602cdf0e10cSrcweir FieldLookupState eState = FAILED; 603cdf0e10cSrcweir switch ( _nCommandType ) 604cdf0e10cSrcweir { 605cdf0e10cSrcweir case CommandType::TABLE: 606cdf0e10cSrcweir eState = HANDLE_TABLE; 607cdf0e10cSrcweir break; 608cdf0e10cSrcweir case CommandType::QUERY: 609cdf0e10cSrcweir eState = HANDLE_QUERY; 610cdf0e10cSrcweir break; 611cdf0e10cSrcweir case CommandType::COMMAND: 612cdf0e10cSrcweir eState = HANDLE_SQL; 613cdf0e10cSrcweir break; 614cdf0e10cSrcweir } 615cdf0e10cSrcweir 616cdf0e10cSrcweir // needed in various states: 617cdf0e10cSrcweir Reference< XNameAccess > xObjectCollection; 618cdf0e10cSrcweir Reference< XColumnsSupplier > xSupplyColumns; 619cdf0e10cSrcweir 620cdf0e10cSrcweir // go! 621cdf0e10cSrcweir while ( ( DONE != eState ) && ( FAILED != eState ) ) 622cdf0e10cSrcweir { 623cdf0e10cSrcweir switch ( eState ) 624cdf0e10cSrcweir { 625cdf0e10cSrcweir case HANDLE_TABLE: 626cdf0e10cSrcweir { 627cdf0e10cSrcweir // initial state for handling the tables 628cdf0e10cSrcweir 629cdf0e10cSrcweir // get the table objects 630cdf0e10cSrcweir Reference< XTablesSupplier > xSupplyTables( _rxConnection, UNO_QUERY ); 631cdf0e10cSrcweir if ( xSupplyTables.is() ) 632cdf0e10cSrcweir xObjectCollection = xSupplyTables->getTables(); 633cdf0e10cSrcweir // if something went wrong 'til here, then this will be handled in the next state 634cdf0e10cSrcweir 635cdf0e10cSrcweir // next state: get the object 636cdf0e10cSrcweir eState = RETRIEVE_OBJECT; 637cdf0e10cSrcweir } 638cdf0e10cSrcweir break; 639cdf0e10cSrcweir 640cdf0e10cSrcweir case HANDLE_QUERY: 641cdf0e10cSrcweir { 642cdf0e10cSrcweir // initial state for handling the tables 643cdf0e10cSrcweir 644cdf0e10cSrcweir // get the table objects 645cdf0e10cSrcweir Reference< XQueriesSupplier > xSupplyQueries( _rxConnection, UNO_QUERY ); 646cdf0e10cSrcweir if ( xSupplyQueries.is() ) 647cdf0e10cSrcweir xObjectCollection = xSupplyQueries->getQueries(); 648cdf0e10cSrcweir // if something went wrong 'til here, then this will be handled in the next state 649cdf0e10cSrcweir 650cdf0e10cSrcweir // next state: get the object 651cdf0e10cSrcweir eState = RETRIEVE_OBJECT; 652cdf0e10cSrcweir } 653cdf0e10cSrcweir break; 654cdf0e10cSrcweir 655cdf0e10cSrcweir case RETRIEVE_OBJECT: 656cdf0e10cSrcweir // here we should have an object (aka query or table) collection, and are going 657cdf0e10cSrcweir // to retrieve the desired object 658cdf0e10cSrcweir 659cdf0e10cSrcweir // next state: default to FAILED 660cdf0e10cSrcweir eState = FAILED; 661cdf0e10cSrcweir 662cdf0e10cSrcweir OSL_ENSURE( xObjectCollection.is(), "::dbtools::getFieldsByCommandDescriptor: invalid connection (no sdb.Connection, or no Tables-/QueriesSupplier)!"); 663cdf0e10cSrcweir if ( xObjectCollection.is() ) 664cdf0e10cSrcweir { 665cdf0e10cSrcweir if ( xObjectCollection.is() && xObjectCollection->hasByName( _rCommand ) ) 666cdf0e10cSrcweir { 667cdf0e10cSrcweir xObjectCollection->getByName( _rCommand ) >>= xSupplyColumns; 668cdf0e10cSrcweir // (xSupplyColumns being NULL will be handled in the next state) 669cdf0e10cSrcweir 670cdf0e10cSrcweir // next: go for the columns 671cdf0e10cSrcweir eState = RETRIEVE_COLUMNS; 672cdf0e10cSrcweir } 673cdf0e10cSrcweir } 674cdf0e10cSrcweir break; 675cdf0e10cSrcweir 676cdf0e10cSrcweir case RETRIEVE_COLUMNS: 677cdf0e10cSrcweir OSL_ENSURE( xSupplyColumns.is(), "::dbtools::getFieldsByCommandDescriptor: could not retrieve the columns supplier!" ); 678cdf0e10cSrcweir 679cdf0e10cSrcweir // next state: default to FAILED 680cdf0e10cSrcweir eState = FAILED; 681cdf0e10cSrcweir 682cdf0e10cSrcweir if ( xSupplyColumns.is() ) 683cdf0e10cSrcweir { 684cdf0e10cSrcweir xFields = xSupplyColumns->getColumns(); 685cdf0e10cSrcweir // that's it 686cdf0e10cSrcweir eState = DONE; 687cdf0e10cSrcweir } 688cdf0e10cSrcweir break; 689cdf0e10cSrcweir 690cdf0e10cSrcweir case HANDLE_SQL: 691cdf0e10cSrcweir { 692cdf0e10cSrcweir ::rtl::OUString sStatementToExecute( _rCommand ); 693cdf0e10cSrcweir 694cdf0e10cSrcweir // well, the main problem here is to handle statements which contain a parameter 695cdf0e10cSrcweir // If we would simply execute a parametrized statement, then this will fail because 696cdf0e10cSrcweir // we cannot supply any parameter values. 697cdf0e10cSrcweir // Thus, we try to analyze the statement, and to append a WHERE 0=1 filter criterion 698cdf0e10cSrcweir // This should cause every driver to not really execute the statement, but to return 699cdf0e10cSrcweir // an empty result set with the proper structure. We then can use this result set 700cdf0e10cSrcweir // to retrieve the columns. 701cdf0e10cSrcweir 702cdf0e10cSrcweir try 703cdf0e10cSrcweir { 704cdf0e10cSrcweir Reference< XMultiServiceFactory > xComposerFac( _rxConnection, UNO_QUERY ); 705cdf0e10cSrcweir 706cdf0e10cSrcweir if ( xComposerFac.is() ) 707cdf0e10cSrcweir { 708cdf0e10cSrcweir Reference< XSingleSelectQueryComposer > xComposer(xComposerFac->createInstance( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdb.SingleSelectQueryComposer"))),UNO_QUERY); 709cdf0e10cSrcweir if ( xComposer.is() ) 710cdf0e10cSrcweir { 711cdf0e10cSrcweir xComposer->setQuery( sStatementToExecute ); 712cdf0e10cSrcweir 713cdf0e10cSrcweir // Now set the filter to a dummy restriction which will result in an empty 714cdf0e10cSrcweir // result set. 715cdf0e10cSrcweir xComposer->setFilter( ::rtl::OUString::createFromAscii( "0=1" ) ); 716cdf0e10cSrcweir sStatementToExecute = xComposer->getQuery( ); 717cdf0e10cSrcweir } 718cdf0e10cSrcweir } 719cdf0e10cSrcweir } 720cdf0e10cSrcweir catch( const Exception& ) 721cdf0e10cSrcweir { 722cdf0e10cSrcweir // silent this error, this was just a try. If we're here, we did not change sStatementToExecute, 723cdf0e10cSrcweir // so it will still be _rCommand, which then will be executed without being touched 724cdf0e10cSrcweir } 725cdf0e10cSrcweir 726cdf0e10cSrcweir // now execute 727cdf0e10cSrcweir Reference< XPreparedStatement > xStatement = _rxConnection->prepareStatement( sStatementToExecute ); 728cdf0e10cSrcweir // transfer ownership of this temporary object to the caller 729cdf0e10cSrcweir _rxKeepFieldsAlive = _rxKeepFieldsAlive.query( xStatement ); 730cdf0e10cSrcweir 731cdf0e10cSrcweir // set the "MaxRows" to 0. This is just in case our attempt to append a 0=1 filter 732cdf0e10cSrcweir // failed - in this case, the MaxRows restriction should at least ensure that there 733cdf0e10cSrcweir // is no data returned (which would be potentially expensive) 734cdf0e10cSrcweir Reference< XPropertySet > xStatementProps( xStatement,UNO_QUERY ); 735cdf0e10cSrcweir try 736cdf0e10cSrcweir { 737cdf0e10cSrcweir if ( xStatementProps.is() ) 738cdf0e10cSrcweir xStatementProps->setPropertyValue( 739cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MaxRows" ) ), 740cdf0e10cSrcweir makeAny( sal_Int32( 0 ) ) 741cdf0e10cSrcweir ); 742cdf0e10cSrcweir } 743cdf0e10cSrcweir catch( const Exception& ) 744cdf0e10cSrcweir { 745cdf0e10cSrcweir OSL_ENSURE( sal_False, "::dbtools::getFieldsByCommandDescriptor: could not set the MaxRows!" ); 746cdf0e10cSrcweir // oh damn. Not much of a chance to recover, we will no retrieve the complete 747cdf0e10cSrcweir // full blown result set 748cdf0e10cSrcweir } 749cdf0e10cSrcweir 750cdf0e10cSrcweir xSupplyColumns = xSupplyColumns.query( xStatement->executeQuery() ); 751cdf0e10cSrcweir // this should have given us a result set which does not contain any data, but 752cdf0e10cSrcweir // the structural information we need 753cdf0e10cSrcweir 754cdf0e10cSrcweir // so the next state is to get the columns 755cdf0e10cSrcweir eState = RETRIEVE_COLUMNS; 756cdf0e10cSrcweir } 757cdf0e10cSrcweir break; 758cdf0e10cSrcweir 759cdf0e10cSrcweir default: 760cdf0e10cSrcweir OSL_ENSURE( sal_False, "::dbtools::getFieldsByCommandDescriptor: oops! unhandled state here!" ); 761cdf0e10cSrcweir eState = FAILED; 762cdf0e10cSrcweir } 763cdf0e10cSrcweir } 764cdf0e10cSrcweir } 765cdf0e10cSrcweir catch( const SQLContext& e ) { if ( _pErrorInfo ) *_pErrorInfo = SQLExceptionInfo( e ); } 766cdf0e10cSrcweir catch( const SQLWarning& e ) { if ( _pErrorInfo ) *_pErrorInfo = SQLExceptionInfo( e ); } 767cdf0e10cSrcweir catch( const SQLException& e ) { if ( _pErrorInfo ) *_pErrorInfo = SQLExceptionInfo( e ); } 768cdf0e10cSrcweir catch( const Exception& ) 769cdf0e10cSrcweir { 770cdf0e10cSrcweir OSL_ENSURE( sal_False, "::dbtools::getFieldsByCommandDescriptor: caught an exception while retrieving the fields!" ); 771cdf0e10cSrcweir } 772cdf0e10cSrcweir 773cdf0e10cSrcweir return xFields; 774cdf0e10cSrcweir } 775cdf0e10cSrcweir 776cdf0e10cSrcweir //------------------------------------------------------------------------------ 777cdf0e10cSrcweir Sequence< ::rtl::OUString > getFieldNamesByCommandDescriptor( const Reference< XConnection >& _rxConnection, 778cdf0e10cSrcweir const sal_Int32 _nCommandType, const ::rtl::OUString& _rCommand, 779cdf0e10cSrcweir SQLExceptionInfo* _pErrorInfo ) SAL_THROW( ( ) ) 780cdf0e10cSrcweir { 781cdf0e10cSrcweir // get the container for the fields 782cdf0e10cSrcweir Reference< XComponent > xKeepFieldsAlive; 783cdf0e10cSrcweir Reference< XNameAccess > xFieldContainer = getFieldsByCommandDescriptor( _rxConnection, _nCommandType, _rCommand, xKeepFieldsAlive, _pErrorInfo ); 784cdf0e10cSrcweir 785cdf0e10cSrcweir // get the names of the fields 786cdf0e10cSrcweir Sequence< ::rtl::OUString > aNames; 787cdf0e10cSrcweir if ( xFieldContainer.is() ) 788cdf0e10cSrcweir aNames = xFieldContainer->getElementNames(); 789cdf0e10cSrcweir 790cdf0e10cSrcweir // clean up any temporary objects which have been created 791cdf0e10cSrcweir disposeComponent( xKeepFieldsAlive ); 792cdf0e10cSrcweir 793cdf0e10cSrcweir // outta here 794cdf0e10cSrcweir return aNames; 795cdf0e10cSrcweir } 796cdf0e10cSrcweir 797cdf0e10cSrcweir //------------------------------------------------------------------------------ 798cdf0e10cSrcweir SQLContext prependContextInfo(const SQLException& _rException, const Reference< XInterface >& _rxContext, const ::rtl::OUString& _rContextDescription, const ::rtl::OUString& _rContextDetails) 799cdf0e10cSrcweir { 800cdf0e10cSrcweir return SQLContext( _rContextDescription, _rxContext, ::rtl::OUString(), 0, makeAny( _rException ), _rContextDetails ); 801cdf0e10cSrcweir } 802cdf0e10cSrcweir //------------------------------------------------------------------------------ 803cdf0e10cSrcweir SQLException prependErrorInfo( const SQLException& _rChainedException, const Reference< XInterface >& _rxContext, 804cdf0e10cSrcweir const ::rtl::OUString& _rAdditionalError, const StandardSQLState _eSQLState, const sal_Int32 _nErrorCode ) 805cdf0e10cSrcweir { 806cdf0e10cSrcweir return SQLException( _rAdditionalError, _rxContext, 807cdf0e10cSrcweir _eSQLState == SQL_ERROR_UNSPECIFIED ? ::rtl::OUString() : getStandardSQLState( _eSQLState ), 808cdf0e10cSrcweir _nErrorCode, makeAny( _rChainedException ) ); 809cdf0e10cSrcweir } 810cdf0e10cSrcweir 811cdf0e10cSrcweir //-------------------------------------------------------------------------- 812cdf0e10cSrcweir namespace 813cdf0e10cSrcweir { 814cdf0e10cSrcweir struct NameComponentSupport 815cdf0e10cSrcweir { 816cdf0e10cSrcweir const bool bCatalogs; 817cdf0e10cSrcweir const bool bSchemas; 818cdf0e10cSrcweir 819cdf0e10cSrcweir NameComponentSupport( ) 820cdf0e10cSrcweir :bCatalogs( true ) 821cdf0e10cSrcweir ,bSchemas( true ) 822cdf0e10cSrcweir { 823cdf0e10cSrcweir } 824cdf0e10cSrcweir 825cdf0e10cSrcweir NameComponentSupport( const bool _bCatalogs, const bool _bSchemas ) 826cdf0e10cSrcweir :bCatalogs( _bCatalogs ) 827cdf0e10cSrcweir ,bSchemas( _bSchemas ) 828cdf0e10cSrcweir { 829cdf0e10cSrcweir } 830cdf0e10cSrcweir }; 831cdf0e10cSrcweir 832cdf0e10cSrcweir NameComponentSupport lcl_getNameComponentSupport( const Reference< XDatabaseMetaData >& _rxMetaData, EComposeRule _eComposeRule ) 833cdf0e10cSrcweir { 834cdf0e10cSrcweir OSL_PRECOND( _rxMetaData.is(), "lcl_getNameComponentSupport: invalid meta data!" ); 835cdf0e10cSrcweir 836cdf0e10cSrcweir FMetaDataSupport pCatalogCall = &XDatabaseMetaData::supportsCatalogsInDataManipulation; 837cdf0e10cSrcweir FMetaDataSupport pSchemaCall = &XDatabaseMetaData::supportsSchemasInDataManipulation; 838cdf0e10cSrcweir bool bIgnoreMetaData = false; 839cdf0e10cSrcweir 840cdf0e10cSrcweir switch ( _eComposeRule ) 841cdf0e10cSrcweir { 842cdf0e10cSrcweir case eInTableDefinitions: 843cdf0e10cSrcweir pCatalogCall = &XDatabaseMetaData::supportsCatalogsInTableDefinitions; 844cdf0e10cSrcweir pSchemaCall = &XDatabaseMetaData::supportsSchemasInTableDefinitions; 845cdf0e10cSrcweir break; 846cdf0e10cSrcweir case eInIndexDefinitions: 847cdf0e10cSrcweir pCatalogCall = &XDatabaseMetaData::supportsCatalogsInIndexDefinitions; 848cdf0e10cSrcweir pSchemaCall = &XDatabaseMetaData::supportsSchemasInIndexDefinitions; 849cdf0e10cSrcweir break; 850cdf0e10cSrcweir case eInProcedureCalls: 851cdf0e10cSrcweir pCatalogCall = &XDatabaseMetaData::supportsCatalogsInProcedureCalls; 852cdf0e10cSrcweir pSchemaCall = &XDatabaseMetaData::supportsSchemasInProcedureCalls; 853cdf0e10cSrcweir break; 854cdf0e10cSrcweir case eInPrivilegeDefinitions: 855cdf0e10cSrcweir pCatalogCall = &XDatabaseMetaData::supportsCatalogsInPrivilegeDefinitions; 856cdf0e10cSrcweir pSchemaCall = &XDatabaseMetaData::supportsSchemasInPrivilegeDefinitions; 857cdf0e10cSrcweir break; 858cdf0e10cSrcweir case eComplete: 859cdf0e10cSrcweir bIgnoreMetaData = true; 860cdf0e10cSrcweir break; 861cdf0e10cSrcweir case eInDataManipulation: 862cdf0e10cSrcweir // already properly set above 863cdf0e10cSrcweir break; 864cdf0e10cSrcweir } 865cdf0e10cSrcweir return NameComponentSupport( 866cdf0e10cSrcweir bIgnoreMetaData ? true : (_rxMetaData.get()->*pCatalogCall)(), 867cdf0e10cSrcweir bIgnoreMetaData ? true : (_rxMetaData.get()->*pSchemaCall)() 868cdf0e10cSrcweir ); 869cdf0e10cSrcweir } 870cdf0e10cSrcweir } 871cdf0e10cSrcweir 872cdf0e10cSrcweir //-------------------------------------------------------------------------- 873cdf0e10cSrcweir static ::rtl::OUString impl_doComposeTableName( const Reference< XDatabaseMetaData >& _rxMetaData, 874cdf0e10cSrcweir const ::rtl::OUString& _rCatalog, const ::rtl::OUString& _rSchema, const ::rtl::OUString& _rName, 875cdf0e10cSrcweir sal_Bool _bQuote, EComposeRule _eComposeRule ) 876cdf0e10cSrcweir { 877cdf0e10cSrcweir OSL_ENSURE(_rxMetaData.is(), "impl_doComposeTableName : invalid meta data !"); 878cdf0e10cSrcweir if ( !_rxMetaData.is() ) 879cdf0e10cSrcweir return ::rtl::OUString(); 880cdf0e10cSrcweir OSL_ENSURE(_rName.getLength(), "impl_doComposeTableName : at least the name should be non-empty !"); 881cdf0e10cSrcweir 882cdf0e10cSrcweir const ::rtl::OUString sQuoteString = _rxMetaData->getIdentifierQuoteString(); 883cdf0e10cSrcweir const NameComponentSupport aNameComps( lcl_getNameComponentSupport( _rxMetaData, _eComposeRule ) ); 884cdf0e10cSrcweir 885cdf0e10cSrcweir ::rtl::OUStringBuffer aComposedName; 886cdf0e10cSrcweir 887cdf0e10cSrcweir ::rtl::OUString sCatalogSep; 888cdf0e10cSrcweir sal_Bool bCatlogAtStart = sal_True; 889cdf0e10cSrcweir if ( _rCatalog.getLength() && aNameComps.bCatalogs ) 890cdf0e10cSrcweir { 891cdf0e10cSrcweir sCatalogSep = _rxMetaData->getCatalogSeparator(); 892cdf0e10cSrcweir bCatlogAtStart = _rxMetaData->isCatalogAtStart(); 893cdf0e10cSrcweir 894cdf0e10cSrcweir if ( bCatlogAtStart && sCatalogSep.getLength()) 895cdf0e10cSrcweir { 896cdf0e10cSrcweir aComposedName.append( _bQuote ? quoteName( sQuoteString, _rCatalog ) : _rCatalog ); 897cdf0e10cSrcweir aComposedName.append( sCatalogSep ); 898cdf0e10cSrcweir } 899cdf0e10cSrcweir } 900cdf0e10cSrcweir 901cdf0e10cSrcweir if ( _rSchema.getLength() && aNameComps.bSchemas ) 902cdf0e10cSrcweir { 903cdf0e10cSrcweir aComposedName.append( _bQuote ? quoteName( sQuoteString, _rSchema ) : _rSchema ); 904cdf0e10cSrcweir aComposedName.appendAscii( "." ); 905cdf0e10cSrcweir } 906cdf0e10cSrcweir 907cdf0e10cSrcweir aComposedName.append( _bQuote ? quoteName( sQuoteString, _rName ) : _rName ); 908cdf0e10cSrcweir 909cdf0e10cSrcweir if ( _rCatalog.getLength() 910cdf0e10cSrcweir && !bCatlogAtStart 911cdf0e10cSrcweir && sCatalogSep.getLength() 912cdf0e10cSrcweir && aNameComps.bCatalogs 913cdf0e10cSrcweir ) 914cdf0e10cSrcweir { 915cdf0e10cSrcweir aComposedName.append( sCatalogSep ); 916cdf0e10cSrcweir aComposedName.append( _bQuote ? quoteName( sQuoteString, _rCatalog ) : _rCatalog ); 917cdf0e10cSrcweir } 918cdf0e10cSrcweir 919cdf0e10cSrcweir return aComposedName.makeStringAndClear(); 920cdf0e10cSrcweir } 921cdf0e10cSrcweir 922cdf0e10cSrcweir //------------------------------------------------------------------------------ 923cdf0e10cSrcweir ::rtl::OUString quoteTableName(const Reference< XDatabaseMetaData>& _rxMeta 924cdf0e10cSrcweir , const ::rtl::OUString& _rName 925cdf0e10cSrcweir , EComposeRule _eComposeRule) 926cdf0e10cSrcweir { 927cdf0e10cSrcweir ::rtl::OUString sCatalog, sSchema, sTable; 928cdf0e10cSrcweir qualifiedNameComponents(_rxMeta,_rName,sCatalog,sSchema,sTable,_eComposeRule); 929cdf0e10cSrcweir return impl_doComposeTableName( _rxMeta, sCatalog, sSchema, sTable, sal_True, _eComposeRule ); 930cdf0e10cSrcweir } 931cdf0e10cSrcweir 932cdf0e10cSrcweir //------------------------------------------------------------------------------ 933cdf0e10cSrcweir void qualifiedNameComponents(const Reference< XDatabaseMetaData >& _rxConnMetaData, const ::rtl::OUString& _rQualifiedName, ::rtl::OUString& _rCatalog, ::rtl::OUString& _rSchema, ::rtl::OUString& _rName,EComposeRule _eComposeRule) 934cdf0e10cSrcweir { 935cdf0e10cSrcweir OSL_ENSURE(_rxConnMetaData.is(), "QualifiedNameComponents : invalid meta data!"); 936cdf0e10cSrcweir 937cdf0e10cSrcweir NameComponentSupport aNameComps( lcl_getNameComponentSupport( _rxConnMetaData, _eComposeRule ) ); 938cdf0e10cSrcweir 939cdf0e10cSrcweir ::rtl::OUString sSeparator = _rxConnMetaData->getCatalogSeparator(); 940cdf0e10cSrcweir 941cdf0e10cSrcweir ::rtl::OUString sName(_rQualifiedName); 942cdf0e10cSrcweir // do we have catalogs ? 943cdf0e10cSrcweir if ( aNameComps.bCatalogs ) 944cdf0e10cSrcweir { 945cdf0e10cSrcweir if (_rxConnMetaData->isCatalogAtStart()) 946cdf0e10cSrcweir { 947cdf0e10cSrcweir // search for the catalog name at the beginning 948cdf0e10cSrcweir sal_Int32 nIndex = sName.indexOf(sSeparator); 949cdf0e10cSrcweir if (-1 != nIndex) 950cdf0e10cSrcweir { 951cdf0e10cSrcweir _rCatalog = sName.copy(0, nIndex); 952cdf0e10cSrcweir sName = sName.copy(nIndex + 1); 953cdf0e10cSrcweir } 954cdf0e10cSrcweir } 955cdf0e10cSrcweir else 956cdf0e10cSrcweir { 957cdf0e10cSrcweir // Katalogname am Ende 958cdf0e10cSrcweir sal_Int32 nIndex = sName.lastIndexOf(sSeparator); 959cdf0e10cSrcweir if (-1 != nIndex) 960cdf0e10cSrcweir { 961cdf0e10cSrcweir _rCatalog = sName.copy(nIndex + 1); 962cdf0e10cSrcweir sName = sName.copy(0, nIndex); 963cdf0e10cSrcweir } 964cdf0e10cSrcweir } 965cdf0e10cSrcweir } 966cdf0e10cSrcweir 967cdf0e10cSrcweir if ( aNameComps.bSchemas ) 968cdf0e10cSrcweir { 969cdf0e10cSrcweir sal_Int32 nIndex = sName.indexOf((sal_Unicode)'.'); 970cdf0e10cSrcweir // OSL_ENSURE(-1 != nIndex, "QualifiedNameComponents : no schema separator!"); 971cdf0e10cSrcweir if ( nIndex != -1 ) 972cdf0e10cSrcweir _rSchema = sName.copy(0, nIndex); 973cdf0e10cSrcweir sName = sName.copy(nIndex + 1); 974cdf0e10cSrcweir } 975cdf0e10cSrcweir 976cdf0e10cSrcweir _rName = sName; 977cdf0e10cSrcweir } 978cdf0e10cSrcweir 979cdf0e10cSrcweir //------------------------------------------------------------------------------ 980cdf0e10cSrcweir Reference< XNumberFormatsSupplier> getNumberFormats( 981cdf0e10cSrcweir const Reference< XConnection>& _rxConn, 982cdf0e10cSrcweir sal_Bool _bAlloweDefault, 983cdf0e10cSrcweir const Reference< XMultiServiceFactory>& _rxFactory) 984cdf0e10cSrcweir { 985cdf0e10cSrcweir // ask the parent of the connection (should be an DatabaseAccess) 986cdf0e10cSrcweir Reference< XNumberFormatsSupplier> xReturn; 987cdf0e10cSrcweir Reference< XChild> xConnAsChild(_rxConn, UNO_QUERY); 988cdf0e10cSrcweir ::rtl::OUString sPropFormatsSupplier = ::rtl::OUString::createFromAscii("NumberFormatsSupplier"); 989cdf0e10cSrcweir if (xConnAsChild.is()) 990cdf0e10cSrcweir { 991cdf0e10cSrcweir Reference< XPropertySet> xConnParentProps(xConnAsChild->getParent(), UNO_QUERY); 992cdf0e10cSrcweir if (xConnParentProps.is() && hasProperty(sPropFormatsSupplier, xConnParentProps)) 993cdf0e10cSrcweir xConnParentProps->getPropertyValue(sPropFormatsSupplier) >>= xReturn; 994cdf0e10cSrcweir } 995cdf0e10cSrcweir else if(_bAlloweDefault && _rxFactory.is()) 996cdf0e10cSrcweir { 997cdf0e10cSrcweir xReturn = Reference< XNumberFormatsSupplier>(_rxFactory->createInstance(::rtl::OUString::createFromAscii("com.sun.star.util.NumberFormatsSupplier")),UNO_QUERY); 998cdf0e10cSrcweir } 999cdf0e10cSrcweir return xReturn; 1000cdf0e10cSrcweir } 1001cdf0e10cSrcweir 1002cdf0e10cSrcweir //============================================================================== 1003cdf0e10cSrcweir //------------------------------------------------------------------------------ 1004cdf0e10cSrcweir void TransferFormComponentProperties( 1005cdf0e10cSrcweir const Reference< XPropertySet>& xOldProps, 1006cdf0e10cSrcweir const Reference< XPropertySet>& xNewProps, 1007cdf0e10cSrcweir const Locale& _rLocale) 1008cdf0e10cSrcweir { 1009cdf0e10cSrcweir try 1010cdf0e10cSrcweir { 1011cdf0e10cSrcweir OSL_ENSURE( xOldProps.is() && xNewProps.is(), "TransferFormComponentProperties: invalid source/dest!" ); 1012cdf0e10cSrcweir if ( !xOldProps.is() || !xNewProps.is() ) 1013cdf0e10cSrcweir return; 1014cdf0e10cSrcweir 1015cdf0e10cSrcweir // kopieren wir erst mal alle Props, die in Quelle und Ziel vorhanden sind und identische Beschreibungen haben 1016cdf0e10cSrcweir Reference< XPropertySetInfo> xOldInfo( xOldProps->getPropertySetInfo()); 1017cdf0e10cSrcweir Reference< XPropertySetInfo> xNewInfo( xNewProps->getPropertySetInfo()); 1018cdf0e10cSrcweir 1019cdf0e10cSrcweir Sequence< Property> aOldProperties = xOldInfo->getProperties(); 1020cdf0e10cSrcweir Sequence< Property> aNewProperties = xNewInfo->getProperties(); 1021cdf0e10cSrcweir int nNewLen = aNewProperties.getLength(); 1022cdf0e10cSrcweir 1023cdf0e10cSrcweir Property* pOldProps = aOldProperties.getArray(); 1024cdf0e10cSrcweir Property* pNewProps = aNewProperties.getArray(); 1025cdf0e10cSrcweir 1026cdf0e10cSrcweir ::rtl::OUString sPropDefaultControl(::rtl::OUString::createFromAscii("DefaultControl")); 1027cdf0e10cSrcweir ::rtl::OUString sPropLabelControl(::rtl::OUString::createFromAscii("LabelControl")); 1028cdf0e10cSrcweir ::rtl::OUString sPropFormatsSupplier(::rtl::OUString::createFromAscii("FormatsSupplier")); 1029cdf0e10cSrcweir ::rtl::OUString sPropCurrencySymbol(::rtl::OUString::createFromAscii("CurrencySymbol")); 1030cdf0e10cSrcweir ::rtl::OUString sPropDecimals(::rtl::OUString::createFromAscii("Decimals")); 1031cdf0e10cSrcweir ::rtl::OUString sPropEffectiveMin(::rtl::OUString::createFromAscii("EffectiveMin")); 1032cdf0e10cSrcweir ::rtl::OUString sPropEffectiveMax(::rtl::OUString::createFromAscii("EffectiveMax")); 1033cdf0e10cSrcweir ::rtl::OUString sPropEffectiveDefault(::rtl::OUString::createFromAscii("EffectiveDefault")); 1034cdf0e10cSrcweir ::rtl::OUString sPropDefaultText(::rtl::OUString::createFromAscii("DefaultText")); 1035cdf0e10cSrcweir ::rtl::OUString sPropDefaultDate(::rtl::OUString::createFromAscii("DefaultDate")); 1036cdf0e10cSrcweir ::rtl::OUString sPropDefaultTime(::rtl::OUString::createFromAscii("DefaultTime")); 1037cdf0e10cSrcweir ::rtl::OUString sPropValueMin(::rtl::OUString::createFromAscii("ValueMin")); 1038cdf0e10cSrcweir ::rtl::OUString sPropValueMax(::rtl::OUString::createFromAscii("ValueMax")); 1039cdf0e10cSrcweir ::rtl::OUString sPropDecimalAccuracy(::rtl::OUString::createFromAscii("DecimalAccuracy")); 1040cdf0e10cSrcweir ::rtl::OUString sPropClassId(::rtl::OUString::createFromAscii("ClassId")); 1041cdf0e10cSrcweir ::rtl::OUString sFormattedServiceName( ::rtl::OUString::createFromAscii( "com.sun.star.form.component.FormattedField" ) ); 1042cdf0e10cSrcweir 1043cdf0e10cSrcweir for (sal_Int16 i=0; i<aOldProperties.getLength(); ++i) 1044cdf0e10cSrcweir { 1045cdf0e10cSrcweir if ( (!pOldProps[i].Name.equals(sPropDefaultControl)) 1046cdf0e10cSrcweir && (!pOldProps[i].Name.equals(sPropLabelControl)) 1047cdf0e10cSrcweir ) 1048cdf0e10cSrcweir { 1049cdf0e10cSrcweir // binaere Suche 1050cdf0e10cSrcweir Property* pResult = ::std::lower_bound(pNewProps, pNewProps + nNewLen,pOldProps[i].Name, ::comphelper::PropertyStringLessFunctor()); 1051cdf0e10cSrcweir if ( pResult 1052cdf0e10cSrcweir && ( pResult != pNewProps + nNewLen && pResult->Name == pOldProps[i].Name ) 1053cdf0e10cSrcweir && ( (pResult->Attributes & PropertyAttribute::READONLY) == 0 ) 1054cdf0e10cSrcweir && ( pResult->Type.equals(pOldProps[i].Type)) ) 1055cdf0e10cSrcweir { // Attribute stimmen ueberein und Property ist nicht read-only 1056cdf0e10cSrcweir try 1057cdf0e10cSrcweir { 1058cdf0e10cSrcweir xNewProps->setPropertyValue(pResult->Name, xOldProps->getPropertyValue(pResult->Name)); 1059cdf0e10cSrcweir } 1060cdf0e10cSrcweir catch(IllegalArgumentException& e) 1061cdf0e10cSrcweir { 1062cdf0e10cSrcweir OSL_UNUSED( e ); 1063cdf0e10cSrcweir #ifdef DBG_UTIL 1064cdf0e10cSrcweir ::rtl::OUString sMessage = ::rtl::OUString::createFromAscii("TransferFormComponentProperties : could not transfer the value for property \""); 1065cdf0e10cSrcweir sMessage += pResult->Name; 1066cdf0e10cSrcweir sMessage += ::rtl::OUString::createFromAscii("\"");; 1067cdf0e10cSrcweir OSL_ENSURE(sal_False, ::rtl::OUStringToOString(sMessage, RTL_TEXTENCODING_ASCII_US)); 1068cdf0e10cSrcweir #endif 1069cdf0e10cSrcweir } 1070cdf0e10cSrcweir } 1071cdf0e10cSrcweir } 1072cdf0e10cSrcweir } 1073cdf0e10cSrcweir 1074cdf0e10cSrcweir 1075cdf0e10cSrcweir // fuer formatierte Felder (entweder alt oder neu) haben wir ein paar Sonderbehandlungen 1076cdf0e10cSrcweir Reference< XServiceInfo > xSI( xOldProps, UNO_QUERY ); 1077cdf0e10cSrcweir sal_Bool bOldIsFormatted = xSI.is() && xSI->supportsService( sFormattedServiceName ); 1078cdf0e10cSrcweir xSI = Reference< XServiceInfo >( xNewProps, UNO_QUERY ); 1079cdf0e10cSrcweir sal_Bool bNewIsFormatted = xSI.is() && xSI->supportsService( sFormattedServiceName ); 1080cdf0e10cSrcweir 1081cdf0e10cSrcweir if (!bOldIsFormatted && !bNewIsFormatted) 1082cdf0e10cSrcweir return; // nothing to do 1083cdf0e10cSrcweir 1084cdf0e10cSrcweir if (bOldIsFormatted && bNewIsFormatted) 1085cdf0e10cSrcweir // nein, wenn beide formatierte Felder sind, dann machen wir keinerlei Konvertierungen 1086cdf0e10cSrcweir // Das geht zu weit ;) 1087cdf0e10cSrcweir return; 1088cdf0e10cSrcweir 1089cdf0e10cSrcweir if (bOldIsFormatted) 1090cdf0e10cSrcweir { 1091cdf0e10cSrcweir // aus dem eingestellten Format ein paar Properties rausziehen und zum neuen Set durchschleifen 1092cdf0e10cSrcweir Any aFormatKey( xOldProps->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FORMATKEY)) ); 1093cdf0e10cSrcweir if (aFormatKey.hasValue()) 1094cdf0e10cSrcweir { 1095cdf0e10cSrcweir Reference< XNumberFormatsSupplier> xSupplier; 1096cdf0e10cSrcweir xOldProps->getPropertyValue(sPropFormatsSupplier) >>= xSupplier; 1097cdf0e10cSrcweir if (xSupplier.is()) 1098cdf0e10cSrcweir { 1099cdf0e10cSrcweir Reference< XNumberFormats> xFormats(xSupplier->getNumberFormats()); 1100cdf0e10cSrcweir Reference< XPropertySet> xFormat(xFormats->getByKey(getINT32(aFormatKey))); 1101cdf0e10cSrcweir if (hasProperty(sPropCurrencySymbol, xFormat)) 1102cdf0e10cSrcweir { 1103cdf0e10cSrcweir Any aVal( xFormat->getPropertyValue(sPropCurrencySymbol) ); 1104cdf0e10cSrcweir if (aVal.hasValue() && hasProperty(sPropCurrencySymbol, xNewProps)) 1105cdf0e10cSrcweir // (wenn die Quelle das nicht gesetzt hat, dann auch nicht kopieren, um den 1106cdf0e10cSrcweir // Default-Wert nicht zu ueberschreiben 1107cdf0e10cSrcweir xNewProps->setPropertyValue(sPropCurrencySymbol, aVal); 1108cdf0e10cSrcweir } 1109cdf0e10cSrcweir if (hasProperty(sPropDecimals, xFormat) && hasProperty(sPropDecimals, xNewProps)) 1110cdf0e10cSrcweir xNewProps->setPropertyValue(sPropDecimals, xFormat->getPropertyValue(sPropDecimals)); 1111cdf0e10cSrcweir } 1112cdf0e10cSrcweir } 1113cdf0e10cSrcweir 1114cdf0e10cSrcweir // eine eventuelle-Min-Max-Konvertierung 1115cdf0e10cSrcweir Any aEffectiveMin( xOldProps->getPropertyValue(sPropEffectiveMin) ); 1116cdf0e10cSrcweir if (aEffectiveMin.hasValue()) 1117cdf0e10cSrcweir { // im Gegensatz zu ValueMin kann EffectiveMin void sein 1118cdf0e10cSrcweir if (hasProperty(sPropValueMin, xNewProps)) 1119cdf0e10cSrcweir { 1120cdf0e10cSrcweir OSL_ENSURE(aEffectiveMin.getValueType().getTypeClass() == TypeClass_DOUBLE, 1121cdf0e10cSrcweir "TransferFormComponentProperties : invalid property type !"); 1122cdf0e10cSrcweir xNewProps->setPropertyValue(sPropValueMin, aEffectiveMin); 1123cdf0e10cSrcweir } 1124cdf0e10cSrcweir } 1125cdf0e10cSrcweir Any aEffectiveMax( xOldProps->getPropertyValue(sPropEffectiveMax) ); 1126cdf0e10cSrcweir if (aEffectiveMax.hasValue()) 1127cdf0e10cSrcweir { // analog 1128cdf0e10cSrcweir if (hasProperty(sPropValueMax, xNewProps)) 1129cdf0e10cSrcweir { 1130cdf0e10cSrcweir OSL_ENSURE(aEffectiveMax.getValueType().getTypeClass() == TypeClass_DOUBLE, 1131cdf0e10cSrcweir "TransferFormComponentProperties : invalid property type !"); 1132cdf0e10cSrcweir xNewProps->setPropertyValue(sPropValueMax, aEffectiveMax); 1133cdf0e10cSrcweir } 1134cdf0e10cSrcweir } 1135cdf0e10cSrcweir 1136cdf0e10cSrcweir // dann koennen wir noch Default-Werte konvertieren und uebernehmen 1137cdf0e10cSrcweir Any aEffectiveDefault( xOldProps->getPropertyValue(sPropEffectiveDefault) ); 1138cdf0e10cSrcweir if (aEffectiveDefault.hasValue()) 1139cdf0e10cSrcweir { 1140cdf0e10cSrcweir sal_Bool bIsString = aEffectiveDefault.getValueType().getTypeClass() == TypeClass_STRING; 1141cdf0e10cSrcweir OSL_ENSURE(bIsString || aEffectiveDefault.getValueType().getTypeClass() == TypeClass_DOUBLE, 1142cdf0e10cSrcweir "TransferFormComponentProperties : invalid property type !"); 1143cdf0e10cSrcweir // die Effective-Properties sollten immer void oder string oder double sein .... 1144cdf0e10cSrcweir 1145cdf0e10cSrcweir if (hasProperty(sPropDefaultDate, xNewProps) && !bIsString) 1146cdf0e10cSrcweir { // (einen ::rtl::OUString in ein Datum zu konvertieren muss nicht immer klappen, denn das ganze kann ja an 1147cdf0e10cSrcweir // eine Textspalte gebunden gewesen sein, aber mit einem double koennen wir was anfangen) 1148cdf0e10cSrcweir Date aDate = DBTypeConversion::toDate(getDouble(aEffectiveDefault)); 1149cdf0e10cSrcweir xNewProps->setPropertyValue(sPropDefaultDate, makeAny(aDate)); 1150cdf0e10cSrcweir } 1151cdf0e10cSrcweir 1152cdf0e10cSrcweir if (hasProperty(sPropDefaultTime, xNewProps) && !bIsString) 1153cdf0e10cSrcweir { // voellig analog mit Zeit 1154cdf0e10cSrcweir Time aTime = DBTypeConversion::toTime(getDouble(aEffectiveDefault)); 1155cdf0e10cSrcweir xNewProps->setPropertyValue(sPropDefaultTime, makeAny(aTime)); 1156cdf0e10cSrcweir } 1157cdf0e10cSrcweir 1158cdf0e10cSrcweir if (hasProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DEFAULTVALUE), xNewProps) && !bIsString) 1159cdf0e10cSrcweir { // hier koennen wir einfach das double durchreichen 1160cdf0e10cSrcweir xNewProps->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DEFAULTVALUE), aEffectiveDefault); 1161cdf0e10cSrcweir } 1162cdf0e10cSrcweir 1163cdf0e10cSrcweir if (hasProperty(sPropDefaultText, xNewProps) && bIsString) 1164cdf0e10cSrcweir { // und hier den ::rtl::OUString 1165cdf0e10cSrcweir xNewProps->setPropertyValue(sPropDefaultText, aEffectiveDefault); 1166cdf0e10cSrcweir } 1167cdf0e10cSrcweir 1168cdf0e10cSrcweir // nyi: die Uebersetzung zwischen doubles und ::rtl::OUString wuerde noch mehr Moeglichkeien eroeffnen 1169cdf0e10cSrcweir } 1170cdf0e10cSrcweir } 1171cdf0e10cSrcweir 1172cdf0e10cSrcweir // die andere Richtung : das neu Control soll formatiert sein 1173cdf0e10cSrcweir if (bNewIsFormatted) 1174cdf0e10cSrcweir { 1175cdf0e10cSrcweir // zuerst die Formatierung 1176cdf0e10cSrcweir // einen Supplier koennen wir nicht setzen, also muss das neue Set schon einen mitbringen 1177cdf0e10cSrcweir Reference< XNumberFormatsSupplier> xSupplier; 1178cdf0e10cSrcweir xNewProps->getPropertyValue(sPropFormatsSupplier) >>= xSupplier; 1179cdf0e10cSrcweir if (xSupplier.is()) 1180cdf0e10cSrcweir { 1181cdf0e10cSrcweir Reference< XNumberFormats> xFormats(xSupplier->getNumberFormats()); 1182cdf0e10cSrcweir 1183cdf0e10cSrcweir // Dezimal-Stellen 1184cdf0e10cSrcweir sal_Int16 nDecimals = 2; 1185cdf0e10cSrcweir if (hasProperty(sPropDecimalAccuracy, xOldProps)) 1186cdf0e10cSrcweir xOldProps->getPropertyValue(sPropDecimalAccuracy) >>= nDecimals; 1187cdf0e10cSrcweir 1188cdf0e10cSrcweir // Grund-Format (je nach ClassId des alten Sets) 1189cdf0e10cSrcweir sal_Int32 nBaseKey = 0; 1190cdf0e10cSrcweir if (hasProperty(sPropClassId, xOldProps)) 1191cdf0e10cSrcweir { 1192cdf0e10cSrcweir Reference< XNumberFormatTypes> xTypeList(xFormats, UNO_QUERY); 1193cdf0e10cSrcweir if (xTypeList.is()) 1194cdf0e10cSrcweir { 1195cdf0e10cSrcweir sal_Int16 nClassId = 0; 1196cdf0e10cSrcweir xOldProps->getPropertyValue(sPropClassId) >>= nClassId; 1197cdf0e10cSrcweir switch (nClassId) 1198cdf0e10cSrcweir { 1199cdf0e10cSrcweir case FormComponentType::DATEFIELD : 1200cdf0e10cSrcweir nBaseKey = xTypeList->getStandardFormat(NumberFormat::DATE, _rLocale); 1201cdf0e10cSrcweir break; 1202cdf0e10cSrcweir 1203cdf0e10cSrcweir case FormComponentType::TIMEFIELD : 1204cdf0e10cSrcweir nBaseKey = xTypeList->getStandardFormat(NumberFormat::TIME, _rLocale); 1205cdf0e10cSrcweir break; 1206cdf0e10cSrcweir 1207cdf0e10cSrcweir case FormComponentType::CURRENCYFIELD : 1208cdf0e10cSrcweir nBaseKey = xTypeList->getStandardFormat(NumberFormat::CURRENCY, _rLocale); 1209cdf0e10cSrcweir break; 1210cdf0e10cSrcweir } 1211cdf0e10cSrcweir } 1212cdf0e10cSrcweir } 1213cdf0e10cSrcweir 1214cdf0e10cSrcweir // damit koennen wir ein neues Format basteln ... 1215cdf0e10cSrcweir ::rtl::OUString sNewFormat = xFormats->generateFormat(nBaseKey, _rLocale, sal_False, sal_False, nDecimals, 0); 1216cdf0e10cSrcweir // kein Tausender-Trennzeichen, negative Zahlen nicht in Rot, keine fuehrenden Nullen 1217cdf0e10cSrcweir 1218cdf0e10cSrcweir // ... und zum FormatsSupplier hinzufuegen (wenn noetig) 1219cdf0e10cSrcweir sal_Int32 nKey = xFormats->queryKey(sNewFormat, _rLocale, sal_False); 1220cdf0e10cSrcweir if (nKey == (sal_Int32)-1) 1221cdf0e10cSrcweir { // noch nicht vorhanden in meinem Formatter ... 1222cdf0e10cSrcweir nKey = xFormats->addNew(sNewFormat, _rLocale); 1223cdf0e10cSrcweir } 1224cdf0e10cSrcweir 1225cdf0e10cSrcweir xNewProps->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FORMATKEY), makeAny((sal_Int32)nKey)); 1226cdf0e10cSrcweir } 1227cdf0e10cSrcweir 1228cdf0e10cSrcweir // min-/max-Werte 1229cdf0e10cSrcweir Any aNewMin, aNewMax; 1230cdf0e10cSrcweir if (hasProperty(sPropValueMin, xOldProps)) 1231cdf0e10cSrcweir aNewMin = xOldProps->getPropertyValue(sPropValueMin); 1232cdf0e10cSrcweir if (hasProperty(sPropValueMax, xOldProps)) 1233cdf0e10cSrcweir aNewMax = xOldProps->getPropertyValue(sPropValueMax); 1234cdf0e10cSrcweir xNewProps->setPropertyValue(sPropEffectiveMin, aNewMin); 1235cdf0e10cSrcweir xNewProps->setPropertyValue(sPropEffectiveMax, aNewMax); 1236cdf0e10cSrcweir 1237cdf0e10cSrcweir // Default-Wert 1238cdf0e10cSrcweir Any aNewDefault; 1239cdf0e10cSrcweir if (hasProperty(sPropDefaultDate, xOldProps)) 1240cdf0e10cSrcweir { 1241cdf0e10cSrcweir Any aDate( xOldProps->getPropertyValue(sPropDefaultDate) ); 1242cdf0e10cSrcweir if (aDate.hasValue()) 1243cdf0e10cSrcweir aNewDefault <<= DBTypeConversion::toDouble(*(Date*)aDate.getValue()); 1244cdf0e10cSrcweir } 1245cdf0e10cSrcweir 1246cdf0e10cSrcweir if (hasProperty(sPropDefaultTime, xOldProps)) 1247cdf0e10cSrcweir { 1248cdf0e10cSrcweir Any aTime( xOldProps->getPropertyValue(sPropDefaultTime) ); 1249cdf0e10cSrcweir if (aTime.hasValue()) 1250cdf0e10cSrcweir aNewDefault <<= DBTypeConversion::toDouble(*(Time*)aTime.getValue()); 1251cdf0e10cSrcweir } 1252cdf0e10cSrcweir 1253cdf0e10cSrcweir // double oder ::rtl::OUString werden direkt uebernommen 1254cdf0e10cSrcweir if (hasProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DEFAULTVALUE), xOldProps)) 1255cdf0e10cSrcweir aNewDefault = xOldProps->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DEFAULTVALUE)); 1256cdf0e10cSrcweir if (hasProperty(sPropDefaultText, xOldProps)) 1257cdf0e10cSrcweir aNewDefault = xOldProps->getPropertyValue(sPropDefaultText); 1258cdf0e10cSrcweir 1259cdf0e10cSrcweir if (aNewDefault.hasValue()) 1260cdf0e10cSrcweir xNewProps->setPropertyValue(sPropEffectiveDefault, aNewDefault); 1261cdf0e10cSrcweir } 1262cdf0e10cSrcweir } 1263cdf0e10cSrcweir catch(const Exception&) 1264cdf0e10cSrcweir { 1265cdf0e10cSrcweir OSL_ENSURE( sal_False, "TransferFormComponentProperties: caught an exception!" ); 1266cdf0e10cSrcweir } 1267cdf0e10cSrcweir } 1268cdf0e10cSrcweir 1269cdf0e10cSrcweir //------------------------------------------------------------------------------ 1270cdf0e10cSrcweir sal_Bool canInsert(const Reference< XPropertySet>& _rxCursorSet) 1271cdf0e10cSrcweir { 1272cdf0e10cSrcweir return ((_rxCursorSet.is() && (getINT32(_rxCursorSet->getPropertyValue(::rtl::OUString::createFromAscii("Privileges"))) & Privilege::INSERT) != 0)); 1273cdf0e10cSrcweir } 1274cdf0e10cSrcweir 1275cdf0e10cSrcweir //------------------------------------------------------------------------------ 1276cdf0e10cSrcweir sal_Bool canUpdate(const Reference< XPropertySet>& _rxCursorSet) 1277cdf0e10cSrcweir { 1278cdf0e10cSrcweir return ((_rxCursorSet.is() && (getINT32(_rxCursorSet->getPropertyValue(::rtl::OUString::createFromAscii("Privileges"))) & Privilege::UPDATE) != 0)); 1279cdf0e10cSrcweir } 1280cdf0e10cSrcweir 1281cdf0e10cSrcweir //------------------------------------------------------------------------------ 1282cdf0e10cSrcweir sal_Bool canDelete(const Reference< XPropertySet>& _rxCursorSet) 1283cdf0e10cSrcweir { 1284cdf0e10cSrcweir return ((_rxCursorSet.is() && (getINT32(_rxCursorSet->getPropertyValue(::rtl::OUString::createFromAscii("Privileges"))) & Privilege::DELETE) != 0)); 1285cdf0e10cSrcweir } 1286cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1287cdf0e10cSrcweir Reference< XDataSource> findDataSource(const Reference< XInterface >& _xParent) 1288cdf0e10cSrcweir { 1289cdf0e10cSrcweir Reference< XOfficeDatabaseDocument> xDatabaseDocument(_xParent, UNO_QUERY); 1290cdf0e10cSrcweir Reference< XDataSource> xDataSource; 1291cdf0e10cSrcweir if ( xDatabaseDocument.is() ) 1292cdf0e10cSrcweir xDataSource = xDatabaseDocument->getDataSource(); 1293cdf0e10cSrcweir if ( !xDataSource.is() ) 1294cdf0e10cSrcweir xDataSource.set(_xParent, UNO_QUERY); 1295cdf0e10cSrcweir if (!xDataSource.is()) 1296cdf0e10cSrcweir { 1297cdf0e10cSrcweir Reference< XChild> xChild(_xParent, UNO_QUERY); 1298cdf0e10cSrcweir if ( xChild.is() ) 1299cdf0e10cSrcweir xDataSource = findDataSource(xChild->getParent()); 1300cdf0e10cSrcweir } 1301cdf0e10cSrcweir return xDataSource; 1302cdf0e10cSrcweir } 1303cdf0e10cSrcweir 1304cdf0e10cSrcweir //------------------------------------------------------------------------------ 1305cdf0e10cSrcweir ::rtl::OUString getComposedRowSetStatement( const Reference< XPropertySet >& _rxRowSet, const Reference< XMultiServiceFactory>& _rxFactory, 1306cdf0e10cSrcweir sal_Bool _bUseRowSetFilter, sal_Bool _bUseRowSetOrder, Reference< XSingleSelectQueryComposer >* _pxComposer ) 1307cdf0e10cSrcweir SAL_THROW( ( SQLException ) ) 1308cdf0e10cSrcweir { 1309cdf0e10cSrcweir ::rtl::OUString sStatement; 1310cdf0e10cSrcweir try 1311cdf0e10cSrcweir { 1312cdf0e10cSrcweir Reference< XConnection> xConn = connectRowset( Reference< XRowSet >( _rxRowSet, UNO_QUERY ), _rxFactory, sal_True ); 1313cdf0e10cSrcweir if ( xConn.is() ) // implies _rxRowSet.is() 1314cdf0e10cSrcweir { 1315cdf0e10cSrcweir // build the statement the row set is based on (can't use the ActiveCommand property of the set 1316cdf0e10cSrcweir // as this reflects the status after the last execute, not the currently set properties) 1317cdf0e10cSrcweir 1318cdf0e10cSrcweir sal_Int32 nCommandType = CommandType::COMMAND; 1319cdf0e10cSrcweir ::rtl::OUString sCommand; 1320cdf0e10cSrcweir sal_Bool bEscapeProcessing = sal_False; 1321cdf0e10cSrcweir 1322cdf0e10cSrcweir OSL_VERIFY( _rxRowSet->getPropertyValue( ::rtl::OUString::createFromAscii( "CommandType" ) ) >>= nCommandType ); 1323cdf0e10cSrcweir OSL_VERIFY( _rxRowSet->getPropertyValue( ::rtl::OUString::createFromAscii( "Command" ) ) >>= sCommand ); 1324cdf0e10cSrcweir OSL_VERIFY( _rxRowSet->getPropertyValue( ::rtl::OUString::createFromAscii( "EscapeProcessing" ) ) >>= bEscapeProcessing ); 1325cdf0e10cSrcweir 1326cdf0e10cSrcweir StatementComposer aComposer( xConn, sCommand, nCommandType, bEscapeProcessing ); 1327cdf0e10cSrcweir // append sort 1328cdf0e10cSrcweir if ( _bUseRowSetOrder ) 1329cdf0e10cSrcweir aComposer.setOrder( getString( _rxRowSet->getPropertyValue( ::rtl::OUString::createFromAscii( "Order" ) ) ) ); 1330cdf0e10cSrcweir 1331cdf0e10cSrcweir // append filter 1332cdf0e10cSrcweir if ( _bUseRowSetFilter ) 1333cdf0e10cSrcweir { 1334cdf0e10cSrcweir sal_Bool bApplyFilter = sal_True; 1335cdf0e10cSrcweir _rxRowSet->getPropertyValue( ::rtl::OUString::createFromAscii( "ApplyFilter" ) ) >>= bApplyFilter; 1336cdf0e10cSrcweir if ( bApplyFilter ) 1337cdf0e10cSrcweir aComposer.setFilter( getString( _rxRowSet->getPropertyValue( ::rtl::OUString::createFromAscii( "Filter" ) ) ) ); 1338cdf0e10cSrcweir } 1339cdf0e10cSrcweir 1340cdf0e10cSrcweir sStatement = aComposer.getQuery(); 1341cdf0e10cSrcweir 1342cdf0e10cSrcweir if ( _pxComposer ) 1343cdf0e10cSrcweir { 1344cdf0e10cSrcweir *_pxComposer = aComposer.getComposer(); 1345cdf0e10cSrcweir aComposer.setDisposeComposer( false ); 1346cdf0e10cSrcweir } 1347cdf0e10cSrcweir } 1348cdf0e10cSrcweir } 1349cdf0e10cSrcweir catch( const SQLException& ) 1350cdf0e10cSrcweir { 1351cdf0e10cSrcweir throw; 1352cdf0e10cSrcweir } 1353cdf0e10cSrcweir catch( const Exception& ) 1354cdf0e10cSrcweir { 1355cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 1356cdf0e10cSrcweir } 1357cdf0e10cSrcweir 1358cdf0e10cSrcweir return sStatement; 1359cdf0e10cSrcweir } 1360cdf0e10cSrcweir 1361cdf0e10cSrcweir //------------------------------------------------------------------------------ 1362cdf0e10cSrcweir ::rtl::OUString getComposedRowSetStatement( 1363cdf0e10cSrcweir const Reference< XPropertySet >& _rxRowSet, const Reference< XMultiServiceFactory>& _rxFactory, 1364cdf0e10cSrcweir sal_Bool _bUseRowSetFilter, sal_Bool _bUseRowSetOrder ) 1365cdf0e10cSrcweir { 1366cdf0e10cSrcweir return getComposedRowSetStatement( _rxRowSet, _rxFactory, _bUseRowSetFilter, _bUseRowSetOrder, NULL ); 1367cdf0e10cSrcweir } 1368cdf0e10cSrcweir 1369cdf0e10cSrcweir //------------------------------------------------------------------------------ 1370cdf0e10cSrcweir Reference< XSingleSelectQueryComposer > getCurrentSettingsComposer( 1371cdf0e10cSrcweir const Reference< XPropertySet>& _rxRowSetProps, 1372cdf0e10cSrcweir const Reference< XMultiServiceFactory>& _rxFactory) 1373cdf0e10cSrcweir { 1374cdf0e10cSrcweir Reference< XSingleSelectQueryComposer > xReturn; 1375cdf0e10cSrcweir try 1376cdf0e10cSrcweir { 1377cdf0e10cSrcweir getComposedRowSetStatement( _rxRowSetProps, _rxFactory, sal_True, sal_True, &xReturn ); 1378cdf0e10cSrcweir } 1379cdf0e10cSrcweir catch( const SQLException& ) 1380cdf0e10cSrcweir { 1381cdf0e10cSrcweir throw; 1382cdf0e10cSrcweir } 1383cdf0e10cSrcweir catch( const Exception& ) 1384cdf0e10cSrcweir { 1385cdf0e10cSrcweir OSL_ENSURE( sal_False, "::getCurrentSettingsComposer : caught an exception !" ); 1386cdf0e10cSrcweir } 1387cdf0e10cSrcweir 1388cdf0e10cSrcweir return xReturn; 1389cdf0e10cSrcweir } 1390cdf0e10cSrcweir //-------------------------------------------------------------------------- 1391cdf0e10cSrcweir ::rtl::OUString composeTableName( const Reference< XDatabaseMetaData >& _rxMetaData, 1392cdf0e10cSrcweir const ::rtl::OUString& _rCatalog, 1393cdf0e10cSrcweir const ::rtl::OUString& _rSchema, 1394cdf0e10cSrcweir const ::rtl::OUString& _rName, 1395cdf0e10cSrcweir sal_Bool _bQuote, 1396cdf0e10cSrcweir EComposeRule _eComposeRule) 1397cdf0e10cSrcweir { 1398cdf0e10cSrcweir return impl_doComposeTableName( _rxMetaData, _rCatalog, _rSchema, _rName, _bQuote, _eComposeRule ); 1399cdf0e10cSrcweir } 1400cdf0e10cSrcweir 1401cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1402cdf0e10cSrcweir ::rtl::OUString composeTableNameForSelect( const Reference< XConnection >& _rxConnection, 1403cdf0e10cSrcweir const ::rtl::OUString& _rCatalog, const ::rtl::OUString& _rSchema, const ::rtl::OUString& _rName ) 1404cdf0e10cSrcweir { 1405cdf0e10cSrcweir sal_Bool bUseCatalogInSelect = isDataSourcePropertyEnabled( _rxConnection, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UseCatalogInSelect" ) ), sal_True ); 1406cdf0e10cSrcweir sal_Bool bUseSchemaInSelect = isDataSourcePropertyEnabled( _rxConnection, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UseSchemaInSelect" ) ), sal_True ); 1407cdf0e10cSrcweir 1408cdf0e10cSrcweir return impl_doComposeTableName( 1409cdf0e10cSrcweir _rxConnection->getMetaData(), 1410cdf0e10cSrcweir bUseCatalogInSelect ? _rCatalog : ::rtl::OUString(), 1411cdf0e10cSrcweir bUseSchemaInSelect ? _rSchema : ::rtl::OUString(), 1412cdf0e10cSrcweir _rName, 1413cdf0e10cSrcweir true, 1414cdf0e10cSrcweir eInDataManipulation 1415cdf0e10cSrcweir ); 1416cdf0e10cSrcweir } 1417cdf0e10cSrcweir 1418cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1419cdf0e10cSrcweir namespace 1420cdf0e10cSrcweir { 1421cdf0e10cSrcweir static void lcl_getTableNameComponents( const Reference<XPropertySet>& _xTable, 1422cdf0e10cSrcweir ::rtl::OUString& _out_rCatalog, ::rtl::OUString& _out_rSchema, ::rtl::OUString& _out_rName ) 1423cdf0e10cSrcweir { 1424cdf0e10cSrcweir ::dbtools::OPropertyMap& rPropMap = OMetaConnection::getPropMap(); 1425cdf0e10cSrcweir Reference< XPropertySetInfo > xInfo = _xTable->getPropertySetInfo(); 1426cdf0e10cSrcweir if ( xInfo.is() 1427cdf0e10cSrcweir && xInfo->hasPropertyByName(rPropMap.getNameByIndex(PROPERTY_ID_NAME)) ) 1428cdf0e10cSrcweir { 1429cdf0e10cSrcweir 1430cdf0e10cSrcweir ::rtl::OUString aCatalog; 1431cdf0e10cSrcweir ::rtl::OUString aSchema; 1432cdf0e10cSrcweir ::rtl::OUString aTable; 1433cdf0e10cSrcweir if ( xInfo->hasPropertyByName(rPropMap.getNameByIndex(PROPERTY_ID_CATALOGNAME)) 1434cdf0e10cSrcweir && xInfo->hasPropertyByName(rPropMap.getNameByIndex(PROPERTY_ID_SCHEMANAME)) ) 1435cdf0e10cSrcweir { 1436cdf0e10cSrcweir _xTable->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_CATALOGNAME)) >>= _out_rCatalog; 1437cdf0e10cSrcweir _xTable->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_SCHEMANAME)) >>= _out_rSchema; 1438cdf0e10cSrcweir } 1439cdf0e10cSrcweir _xTable->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_NAME)) >>= _out_rName; 1440cdf0e10cSrcweir } 1441cdf0e10cSrcweir else 1442cdf0e10cSrcweir OSL_ENSURE( false, "::dbtools::lcl_getTableNameComponents: this is no table object!" ); 1443cdf0e10cSrcweir } 1444cdf0e10cSrcweir } 1445cdf0e10cSrcweir 1446cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1447cdf0e10cSrcweir ::rtl::OUString composeTableNameForSelect( const Reference< XConnection >& _rxConnection, const Reference<XPropertySet>& _xTable ) 1448cdf0e10cSrcweir { 1449cdf0e10cSrcweir ::rtl::OUString sCatalog, sSchema, sName; 1450cdf0e10cSrcweir lcl_getTableNameComponents( _xTable, sCatalog, sSchema, sName ); 1451cdf0e10cSrcweir 1452cdf0e10cSrcweir return composeTableNameForSelect( _rxConnection, sCatalog, sSchema, sName ); 1453cdf0e10cSrcweir } 1454cdf0e10cSrcweir 1455cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1456cdf0e10cSrcweir ::rtl::OUString composeTableName(const Reference<XDatabaseMetaData>& _xMetaData, 1457cdf0e10cSrcweir const Reference<XPropertySet>& _xTable, 1458cdf0e10cSrcweir EComposeRule _eComposeRule, 1459cdf0e10cSrcweir bool _bSuppressCatalog, 1460cdf0e10cSrcweir bool _bSuppressSchema, 1461cdf0e10cSrcweir bool _bQuote ) 1462cdf0e10cSrcweir { 1463cdf0e10cSrcweir ::rtl::OUString sCatalog, sSchema, sName; 1464cdf0e10cSrcweir lcl_getTableNameComponents( _xTable, sCatalog, sSchema, sName ); 1465cdf0e10cSrcweir 1466cdf0e10cSrcweir return impl_doComposeTableName( 1467cdf0e10cSrcweir _xMetaData, 1468cdf0e10cSrcweir _bSuppressCatalog ? ::rtl::OUString() : sCatalog, 1469cdf0e10cSrcweir _bSuppressSchema ? ::rtl::OUString() : sSchema, 1470cdf0e10cSrcweir sName, 1471cdf0e10cSrcweir _bQuote, 1472cdf0e10cSrcweir _eComposeRule 1473cdf0e10cSrcweir ); 1474cdf0e10cSrcweir } 1475cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1476cdf0e10cSrcweir sal_Int32 getSearchColumnFlag( const Reference< XConnection>& _rxConn,sal_Int32 _nDataType) 1477cdf0e10cSrcweir { 1478cdf0e10cSrcweir sal_Int32 nSearchFlag = 0; 1479cdf0e10cSrcweir Reference<XResultSet> xSet = _rxConn->getMetaData()->getTypeInfo(); 1480cdf0e10cSrcweir if(xSet.is()) 1481cdf0e10cSrcweir { 1482cdf0e10cSrcweir Reference<XRow> xRow(xSet,UNO_QUERY); 1483cdf0e10cSrcweir while(xSet->next()) 1484cdf0e10cSrcweir { 1485cdf0e10cSrcweir if(xRow->getInt(2) == _nDataType) 1486cdf0e10cSrcweir { 1487cdf0e10cSrcweir nSearchFlag = xRow->getInt(9); 1488cdf0e10cSrcweir break; 1489cdf0e10cSrcweir } 1490cdf0e10cSrcweir } 1491cdf0e10cSrcweir } 1492cdf0e10cSrcweir return nSearchFlag; 1493cdf0e10cSrcweir } 1494cdf0e10cSrcweir 1495cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1496cdf0e10cSrcweir ::rtl::OUString createUniqueName( const Sequence< ::rtl::OUString >& _rNames, const ::rtl::OUString& _rBaseName, sal_Bool _bStartWithNumber ) 1497cdf0e10cSrcweir { 1498cdf0e10cSrcweir ::std::set< ::rtl::OUString > aUsedNames; 1499cdf0e10cSrcweir ::std::copy( 1500cdf0e10cSrcweir _rNames.getConstArray(), 1501cdf0e10cSrcweir _rNames.getConstArray() + _rNames.getLength(), 1502cdf0e10cSrcweir ::std::insert_iterator< ::std::set< ::rtl::OUString > >( aUsedNames, aUsedNames.end() ) 1503cdf0e10cSrcweir ); 1504cdf0e10cSrcweir 1505cdf0e10cSrcweir ::rtl::OUString sName( _rBaseName ); 1506cdf0e10cSrcweir sal_Int32 nPos = 1; 1507cdf0e10cSrcweir if ( _bStartWithNumber ) 1508cdf0e10cSrcweir sName += ::rtl::OUString::valueOf( nPos ); 1509cdf0e10cSrcweir 1510cdf0e10cSrcweir while ( aUsedNames.find( sName ) != aUsedNames.end() ) 1511cdf0e10cSrcweir { 1512cdf0e10cSrcweir sName = _rBaseName; 1513cdf0e10cSrcweir sName += ::rtl::OUString::valueOf( ++nPos ); 1514cdf0e10cSrcweir } 1515cdf0e10cSrcweir return sName; 1516cdf0e10cSrcweir } 1517cdf0e10cSrcweir 1518cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1519cdf0e10cSrcweir ::rtl::OUString createUniqueName(const Reference<XNameAccess>& _rxContainer,const ::rtl::OUString& _rBaseName,sal_Bool _bStartWithNumber) 1520cdf0e10cSrcweir { 1521cdf0e10cSrcweir Sequence< ::rtl::OUString > aElementNames; 1522cdf0e10cSrcweir 1523cdf0e10cSrcweir OSL_ENSURE( _rxContainer.is(), "createUniqueName: invalid container!" ); 1524cdf0e10cSrcweir if ( _rxContainer.is() ) 1525cdf0e10cSrcweir aElementNames = _rxContainer->getElementNames(); 1526cdf0e10cSrcweir 1527cdf0e10cSrcweir return createUniqueName( aElementNames, _rBaseName, _bStartWithNumber ); 1528cdf0e10cSrcweir } 1529cdf0e10cSrcweir 1530cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1531cdf0e10cSrcweir void showError(const SQLExceptionInfo& _rInfo, 1532cdf0e10cSrcweir const Reference< XWindow>& _xParent, 1533cdf0e10cSrcweir const Reference< XMultiServiceFactory >& _xFactory) 1534cdf0e10cSrcweir { 1535cdf0e10cSrcweir if (_rInfo.isValid()) 1536cdf0e10cSrcweir { 1537cdf0e10cSrcweir try 1538cdf0e10cSrcweir { 1539cdf0e10cSrcweir Sequence< Any > aArgs(2); 1540cdf0e10cSrcweir aArgs[0] <<= PropertyValue(::rtl::OUString::createFromAscii("SQLException"), 0, _rInfo.get(), PropertyState_DIRECT_VALUE); 1541cdf0e10cSrcweir aArgs[1] <<= PropertyValue(::rtl::OUString::createFromAscii("ParentWindow"), 0, makeAny(_xParent), PropertyState_DIRECT_VALUE); 1542cdf0e10cSrcweir 1543cdf0e10cSrcweir static ::rtl::OUString s_sDialogServiceName = ::rtl::OUString::createFromAscii("com.sun.star.sdb.ErrorMessageDialog"); 1544cdf0e10cSrcweir Reference< XExecutableDialog > xErrorDialog( 1545cdf0e10cSrcweir _xFactory->createInstanceWithArguments(s_sDialogServiceName, aArgs), UNO_QUERY); 1546cdf0e10cSrcweir if (xErrorDialog.is()) 1547cdf0e10cSrcweir xErrorDialog->execute(); 1548cdf0e10cSrcweir else 1549cdf0e10cSrcweir { 1550cdf0e10cSrcweir OSL_ENSURE(0,"dbtools::showError: no XExecutableDialog found!"); 1551cdf0e10cSrcweir } 1552cdf0e10cSrcweir } 1553cdf0e10cSrcweir catch(Exception&) 1554cdf0e10cSrcweir { 1555cdf0e10cSrcweir OSL_ENSURE(0,"showError: could not display the error message!"); 1556cdf0e10cSrcweir } 1557cdf0e10cSrcweir } 1558cdf0e10cSrcweir } 1559cdf0e10cSrcweir 1560cdf0e10cSrcweir // ------------------------------------------------------------------------- 1561cdf0e10cSrcweir sal_Bool implUpdateObject(const Reference< XRowUpdate >& _rxUpdatedObject, 1562cdf0e10cSrcweir const sal_Int32 _nColumnIndex, const Any& _rValue) SAL_THROW ( ( SQLException, RuntimeException ) ) 1563cdf0e10cSrcweir { 1564cdf0e10cSrcweir sal_Bool bSuccessfullyReRouted = sal_True; 1565cdf0e10cSrcweir switch (_rValue.getValueTypeClass()) 1566cdf0e10cSrcweir { 1567cdf0e10cSrcweir case TypeClass_ANY: 1568cdf0e10cSrcweir { 1569cdf0e10cSrcweir Any aInnerValue; 1570cdf0e10cSrcweir _rValue >>= aInnerValue; 1571cdf0e10cSrcweir bSuccessfullyReRouted = implUpdateObject(_rxUpdatedObject, _nColumnIndex, aInnerValue); 1572cdf0e10cSrcweir } 1573cdf0e10cSrcweir break; 1574cdf0e10cSrcweir 1575cdf0e10cSrcweir case TypeClass_VOID: 1576cdf0e10cSrcweir _rxUpdatedObject->updateNull(_nColumnIndex); 1577cdf0e10cSrcweir break; 1578cdf0e10cSrcweir 1579cdf0e10cSrcweir case TypeClass_STRING: 1580cdf0e10cSrcweir _rxUpdatedObject->updateString(_nColumnIndex, *(rtl::OUString*)_rValue.getValue()); 1581cdf0e10cSrcweir break; 1582cdf0e10cSrcweir 1583cdf0e10cSrcweir case TypeClass_BOOLEAN: 1584cdf0e10cSrcweir _rxUpdatedObject->updateBoolean(_nColumnIndex, *(sal_Bool *)_rValue.getValue()); 1585cdf0e10cSrcweir break; 1586cdf0e10cSrcweir 1587cdf0e10cSrcweir case TypeClass_BYTE: 1588cdf0e10cSrcweir _rxUpdatedObject->updateByte(_nColumnIndex, *(sal_Int8 *)_rValue.getValue()); 1589cdf0e10cSrcweir break; 1590cdf0e10cSrcweir 1591cdf0e10cSrcweir case TypeClass_UNSIGNED_SHORT: 1592cdf0e10cSrcweir case TypeClass_SHORT: 1593cdf0e10cSrcweir _rxUpdatedObject->updateShort(_nColumnIndex, *(sal_Int16*)_rValue.getValue()); 1594cdf0e10cSrcweir break; 1595cdf0e10cSrcweir 1596cdf0e10cSrcweir case TypeClass_CHAR: 1597cdf0e10cSrcweir _rxUpdatedObject->updateString(_nColumnIndex,::rtl::OUString((sal_Unicode *)_rValue.getValue(),1)); 1598cdf0e10cSrcweir break; 1599cdf0e10cSrcweir 1600cdf0e10cSrcweir case TypeClass_UNSIGNED_LONG: 1601cdf0e10cSrcweir case TypeClass_LONG: 1602cdf0e10cSrcweir _rxUpdatedObject->updateInt(_nColumnIndex, *(sal_Int32*)_rValue.getValue()); 1603cdf0e10cSrcweir break; 1604cdf0e10cSrcweir 1605cdf0e10cSrcweir case TypeClass_HYPER: 1606cdf0e10cSrcweir { 1607cdf0e10cSrcweir sal_Int64 nValue = 0; 1608cdf0e10cSrcweir OSL_VERIFY( _rValue >>= nValue ); 1609cdf0e10cSrcweir _rxUpdatedObject->updateLong( _nColumnIndex, nValue ); 1610cdf0e10cSrcweir } 1611cdf0e10cSrcweir break; 1612cdf0e10cSrcweir 1613cdf0e10cSrcweir case TypeClass_FLOAT: 1614cdf0e10cSrcweir _rxUpdatedObject->updateFloat(_nColumnIndex, *(float*)_rValue.getValue()); 1615cdf0e10cSrcweir break; 1616cdf0e10cSrcweir 1617cdf0e10cSrcweir case TypeClass_DOUBLE: 1618cdf0e10cSrcweir _rxUpdatedObject->updateDouble(_nColumnIndex, *(double*)_rValue.getValue()); 1619cdf0e10cSrcweir break; 1620cdf0e10cSrcweir 1621cdf0e10cSrcweir case TypeClass_SEQUENCE: 1622cdf0e10cSrcweir if (_rValue.getValueType() == ::getCppuType((const Sequence< sal_Int8 > *)0)) 1623cdf0e10cSrcweir _rxUpdatedObject->updateBytes(_nColumnIndex, *(Sequence<sal_Int8>*)_rValue.getValue()); 1624cdf0e10cSrcweir else 1625cdf0e10cSrcweir bSuccessfullyReRouted = sal_False; 1626cdf0e10cSrcweir break; 1627cdf0e10cSrcweir case TypeClass_STRUCT: 1628cdf0e10cSrcweir if (_rValue.getValueType() == ::getCppuType((const DateTime*)0)) 1629cdf0e10cSrcweir _rxUpdatedObject->updateTimestamp(_nColumnIndex, *(DateTime*)_rValue.getValue()); 1630cdf0e10cSrcweir else if (_rValue.getValueType() == ::getCppuType((const Date*)0)) 1631cdf0e10cSrcweir _rxUpdatedObject->updateDate(_nColumnIndex, *(Date*)_rValue.getValue()); 1632cdf0e10cSrcweir else if (_rValue.getValueType() == ::getCppuType((const Time*)0)) 1633cdf0e10cSrcweir _rxUpdatedObject->updateTime(_nColumnIndex, *(Time*)_rValue.getValue()); 1634cdf0e10cSrcweir else 1635cdf0e10cSrcweir bSuccessfullyReRouted = sal_False; 1636cdf0e10cSrcweir break; 1637cdf0e10cSrcweir 1638cdf0e10cSrcweir case TypeClass_INTERFACE: 1639cdf0e10cSrcweir if (_rValue.getValueType() == ::getCppuType(static_cast<Reference< XInputStream>*>(NULL))) 1640cdf0e10cSrcweir { 1641cdf0e10cSrcweir Reference< XInputStream > xStream; 1642cdf0e10cSrcweir _rValue >>= xStream; 1643cdf0e10cSrcweir _rxUpdatedObject->updateBinaryStream(_nColumnIndex, xStream, xStream->available()); 1644cdf0e10cSrcweir break; 1645cdf0e10cSrcweir } 1646cdf0e10cSrcweir // run through 1647cdf0e10cSrcweir default: 1648cdf0e10cSrcweir bSuccessfullyReRouted = sal_False; 1649cdf0e10cSrcweir } 1650cdf0e10cSrcweir 1651cdf0e10cSrcweir return bSuccessfullyReRouted; 1652cdf0e10cSrcweir } 1653cdf0e10cSrcweir // ------------------------------------------------------------------------- 1654cdf0e10cSrcweir sal_Bool implSetObject( const Reference< XParameters >& _rxParameters, 1655cdf0e10cSrcweir const sal_Int32 _nColumnIndex, const Any& _rValue) SAL_THROW ( ( SQLException, RuntimeException ) ) 1656cdf0e10cSrcweir { 1657cdf0e10cSrcweir sal_Bool bSuccessfullyReRouted = sal_True; 1658cdf0e10cSrcweir switch (_rValue.getValueTypeClass()) 1659cdf0e10cSrcweir { 1660cdf0e10cSrcweir case TypeClass_HYPER: 1661cdf0e10cSrcweir { 1662cdf0e10cSrcweir sal_Int64 nValue = 0; 1663cdf0e10cSrcweir OSL_VERIFY( _rValue >>= nValue ); 1664cdf0e10cSrcweir _rxParameters->setLong( _nColumnIndex, nValue ); 1665cdf0e10cSrcweir } 1666cdf0e10cSrcweir break; 1667cdf0e10cSrcweir 1668cdf0e10cSrcweir case TypeClass_ANY: 1669cdf0e10cSrcweir { 1670cdf0e10cSrcweir Any aInnerValue; 1671cdf0e10cSrcweir _rValue >>= aInnerValue; 1672cdf0e10cSrcweir bSuccessfullyReRouted = implSetObject(_rxParameters, _nColumnIndex, aInnerValue); 1673cdf0e10cSrcweir } 1674cdf0e10cSrcweir break; 1675cdf0e10cSrcweir 1676cdf0e10cSrcweir case TypeClass_VOID: 1677cdf0e10cSrcweir _rxParameters->setNull(_nColumnIndex,DataType::VARCHAR); 1678cdf0e10cSrcweir break; 1679cdf0e10cSrcweir 1680cdf0e10cSrcweir case TypeClass_STRING: 1681cdf0e10cSrcweir _rxParameters->setString(_nColumnIndex, *(rtl::OUString*)_rValue.getValue()); 1682cdf0e10cSrcweir break; 1683cdf0e10cSrcweir 1684cdf0e10cSrcweir case TypeClass_BOOLEAN: 1685cdf0e10cSrcweir _rxParameters->setBoolean(_nColumnIndex, *(sal_Bool *)_rValue.getValue()); 1686cdf0e10cSrcweir break; 1687cdf0e10cSrcweir 1688cdf0e10cSrcweir case TypeClass_BYTE: 1689cdf0e10cSrcweir _rxParameters->setByte(_nColumnIndex, *(sal_Int8 *)_rValue.getValue()); 1690cdf0e10cSrcweir break; 1691cdf0e10cSrcweir 1692cdf0e10cSrcweir case TypeClass_UNSIGNED_SHORT: 1693cdf0e10cSrcweir case TypeClass_SHORT: 1694cdf0e10cSrcweir _rxParameters->setShort(_nColumnIndex, *(sal_Int16*)_rValue.getValue()); 1695cdf0e10cSrcweir break; 1696cdf0e10cSrcweir 1697cdf0e10cSrcweir case TypeClass_CHAR: 1698cdf0e10cSrcweir _rxParameters->setString(_nColumnIndex, ::rtl::OUString((sal_Unicode *)_rValue.getValue(),1)); 1699cdf0e10cSrcweir break; 1700cdf0e10cSrcweir 1701cdf0e10cSrcweir case TypeClass_UNSIGNED_LONG: 1702cdf0e10cSrcweir case TypeClass_LONG: 1703cdf0e10cSrcweir _rxParameters->setInt(_nColumnIndex, *(sal_Int32*)_rValue.getValue()); 1704cdf0e10cSrcweir break; 1705cdf0e10cSrcweir 1706cdf0e10cSrcweir case TypeClass_FLOAT: 1707cdf0e10cSrcweir _rxParameters->setFloat(_nColumnIndex, *(float*)_rValue.getValue()); 1708cdf0e10cSrcweir break; 1709cdf0e10cSrcweir 1710cdf0e10cSrcweir case TypeClass_DOUBLE: 1711cdf0e10cSrcweir _rxParameters->setDouble(_nColumnIndex, *(double*)_rValue.getValue()); 1712cdf0e10cSrcweir break; 1713cdf0e10cSrcweir 1714cdf0e10cSrcweir case TypeClass_SEQUENCE: 1715cdf0e10cSrcweir if (_rValue.getValueType() == ::getCppuType((const Sequence< sal_Int8 > *)0)) 1716cdf0e10cSrcweir { 1717cdf0e10cSrcweir _rxParameters->setBytes(_nColumnIndex, *(Sequence<sal_Int8>*)_rValue.getValue()); 1718cdf0e10cSrcweir } 1719cdf0e10cSrcweir else 1720cdf0e10cSrcweir bSuccessfullyReRouted = sal_False; 1721cdf0e10cSrcweir break; 1722cdf0e10cSrcweir case TypeClass_STRUCT: 1723cdf0e10cSrcweir if (_rValue.getValueType() == ::getCppuType((const DateTime*)0)) 1724cdf0e10cSrcweir _rxParameters->setTimestamp(_nColumnIndex, *(DateTime*)_rValue.getValue()); 1725cdf0e10cSrcweir else if (_rValue.getValueType() == ::getCppuType((const Date*)0)) 1726cdf0e10cSrcweir _rxParameters->setDate(_nColumnIndex, *(Date*)_rValue.getValue()); 1727cdf0e10cSrcweir else if (_rValue.getValueType() == ::getCppuType((const Time*)0)) 1728cdf0e10cSrcweir _rxParameters->setTime(_nColumnIndex, *(Time*)_rValue.getValue()); 1729cdf0e10cSrcweir else 1730cdf0e10cSrcweir bSuccessfullyReRouted = sal_False; 1731cdf0e10cSrcweir break; 1732cdf0e10cSrcweir 1733cdf0e10cSrcweir case TypeClass_INTERFACE: 1734cdf0e10cSrcweir if (_rValue.getValueType() == ::getCppuType(static_cast<Reference< XInputStream>*>(NULL))) 1735cdf0e10cSrcweir { 1736cdf0e10cSrcweir Reference< XInputStream > xStream; 1737cdf0e10cSrcweir _rValue >>= xStream; 1738cdf0e10cSrcweir _rxParameters->setBinaryStream(_nColumnIndex, xStream, xStream->available()); 1739cdf0e10cSrcweir break; 1740cdf0e10cSrcweir } 1741cdf0e10cSrcweir // run through 1742cdf0e10cSrcweir default: 1743cdf0e10cSrcweir bSuccessfullyReRouted = sal_False; 1744cdf0e10cSrcweir 1745cdf0e10cSrcweir } 1746cdf0e10cSrcweir 1747cdf0e10cSrcweir return bSuccessfullyReRouted; 1748cdf0e10cSrcweir } 1749cdf0e10cSrcweir 1750cdf0e10cSrcweir //.................................................................. 1751cdf0e10cSrcweir namespace 1752cdf0e10cSrcweir { 1753cdf0e10cSrcweir class OParameterWrapper : public ::cppu::WeakImplHelper1< XIndexAccess > 1754cdf0e10cSrcweir { 1755cdf0e10cSrcweir ::std::bit_vector m_aSet; 1756cdf0e10cSrcweir Reference<XIndexAccess> m_xSource; 1757cdf0e10cSrcweir public: 1758cdf0e10cSrcweir OParameterWrapper(const ::std::bit_vector& _aSet,const Reference<XIndexAccess>& _xSource) : m_aSet(_aSet),m_xSource(_xSource){} 1759cdf0e10cSrcweir private: 1760cdf0e10cSrcweir // ::com::sun::star::container::XElementAccess 1761cdf0e10cSrcweir virtual Type SAL_CALL getElementType() throw(RuntimeException) 1762cdf0e10cSrcweir { 1763cdf0e10cSrcweir return m_xSource->getElementType(); 1764cdf0e10cSrcweir } 1765cdf0e10cSrcweir virtual sal_Bool SAL_CALL hasElements( ) throw(RuntimeException) 1766cdf0e10cSrcweir { 1767cdf0e10cSrcweir if ( m_aSet.empty() ) 1768cdf0e10cSrcweir return m_xSource->hasElements(); 1769cdf0e10cSrcweir return ::std::count(m_aSet.begin(),m_aSet.end(),false) != 0; 1770cdf0e10cSrcweir } 1771cdf0e10cSrcweir // ::com::sun::star::container::XIndexAccess 1772cdf0e10cSrcweir virtual sal_Int32 SAL_CALL getCount( ) throw(RuntimeException) 1773cdf0e10cSrcweir { 1774cdf0e10cSrcweir if ( m_aSet.empty() ) 1775cdf0e10cSrcweir return m_xSource->getCount(); 1776cdf0e10cSrcweir return ::std::count(m_aSet.begin(),m_aSet.end(),false); 1777cdf0e10cSrcweir } 1778cdf0e10cSrcweir virtual Any SAL_CALL getByIndex( sal_Int32 Index ) throw(IndexOutOfBoundsException, WrappedTargetException, RuntimeException) 1779cdf0e10cSrcweir { 1780cdf0e10cSrcweir if ( m_aSet.empty() ) 1781cdf0e10cSrcweir return m_xSource->getByIndex(Index); 1782cdf0e10cSrcweir if ( m_aSet.size() < (size_t)Index ) 1783cdf0e10cSrcweir throw IndexOutOfBoundsException(); 1784cdf0e10cSrcweir 1785cdf0e10cSrcweir ::std::bit_vector::iterator aIter = m_aSet.begin(); 1786cdf0e10cSrcweir ::std::bit_vector::iterator aEnd = m_aSet.end(); 1787cdf0e10cSrcweir sal_Int32 i = 0; 1788cdf0e10cSrcweir sal_Int32 nParamPos = -1; 1789cdf0e10cSrcweir for(; aIter != aEnd && i <= Index; ++aIter) 1790cdf0e10cSrcweir { 1791cdf0e10cSrcweir ++nParamPos; 1792cdf0e10cSrcweir if ( !*aIter ) 1793cdf0e10cSrcweir { 1794cdf0e10cSrcweir ++i; 1795cdf0e10cSrcweir } 1796cdf0e10cSrcweir } 1797cdf0e10cSrcweir return m_xSource->getByIndex(nParamPos); 1798cdf0e10cSrcweir } 1799cdf0e10cSrcweir }; 1800cdf0e10cSrcweir } 1801cdf0e10cSrcweir 1802cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1803cdf0e10cSrcweir void askForParameters(const Reference< XSingleSelectQueryComposer >& _xComposer, 1804cdf0e10cSrcweir const Reference<XParameters>& _xParameters, 1805cdf0e10cSrcweir const Reference< XConnection>& _xConnection, 1806cdf0e10cSrcweir const Reference< XInteractionHandler >& _rxHandler, 1807cdf0e10cSrcweir const ::std::bit_vector& _aParametersSet) 1808cdf0e10cSrcweir { 1809cdf0e10cSrcweir OSL_ENSURE(_xComposer.is(),"dbtools::askForParameters XSQLQueryComposer is null!"); 1810cdf0e10cSrcweir OSL_ENSURE(_xParameters.is(),"dbtools::askForParameters XParameters is null!"); 1811cdf0e10cSrcweir OSL_ENSURE(_xConnection.is(),"dbtools::askForParameters XConnection is null!"); 1812cdf0e10cSrcweir OSL_ENSURE(_rxHandler.is(),"dbtools::askForParameters XInteractionHandler is null!"); 1813cdf0e10cSrcweir 1814cdf0e10cSrcweir // we have to set this here again because getCurrentSettingsComposer can force a setpropertyvalue 1815cdf0e10cSrcweir Reference<XParametersSupplier> xParameters = Reference<XParametersSupplier> (_xComposer, UNO_QUERY); 1816cdf0e10cSrcweir 1817cdf0e10cSrcweir Reference<XIndexAccess> xParamsAsIndicies = xParameters.is() ? xParameters->getParameters() : Reference<XIndexAccess>(); 1818cdf0e10cSrcweir Reference<XNameAccess> xParamsAsNames(xParamsAsIndicies, UNO_QUERY); 1819cdf0e10cSrcweir sal_Int32 nParamCount = xParamsAsIndicies.is() ? xParamsAsIndicies->getCount() : 0; 1820cdf0e10cSrcweir ::std::bit_vector aNewParameterSet( _aParametersSet ); 1821cdf0e10cSrcweir if ( nParamCount || ::std::count(aNewParameterSet.begin(),aNewParameterSet.end(),true) != nParamCount ) 1822cdf0e10cSrcweir { 1823cdf0e10cSrcweir static const ::rtl::OUString PROPERTY_NAME(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME)); 1824cdf0e10cSrcweir aNewParameterSet.resize(nParamCount ,false); 1825cdf0e10cSrcweir typedef ::std::map< ::rtl::OUString, ::std::vector<sal_Int32> > TParameterPositions; 1826cdf0e10cSrcweir TParameterPositions aParameterNames; 1827cdf0e10cSrcweir for(sal_Int32 i = 0; i < nParamCount; ++i) 1828cdf0e10cSrcweir { 1829cdf0e10cSrcweir Reference<XPropertySet> xParam(xParamsAsIndicies->getByIndex(i),UNO_QUERY); 1830cdf0e10cSrcweir ::rtl::OUString sName; 1831cdf0e10cSrcweir xParam->getPropertyValue(PROPERTY_NAME) >>= sName; 1832cdf0e10cSrcweir 1833cdf0e10cSrcweir TParameterPositions::iterator aFind = aParameterNames.find(sName); 1834cdf0e10cSrcweir if ( aFind != aParameterNames.end() ) 1835cdf0e10cSrcweir aNewParameterSet[i] = true; 1836cdf0e10cSrcweir aParameterNames[sName].push_back(i+1); 1837cdf0e10cSrcweir } 1838cdf0e10cSrcweir // build an interaction request 1839cdf0e10cSrcweir // two continuations (Ok and Cancel) 1840cdf0e10cSrcweir OInteractionAbort* pAbort = new OInteractionAbort; 1841cdf0e10cSrcweir OParameterContinuation* pParams = new OParameterContinuation; 1842cdf0e10cSrcweir // the request 1843cdf0e10cSrcweir ParametersRequest aRequest; 1844cdf0e10cSrcweir Reference<XIndexAccess> xWrappedParameters = new OParameterWrapper(aNewParameterSet,xParamsAsIndicies); 1845cdf0e10cSrcweir aRequest.Parameters = xWrappedParameters; 1846cdf0e10cSrcweir aRequest.Connection = _xConnection; 1847cdf0e10cSrcweir OInteractionRequest* pRequest = new OInteractionRequest(makeAny(aRequest)); 1848cdf0e10cSrcweir Reference< XInteractionRequest > xRequest(pRequest); 1849cdf0e10cSrcweir // some knittings 1850cdf0e10cSrcweir pRequest->addContinuation(pAbort); 1851cdf0e10cSrcweir pRequest->addContinuation(pParams); 1852cdf0e10cSrcweir 1853cdf0e10cSrcweir // execute the request 1854cdf0e10cSrcweir _rxHandler->handle(xRequest); 1855cdf0e10cSrcweir 1856cdf0e10cSrcweir if (!pParams->wasSelected()) 1857cdf0e10cSrcweir { 1858cdf0e10cSrcweir // canceled by the user (i.e. (s)he canceled the dialog) 1859cdf0e10cSrcweir RowSetVetoException e; 1860cdf0e10cSrcweir e.ErrorCode = ParameterInteractionCancelled; 1861cdf0e10cSrcweir throw e; 1862cdf0e10cSrcweir } 1863cdf0e10cSrcweir 1864cdf0e10cSrcweir // now transfer the values from the continuation object to the parameter columns 1865cdf0e10cSrcweir Sequence< PropertyValue > aFinalValues = pParams->getValues(); 1866cdf0e10cSrcweir const PropertyValue* pFinalValues = aFinalValues.getConstArray(); 1867cdf0e10cSrcweir for (sal_Int32 i=0; i<aFinalValues.getLength(); ++i, ++pFinalValues) 1868cdf0e10cSrcweir { 1869cdf0e10cSrcweir Reference< XPropertySet > xParamColumn(xWrappedParameters->getByIndex(i),UNO_QUERY); 1870cdf0e10cSrcweir if (xParamColumn.is()) 1871cdf0e10cSrcweir { 1872cdf0e10cSrcweir ::rtl::OUString sName; 1873cdf0e10cSrcweir xParamColumn->getPropertyValue(PROPERTY_NAME) >>= sName; 1874cdf0e10cSrcweir OSL_ENSURE(sName.equals(pFinalValues->Name), "::dbaui::askForParameters: inconsistent parameter names!"); 1875cdf0e10cSrcweir 1876cdf0e10cSrcweir // determine the field type and ... 1877cdf0e10cSrcweir sal_Int32 nParamType = 0; 1878cdf0e10cSrcweir xParamColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE)) >>= nParamType; 1879cdf0e10cSrcweir // ... the scale of the parameter column 1880cdf0e10cSrcweir sal_Int32 nScale = 0; 1881cdf0e10cSrcweir if (hasProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE), xParamColumn)) 1882cdf0e10cSrcweir xParamColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE)) >>= nScale; 1883cdf0e10cSrcweir // (the index of the parameters is one-based) 1884cdf0e10cSrcweir TParameterPositions::iterator aFind = aParameterNames.find(pFinalValues->Name); 1885cdf0e10cSrcweir ::std::vector<sal_Int32>::iterator aIterPos = aFind->second.begin(); 1886cdf0e10cSrcweir ::std::vector<sal_Int32>::iterator aEndPos = aFind->second.end(); 1887cdf0e10cSrcweir for(;aIterPos != aEndPos;++aIterPos) 1888cdf0e10cSrcweir { 1889cdf0e10cSrcweir if ( _aParametersSet.empty() || !_aParametersSet[(*aIterPos)-1] ) 1890cdf0e10cSrcweir { 1891cdf0e10cSrcweir _xParameters->setObjectWithInfo(*aIterPos, pFinalValues->Value, nParamType, nScale); 1892cdf0e10cSrcweir } 1893cdf0e10cSrcweir } 1894cdf0e10cSrcweir } 1895cdf0e10cSrcweir } 1896cdf0e10cSrcweir } 1897cdf0e10cSrcweir } 1898cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1899cdf0e10cSrcweir void setObjectWithInfo(const Reference<XParameters>& _xParams, 1900cdf0e10cSrcweir sal_Int32 parameterIndex, 1901cdf0e10cSrcweir const Any& x, 1902cdf0e10cSrcweir sal_Int32 sqlType, 1903cdf0e10cSrcweir sal_Int32 scale) throw(SQLException, RuntimeException) 1904cdf0e10cSrcweir { 1905cdf0e10cSrcweir ORowSetValue aVal; 1906cdf0e10cSrcweir aVal.fill(x); 1907cdf0e10cSrcweir setObjectWithInfo(_xParams,parameterIndex,aVal,sqlType,scale); 1908cdf0e10cSrcweir } 1909cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1910cdf0e10cSrcweir void setObjectWithInfo(const Reference<XParameters>& _xParams, 1911cdf0e10cSrcweir sal_Int32 parameterIndex, 1912cdf0e10cSrcweir const ::connectivity::ORowSetValue& _rValue, 1913cdf0e10cSrcweir sal_Int32 sqlType, 1914cdf0e10cSrcweir sal_Int32 scale) throw(SQLException, RuntimeException) 1915cdf0e10cSrcweir { 1916cdf0e10cSrcweir if ( _rValue.isNull() ) 1917cdf0e10cSrcweir _xParams->setNull(parameterIndex,sqlType); 1918cdf0e10cSrcweir else 1919cdf0e10cSrcweir { 1920cdf0e10cSrcweir switch(sqlType) 1921cdf0e10cSrcweir { 1922cdf0e10cSrcweir case DataType::DECIMAL: 1923cdf0e10cSrcweir case DataType::NUMERIC: 1924cdf0e10cSrcweir _xParams->setObjectWithInfo(parameterIndex,_rValue.makeAny(),sqlType,scale); 1925cdf0e10cSrcweir break; 1926cdf0e10cSrcweir case DataType::CHAR: 1927cdf0e10cSrcweir case DataType::VARCHAR: 1928cdf0e10cSrcweir case DataType::LONGVARCHAR: 1929cdf0e10cSrcweir _xParams->setString(parameterIndex,_rValue); 1930cdf0e10cSrcweir break; 1931cdf0e10cSrcweir case DataType::CLOB: 1932cdf0e10cSrcweir { 1933cdf0e10cSrcweir Any x(_rValue.makeAny()); 1934cdf0e10cSrcweir ::rtl::OUString sValue; 1935cdf0e10cSrcweir if ( x >>= sValue ) 1936cdf0e10cSrcweir _xParams->setString(parameterIndex,sValue); 1937cdf0e10cSrcweir else 1938cdf0e10cSrcweir { 1939cdf0e10cSrcweir Reference< XClob > xClob; 1940cdf0e10cSrcweir if(x >>= xClob) 1941cdf0e10cSrcweir _xParams->setClob(parameterIndex,xClob); 1942cdf0e10cSrcweir else 1943cdf0e10cSrcweir { 1944cdf0e10cSrcweir Reference< ::com::sun::star::io::XInputStream > xStream; 1945cdf0e10cSrcweir if(x >>= xStream) 1946cdf0e10cSrcweir _xParams->setCharacterStream(parameterIndex,xStream,xStream->available()); 1947cdf0e10cSrcweir } 1948cdf0e10cSrcweir } 1949cdf0e10cSrcweir } 1950cdf0e10cSrcweir break; 1951cdf0e10cSrcweir case DataType::BIGINT: 1952cdf0e10cSrcweir if ( _rValue.isSigned() ) 1953cdf0e10cSrcweir _xParams->setLong(parameterIndex,_rValue); 1954cdf0e10cSrcweir else 1955cdf0e10cSrcweir _xParams->setString(parameterIndex,_rValue); 1956cdf0e10cSrcweir break; 1957cdf0e10cSrcweir 1958cdf0e10cSrcweir case DataType::FLOAT: 1959cdf0e10cSrcweir _xParams->setFloat(parameterIndex,_rValue); 1960cdf0e10cSrcweir break; 1961cdf0e10cSrcweir case DataType::REAL: 1962cdf0e10cSrcweir case DataType::DOUBLE: 1963cdf0e10cSrcweir _xParams->setDouble(parameterIndex,_rValue); 1964cdf0e10cSrcweir break; 1965cdf0e10cSrcweir case DataType::DATE: 1966cdf0e10cSrcweir _xParams->setDate(parameterIndex,_rValue); 1967cdf0e10cSrcweir break; 1968cdf0e10cSrcweir case DataType::TIME: 1969cdf0e10cSrcweir _xParams->setTime(parameterIndex,_rValue); 1970cdf0e10cSrcweir break; 1971cdf0e10cSrcweir case DataType::TIMESTAMP: 1972cdf0e10cSrcweir _xParams->setTimestamp(parameterIndex,_rValue); 1973cdf0e10cSrcweir break; 1974cdf0e10cSrcweir case DataType::BINARY: 1975cdf0e10cSrcweir case DataType::VARBINARY: 1976cdf0e10cSrcweir case DataType::LONGVARBINARY: 1977cdf0e10cSrcweir case DataType::BLOB: 1978cdf0e10cSrcweir { 1979cdf0e10cSrcweir Any x(_rValue.makeAny()); 1980cdf0e10cSrcweir Sequence< sal_Int8> aBytes; 1981cdf0e10cSrcweir if(x >>= aBytes) 1982cdf0e10cSrcweir _xParams->setBytes(parameterIndex,aBytes); 1983cdf0e10cSrcweir else 1984cdf0e10cSrcweir { 1985cdf0e10cSrcweir Reference< XBlob > xBlob; 1986cdf0e10cSrcweir if(x >>= xBlob) 1987cdf0e10cSrcweir _xParams->setBlob(parameterIndex,xBlob); 1988cdf0e10cSrcweir else 1989cdf0e10cSrcweir { 1990cdf0e10cSrcweir Reference< XClob > xClob; 1991cdf0e10cSrcweir if(x >>= xClob) 1992cdf0e10cSrcweir _xParams->setClob(parameterIndex,xClob); 1993cdf0e10cSrcweir else 1994cdf0e10cSrcweir { 1995cdf0e10cSrcweir Reference< ::com::sun::star::io::XInputStream > xBinStream; 1996cdf0e10cSrcweir if(x >>= xBinStream) 1997cdf0e10cSrcweir _xParams->setBinaryStream(parameterIndex,xBinStream,xBinStream->available()); 1998cdf0e10cSrcweir } 1999cdf0e10cSrcweir } 2000cdf0e10cSrcweir } 2001cdf0e10cSrcweir } 2002cdf0e10cSrcweir break; 2003cdf0e10cSrcweir case DataType::BIT: 2004cdf0e10cSrcweir case DataType::BOOLEAN: 2005cdf0e10cSrcweir _xParams->setBoolean(parameterIndex,_rValue); 2006cdf0e10cSrcweir break; 2007cdf0e10cSrcweir case DataType::TINYINT: 2008cdf0e10cSrcweir if ( _rValue.isSigned() ) 2009cdf0e10cSrcweir _xParams->setByte(parameterIndex,_rValue); 2010cdf0e10cSrcweir else 2011cdf0e10cSrcweir _xParams->setShort(parameterIndex,_rValue); 2012cdf0e10cSrcweir break; 2013cdf0e10cSrcweir case DataType::SMALLINT: 2014cdf0e10cSrcweir if ( _rValue.isSigned() ) 2015cdf0e10cSrcweir _xParams->setShort(parameterIndex,_rValue); 2016cdf0e10cSrcweir else 2017cdf0e10cSrcweir _xParams->setInt(parameterIndex,_rValue); 2018cdf0e10cSrcweir break; 2019cdf0e10cSrcweir case DataType::INTEGER: 2020cdf0e10cSrcweir if ( _rValue.isSigned() ) 2021cdf0e10cSrcweir _xParams->setInt(parameterIndex,_rValue); 2022cdf0e10cSrcweir else 2023cdf0e10cSrcweir _xParams->setLong(parameterIndex,_rValue); 2024cdf0e10cSrcweir break; 2025cdf0e10cSrcweir default: 2026cdf0e10cSrcweir { 2027cdf0e10cSrcweir ::connectivity::SharedResources aResources; 2028cdf0e10cSrcweir const ::rtl::OUString sError( aResources.getResourceStringWithSubstitution( 2029cdf0e10cSrcweir STR_UNKNOWN_PARA_TYPE, 2030cdf0e10cSrcweir "$position$", ::rtl::OUString::valueOf(parameterIndex) 2031cdf0e10cSrcweir ) ); 2032cdf0e10cSrcweir ::dbtools::throwGenericSQLException(sError,NULL); 2033cdf0e10cSrcweir } 2034cdf0e10cSrcweir } 2035cdf0e10cSrcweir } 2036cdf0e10cSrcweir } 2037cdf0e10cSrcweir 2038cdf0e10cSrcweir // -------------------------------------------------------------------- 2039cdf0e10cSrcweir void getBoleanComparisonPredicate( const ::rtl::OUString& _rExpression, const sal_Bool _bValue, const sal_Int32 _nBooleanComparisonMode, 2040cdf0e10cSrcweir ::rtl::OUStringBuffer& _out_rSQLPredicate ) 2041cdf0e10cSrcweir { 2042cdf0e10cSrcweir switch ( _nBooleanComparisonMode ) 2043cdf0e10cSrcweir { 2044cdf0e10cSrcweir case BooleanComparisonMode::IS_LITERAL: 2045cdf0e10cSrcweir _out_rSQLPredicate.append( _rExpression ); 2046cdf0e10cSrcweir if ( _bValue ) 2047cdf0e10cSrcweir _out_rSQLPredicate.appendAscii( " IS TRUE" ); 2048cdf0e10cSrcweir else 2049cdf0e10cSrcweir _out_rSQLPredicate.appendAscii( " IS FALSE" ); 2050cdf0e10cSrcweir break; 2051cdf0e10cSrcweir 2052cdf0e10cSrcweir case BooleanComparisonMode::EQUAL_LITERAL: 2053cdf0e10cSrcweir _out_rSQLPredicate.append( _rExpression ); 2054cdf0e10cSrcweir _out_rSQLPredicate.appendAscii( _bValue ? " = TRUE" : " = FALSE" ); 2055cdf0e10cSrcweir break; 2056cdf0e10cSrcweir 2057cdf0e10cSrcweir case BooleanComparisonMode::ACCESS_COMPAT: 2058cdf0e10cSrcweir if ( _bValue ) 2059cdf0e10cSrcweir { 2060cdf0e10cSrcweir _out_rSQLPredicate.appendAscii( " NOT ( ( " ); 2061cdf0e10cSrcweir _out_rSQLPredicate.append( _rExpression ); 2062cdf0e10cSrcweir _out_rSQLPredicate.appendAscii( " = 0 ) OR ( " ); 2063cdf0e10cSrcweir _out_rSQLPredicate.append( _rExpression ); 2064cdf0e10cSrcweir _out_rSQLPredicate.appendAscii( " IS NULL ) )" ); 2065cdf0e10cSrcweir } 2066cdf0e10cSrcweir else 2067cdf0e10cSrcweir { 2068cdf0e10cSrcweir _out_rSQLPredicate.append( _rExpression ); 2069cdf0e10cSrcweir _out_rSQLPredicate.appendAscii( " = 0" ); 2070cdf0e10cSrcweir } 2071cdf0e10cSrcweir break; 2072cdf0e10cSrcweir 2073cdf0e10cSrcweir case BooleanComparisonMode::EQUAL_INTEGER: 2074cdf0e10cSrcweir // fall through 2075cdf0e10cSrcweir default: 2076cdf0e10cSrcweir _out_rSQLPredicate.append( _rExpression ); 2077cdf0e10cSrcweir _out_rSQLPredicate.appendAscii( _bValue ? " = 1" : " = 0" ); 2078cdf0e10cSrcweir break; 2079cdf0e10cSrcweir } 2080cdf0e10cSrcweir } 2081cdf0e10cSrcweir 2082cdf0e10cSrcweir //......................................................................... 2083cdf0e10cSrcweir } // namespace dbtools 2084cdf0e10cSrcweir //......................................................................... 2085cdf0e10cSrcweir 2086cdf0e10cSrcweir //......................................................................... 2087cdf0e10cSrcweir namespace connectivity 2088cdf0e10cSrcweir { 2089cdf0e10cSrcweir //......................................................................... 2090cdf0e10cSrcweir 2091cdf0e10cSrcweir void release(oslInterlockedCount& _refCount, 2092cdf0e10cSrcweir ::cppu::OBroadcastHelper& rBHelper, 2093cdf0e10cSrcweir Reference< XInterface >& _xInterface, 2094cdf0e10cSrcweir ::com::sun::star::lang::XComponent* _pObject) 2095cdf0e10cSrcweir { 2096cdf0e10cSrcweir if (osl_decrementInterlockedCount( &_refCount ) == 0) 2097cdf0e10cSrcweir { 2098cdf0e10cSrcweir osl_incrementInterlockedCount( &_refCount ); 2099cdf0e10cSrcweir 2100cdf0e10cSrcweir if (!rBHelper.bDisposed && !rBHelper.bInDispose) 2101cdf0e10cSrcweir { 2102cdf0e10cSrcweir // remember the parent 2103cdf0e10cSrcweir Reference< XInterface > xParent; 2104cdf0e10cSrcweir { 2105cdf0e10cSrcweir ::osl::MutexGuard aGuard( rBHelper.rMutex ); 2106cdf0e10cSrcweir xParent = _xInterface; 2107cdf0e10cSrcweir _xInterface = NULL; 2108cdf0e10cSrcweir } 2109cdf0e10cSrcweir 2110cdf0e10cSrcweir // First dispose 2111cdf0e10cSrcweir _pObject->dispose(); 2112cdf0e10cSrcweir 2113cdf0e10cSrcweir // only the alive ref holds the object 2114cdf0e10cSrcweir OSL_ASSERT( _refCount == 1 ); 2115cdf0e10cSrcweir 2116cdf0e10cSrcweir // release the parent in the ~ 2117cdf0e10cSrcweir if (xParent.is()) 2118cdf0e10cSrcweir { 2119cdf0e10cSrcweir ::osl::MutexGuard aGuard( rBHelper.rMutex ); 2120cdf0e10cSrcweir _xInterface = xParent; 2121cdf0e10cSrcweir } 2122cdf0e10cSrcweir 2123cdf0e10cSrcweir // // destroy the object if xHoldAlive decrement the refcount to 0 2124cdf0e10cSrcweir // m_pDerivedImplementation->WEAK::release(); 2125cdf0e10cSrcweir } 2126cdf0e10cSrcweir } 2127cdf0e10cSrcweir else 2128cdf0e10cSrcweir osl_incrementInterlockedCount( &_refCount ); 2129cdf0e10cSrcweir } 2130cdf0e10cSrcweir 2131cdf0e10cSrcweir void checkDisposed(sal_Bool _bThrow) throw ( DisposedException ) 2132cdf0e10cSrcweir { 2133cdf0e10cSrcweir if (_bThrow) 2134cdf0e10cSrcweir throw DisposedException(); 2135cdf0e10cSrcweir 2136cdf0e10cSrcweir } 2137cdf0e10cSrcweir // ------------------------------------------------------------------------- 2138cdf0e10cSrcweir OSQLColumns::Vector::const_iterator find( OSQLColumns::Vector::const_iterator __first, 2139cdf0e10cSrcweir OSQLColumns::Vector::const_iterator __last, 2140cdf0e10cSrcweir const ::rtl::OUString& _rVal, 2141cdf0e10cSrcweir const ::comphelper::UStringMixEqual& _rCase) 2142cdf0e10cSrcweir { 2143cdf0e10cSrcweir ::rtl::OUString sName = OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME); 2144cdf0e10cSrcweir return find(__first,__last,sName,_rVal,_rCase); 2145cdf0e10cSrcweir } 2146cdf0e10cSrcweir // ------------------------------------------------------------------------- 2147cdf0e10cSrcweir OSQLColumns::Vector::const_iterator findRealName( OSQLColumns::Vector::const_iterator __first, 2148cdf0e10cSrcweir OSQLColumns::Vector::const_iterator __last, 2149cdf0e10cSrcweir const ::rtl::OUString& _rVal, 2150cdf0e10cSrcweir const ::comphelper::UStringMixEqual& _rCase) 2151cdf0e10cSrcweir { 2152cdf0e10cSrcweir ::rtl::OUString sRealName = OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_REALNAME); 2153cdf0e10cSrcweir return find(__first,__last,sRealName,_rVal,_rCase); 2154cdf0e10cSrcweir } 2155cdf0e10cSrcweir // ------------------------------------------------------------------------- 2156cdf0e10cSrcweir OSQLColumns::Vector::const_iterator find( OSQLColumns::Vector::const_iterator __first, 2157cdf0e10cSrcweir OSQLColumns::Vector::const_iterator __last, 2158cdf0e10cSrcweir const ::rtl::OUString& _rProp, 2159cdf0e10cSrcweir const ::rtl::OUString& _rVal, 2160cdf0e10cSrcweir const ::comphelper::UStringMixEqual& _rCase) 2161cdf0e10cSrcweir { 2162cdf0e10cSrcweir while (__first != __last && !_rCase(getString((*__first)->getPropertyValue(_rProp)),_rVal)) 2163cdf0e10cSrcweir ++__first; 2164cdf0e10cSrcweir return __first; 2165cdf0e10cSrcweir } 2166cdf0e10cSrcweir 2167cdf0e10cSrcweir // ----------------------------------------------------------------------------- 2168cdf0e10cSrcweir } //namespace connectivity 2169cdf0e10cSrcweir // ----------------------------------------------------------------------------- 2170cdf0e10cSrcweir 2171