1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
)
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
);
53 m_xConnections
.clear();
55 ODriver_BASE::disposing();
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" };
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
) )
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
));
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(
128 ,"CharSet of the database."
131 ,Sequence
< OUString
>())
133 aDriverInfo
.push_back(DriverPropertyInfo(
135 ,"Use catalog for file-based databases."
140 aDriverInfo
.push_back(DriverPropertyInfo(
141 "SystemDriverSettings"
145 ,Sequence
< OUString
>())
147 aDriverInfo
.push_back(DriverPropertyInfo(
148 "ParameterNameSubstitution"
149 ,"Change named parameters with '?'."
154 aDriverInfo
.push_back(DriverPropertyInfo(
155 "IgnoreDriverPrivileges"
156 ,"Ignore the privileges from the database driver."
161 aDriverInfo
.push_back(DriverPropertyInfo(
162 "IsAutoRetrievingEnabled"
163 ,"Retrieve generated values."
168 aDriverInfo
.push_back(DriverPropertyInfo(
169 "AutoRetrievingStatement"
170 ,"Auto-increment statement."
173 ,Sequence
< OUString
>())
175 aDriverInfo
.push_back(DriverPropertyInfo(
176 "GenerateASBeforeCorrelationName"
177 ,"Generate AS before table correlation names."
182 aDriverInfo
.push_back(DriverPropertyInfo(
184 ,"Escape date time format."
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( )
203 sal_Int32 SAL_CALL
ODBCDriver::getMinorVersion( )
209 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */