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