LibreOffice Module connectivity (master) 1
ODriver.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <odbc/ODriver.hxx>
21#include <odbc/OConnection.hxx>
22#include <odbc/OTools.hxx>
25#include <strings.hrc>
27#include <utility>
28
29using namespace connectivity::odbc;
30using namespace com::sun::star::uno;
31using namespace com::sun::star::lang;
32using namespace com::sun::star::beans;
33using namespace com::sun::star::sdbc;
34
35ODBCDriver::ODBCDriver(css::uno::Reference< css::uno::XComponentContext > _xContext)
37 ,m_xContext(std::move(_xContext))
38 ,m_pDriverHandle(SQL_NULL_HANDLE)
39{
40}
41
43{
44 ::osl::MutexGuard aGuard(m_aMutex);
45
46
47 for (auto const& connection : m_xConnections)
48 {
49 Reference< XComponent > xComp(connection.get(), UNO_QUERY);
50 if (xComp.is())
51 xComp->dispose();
52 }
53 m_xConnections.clear();
54
55 ODriver_BASE::disposing();
56}
57
58// static ServiceInfo
59
61{
62 return "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.
65}
66
67
69{
70 return { "com.sun.star.sdbc.Driver" };
71}
72
73
74sal_Bool SAL_CALL ODBCDriver::supportsService( const OUString& _rServiceName )
75{
76 return cppu::supportsService(this, _rServiceName);
77}
78
79
81{
82 if ( ! acceptsURL(url) )
83 return nullptr;
84
86 {
87 OUString aPath;
88 if(!EnvironmentHandle(aPath))
89 throw SQLException(aPath,*this,OUString(),1000,Any());
90 }
92 pCon->Construct(url,info);
93 m_xConnections.push_back(WeakReferenceHelper(*pCon));
94
95 return pCon;
96}
97
98sal_Bool SAL_CALL ODBCDriver::acceptsURL( const OUString& url )
99{
100 return url.startsWith("sdbc:odbc:");
101}
102
104{
105 if ( acceptsURL(url) )
106 {
107 Sequence< OUString > aBooleanValues{ "false", "true" };
108
109 return
110 {
111 {
112 "CharSet",
113 "CharSet of the database.",
114 false,
115 {},
116 {}
117 },
118 {
119 "UseCatalog",
120 "Use catalog for file-based databases.",
121 false,
122 "false",
123 aBooleanValues
124 },
125 {
126 "SystemDriverSettings",
127 "Driver settings.",
128 false,
129 {},
130 {}
131 },
132 {
133 "ParameterNameSubstitution",
134 "Change named parameters with '?'.",
135 false,
136 "false",
137 aBooleanValues
138 },
139 {
140 "IgnoreDriverPrivileges",
141 "Ignore the privileges from the database driver.",
142 false,
143 "false",
144 aBooleanValues
145 },
146 {
147 "IsAutoRetrievingEnabled",
148 "Retrieve generated values.",
149 false,
150 "false",
151 aBooleanValues
152 },
153 {
154 "AutoRetrievingStatement",
155 "Auto-increment statement.",
156 false,
157 {},
158 {}
159 },
160 {
161 "GenerateASBeforeCorrelationName",
162 "Generate AS before table correlation names.",
163 false,
164 "false",
165 aBooleanValues
166 },
167 {
168 "EscapeDateTime",
169 "Escape date time format.",
170 false,
171 "true",
172 aBooleanValues
173 }
174 };
175 }
177 const OUString sMessage = aResources.getResourceString(STR_URI_SYNTAX_ERROR);
180}
181
182sal_Int32 SAL_CALL ODBCDriver::getMajorVersion( )
183{
184 return 1;
185}
186
187sal_Int32 SAL_CALL ODBCDriver::getMinorVersion( )
188{
189 return 0;
190}
191
192
193/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XComponentContext > m_xContext
helper class for accessing resources shared by different libraries in the connectivity module
OUString getResourceString(TranslateId pResId) const
loads a string from the shared resource file
virtual sal_Int32 SAL_CALL getMajorVersion() override
Definition: ODriver.cxx:182
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: ODriver.cxx:68
virtual void SAL_CALL disposing() override
Definition: ODriver.cxx:42
virtual css::uno::Sequence< css::sdbc::DriverPropertyInfo > SAL_CALL getPropertyInfo(const OUString &url, const css::uno::Sequence< css::beans::PropertyValue > &info) override
Definition: ODriver.cxx:103
virtual SQLHANDLE EnvironmentHandle(OUString &_rPath)=0
connectivity::OWeakRefArray m_xConnections
Definition: ODriver.hxx:41
virtual sal_Bool SAL_CALL acceptsURL(const OUString &url) override
Definition: ODriver.cxx:98
virtual sal_Int32 SAL_CALL getMinorVersion() override
Definition: ODriver.cxx:187
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
Definition: ODriver.cxx:74
virtual css::uno::Reference< css::sdbc::XConnection > SAL_CALL connect(const OUString &url, const css::uno::Sequence< css::beans::PropertyValue > &info) override
Definition: ODriver.cxx:80
virtual OUString SAL_CALL getImplementationName() override
Definition: ODriver.cxx:60
std::mutex m_aMutex
::cppu::WeakComponentImplHelper< css::sdbc::XDriver, css::lang::XServiceInfo > ODriver_BASE
Definition: ODriver.hxx:34
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
void throwGenericSQLException(const OUString &_rMsg, const css::uno::Reference< css::uno::XInterface > &_rxSource)
throw a generic SQLException, i.e.
OUString sMessage
unsigned char sal_Bool
Reference< XComponentContext > _xContext