Branch data Line data Source code
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/OFunctions.hxx"
23 : : #include "odbc/OTools.hxx"
24 : : #include "connectivity/dbexception.hxx"
25 : : #include "resource/common_res.hrc"
26 : : #include "resource/sharedresources.hxx"
27 : :
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 : 0 : ODBCDriver::ODBCDriver(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory)
35 : : :ODriver_BASE(m_aMutex)
36 : : ,m_xORB(_rxFactory)
37 : 0 : ,m_pDriverHandle(SQL_NULL_HANDLE)
38 : : {
39 : 0 : }
40 : : // --------------------------------------------------------------------------------
41 : 0 : void ODBCDriver::disposing()
42 : : {
43 : 0 : ::osl::MutexGuard aGuard(m_aMutex);
44 : :
45 : :
46 : 0 : for (OWeakRefArray::iterator i = m_xConnections.begin(); m_xConnections.end() != i; ++i)
47 : : {
48 : 0 : Reference< XComponent > xComp(i->get(), UNO_QUERY);
49 : 0 : if (xComp.is())
50 : 0 : xComp->dispose();
51 : 0 : }
52 : 0 : m_xConnections.clear();
53 : :
54 : 0 : ODriver_BASE::disposing();
55 : 0 : }
56 : :
57 : : // static ServiceInfo
58 : : //------------------------------------------------------------------------------
59 : 0 : rtl::OUString ODBCDriver::getImplementationName_Static( ) throw(RuntimeException)
60 : : {
61 : 0 : return rtl::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.
64 : : }
65 : :
66 : : //------------------------------------------------------------------------------
67 : 0 : Sequence< ::rtl::OUString > ODBCDriver::getSupportedServiceNames_Static( ) throw (RuntimeException)
68 : : {
69 : 0 : Sequence< ::rtl::OUString > aSNS( 1 );
70 : 0 : aSNS[0] = ::rtl::OUString("com.sun.star.sdbc.Driver");
71 : 0 : return aSNS;
72 : : }
73 : :
74 : : //------------------------------------------------------------------
75 : 0 : ::rtl::OUString SAL_CALL ODBCDriver::getImplementationName( ) throw(RuntimeException)
76 : : {
77 : 0 : return getImplementationName_Static();
78 : : }
79 : :
80 : : //------------------------------------------------------------------
81 : 0 : sal_Bool SAL_CALL ODBCDriver::supportsService( const ::rtl::OUString& _rServiceName ) throw(RuntimeException)
82 : : {
83 : 0 : Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames());
84 : 0 : const ::rtl::OUString* pSupported = aSupported.getConstArray();
85 : 0 : const ::rtl::OUString* pEnd = pSupported + aSupported.getLength();
86 : 0 : for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported)
87 : : ;
88 : :
89 : 0 : return pSupported != pEnd;
90 : : }
91 : :
92 : : //------------------------------------------------------------------
93 : 0 : Sequence< ::rtl::OUString > SAL_CALL ODBCDriver::getSupportedServiceNames( ) throw(RuntimeException)
94 : : {
95 : 0 : return getSupportedServiceNames_Static();
96 : : }
97 : :
98 : : // --------------------------------------------------------------------------------
99 : 0 : Reference< XConnection > SAL_CALL ODBCDriver::connect( const ::rtl::OUString& url, const Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException)
100 : : {
101 : 0 : if ( ! acceptsURL(url) )
102 : 0 : return NULL;
103 : :
104 : 0 : if(!m_pDriverHandle)
105 : : {
106 : 0 : ::rtl::OUString aPath;
107 : 0 : if(!EnvironmentHandle(aPath))
108 : 0 : throw SQLException(aPath,*this,::rtl::OUString(),1000,Any());
109 : : }
110 : 0 : OConnection* pCon = new OConnection(m_pDriverHandle,this);
111 : 0 : Reference< XConnection > xCon = pCon;
112 : 0 : pCon->Construct(url,info);
113 : 0 : m_xConnections.push_back(WeakReferenceHelper(*pCon));
114 : :
115 : 0 : return xCon;
116 : : }
117 : : // --------------------------------------------------------------------------------
118 : 0 : sal_Bool SAL_CALL ODBCDriver::acceptsURL( const ::rtl::OUString& url )
119 : : throw(SQLException, RuntimeException)
120 : : {
121 : 0 : return (!url.compareTo(::rtl::OUString("sdbc:odbc:"),10));
122 : : }
123 : : // --------------------------------------------------------------------------------
124 : 0 : Sequence< DriverPropertyInfo > SAL_CALL ODBCDriver::getPropertyInfo( const ::rtl::OUString& url, const Sequence< PropertyValue >& /*info*/ ) throw(SQLException, RuntimeException)
125 : : {
126 : 0 : if ( acceptsURL(url) )
127 : : {
128 : 0 : ::std::vector< DriverPropertyInfo > aDriverInfo;
129 : :
130 : 0 : Sequence< ::rtl::OUString > aBooleanValues(2);
131 : 0 : aBooleanValues[0] = ::rtl::OUString( "false" );
132 : 0 : aBooleanValues[1] = ::rtl::OUString( "true" );
133 : :
134 : : aDriverInfo.push_back(DriverPropertyInfo(
135 : : ::rtl::OUString("CharSet")
136 : : ,::rtl::OUString("CharSet of the database.")
137 : : ,sal_False
138 : : ,::rtl::OUString()
139 : : ,Sequence< ::rtl::OUString >())
140 : 0 : );
141 : : aDriverInfo.push_back(DriverPropertyInfo(
142 : : ::rtl::OUString("UseCatalog")
143 : : ,::rtl::OUString("Use catalog for file-based databases.")
144 : : ,sal_False
145 : : ,::rtl::OUString( "false" )
146 : : ,aBooleanValues)
147 : 0 : );
148 : : aDriverInfo.push_back(DriverPropertyInfo(
149 : : ::rtl::OUString("SystemDriverSettings")
150 : : ,::rtl::OUString("Driver settings.")
151 : : ,sal_False
152 : : ,::rtl::OUString()
153 : : ,Sequence< ::rtl::OUString >())
154 : 0 : );
155 : : aDriverInfo.push_back(DriverPropertyInfo(
156 : : ::rtl::OUString("ParameterNameSubstitution")
157 : : ,::rtl::OUString("Change named parameters with '?'.")
158 : : ,sal_False
159 : : ,::rtl::OUString( "false" )
160 : : ,aBooleanValues)
161 : 0 : );
162 : : aDriverInfo.push_back(DriverPropertyInfo(
163 : : ::rtl::OUString("IgnoreDriverPrivileges")
164 : : ,::rtl::OUString("Ignore the privileges from the database driver.")
165 : : ,sal_False
166 : : ,::rtl::OUString( "false" )
167 : : ,aBooleanValues)
168 : 0 : );
169 : : aDriverInfo.push_back(DriverPropertyInfo(
170 : : ::rtl::OUString("IsAutoRetrievingEnabled")
171 : : ,::rtl::OUString("Retrieve generated values.")
172 : : ,sal_False
173 : : ,::rtl::OUString( "false" )
174 : : ,aBooleanValues)
175 : 0 : );
176 : : aDriverInfo.push_back(DriverPropertyInfo(
177 : : ::rtl::OUString("AutoRetrievingStatement")
178 : : ,::rtl::OUString("Auto-increment statement.")
179 : : ,sal_False
180 : : ,::rtl::OUString()
181 : : ,Sequence< ::rtl::OUString >())
182 : 0 : );
183 : : aDriverInfo.push_back(DriverPropertyInfo(
184 : : ::rtl::OUString("GenerateASBeforeCorrelationName")
185 : : ,::rtl::OUString("Generate AS before table correlation names.")
186 : : ,sal_False
187 : : ,::rtl::OUString( "true" )
188 : : ,aBooleanValues)
189 : 0 : );
190 : : aDriverInfo.push_back(DriverPropertyInfo(
191 : : ::rtl::OUString("EscapeDateTime")
192 : : ,::rtl::OUString("Escape date time format.")
193 : : ,sal_False
194 : : ,::rtl::OUString( "true" )
195 : : ,aBooleanValues)
196 : 0 : );
197 : :
198 : 0 : return Sequence< DriverPropertyInfo >(&aDriverInfo[0],aDriverInfo.size());
199 : : }
200 : 0 : ::connectivity::SharedResources aResources;
201 : 0 : const ::rtl::OUString sMessage = aResources.getResourceString(STR_URI_SYNTAX_ERROR);
202 : 0 : ::dbtools::throwGenericSQLException(sMessage ,*this);
203 : 0 : return Sequence< DriverPropertyInfo >();
204 : : }
205 : : // --------------------------------------------------------------------------------
206 : 0 : sal_Int32 SAL_CALL ODBCDriver::getMajorVersion( ) throw(RuntimeException)
207 : : {
208 : 0 : return 1;
209 : : }
210 : : // --------------------------------------------------------------------------------
211 : 0 : sal_Int32 SAL_CALL ODBCDriver::getMinorVersion( ) throw(RuntimeException)
212 : : {
213 : 0 : return 0;
214 : : }
215 : : // --------------------------------------------------------------------------------
216 : : //-----------------------------------------------------------------------------
217 : :
218 : :
219 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|