1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_connectivity.hxx"
26 #include "odbc/ODriver.hxx"
27 #include "odbc/OConnection.hxx"
28 #include "odbc/OFunctions.hxx"
29 #include "odbc/OTools.hxx"
30 #include "connectivity/dbexception.hxx"
31 #include "resource/common_res.hrc"
32 #include "resource/sharedresources.hxx"
33
34 using namespace connectivity::odbc;
35 using namespace com::sun::star::uno;
36 using namespace com::sun::star::lang;
37 using namespace com::sun::star::beans;
38 using namespace com::sun::star::sdbc;
39 // --------------------------------------------------------------------------------
ODBCDriver(const::com::sun::star::uno::Reference<::com::sun::star::lang::XMultiServiceFactory> & _rxFactory)40 ODBCDriver::ODBCDriver(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory)
41 :ODriver_BASE(m_aMutex)
42 ,m_xORB(_rxFactory)
43 ,m_pDriverHandle(SQL_NULL_HANDLE)
44 {
45 }
46 // --------------------------------------------------------------------------------
disposing()47 void ODBCDriver::disposing()
48 {
49 ::osl::MutexGuard aGuard(m_aMutex);
50
51
52 for (OWeakRefArray::iterator i = m_xConnections.begin(); m_xConnections.end() != i; ++i)
53 {
54 Reference< XComponent > xComp(i->get(), UNO_QUERY);
55 if (xComp.is())
56 xComp->dispose();
57 }
58 m_xConnections.clear();
59
60 ODriver_BASE::disposing();
61 }
62
63 // static ServiceInfo
64 //------------------------------------------------------------------------------
getImplementationName_Static()65 rtl::OUString ODBCDriver::getImplementationName_Static( ) throw(RuntimeException)
66 {
67 return rtl::OUString::createFromAscii("com.sun.star.comp.sdbc.ODBCDriver");
68 // this name is referenced in the configuration and in the odbc.xml
69 // Please take care when changing it.
70 }
71
72 typedef Sequence< ::rtl::OUString > SSEQ;
73 //------------------------------------------------------------------------------
getSupportedServiceNames_Static()74 SSEQ ODBCDriver::getSupportedServiceNames_Static( ) throw (RuntimeException)
75 {
76 SSEQ aSNS( 1 );
77 aSNS[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbc.Driver");
78 return aSNS;
79 }
80
81 //------------------------------------------------------------------
getImplementationName()82 ::rtl::OUString SAL_CALL ODBCDriver::getImplementationName( ) throw(RuntimeException)
83 {
84 return getImplementationName_Static();
85 }
86
87 //------------------------------------------------------------------
supportsService(const::rtl::OUString & _rServiceName)88 sal_Bool SAL_CALL ODBCDriver::supportsService( const ::rtl::OUString& _rServiceName ) throw(RuntimeException)
89 {
90 SSEQ aSupported(getSupportedServiceNames());
91 const ::rtl::OUString* pSupported = aSupported.getConstArray();
92 const ::rtl::OUString* pEnd = pSupported + aSupported.getLength();
93 for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported)
94 ;
95
96 return pSupported != pEnd;
97 }
98
99 //------------------------------------------------------------------
getSupportedServiceNames()100 SSEQ SAL_CALL ODBCDriver::getSupportedServiceNames( ) throw(RuntimeException)
101 {
102 return getSupportedServiceNames_Static();
103 }
104
105 // --------------------------------------------------------------------------------
connect(const::rtl::OUString & url,const Sequence<PropertyValue> & info)106 Reference< XConnection > SAL_CALL ODBCDriver::connect( const ::rtl::OUString& url, const Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException)
107 {
108 if ( ! acceptsURL(url) )
109 return NULL;
110
111 if(!m_pDriverHandle)
112 {
113 ::rtl::OUString aPath;
114 if(!EnvironmentHandle(aPath))
115 throw SQLException(aPath,*this,::rtl::OUString(),1000,Any());
116 }
117 OConnection* pCon = new OConnection(m_pDriverHandle,this);
118 Reference< XConnection > xCon = pCon;
119 pCon->Construct(url,info);
120 m_xConnections.push_back(WeakReferenceHelper(*pCon));
121
122 return xCon;
123 }
124 // --------------------------------------------------------------------------------
acceptsURL(const::rtl::OUString & url)125 sal_Bool SAL_CALL ODBCDriver::acceptsURL( const ::rtl::OUString& url )
126 throw(SQLException, RuntimeException)
127 {
128 return (!url.compareTo(::rtl::OUString::createFromAscii("sdbc:odbc:"),10));
129 }
130 // --------------------------------------------------------------------------------
getPropertyInfo(const::rtl::OUString & url,const Sequence<PropertyValue> &)131 Sequence< DriverPropertyInfo > SAL_CALL ODBCDriver::getPropertyInfo( const ::rtl::OUString& url, const Sequence< PropertyValue >& /*info*/ ) throw(SQLException, RuntimeException)
132 {
133 if ( acceptsURL(url) )
134 {
135 ::std::vector< DriverPropertyInfo > aDriverInfo;
136
137 Sequence< ::rtl::OUString > aBooleanValues(2);
138 aBooleanValues[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "false" ) );
139 aBooleanValues[1] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "true" ) );
140
141 aDriverInfo.push_back(DriverPropertyInfo(
142 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CharSet"))
143 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CharSet of the database."))
144 ,sal_False
145 ,::rtl::OUString()
146 ,Sequence< ::rtl::OUString >())
147 );
148 aDriverInfo.push_back(DriverPropertyInfo(
149 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("UseCatalog"))
150 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Use catalog for file-based databases."))
151 ,sal_False
152 ,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "false" ) )
153 ,aBooleanValues)
154 );
155 aDriverInfo.push_back(DriverPropertyInfo(
156 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SystemDriverSettings"))
157 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Driver settings."))
158 ,sal_False
159 ,::rtl::OUString()
160 ,Sequence< ::rtl::OUString >())
161 );
162 aDriverInfo.push_back(DriverPropertyInfo(
163 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ParameterNameSubstitution"))
164 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Change named parameters with '?'."))
165 ,sal_False
166 ,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "false" ) )
167 ,aBooleanValues)
168 );
169 aDriverInfo.push_back(DriverPropertyInfo(
170 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IgnoreDriverPrivileges"))
171 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Ignore the privileges from the database driver."))
172 ,sal_False
173 ,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "false" ) )
174 ,aBooleanValues)
175 );
176 aDriverInfo.push_back(DriverPropertyInfo(
177 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IsAutoRetrievingEnabled"))
178 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Retrieve generated values."))
179 ,sal_False
180 ,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "false" ) )
181 ,aBooleanValues)
182 );
183 aDriverInfo.push_back(DriverPropertyInfo(
184 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AutoRetrievingStatement"))
185 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Auto-increment statement."))
186 ,sal_False
187 ,::rtl::OUString()
188 ,Sequence< ::rtl::OUString >())
189 );
190 aDriverInfo.push_back(DriverPropertyInfo(
191 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("GenerateASBeforeCorrelationName"))
192 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Generate AS before table correlation names."))
193 ,sal_False
194 ,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "true" ) )
195 ,aBooleanValues)
196 );
197 aDriverInfo.push_back(DriverPropertyInfo(
198 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("EscapeDateTime"))
199 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Escape date time format."))
200 ,sal_False
201 ,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "true" ) )
202 ,aBooleanValues)
203 );
204
205 return Sequence< DriverPropertyInfo >(&aDriverInfo[0],aDriverInfo.size());
206 }
207 ::connectivity::SharedResources aResources;
208 const ::rtl::OUString sMessage = aResources.getResourceString(STR_URI_SYNTAX_ERROR);
209 ::dbtools::throwGenericSQLException(sMessage ,*this);
210 return Sequence< DriverPropertyInfo >();
211 }
212 // --------------------------------------------------------------------------------
getMajorVersion()213 sal_Int32 SAL_CALL ODBCDriver::getMajorVersion( ) throw(RuntimeException)
214 {
215 return 1;
216 }
217 // --------------------------------------------------------------------------------
getMinorVersion()218 sal_Int32 SAL_CALL ODBCDriver::getMinorVersion( ) throw(RuntimeException)
219 {
220 return 0;
221 }
222 // --------------------------------------------------------------------------------
223 //-----------------------------------------------------------------------------
224
225
226