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