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 #include "file/FDriver.hxx" 31*cdf0e10cSrcweir #include "file/FConnection.hxx" 32*cdf0e10cSrcweir #include "file/fcode.hxx" 33*cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp> 34*cdf0e10cSrcweir #include <comphelper/types.hxx> 35*cdf0e10cSrcweir #include "connectivity/dbexception.hxx" 36*cdf0e10cSrcweir #include "resource/common_res.hrc" 37*cdf0e10cSrcweir #include "resource/sharedresources.hxx" 38*cdf0e10cSrcweir #include <rtl/logfile.hxx> 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir using namespace connectivity::file; 42*cdf0e10cSrcweir using namespace com::sun::star::uno; 43*cdf0e10cSrcweir using namespace com::sun::star::lang; 44*cdf0e10cSrcweir using namespace com::sun::star::beans; 45*cdf0e10cSrcweir using namespace com::sun::star::sdbc; 46*cdf0e10cSrcweir using namespace com::sun::star::sdbcx; 47*cdf0e10cSrcweir using namespace com::sun::star::container; 48*cdf0e10cSrcweir // -------------------------------------------------------------------------------- 49*cdf0e10cSrcweir OFileDriver::OFileDriver(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory) 50*cdf0e10cSrcweir : ODriver_BASE(m_aMutex) 51*cdf0e10cSrcweir ,m_xFactory(_rxFactory) 52*cdf0e10cSrcweir { 53*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OFileDriver::OFileDriver" ); 54*cdf0e10cSrcweir } 55*cdf0e10cSrcweir // -------------------------------------------------------------------------------- 56*cdf0e10cSrcweir void OFileDriver::disposing() 57*cdf0e10cSrcweir { 58*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OFileDriver::disposing" ); 59*cdf0e10cSrcweir ::osl::MutexGuard aGuard(m_aMutex); 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir for (OWeakRefArray::iterator i = m_xConnections.begin(); m_xConnections.end() != i; ++i) 63*cdf0e10cSrcweir { 64*cdf0e10cSrcweir Reference< XComponent > xComp(i->get(), UNO_QUERY); 65*cdf0e10cSrcweir if (xComp.is()) 66*cdf0e10cSrcweir xComp->dispose(); 67*cdf0e10cSrcweir } 68*cdf0e10cSrcweir m_xConnections.clear(); 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir ODriver_BASE::disposing(); 71*cdf0e10cSrcweir } 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir // static ServiceInfo 74*cdf0e10cSrcweir //------------------------------------------------------------------------------ 75*cdf0e10cSrcweir rtl::OUString OFileDriver::getImplementationName_Static( ) throw(RuntimeException) 76*cdf0e10cSrcweir { 77*cdf0e10cSrcweir return rtl::OUString::createFromAscii("com.sun.star.sdbc.driver.file.Driver"); 78*cdf0e10cSrcweir } 79*cdf0e10cSrcweir //------------------------------------------------------------------------------ 80*cdf0e10cSrcweir Sequence< ::rtl::OUString > OFileDriver::getSupportedServiceNames_Static( ) throw (RuntimeException) 81*cdf0e10cSrcweir { 82*cdf0e10cSrcweir Sequence< ::rtl::OUString > aSNS( 2 ); 83*cdf0e10cSrcweir aSNS[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbc.Driver"); 84*cdf0e10cSrcweir aSNS[1] = ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.Driver"); 85*cdf0e10cSrcweir return aSNS; 86*cdf0e10cSrcweir } 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir //------------------------------------------------------------------ 89*cdf0e10cSrcweir ::rtl::OUString SAL_CALL OFileDriver::getImplementationName( ) throw(RuntimeException) 90*cdf0e10cSrcweir { 91*cdf0e10cSrcweir return getImplementationName_Static(); 92*cdf0e10cSrcweir } 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir //------------------------------------------------------------------ 95*cdf0e10cSrcweir sal_Bool SAL_CALL OFileDriver::supportsService( const ::rtl::OUString& _rServiceName ) throw(RuntimeException) 96*cdf0e10cSrcweir { 97*cdf0e10cSrcweir Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames()); 98*cdf0e10cSrcweir const ::rtl::OUString* pSupported = aSupported.getConstArray(); 99*cdf0e10cSrcweir const ::rtl::OUString* pEnd = pSupported + aSupported.getLength(); 100*cdf0e10cSrcweir for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported) 101*cdf0e10cSrcweir ; 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir return pSupported != pEnd; 104*cdf0e10cSrcweir } 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir //------------------------------------------------------------------ 107*cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL OFileDriver::getSupportedServiceNames( ) throw(RuntimeException) 108*cdf0e10cSrcweir { 109*cdf0e10cSrcweir return getSupportedServiceNames_Static(); 110*cdf0e10cSrcweir } 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir // -------------------------------------------------------------------------------- 113*cdf0e10cSrcweir Reference< XConnection > SAL_CALL OFileDriver::connect( const ::rtl::OUString& url, const Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException) 114*cdf0e10cSrcweir { 115*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OFileDriver::connect" ); 116*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 117*cdf0e10cSrcweir checkDisposed(ODriver_BASE::rBHelper.bDisposed); 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir OConnection* pCon = new OConnection(this); 120*cdf0e10cSrcweir Reference< XConnection > xCon = pCon; 121*cdf0e10cSrcweir pCon->construct(url,info); 122*cdf0e10cSrcweir m_xConnections.push_back(WeakReferenceHelper(*pCon)); 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir return xCon; 125*cdf0e10cSrcweir } 126*cdf0e10cSrcweir // -------------------------------------------------------------------------------- 127*cdf0e10cSrcweir sal_Bool SAL_CALL OFileDriver::acceptsURL( const ::rtl::OUString& url ) 128*cdf0e10cSrcweir throw(SQLException, RuntimeException) 129*cdf0e10cSrcweir { 130*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OFileDriver::acceptsURL" ); 131*cdf0e10cSrcweir return (!url.compareTo(::rtl::OUString::createFromAscii("sdbc:file:"),10)); 132*cdf0e10cSrcweir } 133*cdf0e10cSrcweir // -------------------------------------------------------------------------------- 134*cdf0e10cSrcweir Sequence< DriverPropertyInfo > SAL_CALL OFileDriver::getPropertyInfo( const ::rtl::OUString& url, const Sequence< PropertyValue >& /*info*/ ) throw(SQLException, RuntimeException) 135*cdf0e10cSrcweir { 136*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OFileDriver::getPropertyInfo" ); 137*cdf0e10cSrcweir if ( acceptsURL(url) ) 138*cdf0e10cSrcweir { 139*cdf0e10cSrcweir ::std::vector< DriverPropertyInfo > aDriverInfo; 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir Sequence< ::rtl::OUString > aBoolean(2); 142*cdf0e10cSrcweir aBoolean[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("0")); 143*cdf0e10cSrcweir aBoolean[1] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("1")); 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir aDriverInfo.push_back(DriverPropertyInfo( 146*cdf0e10cSrcweir ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CharSet")) 147*cdf0e10cSrcweir ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CharSet of the database.")) 148*cdf0e10cSrcweir ,sal_False 149*cdf0e10cSrcweir ,::rtl::OUString() 150*cdf0e10cSrcweir ,Sequence< ::rtl::OUString >()) 151*cdf0e10cSrcweir ); 152*cdf0e10cSrcweir aDriverInfo.push_back(DriverPropertyInfo( 153*cdf0e10cSrcweir ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Extension")) 154*cdf0e10cSrcweir ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Extension of the file format.")) 155*cdf0e10cSrcweir ,sal_False 156*cdf0e10cSrcweir ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".*")) 157*cdf0e10cSrcweir ,Sequence< ::rtl::OUString >()) 158*cdf0e10cSrcweir ); 159*cdf0e10cSrcweir aDriverInfo.push_back(DriverPropertyInfo( 160*cdf0e10cSrcweir ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ShowDeleted")) 161*cdf0e10cSrcweir ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Display inactive records.")) 162*cdf0e10cSrcweir ,sal_False 163*cdf0e10cSrcweir ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("0")) 164*cdf0e10cSrcweir ,aBoolean) 165*cdf0e10cSrcweir ); 166*cdf0e10cSrcweir aDriverInfo.push_back(DriverPropertyInfo( 167*cdf0e10cSrcweir ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("EnableSQL92Check")) 168*cdf0e10cSrcweir ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Use SQL92 naming constraints.")) 169*cdf0e10cSrcweir ,sal_False 170*cdf0e10cSrcweir ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("0")) 171*cdf0e10cSrcweir ,aBoolean) 172*cdf0e10cSrcweir ); 173*cdf0e10cSrcweir aDriverInfo.push_back(DriverPropertyInfo( 174*cdf0e10cSrcweir ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("UseRelativePath")) 175*cdf0e10cSrcweir ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Handle the connection url as relative path.")) 176*cdf0e10cSrcweir ,sal_False 177*cdf0e10cSrcweir ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("0")) 178*cdf0e10cSrcweir ,aBoolean) 179*cdf0e10cSrcweir ); 180*cdf0e10cSrcweir aDriverInfo.push_back(DriverPropertyInfo( 181*cdf0e10cSrcweir ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("URL")) 182*cdf0e10cSrcweir ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("The URL of the database document which is used to create an absolute path.")) 183*cdf0e10cSrcweir ,sal_False 184*cdf0e10cSrcweir ,::rtl::OUString() 185*cdf0e10cSrcweir ,Sequence< ::rtl::OUString >()) 186*cdf0e10cSrcweir ); 187*cdf0e10cSrcweir return Sequence< DriverPropertyInfo >(&(aDriverInfo[0]),aDriverInfo.size()); 188*cdf0e10cSrcweir } // if ( acceptsURL(url) ) 189*cdf0e10cSrcweir { 190*cdf0e10cSrcweir ::connectivity::SharedResources aResources; 191*cdf0e10cSrcweir const ::rtl::OUString sMessage = aResources.getResourceString(STR_URI_SYNTAX_ERROR); 192*cdf0e10cSrcweir ::dbtools::throwGenericSQLException(sMessage ,*this); 193*cdf0e10cSrcweir } // if ( ! acceptsURL(url) ) 194*cdf0e10cSrcweir return Sequence< DriverPropertyInfo >(); 195*cdf0e10cSrcweir } 196*cdf0e10cSrcweir // -------------------------------------------------------------------------------- 197*cdf0e10cSrcweir sal_Int32 SAL_CALL OFileDriver::getMajorVersion( ) throw(RuntimeException) 198*cdf0e10cSrcweir { 199*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OFileDriver::getMajorVersion" ); 200*cdf0e10cSrcweir return 1; 201*cdf0e10cSrcweir } 202*cdf0e10cSrcweir // -------------------------------------------------------------------------------- 203*cdf0e10cSrcweir sal_Int32 SAL_CALL OFileDriver::getMinorVersion( ) throw(RuntimeException) 204*cdf0e10cSrcweir { 205*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OFileDriver::getMinorVersion" ); 206*cdf0e10cSrcweir return 0; 207*cdf0e10cSrcweir } 208*cdf0e10cSrcweir // -------------------------------------------------------------------------------- 209*cdf0e10cSrcweir // -------------------------------------------------------------------------------- 210*cdf0e10cSrcweir // XDataDefinitionSupplier 211*cdf0e10cSrcweir Reference< XTablesSupplier > SAL_CALL OFileDriver::getDataDefinitionByConnection( const Reference< ::com::sun::star::sdbc::XConnection >& connection ) throw(::com::sun::star::sdbc::SQLException, RuntimeException) 212*cdf0e10cSrcweir { 213*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OFileDriver::getDataDefinitionByConnection" ); 214*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 215*cdf0e10cSrcweir checkDisposed(ODriver_BASE::rBHelper.bDisposed); 216*cdf0e10cSrcweir 217*cdf0e10cSrcweir Reference< XTablesSupplier > xTab = NULL; 218*cdf0e10cSrcweir Reference< ::com::sun::star::lang::XUnoTunnel> xTunnel(connection,UNO_QUERY); 219*cdf0e10cSrcweir if(xTunnel.is()) 220*cdf0e10cSrcweir { 221*cdf0e10cSrcweir OConnection* pSearchConnection = reinterpret_cast< OConnection* >( xTunnel->getSomething(OConnection::getUnoTunnelImplementationId()) ); 222*cdf0e10cSrcweir OConnection* pConnection = NULL; 223*cdf0e10cSrcweir for (OWeakRefArray::iterator i = m_xConnections.begin(); m_xConnections.end() != i; ++i) 224*cdf0e10cSrcweir { 225*cdf0e10cSrcweir if ((OConnection*) Reference< XConnection >::query(i->get().get()).get() == pSearchConnection) 226*cdf0e10cSrcweir { 227*cdf0e10cSrcweir pConnection = pSearchConnection; 228*cdf0e10cSrcweir break; 229*cdf0e10cSrcweir } 230*cdf0e10cSrcweir } 231*cdf0e10cSrcweir 232*cdf0e10cSrcweir if(pConnection) 233*cdf0e10cSrcweir xTab = pConnection->createCatalog(); 234*cdf0e10cSrcweir } 235*cdf0e10cSrcweir return xTab; 236*cdf0e10cSrcweir } 237*cdf0e10cSrcweir 238*cdf0e10cSrcweir // -------------------------------------------------------------------------------- 239*cdf0e10cSrcweir Reference< XTablesSupplier > SAL_CALL OFileDriver::getDataDefinitionByURL( const ::rtl::OUString& url, const Sequence< PropertyValue >& info ) throw(::com::sun::star::sdbc::SQLException, RuntimeException) 240*cdf0e10cSrcweir { 241*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OFileDriver::getDataDefinitionByURL" ); 242*cdf0e10cSrcweir if ( ! acceptsURL(url) ) 243*cdf0e10cSrcweir { 244*cdf0e10cSrcweir ::connectivity::SharedResources aResources; 245*cdf0e10cSrcweir const ::rtl::OUString sMessage = aResources.getResourceString(STR_URI_SYNTAX_ERROR); 246*cdf0e10cSrcweir ::dbtools::throwGenericSQLException(sMessage ,*this); 247*cdf0e10cSrcweir } 248*cdf0e10cSrcweir return getDataDefinitionByConnection(connect(url,info)); 249*cdf0e10cSrcweir } 250*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 251*cdf0e10cSrcweir void OOperandParam::describe(const Reference< XPropertySet>& rColumn, ::vos::ORef<connectivity::OSQLColumns> rParameterColumns) 252*cdf0e10cSrcweir { 253*cdf0e10cSrcweir // den alten namen beibehalten 254*cdf0e10cSrcweir 255*cdf0e10cSrcweir OSL_ENSURE(getRowPos() < rParameterColumns->get().size(),"Invalid index for orderkey values!"); 256*cdf0e10cSrcweir 257*cdf0e10cSrcweir Reference< XPropertySet> xColumn = (rParameterColumns->get())[getRowPos()]; 258*cdf0e10cSrcweir 259*cdf0e10cSrcweir try 260*cdf0e10cSrcweir { 261*cdf0e10cSrcweir xColumn->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME),rColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME))); 262*cdf0e10cSrcweir xColumn->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DEFAULTVALUE),rColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DEFAULTVALUE))); 263*cdf0e10cSrcweir xColumn->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRECISION),rColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRECISION))); 264*cdf0e10cSrcweir xColumn->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE),rColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE))); 265*cdf0e10cSrcweir xColumn->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE),rColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE))); 266*cdf0e10cSrcweir xColumn->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISNULLABLE),rColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISNULLABLE))); 267*cdf0e10cSrcweir xColumn->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISAUTOINCREMENT),rColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISAUTOINCREMENT))); 268*cdf0e10cSrcweir } 269*cdf0e10cSrcweir catch(const Exception&) 270*cdf0e10cSrcweir { 271*cdf0e10cSrcweir } 272*cdf0e10cSrcweir 273*cdf0e10cSrcweir m_eDBType = ::comphelper::getINT32(rColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE))); 274*cdf0e10cSrcweir } 275*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 276*cdf0e10cSrcweir OOperandAttr::OOperandAttr(sal_uInt16 _nPos,const Reference< XPropertySet>& _xColumn) 277*cdf0e10cSrcweir : OOperandRow(_nPos,::comphelper::getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE)))) 278*cdf0e10cSrcweir , m_xColumn(_xColumn) 279*cdf0e10cSrcweir { 280*cdf0e10cSrcweir } 281*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 282*cdf0e10cSrcweir 283*cdf0e10cSrcweir 284*cdf0e10cSrcweir 285*cdf0e10cSrcweir 286