xref: /trunk/main/connectivity/source/drivers/odbcbase/ODriver.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_connectivity.hxx"
30 #include "odbc/ODriver.hxx"
31 #include "odbc/OConnection.hxx"
32 #include "odbc/OFunctions.hxx"
33 #include "odbc/OTools.hxx"
34 #include "connectivity/dbexception.hxx"
35 #include "resource/common_res.hrc"
36 #include "resource/sharedresources.hxx"
37 
38 using namespace connectivity::odbc;
39 using namespace com::sun::star::uno;
40 using namespace com::sun::star::lang;
41 using namespace com::sun::star::beans;
42 using namespace com::sun::star::sdbc;
43 // --------------------------------------------------------------------------------
44 ODBCDriver::ODBCDriver(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory)
45     :ODriver_BASE(m_aMutex)
46     ,m_xORB(_rxFactory)
47     ,m_pDriverHandle(SQL_NULL_HANDLE)
48 {
49 }
50 // --------------------------------------------------------------------------------
51 void ODBCDriver::disposing()
52 {
53     ::osl::MutexGuard aGuard(m_aMutex);
54 
55 
56     for (OWeakRefArray::iterator i = m_xConnections.begin(); m_xConnections.end() != i; ++i)
57     {
58         Reference< XComponent > xComp(i->get(), UNO_QUERY);
59         if (xComp.is())
60             xComp->dispose();
61     }
62     m_xConnections.clear();
63 
64     ODriver_BASE::disposing();
65 }
66 
67 // static ServiceInfo
68 //------------------------------------------------------------------------------
69 rtl::OUString ODBCDriver::getImplementationName_Static(  ) throw(RuntimeException)
70 {
71     return rtl::OUString::createFromAscii("com.sun.star.comp.sdbc.ODBCDriver");
72         // this name is referenced in the configuration and in the odbc.xml
73         // Please take care when changing it.
74 }
75 
76 typedef Sequence< ::rtl::OUString > SS;
77 //------------------------------------------------------------------------------
78 SS ODBCDriver::getSupportedServiceNames_Static(  ) throw (RuntimeException)
79 {
80     SS aSNS( 1 );
81     aSNS[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbc.Driver");
82     return aSNS;
83 }
84 
85 //------------------------------------------------------------------
86 ::rtl::OUString SAL_CALL ODBCDriver::getImplementationName(  ) throw(RuntimeException)
87 {
88     return getImplementationName_Static();
89 }
90 
91 //------------------------------------------------------------------
92 sal_Bool SAL_CALL ODBCDriver::supportsService( const ::rtl::OUString& _rServiceName ) throw(RuntimeException)
93 {
94     SS aSupported(getSupportedServiceNames());
95     const ::rtl::OUString* pSupported = aSupported.getConstArray();
96     const ::rtl::OUString* pEnd = pSupported + aSupported.getLength();
97     for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported)
98         ;
99 
100     return pSupported != pEnd;
101 }
102 
103 //------------------------------------------------------------------
104 SS SAL_CALL ODBCDriver::getSupportedServiceNames(  ) throw(RuntimeException)
105 {
106     return getSupportedServiceNames_Static();
107 }
108 
109 // --------------------------------------------------------------------------------
110 Reference< XConnection > SAL_CALL ODBCDriver::connect( const ::rtl::OUString& url, const Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException)
111 {
112     if ( ! acceptsURL(url) )
113         return NULL;
114 
115     if(!m_pDriverHandle)
116     {
117         ::rtl::OUString aPath;
118         if(!EnvironmentHandle(aPath))
119             throw SQLException(aPath,*this,::rtl::OUString(),1000,Any());
120     }
121     OConnection* pCon = new OConnection(m_pDriverHandle,this);
122     Reference< XConnection > xCon = pCon;
123     pCon->Construct(url,info);
124     m_xConnections.push_back(WeakReferenceHelper(*pCon));
125 
126     return xCon;
127 }
128 // --------------------------------------------------------------------------------
129 sal_Bool SAL_CALL ODBCDriver::acceptsURL( const ::rtl::OUString& url )
130         throw(SQLException, RuntimeException)
131 {
132     return (!url.compareTo(::rtl::OUString::createFromAscii("sdbc:odbc:"),10));
133 }
134 // --------------------------------------------------------------------------------
135 Sequence< DriverPropertyInfo > SAL_CALL ODBCDriver::getPropertyInfo( const ::rtl::OUString& url, const Sequence< PropertyValue >& /*info*/ ) throw(SQLException, RuntimeException)
136 {
137     if ( acceptsURL(url) )
138     {
139         ::std::vector< DriverPropertyInfo > aDriverInfo;
140 
141         Sequence< ::rtl::OUString > aBooleanValues(2);
142         aBooleanValues[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "false" ) );
143         aBooleanValues[1] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "true" ) );
144 
145         aDriverInfo.push_back(DriverPropertyInfo(
146                 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CharSet"))
147                 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CharSet of the database."))
148                 ,sal_False
149                 ,::rtl::OUString()
150                 ,Sequence< ::rtl::OUString >())
151                 );
152         aDriverInfo.push_back(DriverPropertyInfo(
153                 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("UseCatalog"))
154                 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Use catalog for file-based databases."))
155                 ,sal_False
156                 ,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "false" ) )
157                 ,aBooleanValues)
158                 );
159         aDriverInfo.push_back(DriverPropertyInfo(
160                 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SystemDriverSettings"))
161                 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Driver settings."))
162                 ,sal_False
163                 ,::rtl::OUString()
164                 ,Sequence< ::rtl::OUString >())
165                 );
166         aDriverInfo.push_back(DriverPropertyInfo(
167                 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ParameterNameSubstitution"))
168                 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Change named parameters with '?'."))
169                 ,sal_False
170                 ,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "false" ) )
171                 ,aBooleanValues)
172                 );
173         aDriverInfo.push_back(DriverPropertyInfo(
174                 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IgnoreDriverPrivileges"))
175                 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Ignore the privileges from the database driver."))
176                 ,sal_False
177                 ,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "false" ) )
178                 ,aBooleanValues)
179                 );
180         aDriverInfo.push_back(DriverPropertyInfo(
181                 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IsAutoRetrievingEnabled"))
182                 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Retrieve generated values."))
183                 ,sal_False
184                 ,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "false" ) )
185                 ,aBooleanValues)
186                 );
187         aDriverInfo.push_back(DriverPropertyInfo(
188                 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AutoRetrievingStatement"))
189                 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Auto-increment statement."))
190                 ,sal_False
191                 ,::rtl::OUString()
192                 ,Sequence< ::rtl::OUString >())
193                 );
194         aDriverInfo.push_back(DriverPropertyInfo(
195                 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("GenerateASBeforeCorrelationName"))
196                 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Generate AS before table correlation names."))
197                 ,sal_False
198                 ,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "true" ) )
199                 ,aBooleanValues)
200                 );
201         aDriverInfo.push_back(DriverPropertyInfo(
202                 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("EscapeDateTime"))
203                 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Escape date time format."))
204                 ,sal_False
205                 ,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "true" ) )
206                 ,aBooleanValues)
207                 );
208 
209         return Sequence< DriverPropertyInfo >(&aDriverInfo[0],aDriverInfo.size());
210     }
211     ::connectivity::SharedResources aResources;
212     const ::rtl::OUString sMessage = aResources.getResourceString(STR_URI_SYNTAX_ERROR);
213     ::dbtools::throwGenericSQLException(sMessage ,*this);
214     return Sequence< DriverPropertyInfo >();
215 }
216 // --------------------------------------------------------------------------------
217 sal_Int32 SAL_CALL ODBCDriver::getMajorVersion(  ) throw(RuntimeException)
218 {
219     return 1;
220 }
221 // --------------------------------------------------------------------------------
222 sal_Int32 SAL_CALL ODBCDriver::getMinorVersion(  ) throw(RuntimeException)
223 {
224     return 0;
225 }
226 // --------------------------------------------------------------------------------
227 //-----------------------------------------------------------------------------
228 
229 
230