bump product version to 6.3.0.0.beta1
[LibreOffice.git] / connectivity / source / drivers / odbc / ODriver.cxx
blob642413bb82f0c8637b3e30387524f0fc2c0a2f11
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 <cppuhelper/supportsservice.hxx>
26 #include <strings.hrc>
27 #include <resource/sharedresources.hxx>
29 using namespace connectivity::odbc;
30 using namespace com::sun::star::uno;
31 using namespace com::sun::star::lang;
32 using namespace com::sun::star::beans;
33 using namespace com::sun::star::sdbc;
35 ODBCDriver::ODBCDriver(const css::uno::Reference< css::lang::XMultiServiceFactory >& _rxFactory)
36 :ODriver_BASE(m_aMutex)
37 ,m_xORB(_rxFactory)
38 ,m_pDriverHandle(SQL_NULL_HANDLE)
42 void ODBCDriver::disposing()
44 ::osl::MutexGuard aGuard(m_aMutex);
47 for (auto const& connection : m_xConnections)
49 Reference< XComponent > xComp(connection.get(), UNO_QUERY);
50 if (xComp.is())
51 xComp->dispose();
53 m_xConnections.clear();
55 ODriver_BASE::disposing();
58 // static ServiceInfo
60 OUString ODBCDriver::getImplementationName_Static( )
62 return OUString("com.sun.star.comp.sdbc.ODBCDriver");
63 // this name is referenced in the configuration and in the odbc.xml
64 // Please take care when changing it.
68 Sequence< OUString > ODBCDriver::getSupportedServiceNames_Static( )
70 Sequence<OUString> aSNS { "com.sun.star.sdbc.Driver" };
71 return aSNS;
75 OUString SAL_CALL ODBCDriver::getImplementationName( )
77 return getImplementationName_Static();
80 sal_Bool SAL_CALL ODBCDriver::supportsService( const OUString& _rServiceName )
82 return cppu::supportsService(this, _rServiceName);
86 Sequence< OUString > SAL_CALL ODBCDriver::getSupportedServiceNames( )
88 return getSupportedServiceNames_Static();
92 Reference< XConnection > SAL_CALL ODBCDriver::connect( const OUString& url, const Sequence< PropertyValue >& info )
94 if ( ! acceptsURL(url) )
95 return nullptr;
97 if(!m_pDriverHandle)
99 OUString aPath;
100 if(!EnvironmentHandle(aPath))
101 throw SQLException(aPath,*this,OUString(),1000,Any());
103 OConnection* pCon = new OConnection(m_pDriverHandle,this);
104 Reference< XConnection > xCon = pCon;
105 pCon->Construct(url,info);
106 m_xConnections.push_back(WeakReferenceHelper(*pCon));
108 return xCon;
111 sal_Bool SAL_CALL ODBCDriver::acceptsURL( const OUString& url )
113 return url.startsWith("sdbc:odbc:");
116 Sequence< DriverPropertyInfo > SAL_CALL ODBCDriver::getPropertyInfo( const OUString& url, const Sequence< PropertyValue >& /*info*/ )
118 if ( acceptsURL(url) )
120 std::vector< DriverPropertyInfo > aDriverInfo;
122 Sequence< OUString > aBooleanValues(2);
123 aBooleanValues[0] = "false";
124 aBooleanValues[1] = "true";
126 aDriverInfo.push_back(DriverPropertyInfo(
127 "CharSet"
128 ,"CharSet of the database."
129 ,false
130 ,OUString()
131 ,Sequence< OUString >())
133 aDriverInfo.push_back(DriverPropertyInfo(
134 "UseCatalog"
135 ,"Use catalog for file-based databases."
136 ,false
137 ,"false"
138 ,aBooleanValues)
140 aDriverInfo.push_back(DriverPropertyInfo(
141 "SystemDriverSettings"
142 ,"Driver settings."
143 ,false
144 ,OUString()
145 ,Sequence< OUString >())
147 aDriverInfo.push_back(DriverPropertyInfo(
148 "ParameterNameSubstitution"
149 ,"Change named parameters with '?'."
150 ,false
151 ,"false"
152 ,aBooleanValues)
154 aDriverInfo.push_back(DriverPropertyInfo(
155 "IgnoreDriverPrivileges"
156 ,"Ignore the privileges from the database driver."
157 ,false
158 ,"false"
159 ,aBooleanValues)
161 aDriverInfo.push_back(DriverPropertyInfo(
162 "IsAutoRetrievingEnabled"
163 ,"Retrieve generated values."
164 ,false
165 ,"false"
166 ,aBooleanValues)
168 aDriverInfo.push_back(DriverPropertyInfo(
169 "AutoRetrievingStatement"
170 ,"Auto-increment statement."
171 ,false
172 ,OUString()
173 ,Sequence< OUString >())
175 aDriverInfo.push_back(DriverPropertyInfo(
176 "GenerateASBeforeCorrelationName"
177 ,"Generate AS before table correlation names."
178 ,false
179 ,"false"
180 ,aBooleanValues)
182 aDriverInfo.push_back(DriverPropertyInfo(
183 "EscapeDateTime"
184 ,"Escape date time format."
185 ,false
186 ,"true"
187 ,aBooleanValues)
190 return Sequence< DriverPropertyInfo >(aDriverInfo.data(),aDriverInfo.size());
192 ::connectivity::SharedResources aResources;
193 const OUString sMessage = aResources.getResourceString(STR_URI_SYNTAX_ERROR);
194 ::dbtools::throwGenericSQLException(sMessage ,*this);
195 return Sequence< DriverPropertyInfo >();
198 sal_Int32 SAL_CALL ODBCDriver::getMajorVersion( )
200 return 1;
203 sal_Int32 SAL_CALL ODBCDriver::getMinorVersion( )
205 return 0;
209 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */