Update ooo320-m1
[ooovba.git] / connectivity / source / drivers / odbcbase / ODriver.cxx
blob4f1f2d4cca7ad7f30c9f2e6a25ab9c632653f595
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ODriver.cxx,v $
10 * $Revision: 1.18.56.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_connectivity.hxx"
33 #include "odbc/ODriver.hxx"
34 #include "odbc/OConnection.hxx"
35 #include "odbc/OFunctions.hxx"
36 #include "odbc/OTools.hxx"
37 #include "connectivity/dbexception.hxx"
38 #include "resource/common_res.hrc"
39 #include "resource/sharedresources.hxx"
41 using namespace connectivity::odbc;
42 using namespace com::sun::star::uno;
43 using namespace com::sun::star::lang;
44 using namespace com::sun::star::beans;
45 using namespace com::sun::star::sdbc;
46 // --------------------------------------------------------------------------------
47 ODBCDriver::ODBCDriver(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory)
48 :ODriver_BASE(m_aMutex)
49 ,m_xORB(_rxFactory)
50 ,m_pDriverHandle(SQL_NULL_HANDLE)
53 // --------------------------------------------------------------------------------
54 void ODBCDriver::disposing()
56 ::osl::MutexGuard aGuard(m_aMutex);
59 for (OWeakRefArray::iterator i = m_xConnections.begin(); m_xConnections.end() != i; ++i)
61 Reference< XComponent > xComp(i->get(), UNO_QUERY);
62 if (xComp.is())
63 xComp->dispose();
65 m_xConnections.clear();
67 ODriver_BASE::disposing();
70 // static ServiceInfo
71 //------------------------------------------------------------------------------
72 rtl::OUString ODBCDriver::getImplementationName_Static( ) throw(RuntimeException)
74 return rtl::OUString::createFromAscii("com.sun.star.comp.sdbc.ODBCDriver");
75 // this name is referenced in the configuration and in the odbc.xml
76 // Please take care when changing it.
79 typedef Sequence< ::rtl::OUString > SS;
80 //------------------------------------------------------------------------------
81 SS ODBCDriver::getSupportedServiceNames_Static( ) throw (RuntimeException)
83 SS aSNS( 1 );
84 aSNS[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbc.Driver");
85 return aSNS;
88 //------------------------------------------------------------------
89 ::rtl::OUString SAL_CALL ODBCDriver::getImplementationName( ) throw(RuntimeException)
91 return getImplementationName_Static();
94 //------------------------------------------------------------------
95 sal_Bool SAL_CALL ODBCDriver::supportsService( const ::rtl::OUString& _rServiceName ) throw(RuntimeException)
97 SS aSupported(getSupportedServiceNames());
98 const ::rtl::OUString* pSupported = aSupported.getConstArray();
99 const ::rtl::OUString* pEnd = pSupported + aSupported.getLength();
100 for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported)
103 return pSupported != pEnd;
106 //------------------------------------------------------------------
107 SS SAL_CALL ODBCDriver::getSupportedServiceNames( ) throw(RuntimeException)
109 return getSupportedServiceNames_Static();
112 // --------------------------------------------------------------------------------
113 Reference< XConnection > SAL_CALL ODBCDriver::connect( const ::rtl::OUString& url, const Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException)
115 if ( ! acceptsURL(url) )
116 return NULL;
118 if(!m_pDriverHandle)
120 ::rtl::OUString aPath;
121 if(!EnvironmentHandle(aPath))
122 throw SQLException(aPath,*this,::rtl::OUString(),1000,Any());
124 OConnection* pCon = new OConnection(m_pDriverHandle,this);
125 Reference< XConnection > xCon = pCon;
126 pCon->Construct(url,info);
127 m_xConnections.push_back(WeakReferenceHelper(*pCon));
129 return xCon;
131 // --------------------------------------------------------------------------------
132 sal_Bool SAL_CALL ODBCDriver::acceptsURL( const ::rtl::OUString& url )
133 throw(SQLException, RuntimeException)
135 return (!url.compareTo(::rtl::OUString::createFromAscii("sdbc:odbc:"),10));
137 // --------------------------------------------------------------------------------
138 Sequence< DriverPropertyInfo > SAL_CALL ODBCDriver::getPropertyInfo( const ::rtl::OUString& url, const Sequence< PropertyValue >& /*info*/ ) throw(SQLException, RuntimeException)
140 if ( acceptsURL(url) )
142 ::std::vector< DriverPropertyInfo > aDriverInfo;
144 Sequence< ::rtl::OUString > aBooleanValues(2);
145 aBooleanValues[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "false" ) );
146 aBooleanValues[1] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "true" ) );
148 aDriverInfo.push_back(DriverPropertyInfo(
149 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CharSet"))
150 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CharSet of the database."))
151 ,sal_False
152 ,::rtl::OUString()
153 ,Sequence< ::rtl::OUString >())
155 aDriverInfo.push_back(DriverPropertyInfo(
156 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("UseCatalog"))
157 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Use catalog for file-based databases."))
158 ,sal_False
159 ,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "false" ) )
160 ,aBooleanValues)
162 aDriverInfo.push_back(DriverPropertyInfo(
163 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SystemDriverSettings"))
164 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Driver settings."))
165 ,sal_False
166 ,::rtl::OUString()
167 ,Sequence< ::rtl::OUString >())
169 aDriverInfo.push_back(DriverPropertyInfo(
170 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ParameterNameSubstitution"))
171 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Change named parameters with '?'."))
172 ,sal_False
173 ,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "false" ) )
174 ,aBooleanValues)
176 aDriverInfo.push_back(DriverPropertyInfo(
177 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IgnoreDriverPrivileges"))
178 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Ignore the privileges from the database driver."))
179 ,sal_False
180 ,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "false" ) )
181 ,aBooleanValues)
183 aDriverInfo.push_back(DriverPropertyInfo(
184 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IsAutoRetrievingEnabled"))
185 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Retrieve generated values."))
186 ,sal_False
187 ,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "false" ) )
188 ,aBooleanValues)
190 aDriverInfo.push_back(DriverPropertyInfo(
191 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AutoRetrievingStatement"))
192 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Auto-increment statement."))
193 ,sal_False
194 ,::rtl::OUString()
195 ,Sequence< ::rtl::OUString >())
197 aDriverInfo.push_back(DriverPropertyInfo(
198 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("GenerateASBeforeCorrelationName"))
199 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Generate AS before table correlation names."))
200 ,sal_False
201 ,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "true" ) )
202 ,aBooleanValues)
204 aDriverInfo.push_back(DriverPropertyInfo(
205 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("EscapeDateTime"))
206 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Escape date time format."))
207 ,sal_False
208 ,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "true" ) )
209 ,aBooleanValues)
212 return Sequence< DriverPropertyInfo >(&aDriverInfo[0],aDriverInfo.size());
214 ::connectivity::SharedResources aResources;
215 const ::rtl::OUString sMessage = aResources.getResourceString(STR_URI_SYNTAX_ERROR);
216 ::dbtools::throwGenericSQLException(sMessage ,*this);
217 return Sequence< DriverPropertyInfo >();
219 // --------------------------------------------------------------------------------
220 sal_Int32 SAL_CALL ODBCDriver::getMajorVersion( ) throw(RuntimeException)
222 return 1;
224 // --------------------------------------------------------------------------------
225 sal_Int32 SAL_CALL ODBCDriver::getMinorVersion( ) throw(RuntimeException)
227 return 0;
229 // --------------------------------------------------------------------------------
230 //-----------------------------------------------------------------------------