19b5730f6SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 39b5730f6SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 49b5730f6SAndrew Rist * or more contributor license agreements. See the NOTICE file 59b5730f6SAndrew Rist * distributed with this work for additional information 69b5730f6SAndrew Rist * regarding copyright ownership. The ASF licenses this file 79b5730f6SAndrew Rist * to you under the Apache License, Version 2.0 (the 89b5730f6SAndrew Rist * "License"); you may not use this file except in compliance 99b5730f6SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 119b5730f6SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 139b5730f6SAndrew Rist * Unless required by applicable law or agreed to in writing, 149b5730f6SAndrew Rist * software distributed under the License is distributed on an 159b5730f6SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 169b5730f6SAndrew Rist * KIND, either express or implied. See the License for the 179b5730f6SAndrew Rist * specific language governing permissions and limitations 189b5730f6SAndrew Rist * under the License. 19cdf0e10cSrcweir * 209b5730f6SAndrew Rist *************************************************************/ 219b5730f6SAndrew Rist 229b5730f6SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_connectivity.hxx" 26cdf0e10cSrcweir #include "odbc/ODriver.hxx" 27cdf0e10cSrcweir #include "odbc/OConnection.hxx" 28cdf0e10cSrcweir #include "odbc/OFunctions.hxx" 29cdf0e10cSrcweir #include "odbc/OTools.hxx" 30cdf0e10cSrcweir #include "connectivity/dbexception.hxx" 31cdf0e10cSrcweir #include "resource/common_res.hrc" 32cdf0e10cSrcweir #include "resource/sharedresources.hxx" 33cdf0e10cSrcweir 34cdf0e10cSrcweir using namespace connectivity::odbc; 35cdf0e10cSrcweir using namespace com::sun::star::uno; 36cdf0e10cSrcweir using namespace com::sun::star::lang; 37cdf0e10cSrcweir using namespace com::sun::star::beans; 38cdf0e10cSrcweir using namespace com::sun::star::sdbc; 39cdf0e10cSrcweir // -------------------------------------------------------------------------------- 40cdf0e10cSrcweir ODBCDriver::ODBCDriver(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory) 41cdf0e10cSrcweir :ODriver_BASE(m_aMutex) 42cdf0e10cSrcweir ,m_xORB(_rxFactory) 43cdf0e10cSrcweir ,m_pDriverHandle(SQL_NULL_HANDLE) 44cdf0e10cSrcweir { 45cdf0e10cSrcweir } 46cdf0e10cSrcweir // -------------------------------------------------------------------------------- 47cdf0e10cSrcweir void ODBCDriver::disposing() 48cdf0e10cSrcweir { 49cdf0e10cSrcweir ::osl::MutexGuard aGuard(m_aMutex); 50cdf0e10cSrcweir 51cdf0e10cSrcweir 52cdf0e10cSrcweir for (OWeakRefArray::iterator i = m_xConnections.begin(); m_xConnections.end() != i; ++i) 53cdf0e10cSrcweir { 54cdf0e10cSrcweir Reference< XComponent > xComp(i->get(), UNO_QUERY); 55cdf0e10cSrcweir if (xComp.is()) 56cdf0e10cSrcweir xComp->dispose(); 57cdf0e10cSrcweir } 58cdf0e10cSrcweir m_xConnections.clear(); 59cdf0e10cSrcweir 60cdf0e10cSrcweir ODriver_BASE::disposing(); 61cdf0e10cSrcweir } 62cdf0e10cSrcweir 63cdf0e10cSrcweir // static ServiceInfo 64cdf0e10cSrcweir //------------------------------------------------------------------------------ 65cdf0e10cSrcweir rtl::OUString ODBCDriver::getImplementationName_Static( ) throw(RuntimeException) 66cdf0e10cSrcweir { 67cdf0e10cSrcweir return rtl::OUString::createFromAscii("com.sun.star.comp.sdbc.ODBCDriver"); 68cdf0e10cSrcweir // this name is referenced in the configuration and in the odbc.xml 69cdf0e10cSrcweir // Please take care when changing it. 70cdf0e10cSrcweir } 71cdf0e10cSrcweir 72*f9333cb5SPedro Giffuni typedef Sequence< ::rtl::OUString > SSEQ; 73cdf0e10cSrcweir //------------------------------------------------------------------------------ 74*f9333cb5SPedro Giffuni SSEQ ODBCDriver::getSupportedServiceNames_Static( ) throw (RuntimeException) 75cdf0e10cSrcweir { 76*f9333cb5SPedro Giffuni SSEQ aSNS( 1 ); 77cdf0e10cSrcweir aSNS[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbc.Driver"); 78cdf0e10cSrcweir return aSNS; 79cdf0e10cSrcweir } 80cdf0e10cSrcweir 81cdf0e10cSrcweir //------------------------------------------------------------------ 82cdf0e10cSrcweir ::rtl::OUString SAL_CALL ODBCDriver::getImplementationName( ) throw(RuntimeException) 83cdf0e10cSrcweir { 84cdf0e10cSrcweir return getImplementationName_Static(); 85cdf0e10cSrcweir } 86cdf0e10cSrcweir 87cdf0e10cSrcweir //------------------------------------------------------------------ 88cdf0e10cSrcweir sal_Bool SAL_CALL ODBCDriver::supportsService( const ::rtl::OUString& _rServiceName ) throw(RuntimeException) 89cdf0e10cSrcweir { 90*f9333cb5SPedro Giffuni SSEQ aSupported(getSupportedServiceNames()); 91cdf0e10cSrcweir const ::rtl::OUString* pSupported = aSupported.getConstArray(); 92cdf0e10cSrcweir const ::rtl::OUString* pEnd = pSupported + aSupported.getLength(); 93cdf0e10cSrcweir for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported) 94cdf0e10cSrcweir ; 95cdf0e10cSrcweir 96cdf0e10cSrcweir return pSupported != pEnd; 97cdf0e10cSrcweir } 98cdf0e10cSrcweir 99cdf0e10cSrcweir //------------------------------------------------------------------ 100*f9333cb5SPedro Giffuni SSEQ SAL_CALL ODBCDriver::getSupportedServiceNames( ) throw(RuntimeException) 101cdf0e10cSrcweir { 102cdf0e10cSrcweir return getSupportedServiceNames_Static(); 103cdf0e10cSrcweir } 104cdf0e10cSrcweir 105cdf0e10cSrcweir // -------------------------------------------------------------------------------- 106cdf0e10cSrcweir Reference< XConnection > SAL_CALL ODBCDriver::connect( const ::rtl::OUString& url, const Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException) 107cdf0e10cSrcweir { 108cdf0e10cSrcweir if ( ! acceptsURL(url) ) 109cdf0e10cSrcweir return NULL; 110cdf0e10cSrcweir 111cdf0e10cSrcweir if(!m_pDriverHandle) 112cdf0e10cSrcweir { 113cdf0e10cSrcweir ::rtl::OUString aPath; 114cdf0e10cSrcweir if(!EnvironmentHandle(aPath)) 115cdf0e10cSrcweir throw SQLException(aPath,*this,::rtl::OUString(),1000,Any()); 116cdf0e10cSrcweir } 117cdf0e10cSrcweir OConnection* pCon = new OConnection(m_pDriverHandle,this); 118cdf0e10cSrcweir Reference< XConnection > xCon = pCon; 119cdf0e10cSrcweir pCon->Construct(url,info); 120cdf0e10cSrcweir m_xConnections.push_back(WeakReferenceHelper(*pCon)); 121cdf0e10cSrcweir 122cdf0e10cSrcweir return xCon; 123cdf0e10cSrcweir } 124cdf0e10cSrcweir // -------------------------------------------------------------------------------- 125cdf0e10cSrcweir sal_Bool SAL_CALL ODBCDriver::acceptsURL( const ::rtl::OUString& url ) 126cdf0e10cSrcweir throw(SQLException, RuntimeException) 127cdf0e10cSrcweir { 128cdf0e10cSrcweir return (!url.compareTo(::rtl::OUString::createFromAscii("sdbc:odbc:"),10)); 129cdf0e10cSrcweir } 130cdf0e10cSrcweir // -------------------------------------------------------------------------------- 131cdf0e10cSrcweir Sequence< DriverPropertyInfo > SAL_CALL ODBCDriver::getPropertyInfo( const ::rtl::OUString& url, const Sequence< PropertyValue >& /*info*/ ) throw(SQLException, RuntimeException) 132cdf0e10cSrcweir { 133cdf0e10cSrcweir if ( acceptsURL(url) ) 134cdf0e10cSrcweir { 135cdf0e10cSrcweir ::std::vector< DriverPropertyInfo > aDriverInfo; 136cdf0e10cSrcweir 137cdf0e10cSrcweir Sequence< ::rtl::OUString > aBooleanValues(2); 138cdf0e10cSrcweir aBooleanValues[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "false" ) ); 139cdf0e10cSrcweir aBooleanValues[1] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "true" ) ); 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("UseCatalog")) 150cdf0e10cSrcweir ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Use catalog for file-based databases.")) 151cdf0e10cSrcweir ,sal_False 152cdf0e10cSrcweir ,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "false" ) ) 153cdf0e10cSrcweir ,aBooleanValues) 154cdf0e10cSrcweir ); 155cdf0e10cSrcweir aDriverInfo.push_back(DriverPropertyInfo( 156cdf0e10cSrcweir ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SystemDriverSettings")) 157cdf0e10cSrcweir ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Driver settings.")) 158cdf0e10cSrcweir ,sal_False 159cdf0e10cSrcweir ,::rtl::OUString() 160cdf0e10cSrcweir ,Sequence< ::rtl::OUString >()) 161cdf0e10cSrcweir ); 162cdf0e10cSrcweir aDriverInfo.push_back(DriverPropertyInfo( 163cdf0e10cSrcweir ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ParameterNameSubstitution")) 164cdf0e10cSrcweir ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Change named parameters with '?'.")) 165cdf0e10cSrcweir ,sal_False 166cdf0e10cSrcweir ,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "false" ) ) 167cdf0e10cSrcweir ,aBooleanValues) 168cdf0e10cSrcweir ); 169cdf0e10cSrcweir aDriverInfo.push_back(DriverPropertyInfo( 170cdf0e10cSrcweir ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IgnoreDriverPrivileges")) 171cdf0e10cSrcweir ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Ignore the privileges from the database driver.")) 172cdf0e10cSrcweir ,sal_False 173cdf0e10cSrcweir ,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "false" ) ) 174cdf0e10cSrcweir ,aBooleanValues) 175cdf0e10cSrcweir ); 176cdf0e10cSrcweir aDriverInfo.push_back(DriverPropertyInfo( 177cdf0e10cSrcweir ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IsAutoRetrievingEnabled")) 178cdf0e10cSrcweir ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Retrieve generated values.")) 179cdf0e10cSrcweir ,sal_False 180cdf0e10cSrcweir ,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "false" ) ) 181cdf0e10cSrcweir ,aBooleanValues) 182cdf0e10cSrcweir ); 183cdf0e10cSrcweir aDriverInfo.push_back(DriverPropertyInfo( 184cdf0e10cSrcweir ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AutoRetrievingStatement")) 185cdf0e10cSrcweir ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Auto-increment statement.")) 186cdf0e10cSrcweir ,sal_False 187cdf0e10cSrcweir ,::rtl::OUString() 188cdf0e10cSrcweir ,Sequence< ::rtl::OUString >()) 189cdf0e10cSrcweir ); 190cdf0e10cSrcweir aDriverInfo.push_back(DriverPropertyInfo( 191cdf0e10cSrcweir ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("GenerateASBeforeCorrelationName")) 192cdf0e10cSrcweir ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Generate AS before table correlation names.")) 193cdf0e10cSrcweir ,sal_False 194cdf0e10cSrcweir ,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "true" ) ) 195cdf0e10cSrcweir ,aBooleanValues) 196cdf0e10cSrcweir ); 197cdf0e10cSrcweir aDriverInfo.push_back(DriverPropertyInfo( 198cdf0e10cSrcweir ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("EscapeDateTime")) 199cdf0e10cSrcweir ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Escape date time format.")) 200cdf0e10cSrcweir ,sal_False 201cdf0e10cSrcweir ,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "true" ) ) 202cdf0e10cSrcweir ,aBooleanValues) 203cdf0e10cSrcweir ); 204cdf0e10cSrcweir 205cdf0e10cSrcweir return Sequence< DriverPropertyInfo >(&aDriverInfo[0],aDriverInfo.size()); 206cdf0e10cSrcweir } 207cdf0e10cSrcweir ::connectivity::SharedResources aResources; 208cdf0e10cSrcweir const ::rtl::OUString sMessage = aResources.getResourceString(STR_URI_SYNTAX_ERROR); 209cdf0e10cSrcweir ::dbtools::throwGenericSQLException(sMessage ,*this); 210cdf0e10cSrcweir return Sequence< DriverPropertyInfo >(); 211cdf0e10cSrcweir } 212cdf0e10cSrcweir // -------------------------------------------------------------------------------- 213cdf0e10cSrcweir sal_Int32 SAL_CALL ODBCDriver::getMajorVersion( ) throw(RuntimeException) 214cdf0e10cSrcweir { 215cdf0e10cSrcweir return 1; 216cdf0e10cSrcweir } 217cdf0e10cSrcweir // -------------------------------------------------------------------------------- 218cdf0e10cSrcweir sal_Int32 SAL_CALL ODBCDriver::getMinorVersion( ) throw(RuntimeException) 219cdf0e10cSrcweir { 220cdf0e10cSrcweir return 0; 221cdf0e10cSrcweir } 222cdf0e10cSrcweir // -------------------------------------------------------------------------------- 223cdf0e10cSrcweir //----------------------------------------------------------------------------- 224cdf0e10cSrcweir 225cdf0e10cSrcweir 226