bump product version to 4.1.6.2
[LibreOffice.git] / connectivity / source / drivers / odbcbase / ODriver.cxx
blob2c04fa2535681105b050bad0031a6809658dd3e4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "odbc/ODriver.hxx"
21 #include "odbc/OConnection.hxx"
22 #include "odbc/OFunctions.hxx"
23 #include "odbc/OTools.hxx"
24 #include "connectivity/dbexception.hxx"
25 #include "resource/common_res.hrc"
26 #include "resource/sharedresources.hxx"
28 using namespace connectivity::odbc;
29 using namespace com::sun::star::uno;
30 using namespace com::sun::star::lang;
31 using namespace com::sun::star::beans;
32 using namespace com::sun::star::sdbc;
33 // --------------------------------------------------------------------------------
34 ODBCDriver::ODBCDriver(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory)
35 :ODriver_BASE(m_aMutex)
36 ,m_xORB(_rxFactory)
37 ,m_pDriverHandle(SQL_NULL_HANDLE)
40 // --------------------------------------------------------------------------------
41 void ODBCDriver::disposing()
43 ::osl::MutexGuard aGuard(m_aMutex);
46 for (OWeakRefArray::iterator i = m_xConnections.begin(); m_xConnections.end() != i; ++i)
48 Reference< XComponent > xComp(i->get(), UNO_QUERY);
49 if (xComp.is())
50 xComp->dispose();
52 m_xConnections.clear();
54 ODriver_BASE::disposing();
57 // static ServiceInfo
58 //------------------------------------------------------------------------------
59 OUString ODBCDriver::getImplementationName_Static( ) throw(RuntimeException)
61 return OUString("com.sun.star.comp.sdbc.ODBCDriver");
62 // this name is referenced in the configuration and in the odbc.xml
63 // Please take care when changing it.
66 //------------------------------------------------------------------------------
67 Sequence< OUString > ODBCDriver::getSupportedServiceNames_Static( ) throw (RuntimeException)
69 Sequence< OUString > aSNS( 1 );
70 aSNS[0] = OUString("com.sun.star.sdbc.Driver");
71 return aSNS;
74 //------------------------------------------------------------------
75 OUString SAL_CALL ODBCDriver::getImplementationName( ) throw(RuntimeException)
77 return getImplementationName_Static();
80 //------------------------------------------------------------------
81 sal_Bool SAL_CALL ODBCDriver::supportsService( const OUString& _rServiceName ) throw(RuntimeException)
83 Sequence< OUString > aSupported(getSupportedServiceNames());
84 const OUString* pSupported = aSupported.getConstArray();
85 const OUString* pEnd = pSupported + aSupported.getLength();
86 for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported)
89 return pSupported != pEnd;
92 //------------------------------------------------------------------
93 Sequence< OUString > SAL_CALL ODBCDriver::getSupportedServiceNames( ) throw(RuntimeException)
95 return getSupportedServiceNames_Static();
98 // --------------------------------------------------------------------------------
99 Reference< XConnection > SAL_CALL ODBCDriver::connect( const OUString& url, const Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException)
101 if ( ! acceptsURL(url) )
102 return NULL;
104 if(!m_pDriverHandle)
106 OUString aPath;
107 if(!EnvironmentHandle(aPath))
108 throw SQLException(aPath,*this,OUString(),1000,Any());
110 OConnection* pCon = new OConnection(m_pDriverHandle,this);
111 Reference< XConnection > xCon = pCon;
112 pCon->Construct(url,info);
113 m_xConnections.push_back(WeakReferenceHelper(*pCon));
115 return xCon;
117 // --------------------------------------------------------------------------------
118 sal_Bool SAL_CALL ODBCDriver::acceptsURL( const OUString& url )
119 throw(SQLException, RuntimeException)
121 return url.startsWith("sdbc:odbc:");
123 // --------------------------------------------------------------------------------
124 Sequence< DriverPropertyInfo > SAL_CALL ODBCDriver::getPropertyInfo( const OUString& url, const Sequence< PropertyValue >& /*info*/ ) throw(SQLException, RuntimeException)
126 if ( acceptsURL(url) )
128 ::std::vector< DriverPropertyInfo > aDriverInfo;
130 Sequence< OUString > aBooleanValues(2);
131 aBooleanValues[0] = OUString( "false" );
132 aBooleanValues[1] = OUString( "true" );
134 aDriverInfo.push_back(DriverPropertyInfo(
135 OUString("CharSet")
136 ,OUString("CharSet of the database.")
137 ,sal_False
138 ,OUString()
139 ,Sequence< OUString >())
141 aDriverInfo.push_back(DriverPropertyInfo(
142 OUString("UseCatalog")
143 ,OUString("Use catalog for file-based databases.")
144 ,sal_False
145 ,OUString( "false" )
146 ,aBooleanValues)
148 aDriverInfo.push_back(DriverPropertyInfo(
149 OUString("SystemDriverSettings")
150 ,OUString("Driver settings.")
151 ,sal_False
152 ,OUString()
153 ,Sequence< OUString >())
155 aDriverInfo.push_back(DriverPropertyInfo(
156 OUString("ParameterNameSubstitution")
157 ,OUString("Change named parameters with '?'.")
158 ,sal_False
159 ,OUString( "false" )
160 ,aBooleanValues)
162 aDriverInfo.push_back(DriverPropertyInfo(
163 OUString("IgnoreDriverPrivileges")
164 ,OUString("Ignore the privileges from the database driver.")
165 ,sal_False
166 ,OUString( "false" )
167 ,aBooleanValues)
169 aDriverInfo.push_back(DriverPropertyInfo(
170 OUString("IsAutoRetrievingEnabled")
171 ,OUString("Retrieve generated values.")
172 ,sal_False
173 ,OUString( "false" )
174 ,aBooleanValues)
176 aDriverInfo.push_back(DriverPropertyInfo(
177 OUString("AutoRetrievingStatement")
178 ,OUString("Auto-increment statement.")
179 ,sal_False
180 ,OUString()
181 ,Sequence< OUString >())
183 aDriverInfo.push_back(DriverPropertyInfo(
184 OUString("GenerateASBeforeCorrelationName")
185 ,OUString("Generate AS before table correlation names.")
186 ,sal_False
187 ,OUString( "true" )
188 ,aBooleanValues)
190 aDriverInfo.push_back(DriverPropertyInfo(
191 OUString("EscapeDateTime")
192 ,OUString("Escape date time format.")
193 ,sal_False
194 ,OUString( "true" )
195 ,aBooleanValues)
198 return Sequence< DriverPropertyInfo >(&aDriverInfo[0],aDriverInfo.size());
200 ::connectivity::SharedResources aResources;
201 const OUString sMessage = aResources.getResourceString(STR_URI_SYNTAX_ERROR);
202 ::dbtools::throwGenericSQLException(sMessage ,*this);
203 return Sequence< DriverPropertyInfo >();
205 // --------------------------------------------------------------------------------
206 sal_Int32 SAL_CALL ODBCDriver::getMajorVersion( ) throw(RuntimeException)
208 return 1;
210 // --------------------------------------------------------------------------------
211 sal_Int32 SAL_CALL ODBCDriver::getMinorVersion( ) throw(RuntimeException)
213 return 0;
215 // --------------------------------------------------------------------------------
216 //-----------------------------------------------------------------------------
219 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */