xref: /trunk/main/connectivity/source/drivers/odbcbase/ODriver.cxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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_odbcbase.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(  )
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(  )
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(  )
83 {
84     return getImplementationName_Static();
85 }
86 
87 //------------------------------------------------------------------
supportsService(const::rtl::OUString & _rServiceName)88 sal_Bool SAL_CALL ODBCDriver::supportsService( const ::rtl::OUString& _rServiceName )
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(  )
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 )
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 {
127     return (!url.compareTo(::rtl::OUString::createFromAscii("sdbc:odbc:"),10));
128 }
129 // --------------------------------------------------------------------------------
getPropertyInfo(const::rtl::OUString & url,const Sequence<PropertyValue> &)130 Sequence< DriverPropertyInfo > SAL_CALL ODBCDriver::getPropertyInfo( const ::rtl::OUString& url, const Sequence< PropertyValue >& /*info*/ )
131 {
132     if ( acceptsURL(url) )
133     {
134         ::std::vector< DriverPropertyInfo > aDriverInfo;
135 
136         Sequence< ::rtl::OUString > aBooleanValues(2);
137         aBooleanValues[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "false" ) );
138         aBooleanValues[1] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "true" ) );
139 
140         aDriverInfo.push_back(DriverPropertyInfo(
141                 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CharSet"))
142                 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CharSet of the database."))
143                 ,sal_False
144                 ,::rtl::OUString()
145                 ,Sequence< ::rtl::OUString >())
146                 );
147         aDriverInfo.push_back(DriverPropertyInfo(
148                 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("UseCatalog"))
149                 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Use catalog for file-based databases."))
150                 ,sal_False
151                 ,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "false" ) )
152                 ,aBooleanValues)
153                 );
154         aDriverInfo.push_back(DriverPropertyInfo(
155                 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SystemDriverSettings"))
156                 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Driver settings."))
157                 ,sal_False
158                 ,::rtl::OUString()
159                 ,Sequence< ::rtl::OUString >())
160                 );
161         aDriverInfo.push_back(DriverPropertyInfo(
162                 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ParameterNameSubstitution"))
163                 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Change named parameters with '?'."))
164                 ,sal_False
165                 ,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "false" ) )
166                 ,aBooleanValues)
167                 );
168         aDriverInfo.push_back(DriverPropertyInfo(
169                 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IgnoreDriverPrivileges"))
170                 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Ignore the privileges from the database driver."))
171                 ,sal_False
172                 ,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "false" ) )
173                 ,aBooleanValues)
174                 );
175         aDriverInfo.push_back(DriverPropertyInfo(
176                 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IsAutoRetrievingEnabled"))
177                 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Retrieve generated values."))
178                 ,sal_False
179                 ,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "false" ) )
180                 ,aBooleanValues)
181                 );
182         aDriverInfo.push_back(DriverPropertyInfo(
183                 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AutoRetrievingStatement"))
184                 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Auto-increment statement."))
185                 ,sal_False
186                 ,::rtl::OUString()
187                 ,Sequence< ::rtl::OUString >())
188                 );
189         aDriverInfo.push_back(DriverPropertyInfo(
190                 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("GenerateASBeforeCorrelationName"))
191                 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Generate AS before table correlation names."))
192                 ,sal_False
193                 ,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "true" ) )
194                 ,aBooleanValues)
195                 );
196         aDriverInfo.push_back(DriverPropertyInfo(
197                 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("EscapeDateTime"))
198                 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Escape date time format."))
199                 ,sal_False
200                 ,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "true" ) )
201                 ,aBooleanValues)
202                 );
203 
204         return Sequence< DriverPropertyInfo >(&aDriverInfo[0],aDriverInfo.size());
205     }
206     ::connectivity::SharedResources aResources;
207     const ::rtl::OUString sMessage = aResources.getResourceString(STR_URI_SYNTAX_ERROR);
208     ::dbtools::throwGenericSQLException(sMessage ,*this);
209     return Sequence< DriverPropertyInfo >();
210 }
211 // --------------------------------------------------------------------------------
getMajorVersion()212 sal_Int32 SAL_CALL ODBCDriver::getMajorVersion(  )
213 {
214     return 1;
215 }
216 // --------------------------------------------------------------------------------
getMinorVersion()217 sal_Int32 SAL_CALL ODBCDriver::getMinorVersion(  )
218 {
219     return 0;
220 }
221 // --------------------------------------------------------------------------------
222 //-----------------------------------------------------------------------------
223