xref: /AOO41X/main/dbaccess/source/ui/dlg/odbcconfig.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_dbaccess.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #ifndef _DBAUI_ODBC_CONFIG_HXX_
32*cdf0e10cSrcweir #include "odbcconfig.hxx"
33*cdf0e10cSrcweir #endif
34*cdf0e10cSrcweir #include <rtl/bootstrap.hxx>
35*cdf0e10cSrcweir #ifndef _RTL_USTRING_HXX_
36*cdf0e10cSrcweir #include <rtl/ustring.hxx>
37*cdf0e10cSrcweir #endif
38*cdf0e10cSrcweir #ifndef _RTL_USTRBUF_HXX_
39*cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
40*cdf0e10cSrcweir #endif
41*cdf0e10cSrcweir #ifndef _OSL_DIAGNOSE_H_
42*cdf0e10cSrcweir #include <osl/diagnose.h>
43*cdf0e10cSrcweir #endif
44*cdf0e10cSrcweir #ifndef _OSL_PROCESS_H_
45*cdf0e10cSrcweir #include <osl/process.h>
46*cdf0e10cSrcweir #endif
47*cdf0e10cSrcweir #ifndef _THREAD_HXX_
48*cdf0e10cSrcweir #include <osl/thread.hxx>
49*cdf0e10cSrcweir #endif
50*cdf0e10cSrcweir #ifndef _TOOLS_DEBUG_HXX
51*cdf0e10cSrcweir #include <tools/debug.hxx>
52*cdf0e10cSrcweir #endif
53*cdf0e10cSrcweir #ifndef _SV_SVAPP_HXX
54*cdf0e10cSrcweir #include <vcl/svapp.hxx>
55*cdf0e10cSrcweir #endif
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir #ifdef HAVE_ODBC_SUPPORT
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir #if defined(OS2)
60*cdf0e10cSrcweir #define ODBC_LIBRARY	"ODBC.DLL"
61*cdf0e10cSrcweir #define ODBC_UI_LIBRARY	"ODBCINST.DLL"
62*cdf0e10cSrcweir #endif
63*cdf0e10cSrcweir #if defined WNT
64*cdf0e10cSrcweir #define ODBC_LIBRARY	"ODBC32.DLL"
65*cdf0e10cSrcweir #define ODBC_UI_LIBRARY	"ODBCCP32.DLL"
66*cdf0e10cSrcweir #endif
67*cdf0e10cSrcweir #ifdef UNX
68*cdf0e10cSrcweir #ifdef MACOSX
69*cdf0e10cSrcweir #define ODBC_LIBRARY		"libiodbc.dylib"
70*cdf0e10cSrcweir #define ODBC_UI_LIBRARY		"libiodbcinst.dylib"
71*cdf0e10cSrcweir #else
72*cdf0e10cSrcweir #define ODBC_LIBRARY_1		"libodbc.so.1"
73*cdf0e10cSrcweir #define ODBC_UI_LIBRARY_1	"libodbcinst.so.1"
74*cdf0e10cSrcweir #define ODBC_LIBRARY		"libodbc.so"
75*cdf0e10cSrcweir #define ODBC_UI_LIBRARY		"libodbcinst.so"
76*cdf0e10cSrcweir #endif
77*cdf0e10cSrcweir #endif
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir // just to go with calling convention of windows
80*cdf0e10cSrcweir // so don't touch this
81*cdf0e10cSrcweir #if defined(WNT)
82*cdf0e10cSrcweir #define SQL_API __stdcall
83*cdf0e10cSrcweir // At least under some circumstances, the below #include <odbc/sqlext.h> re-
84*cdf0e10cSrcweir // defines SQL_API to an empty string, leading to a compiler warning on MSC; to
85*cdf0e10cSrcweir // not break the current behavior, this is worked around by locally disabling
86*cdf0e10cSrcweir // that warning:
87*cdf0e10cSrcweir #if defined _MSC_VER
88*cdf0e10cSrcweir #pragma warning(push)
89*cdf0e10cSrcweir #pragma warning(disable: 4005)
90*cdf0e10cSrcweir #endif
91*cdf0e10cSrcweir #endif // defined(WNT)
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir #if defined(OS2)
94*cdf0e10cSrcweir #define ALLREADY_HAVE_OS2_TYPES
95*cdf0e10cSrcweir #define DONT_TD_VOID
96*cdf0e10cSrcweir #endif
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir #ifdef SYSTEM_ODBC_HEADERS
99*cdf0e10cSrcweir #include <sqlext.h>
100*cdf0e10cSrcweir #else
101*cdf0e10cSrcweir #ifndef __SQLEXT_H
102*cdf0e10cSrcweir #include <odbc/sqlext.h>
103*cdf0e10cSrcweir #endif
104*cdf0e10cSrcweir #endif
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir #if defined(WNT)
107*cdf0e10cSrcweir #if defined _MSC_VER
108*cdf0e10cSrcweir #pragma warning(pop)
109*cdf0e10cSrcweir #endif
110*cdf0e10cSrcweir #undef SQL_API
111*cdf0e10cSrcweir #define SQL_API __stdcall
112*cdf0e10cSrcweir #endif // defined(WNT)
113*cdf0e10cSrcweir // from here on you can do what you want to
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir #if defined(OS2)
116*cdf0e10cSrcweir #define SQL_API _System
117*cdf0e10cSrcweir #endif // defined(OS2)
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir #else
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir #define ODBC_LIBRARY	""
122*cdf0e10cSrcweir #define ODBC_UI_LIBRARY	""
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir #endif	// HAVE_ODBC_SUPPORT
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir //.........................................................................
127*cdf0e10cSrcweir namespace dbaui
128*cdf0e10cSrcweir {
129*cdf0e10cSrcweir //.........................................................................
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir #ifdef HAVE_ODBC_SUPPORT
133*cdf0e10cSrcweir typedef SQLRETURN (SQL_API* TSQLManageDataSource) (SQLHWND hwndParent);
134*cdf0e10cSrcweir typedef SQLRETURN (SQL_API* TSQLAllocHandle) (SQLSMALLINT HandleType, SQLHANDLE InputHandle, SQLHANDLE*	OutputHandlePtr);
135*cdf0e10cSrcweir typedef SQLRETURN (SQL_API* TSQLFreeHandle) (SQLSMALLINT HandleType, SQLHANDLE Handle);
136*cdf0e10cSrcweir typedef SQLRETURN (SQL_API* TSQLSetEnvAttr) (SQLHENV EnvironmentHandle, SQLINTEGER Attribute, SQLPOINTER ValuePtr, SQLINTEGER StringLength);
137*cdf0e10cSrcweir typedef SQLRETURN (SQL_API* TSQLDataSources) (SQLHENV EnvironmentHandle, SQLUSMALLINT	Direction, SQLCHAR* ServerName,
138*cdf0e10cSrcweir 								SQLSMALLINT BufferLength1, SQLSMALLINT* NameLength1Ptr, SQLCHAR* Description, SQLSMALLINT BufferLength2, SQLSMALLINT* NameLength2Ptr);
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir #define NSQLManageDataSource(a) (*(TSQLManageDataSource)(m_pSQLManageDataSource))(a)
141*cdf0e10cSrcweir #define NSQLAllocHandle(a,b,c) (*(TSQLAllocHandle)(m_pAllocHandle))(a,b,c)
142*cdf0e10cSrcweir #define NSQLFreeHandle(a,b) (*(TSQLFreeHandle)(m_pFreeHandle))(a,b)
143*cdf0e10cSrcweir #define NSQLSetEnvAttr(a,b,c,d) (*(TSQLSetEnvAttr)(m_pSetEnvAttr))(a,b,c,d)
144*cdf0e10cSrcweir #define NSQLDataSources(a,b,c,d,e,f,g,h) (*(TSQLDataSources)(m_pDataSources))(a,b,c,d,e,f,g,h)
145*cdf0e10cSrcweir #endif
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir //=========================================================================
148*cdf0e10cSrcweir //= OOdbcLibWrapper
149*cdf0e10cSrcweir //=========================================================================
150*cdf0e10cSrcweir DBG_NAME(OOdbcLibWrapper)
151*cdf0e10cSrcweir //-------------------------------------------------------------------------
152*cdf0e10cSrcweir #ifdef HAVE_ODBC_SUPPORT
153*cdf0e10cSrcweir OOdbcLibWrapper::OOdbcLibWrapper()
154*cdf0e10cSrcweir 	:m_pOdbcLib(NULL)
155*cdf0e10cSrcweir {
156*cdf0e10cSrcweir     DBG_CTOR(OOdbcLibWrapper,NULL);
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir }
159*cdf0e10cSrcweir #endif
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir //-------------------------------------------------------------------------
162*cdf0e10cSrcweir sal_Bool OOdbcLibWrapper::load(const sal_Char* _pLibPath)
163*cdf0e10cSrcweir {
164*cdf0e10cSrcweir 	m_sLibPath = ::rtl::OUString::createFromAscii(_pLibPath);
165*cdf0e10cSrcweir #ifdef HAVE_ODBC_SUPPORT
166*cdf0e10cSrcweir 	// load the module
167*cdf0e10cSrcweir 	m_pOdbcLib = osl_loadModule(m_sLibPath.pData, SAL_LOADMODULE_NOW);
168*cdf0e10cSrcweir 	return (NULL != m_pOdbcLib);
169*cdf0e10cSrcweir #endif
170*cdf0e10cSrcweir }
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir //-------------------------------------------------------------------------
173*cdf0e10cSrcweir void OOdbcLibWrapper::unload()
174*cdf0e10cSrcweir {
175*cdf0e10cSrcweir #ifdef HAVE_ODBC_SUPPORT
176*cdf0e10cSrcweir 	if (isLoaded())
177*cdf0e10cSrcweir 	{
178*cdf0e10cSrcweir 		osl_unloadModule(m_pOdbcLib);
179*cdf0e10cSrcweir 		m_pOdbcLib = NULL;
180*cdf0e10cSrcweir 	}
181*cdf0e10cSrcweir #endif
182*cdf0e10cSrcweir }
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir //-------------------------------------------------------------------------
185*cdf0e10cSrcweir oslGenericFunction OOdbcLibWrapper::loadSymbol(const sal_Char* _pFunctionName)
186*cdf0e10cSrcweir {
187*cdf0e10cSrcweir 	return osl_getFunctionSymbol(m_pOdbcLib, ::rtl::OUString::createFromAscii(_pFunctionName).pData);
188*cdf0e10cSrcweir }
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir //-------------------------------------------------------------------------
191*cdf0e10cSrcweir OOdbcLibWrapper::~OOdbcLibWrapper()
192*cdf0e10cSrcweir {
193*cdf0e10cSrcweir 	unload();
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir     DBG_DTOR(OOdbcLibWrapper,NULL);
196*cdf0e10cSrcweir }
197*cdf0e10cSrcweir 
198*cdf0e10cSrcweir //=========================================================================
199*cdf0e10cSrcweir //= OOdbcEnumeration
200*cdf0e10cSrcweir //=========================================================================
201*cdf0e10cSrcweir struct OdbcTypesImpl
202*cdf0e10cSrcweir {
203*cdf0e10cSrcweir #ifdef HAVE_ODBC_SUPPORT
204*cdf0e10cSrcweir 	SQLHANDLE	hEnvironment;
205*cdf0e10cSrcweir 	OdbcTypesImpl() : hEnvironment(0) { }
206*cdf0e10cSrcweir #else
207*cdf0e10cSrcweir 	void*		pDummy;
208*cdf0e10cSrcweir #endif
209*cdf0e10cSrcweir };
210*cdf0e10cSrcweir DBG_NAME(OOdbcEnumeration)
211*cdf0e10cSrcweir //-------------------------------------------------------------------------
212*cdf0e10cSrcweir OOdbcEnumeration::OOdbcEnumeration()
213*cdf0e10cSrcweir #ifdef HAVE_ODBC_SUPPORT
214*cdf0e10cSrcweir 	:m_pAllocHandle(NULL)
215*cdf0e10cSrcweir 	,m_pSetEnvAttr(NULL)
216*cdf0e10cSrcweir 	,m_pDataSources(NULL)
217*cdf0e10cSrcweir 	,m_pImpl(new OdbcTypesImpl)
218*cdf0e10cSrcweir #endif
219*cdf0e10cSrcweir {
220*cdf0e10cSrcweir     DBG_CTOR(OOdbcEnumeration,NULL);
221*cdf0e10cSrcweir 
222*cdf0e10cSrcweir 	sal_Bool bLoaded = load(ODBC_LIBRARY);
223*cdf0e10cSrcweir #ifdef ODBC_LIBRARY_1
224*cdf0e10cSrcweir 	if ( !bLoaded )
225*cdf0e10cSrcweir 		bLoaded = load(ODBC_LIBRARY_1);
226*cdf0e10cSrcweir #endif
227*cdf0e10cSrcweir 
228*cdf0e10cSrcweir 	if ( bLoaded )
229*cdf0e10cSrcweir 	{
230*cdf0e10cSrcweir #ifdef HAVE_ODBC_SUPPORT
231*cdf0e10cSrcweir 		// load the generic functions
232*cdf0e10cSrcweir 		m_pAllocHandle = loadSymbol("SQLAllocHandle");
233*cdf0e10cSrcweir 		m_pFreeHandle = loadSymbol("SQLFreeHandle");
234*cdf0e10cSrcweir 		m_pSetEnvAttr = loadSymbol("SQLSetEnvAttr");
235*cdf0e10cSrcweir 		m_pDataSources = loadSymbol("SQLDataSources");
236*cdf0e10cSrcweir 
237*cdf0e10cSrcweir 		// all or nothing
238*cdf0e10cSrcweir 		if (!m_pAllocHandle || !m_pSetEnvAttr || !m_pDataSources || !m_pFreeHandle)
239*cdf0e10cSrcweir 		{
240*cdf0e10cSrcweir 			unload();
241*cdf0e10cSrcweir 			m_pAllocHandle = m_pFreeHandle = m_pSetEnvAttr = m_pDataSources = NULL;
242*cdf0e10cSrcweir 		}
243*cdf0e10cSrcweir #endif
244*cdf0e10cSrcweir 	}
245*cdf0e10cSrcweir }
246*cdf0e10cSrcweir 
247*cdf0e10cSrcweir //-------------------------------------------------------------------------
248*cdf0e10cSrcweir OOdbcEnumeration::~OOdbcEnumeration()
249*cdf0e10cSrcweir {
250*cdf0e10cSrcweir 	freeEnv();
251*cdf0e10cSrcweir 	delete m_pImpl;
252*cdf0e10cSrcweir 
253*cdf0e10cSrcweir     DBG_DTOR(OOdbcEnumeration,NULL);
254*cdf0e10cSrcweir }
255*cdf0e10cSrcweir 
256*cdf0e10cSrcweir //-------------------------------------------------------------------------
257*cdf0e10cSrcweir sal_Bool OOdbcEnumeration::allocEnv()
258*cdf0e10cSrcweir {
259*cdf0e10cSrcweir 	OSL_ENSURE(isLoaded(), "OOdbcEnumeration::allocEnv: not loaded!");
260*cdf0e10cSrcweir 	if (!isLoaded())
261*cdf0e10cSrcweir 		return sal_False;
262*cdf0e10cSrcweir 
263*cdf0e10cSrcweir #ifdef HAVE_ODBC_SUPPORT
264*cdf0e10cSrcweir 	if (m_pImpl->hEnvironment)
265*cdf0e10cSrcweir 		// nothing to do
266*cdf0e10cSrcweir 		return sal_True;
267*cdf0e10cSrcweir 	SQLRETURN nResult = NSQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &m_pImpl->hEnvironment);
268*cdf0e10cSrcweir 	if (SQL_SUCCESS != nResult)
269*cdf0e10cSrcweir 		// can't do anything without environment
270*cdf0e10cSrcweir 		return sal_False;
271*cdf0e10cSrcweir 
272*cdf0e10cSrcweir 	NSQLSetEnvAttr(m_pImpl->hEnvironment, SQL_ATTR_ODBC_VERSION, (SQLPOINTER)SQL_OV_ODBC3, SQL_IS_INTEGER);
273*cdf0e10cSrcweir 	return sal_True;
274*cdf0e10cSrcweir #else
275*cdf0e10cSrcweir 	return sal_False;
276*cdf0e10cSrcweir #endif
277*cdf0e10cSrcweir }
278*cdf0e10cSrcweir 
279*cdf0e10cSrcweir //-------------------------------------------------------------------------
280*cdf0e10cSrcweir void OOdbcEnumeration::freeEnv()
281*cdf0e10cSrcweir {
282*cdf0e10cSrcweir #ifdef HAVE_ODBC_SUPPORT
283*cdf0e10cSrcweir 	if (m_pImpl->hEnvironment)
284*cdf0e10cSrcweir 		NSQLFreeHandle(SQL_HANDLE_ENV, m_pImpl->hEnvironment);
285*cdf0e10cSrcweir 	m_pImpl->hEnvironment  = 0;
286*cdf0e10cSrcweir #endif
287*cdf0e10cSrcweir }
288*cdf0e10cSrcweir 
289*cdf0e10cSrcweir //-------------------------------------------------------------------------
290*cdf0e10cSrcweir void OOdbcEnumeration::getDatasourceNames(StringBag& _rNames)
291*cdf0e10cSrcweir {
292*cdf0e10cSrcweir 	OSL_ENSURE(isLoaded(), "OOdbcEnumeration::getDatasourceNames: not loaded!");
293*cdf0e10cSrcweir 	if (!isLoaded())
294*cdf0e10cSrcweir 		return;
295*cdf0e10cSrcweir 
296*cdf0e10cSrcweir 	if (!allocEnv())
297*cdf0e10cSrcweir 	{
298*cdf0e10cSrcweir 		OSL_ENSURE(sal_False, "OOdbcEnumeration::getDatasourceNames: could not allocate an ODBC environment!");
299*cdf0e10cSrcweir 		return;
300*cdf0e10cSrcweir 	}
301*cdf0e10cSrcweir 
302*cdf0e10cSrcweir #ifdef HAVE_ODBC_SUPPORT
303*cdf0e10cSrcweir 	// now that we have an environment collect the data source names
304*cdf0e10cSrcweir 	UCHAR szDSN[SQL_MAX_DSN_LENGTH+1];
305*cdf0e10cSrcweir 	SWORD pcbDSN;
306*cdf0e10cSrcweir 	UCHAR szDescription[1024+1];
307*cdf0e10cSrcweir 	SWORD pcbDescription;
308*cdf0e10cSrcweir 	SQLRETURN nResult = SQL_SUCCESS;
309*cdf0e10cSrcweir     rtl_TextEncoding nTextEncoding = osl_getThreadTextEncoding();
310*cdf0e10cSrcweir 
311*cdf0e10cSrcweir 	for (	nResult = NSQLDataSources(m_pImpl->hEnvironment, SQL_FETCH_FIRST, szDSN, sizeof(szDSN), &pcbDSN, szDescription, sizeof(szDescription)-1, &pcbDescription);
312*cdf0e10cSrcweir 			;
313*cdf0e10cSrcweir 			nResult = NSQLDataSources(m_pImpl->hEnvironment, SQL_FETCH_NEXT, szDSN, sizeof(szDSN), &pcbDSN, szDescription, sizeof(szDescription)-1, &pcbDescription)
314*cdf0e10cSrcweir 		)
315*cdf0e10cSrcweir 	{
316*cdf0e10cSrcweir 		if (nResult != SQL_SUCCESS)
317*cdf0e10cSrcweir 			// no further error handling
318*cdf0e10cSrcweir 			break;
319*cdf0e10cSrcweir 		else
320*cdf0e10cSrcweir 		{
321*cdf0e10cSrcweir             ::rtl::OUString aCurrentDsn(reinterpret_cast<const char*>(szDSN),pcbDSN, nTextEncoding);
322*cdf0e10cSrcweir 			_rNames.insert(aCurrentDsn);
323*cdf0e10cSrcweir 		}
324*cdf0e10cSrcweir 	}
325*cdf0e10cSrcweir #endif
326*cdf0e10cSrcweir }
327*cdf0e10cSrcweir 
328*cdf0e10cSrcweir #ifdef HAVE_ODBC_ADMINISTRATION
329*cdf0e10cSrcweir 
330*cdf0e10cSrcweir //=========================================================================
331*cdf0e10cSrcweir //= ProcessTerminationWait
332*cdf0e10cSrcweir //=========================================================================
333*cdf0e10cSrcweir class ProcessTerminationWait : public ::osl::Thread
334*cdf0e10cSrcweir {
335*cdf0e10cSrcweir     oslProcess  m_hProcessHandle;
336*cdf0e10cSrcweir     Link        m_aFinishHdl;
337*cdf0e10cSrcweir 
338*cdf0e10cSrcweir public:
339*cdf0e10cSrcweir     ProcessTerminationWait( oslProcess _hProcessHandle, const Link& _rFinishHdl )
340*cdf0e10cSrcweir         :m_hProcessHandle( _hProcessHandle )
341*cdf0e10cSrcweir         ,m_aFinishHdl( _rFinishHdl )
342*cdf0e10cSrcweir     {
343*cdf0e10cSrcweir     }
344*cdf0e10cSrcweir 
345*cdf0e10cSrcweir protected:
346*cdf0e10cSrcweir     virtual void SAL_CALL run()
347*cdf0e10cSrcweir     {
348*cdf0e10cSrcweir         osl_joinProcess( m_hProcessHandle );
349*cdf0e10cSrcweir         osl_freeProcessHandle( m_hProcessHandle );
350*cdf0e10cSrcweir         Application::PostUserEvent( m_aFinishHdl );
351*cdf0e10cSrcweir     }
352*cdf0e10cSrcweir };
353*cdf0e10cSrcweir 
354*cdf0e10cSrcweir //=========================================================================
355*cdf0e10cSrcweir //= OOdbcManagement
356*cdf0e10cSrcweir //=========================================================================
357*cdf0e10cSrcweir //-------------------------------------------------------------------------
358*cdf0e10cSrcweir OOdbcManagement::OOdbcManagement( const Link& _rAsyncFinishCallback )
359*cdf0e10cSrcweir     :m_pProcessWait( NULL )
360*cdf0e10cSrcweir     ,m_aAsyncFinishCallback( _rAsyncFinishCallback )
361*cdf0e10cSrcweir {
362*cdf0e10cSrcweir }
363*cdf0e10cSrcweir 
364*cdf0e10cSrcweir //-------------------------------------------------------------------------
365*cdf0e10cSrcweir OOdbcManagement::~OOdbcManagement()
366*cdf0e10cSrcweir {
367*cdf0e10cSrcweir     // wait for our thread to be finished
368*cdf0e10cSrcweir     if ( m_pProcessWait.get() )
369*cdf0e10cSrcweir         m_pProcessWait->join();
370*cdf0e10cSrcweir }
371*cdf0e10cSrcweir 
372*cdf0e10cSrcweir //-------------------------------------------------------------------------
373*cdf0e10cSrcweir bool OOdbcManagement::manageDataSources_async()
374*cdf0e10cSrcweir {
375*cdf0e10cSrcweir     OSL_PRECOND( !isRunning(), "OOdbcManagement::manageDataSources_async: still running from the previous call!" );
376*cdf0e10cSrcweir     if ( isRunning() )
377*cdf0e10cSrcweir         return false;
378*cdf0e10cSrcweir 
379*cdf0e10cSrcweir     // this is done in an external process, due to #i78733#
380*cdf0e10cSrcweir     // (and note this whole functionality is supported on Windows only, ATM)
381*cdf0e10cSrcweir     ::rtl::OUString sExecutableName( RTL_CONSTASCII_USTRINGPARAM( "$OOO_BASE_DIR/program/odbcconfig.exe" ) );
382*cdf0e10cSrcweir     ::rtl::Bootstrap::expandMacros( sExecutableName ); //TODO: detect failure
383*cdf0e10cSrcweir     oslProcess hProcessHandle(0);
384*cdf0e10cSrcweir     oslProcessError eError = osl_executeProcess( sExecutableName.pData, NULL, 0, 0, NULL, NULL, NULL, 0, &hProcessHandle );
385*cdf0e10cSrcweir     if ( eError != osl_Process_E_None )
386*cdf0e10cSrcweir         return false;
387*cdf0e10cSrcweir 
388*cdf0e10cSrcweir     m_pProcessWait.reset( new ProcessTerminationWait( hProcessHandle, m_aAsyncFinishCallback ) );
389*cdf0e10cSrcweir     m_pProcessWait->create();
390*cdf0e10cSrcweir     return true;
391*cdf0e10cSrcweir }
392*cdf0e10cSrcweir 
393*cdf0e10cSrcweir //-------------------------------------------------------------------------
394*cdf0e10cSrcweir bool OOdbcManagement::isRunning() const
395*cdf0e10cSrcweir {
396*cdf0e10cSrcweir     return ( m_pProcessWait.get() && m_pProcessWait->isRunning() );
397*cdf0e10cSrcweir }
398*cdf0e10cSrcweir 
399*cdf0e10cSrcweir #endif // HAVE_ODBC_ADMINISTRATION
400*cdf0e10cSrcweir 
401*cdf0e10cSrcweir //.........................................................................
402*cdf0e10cSrcweir }	// namespace dbaui
403*cdf0e10cSrcweir //.........................................................................
404