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