Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / connectivity / source / drivers / odbc / ODriver.cxx
blobb6ead37a90e16c7931411d420140f330a4ce9495
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 "resource/common_res.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 ::com::sun::star::uno::Reference< ::com::sun::star::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 (OWeakRefArray::iterator i = m_xConnections.begin(); m_xConnections.end() != i; ++i)
49 Reference< XComponent > xComp(i->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( ) throw(RuntimeException)
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( ) throw (RuntimeException)
70 Sequence< OUString > aSNS( 1 );
71 aSNS[0] = "com.sun.star.sdbc.Driver";
72 return aSNS;
76 OUString SAL_CALL ODBCDriver::getImplementationName( ) throw(RuntimeException, std::exception)
78 return getImplementationName_Static();
81 sal_Bool SAL_CALL ODBCDriver::supportsService( const OUString& _rServiceName ) throw(RuntimeException, std::exception)
83 return cppu::supportsService(this, _rServiceName);
87 Sequence< OUString > SAL_CALL ODBCDriver::getSupportedServiceNames( ) throw(RuntimeException, std::exception)
89 return getSupportedServiceNames_Static();
93 Reference< XConnection > SAL_CALL ODBCDriver::connect( const OUString& url, const Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException, std::exception)
95 if ( ! acceptsURL(url) )
96 return NULL;
98 if(!m_pDriverHandle)
100 OUString aPath;
101 if(!EnvironmentHandle(aPath))
102 throw SQLException(aPath,*this,OUString(),1000,Any());
104 OConnection* pCon = new OConnection(m_pDriverHandle,this);
105 Reference< XConnection > xCon = pCon;
106 pCon->Construct(url,info);
107 m_xConnections.push_back(WeakReferenceHelper(*pCon));
109 return xCon;
112 sal_Bool SAL_CALL ODBCDriver::acceptsURL( const OUString& url )
113 throw(SQLException, RuntimeException, std::exception)
115 return url.startsWith("sdbc:odbc:");
118 Sequence< DriverPropertyInfo > SAL_CALL ODBCDriver::getPropertyInfo( const OUString& url, const Sequence< PropertyValue >& /*info*/ ) throw(SQLException, RuntimeException, std::exception)
120 if ( acceptsURL(url) )
122 ::std::vector< DriverPropertyInfo > aDriverInfo;
124 Sequence< OUString > aBooleanValues(2);
125 aBooleanValues[0] = "false";
126 aBooleanValues[1] = "true";
128 aDriverInfo.push_back(DriverPropertyInfo(
129 OUString("CharSet")
130 ,OUString("CharSet of the database.")
131 ,sal_False
132 ,OUString()
133 ,Sequence< OUString >())
135 aDriverInfo.push_back(DriverPropertyInfo(
136 OUString("UseCatalog")
137 ,OUString("Use catalog for file-based databases.")
138 ,sal_False
139 ,OUString( "false" )
140 ,aBooleanValues)
142 aDriverInfo.push_back(DriverPropertyInfo(
143 OUString("SystemDriverSettings")
144 ,OUString("Driver settings.")
145 ,sal_False
146 ,OUString()
147 ,Sequence< OUString >())
149 aDriverInfo.push_back(DriverPropertyInfo(
150 OUString("ParameterNameSubstitution")
151 ,OUString("Change named parameters with '?'.")
152 ,sal_False
153 ,OUString( "false" )
154 ,aBooleanValues)
156 aDriverInfo.push_back(DriverPropertyInfo(
157 OUString("IgnoreDriverPrivileges")
158 ,OUString("Ignore the privileges from the database driver.")
159 ,sal_False
160 ,OUString( "false" )
161 ,aBooleanValues)
163 aDriverInfo.push_back(DriverPropertyInfo(
164 OUString("IsAutoRetrievingEnabled")
165 ,OUString("Retrieve generated values.")
166 ,sal_False
167 ,OUString( "false" )
168 ,aBooleanValues)
170 aDriverInfo.push_back(DriverPropertyInfo(
171 OUString("AutoRetrievingStatement")
172 ,OUString("Auto-increment statement.")
173 ,sal_False
174 ,OUString()
175 ,Sequence< OUString >())
177 aDriverInfo.push_back(DriverPropertyInfo(
178 OUString("GenerateASBeforeCorrelationName")
179 ,OUString("Generate AS before table correlation names.")
180 ,sal_False
181 ,OUString( "true" )
182 ,aBooleanValues)
184 aDriverInfo.push_back(DriverPropertyInfo(
185 OUString("EscapeDateTime")
186 ,OUString("Escape date time format.")
187 ,sal_False
188 ,OUString( "true" )
189 ,aBooleanValues)
192 return Sequence< DriverPropertyInfo >(&aDriverInfo[0],aDriverInfo.size());
194 ::connectivity::SharedResources aResources;
195 const OUString sMessage = aResources.getResourceString(STR_URI_SYNTAX_ERROR);
196 ::dbtools::throwGenericSQLException(sMessage ,*this);
197 return Sequence< DriverPropertyInfo >();
200 sal_Int32 SAL_CALL ODBCDriver::getMajorVersion( ) throw(RuntimeException, std::exception)
202 return 1;
205 sal_Int32 SAL_CALL ODBCDriver::getMinorVersion( ) throw(RuntimeException, std::exception)
207 return 0;
213 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */