Bump for 3.6-28
[LibreOffice.git] / connectivity / source / drivers / odbcbase / ODriver.cxx
blob1454d44c6d84529d1324b0634cc75bc1d2ea436b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "odbc/ODriver.hxx"
30 #include "odbc/OConnection.hxx"
31 #include "odbc/OFunctions.hxx"
32 #include "odbc/OTools.hxx"
33 #include "connectivity/dbexception.hxx"
34 #include "resource/common_res.hrc"
35 #include "resource/sharedresources.hxx"
37 using namespace connectivity::odbc;
38 using namespace com::sun::star::uno;
39 using namespace com::sun::star::lang;
40 using namespace com::sun::star::beans;
41 using namespace com::sun::star::sdbc;
42 // --------------------------------------------------------------------------------
43 ODBCDriver::ODBCDriver(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory)
44 :ODriver_BASE(m_aMutex)
45 ,m_xORB(_rxFactory)
46 ,m_pDriverHandle(SQL_NULL_HANDLE)
49 // --------------------------------------------------------------------------------
50 void ODBCDriver::disposing()
52 ::osl::MutexGuard aGuard(m_aMutex);
55 for (OWeakRefArray::iterator i = m_xConnections.begin(); m_xConnections.end() != i; ++i)
57 Reference< XComponent > xComp(i->get(), UNO_QUERY);
58 if (xComp.is())
59 xComp->dispose();
61 m_xConnections.clear();
63 ODriver_BASE::disposing();
66 // static ServiceInfo
67 //------------------------------------------------------------------------------
68 rtl::OUString ODBCDriver::getImplementationName_Static( ) throw(RuntimeException)
70 return rtl::OUString("com.sun.star.comp.sdbc.ODBCDriver");
71 // this name is referenced in the configuration and in the odbc.xml
72 // Please take care when changing it.
75 typedef Sequence< ::rtl::OUString > SS;
76 //------------------------------------------------------------------------------
77 SS ODBCDriver::getSupportedServiceNames_Static( ) throw (RuntimeException)
79 SS aSNS( 1 );
80 aSNS[0] = ::rtl::OUString("com.sun.star.sdbc.Driver");
81 return aSNS;
84 //------------------------------------------------------------------
85 ::rtl::OUString SAL_CALL ODBCDriver::getImplementationName( ) throw(RuntimeException)
87 return getImplementationName_Static();
90 //------------------------------------------------------------------
91 sal_Bool SAL_CALL ODBCDriver::supportsService( const ::rtl::OUString& _rServiceName ) throw(RuntimeException)
93 SS aSupported(getSupportedServiceNames());
94 const ::rtl::OUString* pSupported = aSupported.getConstArray();
95 const ::rtl::OUString* pEnd = pSupported + aSupported.getLength();
96 for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported)
99 return pSupported != pEnd;
102 //------------------------------------------------------------------
103 SS SAL_CALL ODBCDriver::getSupportedServiceNames( ) throw(RuntimeException)
105 return getSupportedServiceNames_Static();
108 // --------------------------------------------------------------------------------
109 Reference< XConnection > SAL_CALL ODBCDriver::connect( const ::rtl::OUString& url, const Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException)
111 if ( ! acceptsURL(url) )
112 return NULL;
114 if(!m_pDriverHandle)
116 ::rtl::OUString aPath;
117 if(!EnvironmentHandle(aPath))
118 throw SQLException(aPath,*this,::rtl::OUString(),1000,Any());
120 OConnection* pCon = new OConnection(m_pDriverHandle,this);
121 Reference< XConnection > xCon = pCon;
122 pCon->Construct(url,info);
123 m_xConnections.push_back(WeakReferenceHelper(*pCon));
125 return xCon;
127 // --------------------------------------------------------------------------------
128 sal_Bool SAL_CALL ODBCDriver::acceptsURL( const ::rtl::OUString& url )
129 throw(SQLException, RuntimeException)
131 return (!url.compareTo(::rtl::OUString("sdbc:odbc:"),10));
133 // --------------------------------------------------------------------------------
134 Sequence< DriverPropertyInfo > SAL_CALL ODBCDriver::getPropertyInfo( const ::rtl::OUString& url, const Sequence< PropertyValue >& /*info*/ ) throw(SQLException, RuntimeException)
136 if ( acceptsURL(url) )
138 ::std::vector< DriverPropertyInfo > aDriverInfo;
140 Sequence< ::rtl::OUString > aBooleanValues(2);
141 aBooleanValues[0] = ::rtl::OUString( "false" );
142 aBooleanValues[1] = ::rtl::OUString( "true" );
144 aDriverInfo.push_back(DriverPropertyInfo(
145 ::rtl::OUString("CharSet")
146 ,::rtl::OUString("CharSet of the database.")
147 ,sal_False
148 ,::rtl::OUString()
149 ,Sequence< ::rtl::OUString >())
151 aDriverInfo.push_back(DriverPropertyInfo(
152 ::rtl::OUString("UseCatalog")
153 ,::rtl::OUString("Use catalog for file-based databases.")
154 ,sal_False
155 ,::rtl::OUString( "false" )
156 ,aBooleanValues)
158 aDriverInfo.push_back(DriverPropertyInfo(
159 ::rtl::OUString("SystemDriverSettings")
160 ,::rtl::OUString("Driver settings.")
161 ,sal_False
162 ,::rtl::OUString()
163 ,Sequence< ::rtl::OUString >())
165 aDriverInfo.push_back(DriverPropertyInfo(
166 ::rtl::OUString("ParameterNameSubstitution")
167 ,::rtl::OUString("Change named parameters with '?'.")
168 ,sal_False
169 ,::rtl::OUString( "false" )
170 ,aBooleanValues)
172 aDriverInfo.push_back(DriverPropertyInfo(
173 ::rtl::OUString("IgnoreDriverPrivileges")
174 ,::rtl::OUString("Ignore the privileges from the database driver.")
175 ,sal_False
176 ,::rtl::OUString( "false" )
177 ,aBooleanValues)
179 aDriverInfo.push_back(DriverPropertyInfo(
180 ::rtl::OUString("IsAutoRetrievingEnabled")
181 ,::rtl::OUString("Retrieve generated values.")
182 ,sal_False
183 ,::rtl::OUString( "false" )
184 ,aBooleanValues)
186 aDriverInfo.push_back(DriverPropertyInfo(
187 ::rtl::OUString("AutoRetrievingStatement")
188 ,::rtl::OUString("Auto-increment statement.")
189 ,sal_False
190 ,::rtl::OUString()
191 ,Sequence< ::rtl::OUString >())
193 aDriverInfo.push_back(DriverPropertyInfo(
194 ::rtl::OUString("GenerateASBeforeCorrelationName")
195 ,::rtl::OUString("Generate AS before table correlation names.")
196 ,sal_False
197 ,::rtl::OUString( "true" )
198 ,aBooleanValues)
200 aDriverInfo.push_back(DriverPropertyInfo(
201 ::rtl::OUString("EscapeDateTime")
202 ,::rtl::OUString("Escape date time format.")
203 ,sal_False
204 ,::rtl::OUString( "true" )
205 ,aBooleanValues)
208 return Sequence< DriverPropertyInfo >(&aDriverInfo[0],aDriverInfo.size());
210 ::connectivity::SharedResources aResources;
211 const ::rtl::OUString sMessage = aResources.getResourceString(STR_URI_SYNTAX_ERROR);
212 ::dbtools::throwGenericSQLException(sMessage ,*this);
213 return Sequence< DriverPropertyInfo >();
215 // --------------------------------------------------------------------------------
216 sal_Int32 SAL_CALL ODBCDriver::getMajorVersion( ) throw(RuntimeException)
218 return 1;
220 // --------------------------------------------------------------------------------
221 sal_Int32 SAL_CALL ODBCDriver::getMinorVersion( ) throw(RuntimeException)
223 return 0;
225 // --------------------------------------------------------------------------------
226 //-----------------------------------------------------------------------------
229 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */