xref: /AOO41X/main/connectivity/source/drivers/adabas/BDriver.cxx (revision 9b5730f6ddef7eb82608ca4d31dc0d7678e652cf)
1*9b5730f6SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*9b5730f6SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*9b5730f6SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*9b5730f6SAndrew Rist  * distributed with this work for additional information
6*9b5730f6SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*9b5730f6SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*9b5730f6SAndrew Rist  * "License"); you may not use this file except in compliance
9*9b5730f6SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*9b5730f6SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*9b5730f6SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*9b5730f6SAndrew Rist  * software distributed under the License is distributed on an
15*9b5730f6SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9b5730f6SAndrew Rist  * KIND, either express or implied.  See the License for the
17*9b5730f6SAndrew Rist  * specific language governing permissions and limitations
18*9b5730f6SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*9b5730f6SAndrew Rist  *************************************************************/
21*9b5730f6SAndrew Rist 
22*9b5730f6SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_connectivity.hxx"
26cdf0e10cSrcweir #include <unotools/tempfile.hxx>
27cdf0e10cSrcweir #include "adabas/BDriver.hxx"
28cdf0e10cSrcweir #include "adabas/BConnection.hxx"
29cdf0e10cSrcweir #include "odbc/OFunctions.hxx"
30cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp>
31cdf0e10cSrcweir #include "odbc/OTools.hxx"
32cdf0e10cSrcweir #include "connectivity/dbexception.hxx"
33cdf0e10cSrcweir #include "TConnection.hxx"
34cdf0e10cSrcweir #include "diagnose_ex.h"
35cdf0e10cSrcweir #include <vos/process.hxx>
36cdf0e10cSrcweir #include <osl/process.h>
37cdf0e10cSrcweir #include <unotools/ucbhelper.hxx>
38cdf0e10cSrcweir #include <unotools/ucbstreamhelper.hxx>
39cdf0e10cSrcweir #include <unotools/localfilehelper.hxx>
40cdf0e10cSrcweir #include "resource/adabas_res.hrc"
41cdf0e10cSrcweir #include "resource/sharedresources.hxx"
42cdf0e10cSrcweir 
43cdf0e10cSrcweir 
44cdf0e10cSrcweir #include <memory>
45cdf0e10cSrcweir #include <sys/stat.h>
46cdf0e10cSrcweir 
47cdf0e10cSrcweir #if defined(UNX)
48cdf0e10cSrcweir const char sNewLine = '\012';
49cdf0e10cSrcweir #else
50cdf0e10cSrcweir const char sNewLine[] = "\015\012"; // \015\012 and not \n
51cdf0e10cSrcweir #endif
52cdf0e10cSrcweir #define ADABAS_DB_11			"11.02.00"
53cdf0e10cSrcweir #define ADABAS_KERNEL_11		"11.02"
54cdf0e10cSrcweir #define ADABAS_DB_12			"12.01.00"
55cdf0e10cSrcweir #define ADABAS_KERNEL_12		"12.01"
56cdf0e10cSrcweir #define CURRENT_DB_VERSION		"13.01.00"
57cdf0e10cSrcweir #define CURRENT_KERNEL_VERSION	"13.01"
58cdf0e10cSrcweir 
59cdf0e10cSrcweir #define OPROCESS_ADABAS 	(OProcess::TOption_Hidden | OProcess::TOption_Wait | OProcess::TOption_SearchPath)
60cdf0e10cSrcweir #define OPROCESS_ADABAS_DBG (OProcess::TOption_Wait | OProcess::TOption_SearchPath)
61cdf0e10cSrcweir 
62cdf0e10cSrcweir 
63cdf0e10cSrcweir using namespace connectivity;
64cdf0e10cSrcweir namespace connectivity
65cdf0e10cSrcweir {
66cdf0e10cSrcweir 	namespace adabas
67cdf0e10cSrcweir 	{
68cdf0e10cSrcweir 		// extern declaration of the function pointer
69cdf0e10cSrcweir 	extern T3SQLAllocHandle pODBC3SQLAllocHandle;
70cdf0e10cSrcweir 	extern T3SQLConnect pODBC3SQLConnect;
71cdf0e10cSrcweir 	extern T3SQLDriverConnect pODBC3SQLDriverConnect;
72cdf0e10cSrcweir 	extern T3SQLBrowseConnect pODBC3SQLBrowseConnect;
73cdf0e10cSrcweir 	extern T3SQLDataSources pODBC3SQLDataSources;
74cdf0e10cSrcweir 	extern T3SQLDrivers pODBC3SQLDrivers;
75cdf0e10cSrcweir 	extern T3SQLGetInfo pODBC3SQLGetInfo;
76cdf0e10cSrcweir 	extern T3SQLGetFunctions pODBC3SQLGetFunctions;
77cdf0e10cSrcweir 	extern T3SQLGetTypeInfo pODBC3SQLGetTypeInfo;
78cdf0e10cSrcweir 	extern T3SQLSetConnectAttr pODBC3SQLSetConnectAttr;
79cdf0e10cSrcweir 	extern T3SQLGetConnectAttr pODBC3SQLGetConnectAttr;
80cdf0e10cSrcweir 	extern T3SQLSetEnvAttr pODBC3SQLSetEnvAttr;
81cdf0e10cSrcweir 	extern T3SQLGetEnvAttr pODBC3SQLGetEnvAttr;
82cdf0e10cSrcweir 	extern T3SQLSetStmtAttr pODBC3SQLSetStmtAttr;
83cdf0e10cSrcweir 	extern T3SQLGetStmtAttr pODBC3SQLGetStmtAttr;
84cdf0e10cSrcweir 	//extern T3SQLSetDescField pODBC3SQLSetDescField;
85cdf0e10cSrcweir 	//extern T3SQLGetDescField pODBC3SQLGetDescField;
86cdf0e10cSrcweir 	//extern T3SQLGetDescRec pODBC3SQLGetDescRec;
87cdf0e10cSrcweir 	//extern T3SQLSetDescRec pODBC3SQLSetDescRec;
88cdf0e10cSrcweir 	extern T3SQLPrepare pODBC3SQLPrepare;
89cdf0e10cSrcweir 	extern T3SQLBindParameter pODBC3SQLBindParameter;
90cdf0e10cSrcweir 	//extern T3SQLGetCursorName pODBC3SQLGetCursorName;
91cdf0e10cSrcweir 	extern T3SQLSetCursorName pODBC3SQLSetCursorName;
92cdf0e10cSrcweir 	extern T3SQLExecute pODBC3SQLExecute;
93cdf0e10cSrcweir 	extern T3SQLExecDirect pODBC3SQLExecDirect;
94cdf0e10cSrcweir 	//extern T3SQLNativeSql pODBC3SQLNativeSql;
95cdf0e10cSrcweir 	extern T3SQLDescribeParam pODBC3SQLDescribeParam;
96cdf0e10cSrcweir 	extern T3SQLNumParams pODBC3SQLNumParams;
97cdf0e10cSrcweir 	extern T3SQLParamData pODBC3SQLParamData;
98cdf0e10cSrcweir 	extern T3SQLPutData pODBC3SQLPutData;
99cdf0e10cSrcweir 	extern T3SQLRowCount pODBC3SQLRowCount;
100cdf0e10cSrcweir 	extern T3SQLNumResultCols pODBC3SQLNumResultCols;
101cdf0e10cSrcweir 	extern T3SQLDescribeCol pODBC3SQLDescribeCol;
102cdf0e10cSrcweir 	extern T3SQLColAttribute pODBC3SQLColAttribute;
103cdf0e10cSrcweir 	extern T3SQLBindCol pODBC3SQLBindCol;
104cdf0e10cSrcweir 	extern T3SQLFetch pODBC3SQLFetch;
105cdf0e10cSrcweir 	extern T3SQLFetchScroll pODBC3SQLFetchScroll;
106cdf0e10cSrcweir 	extern T3SQLGetData pODBC3SQLGetData;
107cdf0e10cSrcweir 	extern T3SQLSetPos pODBC3SQLSetPos;
108cdf0e10cSrcweir 	extern T3SQLBulkOperations pODBC3SQLBulkOperations;
109cdf0e10cSrcweir 	extern T3SQLMoreResults pODBC3SQLMoreResults;
110cdf0e10cSrcweir 	//extern T3SQLGetDiagField pODBC3SQLGetDiagField;
111cdf0e10cSrcweir 	extern T3SQLGetDiagRec pODBC3SQLGetDiagRec;
112cdf0e10cSrcweir 	extern T3SQLColumnPrivileges pODBC3SQLColumnPrivileges;
113cdf0e10cSrcweir 	extern T3SQLColumns pODBC3SQLColumns;
114cdf0e10cSrcweir 	extern T3SQLForeignKeys pODBC3SQLForeignKeys;
115cdf0e10cSrcweir 	extern T3SQLPrimaryKeys pODBC3SQLPrimaryKeys;
116cdf0e10cSrcweir 	extern T3SQLProcedureColumns pODBC3SQLProcedureColumns;
117cdf0e10cSrcweir 	extern T3SQLProcedures pODBC3SQLProcedures;
118cdf0e10cSrcweir 	extern T3SQLSpecialColumns pODBC3SQLSpecialColumns;
119cdf0e10cSrcweir 	extern T3SQLStatistics pODBC3SQLStatistics;
120cdf0e10cSrcweir 	extern T3SQLTablePrivileges pODBC3SQLTablePrivileges;
121cdf0e10cSrcweir 	extern T3SQLTables pODBC3SQLTables;
122cdf0e10cSrcweir 	extern T3SQLFreeStmt pODBC3SQLFreeStmt;
123cdf0e10cSrcweir 	extern T3SQLCloseCursor pODBC3SQLCloseCursor;
124cdf0e10cSrcweir 	extern T3SQLCancel pODBC3SQLCancel;
125cdf0e10cSrcweir 	extern T3SQLEndTran pODBC3SQLEndTran;
126cdf0e10cSrcweir 	extern T3SQLDisconnect pODBC3SQLDisconnect;
127cdf0e10cSrcweir 	extern T3SQLFreeHandle pODBC3SQLFreeHandle;
128cdf0e10cSrcweir 	extern T3SQLGetCursorName pODBC3SQLGetCursorName;
129cdf0e10cSrcweir 	extern T3SQLNativeSql pODBC3SQLNativeSql;
130cdf0e10cSrcweir 
131cdf0e10cSrcweir using namespace ::com::sun::star::uno;
132cdf0e10cSrcweir using namespace ::com::sun::star::beans;
133cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx;
134cdf0e10cSrcweir using namespace ::com::sun::star::sdbc;
135cdf0e10cSrcweir using namespace ::com::sun::star::container;
136cdf0e10cSrcweir using namespace ::com::sun::star::lang;
137cdf0e10cSrcweir using namespace utl;
138cdf0e10cSrcweir using namespace osl;
139cdf0e10cSrcweir using namespace vos;
140cdf0e10cSrcweir using namespace ::dbtools;
141cdf0e10cSrcweir 
142cdf0e10cSrcweir 	sal_Bool LoadFunctions(oslModule pODBCso);
143cdf0e10cSrcweir 	sal_Bool LoadLibrary_ADABAS(::rtl::OUString &_rPath);
144cdf0e10cSrcweir     // --------------------------------------------------------------------------------
145cdf0e10cSrcweir void ODriver::fillInfo(const Sequence< PropertyValue >& info, TDatabaseStruct& _rDBInfo)
146cdf0e10cSrcweir {
147cdf0e10cSrcweir     const PropertyValue* pIter = info.getConstArray();
148cdf0e10cSrcweir 	const PropertyValue* pEnd = pIter + info.getLength();
149cdf0e10cSrcweir 	for(;pIter != pEnd;++pIter)
150cdf0e10cSrcweir 	{
151cdf0e10cSrcweir         if(pIter->Name.equalsIgnoreAsciiCase(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DatabaseName"))))
152cdf0e10cSrcweir 		{
153cdf0e10cSrcweir 			pIter->Value >>= _rDBInfo.sDBName;
154cdf0e10cSrcweir 		}
155cdf0e10cSrcweir 		else if(pIter->Name.equalsIgnoreAsciiCase(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ControlUser"))))
156cdf0e10cSrcweir 		{
157cdf0e10cSrcweir 			pIter->Value >>= _rDBInfo.sControlUser;
158cdf0e10cSrcweir 		}
159cdf0e10cSrcweir 		else if(pIter->Name.equalsIgnoreAsciiCase(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ControlPassword"))))
160cdf0e10cSrcweir 		{
161cdf0e10cSrcweir 			pIter->Value >>= _rDBInfo.sControlPassword;
162cdf0e10cSrcweir 		}
163cdf0e10cSrcweir         else if(pIter->Name.equalsIgnoreAsciiCase(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DataCacheSizeIncrement"))))
164cdf0e10cSrcweir 			pIter->Value >>= _rDBInfo.nDataIncrement;
165cdf0e10cSrcweir         else if(pIter->Name.equalsIgnoreAsciiCase(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ShutdownDatabase"))))
166cdf0e10cSrcweir 			pIter->Value >>= _rDBInfo.bShutDown;
167cdf0e10cSrcweir 		else if(pIter->Name.equalsIgnoreAsciiCase(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("User"))))
168cdf0e10cSrcweir 		{
169cdf0e10cSrcweir 			pIter->Value >>= _rDBInfo.sSysUser;
170cdf0e10cSrcweir 		}
171cdf0e10cSrcweir 		else if(pIter->Name.equalsIgnoreAsciiCase(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Password"))))
172cdf0e10cSrcweir 		{
173cdf0e10cSrcweir 			pIter->Value >>= _rDBInfo.sSysPassword;
174cdf0e10cSrcweir 		}
175cdf0e10cSrcweir 		else if(pIter->Name.equalsIgnoreAsciiCase(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DomainPassword"))))
176cdf0e10cSrcweir 		{
177cdf0e10cSrcweir 			pIter->Value >>= _rDBInfo.sDomainPassword;
178cdf0e10cSrcweir 		}
179cdf0e10cSrcweir 		else if(pIter->Name.equalsIgnoreAsciiCase(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CacheSize"))))
180cdf0e10cSrcweir 		{
181cdf0e10cSrcweir 			pIter->Value >>= _rDBInfo.sCacheSize;
182cdf0e10cSrcweir 		}
183cdf0e10cSrcweir 		else if(pIter->Name.equalsIgnoreAsciiCase(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("RestoreDatabase"))))
184cdf0e10cSrcweir 		{
185cdf0e10cSrcweir 			pIter->Value >>= _rDBInfo.bRestoreDatabase;
186cdf0e10cSrcweir 		}
187cdf0e10cSrcweir 		else if(pIter->Name.equalsIgnoreAsciiCase(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Backup"))))
188cdf0e10cSrcweir 		{
189cdf0e10cSrcweir 			pIter->Value >>= _rDBInfo.sBackupFile;
190cdf0e10cSrcweir 		}
191cdf0e10cSrcweir 		else if(pIter->Name.equalsIgnoreAsciiCase(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DataDevSpace"))))
192cdf0e10cSrcweir 		{
193cdf0e10cSrcweir 			pIter->Value >>= _rDBInfo.sDataDevName;
194cdf0e10cSrcweir 		}
195cdf0e10cSrcweir 		else if(pIter->Name.equalsIgnoreAsciiCase(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SYSDEVSPACE"))))
196cdf0e10cSrcweir 		{
197cdf0e10cSrcweir 			pIter->Value >>= _rDBInfo.sSysDevSpace;
198cdf0e10cSrcweir 		}
199cdf0e10cSrcweir 		else if(pIter->Name.equalsIgnoreAsciiCase(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TRANSACTION_LOG"))))
200cdf0e10cSrcweir 		{
201cdf0e10cSrcweir 			pIter->Value >>= _rDBInfo.sTransLogName;
202cdf0e10cSrcweir 		}
203cdf0e10cSrcweir 		else if(pIter->Name.equalsIgnoreAsciiCase(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DataDevSize"))))
204cdf0e10cSrcweir 		{
205cdf0e10cSrcweir 			pIter->Value >>= _rDBInfo.nDataSize;
206cdf0e10cSrcweir 		}
207cdf0e10cSrcweir 		else if(pIter->Name.equalsIgnoreAsciiCase(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("LogDevSize"))))
208cdf0e10cSrcweir 		{
209cdf0e10cSrcweir 			pIter->Value >>= _rDBInfo.nLogSize;
210cdf0e10cSrcweir 		}
211cdf0e10cSrcweir 	}
212cdf0e10cSrcweir }
213cdf0e10cSrcweir 
214cdf0e10cSrcweir 
215cdf0e10cSrcweir // --------------------------------------------------------------------------------
216cdf0e10cSrcweir ODriver::ODriver(const Reference< XMultiServiceFactory >& _rxFactory) : ODBCDriver(_rxFactory)
217cdf0e10cSrcweir {
218cdf0e10cSrcweir     osl_incrementInterlockedCount(&m_refCount);
219cdf0e10cSrcweir 	fillEnvironmentVariables();
220cdf0e10cSrcweir 	Reference< XComponent >  xComponent(m_xORB, UNO_QUERY);
221cdf0e10cSrcweir 	if (xComponent.is())
222cdf0e10cSrcweir 	{
223cdf0e10cSrcweir 		Reference< ::com::sun::star::lang::XEventListener> xEvtL((::cppu::OWeakObject*)this,UNO_QUERY);
224cdf0e10cSrcweir 		xComponent->addEventListener(xEvtL);
225cdf0e10cSrcweir 	}
226cdf0e10cSrcweir 	osl_decrementInterlockedCount(&m_refCount);
227cdf0e10cSrcweir }
228cdf0e10cSrcweir //------------------------------------------------------------------------------
229cdf0e10cSrcweir void ODriver::disposing()
230cdf0e10cSrcweir {
231cdf0e10cSrcweir 	::osl::MutexGuard aGuard(m_aMutex);
232cdf0e10cSrcweir 	ODriver_BASE::disposing();
233cdf0e10cSrcweir     Reference< XComponent >  xComponent(m_xORB, UNO_QUERY);
234cdf0e10cSrcweir 	if (xComponent.is())
235cdf0e10cSrcweir 	{
236cdf0e10cSrcweir 		Reference< XEventListener> xEvtL((::cppu::OWeakObject*)this,UNO_QUERY);
237cdf0e10cSrcweir 		xComponent->removeEventListener(xEvtL);
238cdf0e10cSrcweir 	}
239cdf0e10cSrcweir     m_xORB.clear();
240cdf0e10cSrcweir }
241cdf0e10cSrcweir 
242cdf0e10cSrcweir // static ServiceInfo
243cdf0e10cSrcweir //------------------------------------------------------------------------------
244cdf0e10cSrcweir rtl::OUString ODriver::getImplementationName_Static(  ) throw(RuntimeException)
245cdf0e10cSrcweir {
246cdf0e10cSrcweir     return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.sdbcx.adabas.ODriver"));
247cdf0e10cSrcweir }
248cdf0e10cSrcweir //------------------------------------------------------------------------------
249cdf0e10cSrcweir Sequence< ::rtl::OUString > ODriver::getSupportedServiceNames_Static(  ) throw (RuntimeException)
250cdf0e10cSrcweir {
251cdf0e10cSrcweir 	Sequence< ::rtl::OUString > aSNS( 2 );
252cdf0e10cSrcweir     aSNS[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdbc.Driver"));
253cdf0e10cSrcweir     aSNS[1] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdbcx.Driver"));
254cdf0e10cSrcweir 	return aSNS;
255cdf0e10cSrcweir }
256cdf0e10cSrcweir //------------------------------------------------------------------
257cdf0e10cSrcweir ::rtl::OUString SAL_CALL ODriver::getImplementationName(  ) throw(RuntimeException)
258cdf0e10cSrcweir {
259cdf0e10cSrcweir 	return getImplementationName_Static();
260cdf0e10cSrcweir }
261cdf0e10cSrcweir 
262cdf0e10cSrcweir //------------------------------------------------------------------
263cdf0e10cSrcweir sal_Bool SAL_CALL ODriver::supportsService( const ::rtl::OUString& _rServiceName ) throw(RuntimeException)
264cdf0e10cSrcweir {
265cdf0e10cSrcweir 	const Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames());
266cdf0e10cSrcweir 	const ::rtl::OUString* pSupported = aSupported.getConstArray();
267cdf0e10cSrcweir 	const ::rtl::OUString* pEnd = pSupported + aSupported.getLength();
268cdf0e10cSrcweir 	for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported)
269cdf0e10cSrcweir 		;
270cdf0e10cSrcweir 
271cdf0e10cSrcweir 	return pSupported != pEnd;
272cdf0e10cSrcweir }
273cdf0e10cSrcweir //------------------------------------------------------------------
274cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL ODriver::getSupportedServiceNames(  ) throw(RuntimeException)
275cdf0e10cSrcweir {
276cdf0e10cSrcweir 	return getSupportedServiceNames_Static();
277cdf0e10cSrcweir }
278cdf0e10cSrcweir //------------------------------------------------------------------
279cdf0e10cSrcweir Any SAL_CALL ODriver::queryInterface( const Type & rType ) throw(RuntimeException)
280cdf0e10cSrcweir {
281cdf0e10cSrcweir 	Any aRet = ::cppu::queryInterface(rType, static_cast<XDataDefinitionSupplier*>(this));
282cdf0e10cSrcweir     if ( !aRet.hasValue() )
283cdf0e10cSrcweir         aRet = ODriver_BASE::queryInterface(rType);
284cdf0e10cSrcweir 	return aRet.hasValue() ? aRet : ODriver_BASE2::queryInterface(rType);
285cdf0e10cSrcweir }
286cdf0e10cSrcweir //------------------------------------------------------------------
287cdf0e10cSrcweir Reference< XInterface >  SAL_CALL ODriver_CreateInstance(const Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFac) throw( Exception )
288cdf0e10cSrcweir {
289cdf0e10cSrcweir 	return *(new ODriver(_rxFac));
290cdf0e10cSrcweir }
291cdf0e10cSrcweir // -----------------------------------------------------------------------------
292cdf0e10cSrcweir void SAL_CALL ODriver::disposing( const EventObject& Source ) throw(RuntimeException)
293cdf0e10cSrcweir {
294cdf0e10cSrcweir     ::osl::MutexGuard aGuard( m_aMutex );
295cdf0e10cSrcweir 
296cdf0e10cSrcweir 	if(m_xORB.is() && Reference< XMultiServiceFactory >(Source.Source,UNO_QUERY) == m_xORB)
297cdf0e10cSrcweir 	{
298cdf0e10cSrcweir 		TDatabaseMap::iterator aIter = m_aDatabaseMap.begin();
299cdf0e10cSrcweir 		for(;aIter != m_aDatabaseMap.end();++aIter)
300cdf0e10cSrcweir 		{
301cdf0e10cSrcweir 			if(aIter->second.bShutDown)
302cdf0e10cSrcweir 			{
303cdf0e10cSrcweir 				::rtl::OUString sName;
304cdf0e10cSrcweir 				if(getDBName(aIter->first,sName))
305cdf0e10cSrcweir 				{
306cdf0e10cSrcweir 					XUTIL(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SHUTDOWN QUICK")),sName,aIter->second.sControlUser,aIter->second.sControlPassword);
307cdf0e10cSrcweir 					X_STOP(sName);
308cdf0e10cSrcweir 				}
309cdf0e10cSrcweir 			}
310cdf0e10cSrcweir 		}
311cdf0e10cSrcweir 	m_xORB.clear();
312cdf0e10cSrcweir 	}
313cdf0e10cSrcweir }
314cdf0e10cSrcweir // --------------------------------------------------------------------------------
315cdf0e10cSrcweir Reference< XConnection > SAL_CALL ODriver::connect( const ::rtl::OUString& url, const Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException)
316cdf0e10cSrcweir {
317cdf0e10cSrcweir 	if ( ! acceptsURL(url) )
318cdf0e10cSrcweir 		return NULL;
319cdf0e10cSrcweir 
320cdf0e10cSrcweir     ::osl::MutexGuard aGuard( m_aMutex );
321cdf0e10cSrcweir 	if (ODriver_BASE::rBHelper.bDisposed)
322cdf0e10cSrcweir 		throw DisposedException();
323cdf0e10cSrcweir 
324cdf0e10cSrcweir     TDatabaseStruct aDBInfo;
325cdf0e10cSrcweir 	aDBInfo.bShutDown = sal_False;
326cdf0e10cSrcweir     fillInfo(info,aDBInfo);
327cdf0e10cSrcweir     aDBInfo.sControlUser = aDBInfo.sControlUser.toAsciiUpperCase();
328cdf0e10cSrcweir     aDBInfo.sControlPassword = aDBInfo.sControlPassword.toAsciiUpperCase();
329cdf0e10cSrcweir     aDBInfo.sSysUser = aDBInfo.sSysUser.toAsciiUpperCase();
330cdf0e10cSrcweir     aDBInfo.sSysPassword = aDBInfo.sSysPassword.toAsciiUpperCase();
331cdf0e10cSrcweir 
332cdf0e10cSrcweir 
333cdf0e10cSrcweir 	TDatabaseMap::iterator aFind = m_aDatabaseMap.find(url);
334cdf0e10cSrcweir 	if(aFind == m_aDatabaseMap.end()) // only when not found yet
335cdf0e10cSrcweir 		m_aDatabaseMap[url] = aDBInfo;
336cdf0e10cSrcweir 	else
337cdf0e10cSrcweir 	{
338cdf0e10cSrcweir 		if(aFind->second.bShutDown != aDBInfo.bShutDown)
339cdf0e10cSrcweir 			aFind->second.bShutDown &= aDBInfo.bShutDown;
340cdf0e10cSrcweir 	}
341cdf0e10cSrcweir 
342cdf0e10cSrcweir 	::rtl::OUString sName;
343cdf0e10cSrcweir 	if(aDBInfo.sControlPassword.getLength() && aDBInfo.sControlUser.getLength() && getDBName(url,sName))
344cdf0e10cSrcweir 	{
345cdf0e10cSrcweir 		// check if we have to add a new data dev space
346cdf0e10cSrcweir 		checkAndInsertNewDevSpace(sName,aDBInfo);
347cdf0e10cSrcweir 
348cdf0e10cSrcweir 		convertOldVersion(sName,aDBInfo);
349cdf0e10cSrcweir 		// check if we must restart the database
350cdf0e10cSrcweir 		checkAndRestart(sName,aDBInfo);
351cdf0e10cSrcweir 	}
352cdf0e10cSrcweir 
353cdf0e10cSrcweir 
354cdf0e10cSrcweir 	if(!m_pDriverHandle)
355cdf0e10cSrcweir 	{
356cdf0e10cSrcweir 		::rtl::OUString aPath;
357cdf0e10cSrcweir 		if(!EnvironmentHandle(aPath))
358cdf0e10cSrcweir 			throw SQLException(aPath,*this,::rtl::OUString(),1000,Any());
359cdf0e10cSrcweir 	}
360cdf0e10cSrcweir     OAdabasConnection* pCon = new OAdabasConnection(m_pDriverHandle,this);
361cdf0e10cSrcweir 	Reference< XConnection > xCon = pCon;
362cdf0e10cSrcweir 	SQLRETURN nSQLRETURN = pCon->Construct(url,info);
363cdf0e10cSrcweir 
364cdf0e10cSrcweir 	if (nSQLRETURN == SQL_ERROR || nSQLRETURN == SQL_NO_DATA)
365cdf0e10cSrcweir 	{
366cdf0e10cSrcweir 		odbc::OTools::ThrowException(pCon,nSQLRETURN,pCon->getConnection(),SQL_HANDLE_DBC,*this);
367cdf0e10cSrcweir 	}
368cdf0e10cSrcweir 
369cdf0e10cSrcweir 	m_xConnections.push_back(WeakReferenceHelper(*pCon));
370cdf0e10cSrcweir 
371cdf0e10cSrcweir 	return xCon;
372cdf0e10cSrcweir }
373cdf0e10cSrcweir // -----------------------------------------------------------------------------
374cdf0e10cSrcweir sal_Bool ODriver::getDBName(const ::rtl::OUString& _rName,::rtl::OUString& sDBName) const
375cdf0e10cSrcweir {
376cdf0e10cSrcweir 	sDBName = ::rtl::OUString();
377cdf0e10cSrcweir 	::rtl::OUString sName = _rName.copy(12);
378cdf0e10cSrcweir 	sal_Int32 nPos = sName.indexOf(':');
379cdf0e10cSrcweir 	if(nPos != -1 && nPos < 1)
380cdf0e10cSrcweir 		sDBName = sName.copy(1);
381cdf0e10cSrcweir 	return (nPos != -1 && nPos < 1);
382cdf0e10cSrcweir }
383cdf0e10cSrcweir // --------------------------------------------------------------------------------
384cdf0e10cSrcweir sal_Bool SAL_CALL ODriver::acceptsURL( const ::rtl::OUString& url )
385cdf0e10cSrcweir 		throw(SQLException, RuntimeException)
386cdf0e10cSrcweir {
387cdf0e10cSrcweir 	return (!url.compareTo(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:adabas:")),12));
388cdf0e10cSrcweir }
389cdf0e10cSrcweir // --------------------------------------------------------------------------------
390cdf0e10cSrcweir Sequence< DriverPropertyInfo > SAL_CALL ODriver::getPropertyInfo( const ::rtl::OUString& url, const Sequence< PropertyValue >& /*info*/) throw(SQLException, RuntimeException)
391cdf0e10cSrcweir {
392cdf0e10cSrcweir 	if ( acceptsURL(url) )
393cdf0e10cSrcweir 	{
394cdf0e10cSrcweir 		::std::vector< DriverPropertyInfo > aDriverInfo;
395cdf0e10cSrcweir 
396cdf0e10cSrcweir 		aDriverInfo.push_back(DriverPropertyInfo(
397cdf0e10cSrcweir 				::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ShutdownDatabase"))
398cdf0e10cSrcweir 				,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Shut down service when closing."))
399cdf0e10cSrcweir 				,sal_False
400cdf0e10cSrcweir 				,::rtl::OUString()
401cdf0e10cSrcweir 				,Sequence< ::rtl::OUString >())
402cdf0e10cSrcweir 				);
403cdf0e10cSrcweir 		aDriverInfo.push_back(DriverPropertyInfo(
404cdf0e10cSrcweir 				::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ControlUser"))
405cdf0e10cSrcweir 				,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Control user name."))
406cdf0e10cSrcweir 				,sal_False
407cdf0e10cSrcweir 				,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("0"))
408cdf0e10cSrcweir 				,Sequence< ::rtl::OUString >())
409cdf0e10cSrcweir 				);
410cdf0e10cSrcweir 		aDriverInfo.push_back(DriverPropertyInfo(
411cdf0e10cSrcweir 				::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ControlPassword"))
412cdf0e10cSrcweir 				,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Control password."))
413cdf0e10cSrcweir 				,sal_False
414cdf0e10cSrcweir 				,::rtl::OUString()
415cdf0e10cSrcweir 				,Sequence< ::rtl::OUString >())
416cdf0e10cSrcweir 				);
417cdf0e10cSrcweir 		aDriverInfo.push_back(DriverPropertyInfo(
418cdf0e10cSrcweir 				::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DataCacheSizeIncrement"))
419cdf0e10cSrcweir 				,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Data increment (MB)."))
420cdf0e10cSrcweir 				,sal_False
421cdf0e10cSrcweir 				,::rtl::OUString()
422cdf0e10cSrcweir 				,Sequence< ::rtl::OUString >())
423cdf0e10cSrcweir 				);
424cdf0e10cSrcweir 		aDriverInfo.push_back(DriverPropertyInfo(
425cdf0e10cSrcweir 				::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CharSet"))
426cdf0e10cSrcweir 				,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CharSet of the database."))
427cdf0e10cSrcweir 				,sal_False
428cdf0e10cSrcweir 				,::rtl::OUString()
429cdf0e10cSrcweir 				,Sequence< ::rtl::OUString >())
430cdf0e10cSrcweir 				);
431cdf0e10cSrcweir 		return Sequence< DriverPropertyInfo >(&aDriverInfo[0],aDriverInfo.size());
432cdf0e10cSrcweir 	}
433cdf0e10cSrcweir 
434cdf0e10cSrcweir 	SharedResources aResources;
435cdf0e10cSrcweir     const ::rtl::OUString sMessage = aResources.getResourceString(STR_URI_SYNTAX_ERROR);
436cdf0e10cSrcweir 	::dbtools::throwGenericSQLException(sMessage ,*this);
437cdf0e10cSrcweir 	return Sequence< DriverPropertyInfo >();
438cdf0e10cSrcweir }
439cdf0e10cSrcweir // --------------------------------------------------------------------------------
440cdf0e10cSrcweir sal_Int32 SAL_CALL ODriver::getMajorVersion(  ) throw(RuntimeException)
441cdf0e10cSrcweir {
442cdf0e10cSrcweir 	return 1;
443cdf0e10cSrcweir }
444cdf0e10cSrcweir // --------------------------------------------------------------------------------
445cdf0e10cSrcweir sal_Int32 SAL_CALL ODriver::getMinorVersion(  ) throw(RuntimeException)
446cdf0e10cSrcweir {
447cdf0e10cSrcweir 	return 0;
448cdf0e10cSrcweir }
449cdf0e10cSrcweir // -----------------------------------------------------------------------------
450cdf0e10cSrcweir // XCreateCatalog
451cdf0e10cSrcweir void SAL_CALL ODriver::createCatalog( const Sequence< PropertyValue >& info ) throw(SQLException, ElementExistException, RuntimeException)
452cdf0e10cSrcweir {
453cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
454cdf0e10cSrcweir 	if (ODriver_BASE::rBHelper.bDisposed)
455cdf0e10cSrcweir 		throw DisposedException();
456cdf0e10cSrcweir 
457cdf0e10cSrcweir 	try
458cdf0e10cSrcweir 	{
459cdf0e10cSrcweir 		TDatabaseStruct aDBInfo;
460cdf0e10cSrcweir         fillInfo(info,aDBInfo);
461cdf0e10cSrcweir 
462cdf0e10cSrcweir 		::rtl::OUString envVar(RTL_CONSTASCII_USTRINGPARAM("DBSERVICE"));
463cdf0e10cSrcweir 		::rtl::OUString envData(RTL_CONSTASCII_USTRINGPARAM("0"));
464cdf0e10cSrcweir 		osl_setEnvironment(envVar.pData, envData.pData);
465cdf0e10cSrcweir 
466cdf0e10cSrcweir 		m_sDbRunDir = m_sDbWorkURL + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/wrk/")) + aDBInfo.sDBName;
467cdf0e10cSrcweir 		String sTemp;
468cdf0e10cSrcweir 		LocalFileHelper::ConvertURLToPhysicalName(m_sDbRunDir,sTemp);
469cdf0e10cSrcweir 		m_sDbRunDir = sTemp;
470cdf0e10cSrcweir 
471cdf0e10cSrcweir 		createNeededDirs(aDBInfo.sDBName);
472cdf0e10cSrcweir 		if(CreateFiles(aDBInfo))
473cdf0e10cSrcweir         {
474cdf0e10cSrcweir             ::connectivity::SharedResources aResources;
475cdf0e10cSrcweir             const ::rtl::OUString sError( aResources.getResourceStringWithSubstitution(
476cdf0e10cSrcweir                     STR_NO_DISK_SPACE,
477cdf0e10cSrcweir                     "$filename$",aDBInfo.sDBName
478cdf0e10cSrcweir                  ) );
479cdf0e10cSrcweir 	        ::dbtools::throwGenericSQLException(sError,*this);
480cdf0e10cSrcweir         } // if(CreateFiles(aDBInfo))
481cdf0e10cSrcweir 
482cdf0e10cSrcweir 		createDb(aDBInfo);
483cdf0e10cSrcweir 	}
484cdf0e10cSrcweir 	catch( SQLException&)
485cdf0e10cSrcweir 	{
486cdf0e10cSrcweir 		throw;
487cdf0e10cSrcweir 	}
488cdf0e10cSrcweir 	catch(Exception&)
489cdf0e10cSrcweir 	{
490cdf0e10cSrcweir 		throw SQLException();
491cdf0e10cSrcweir 	}
492cdf0e10cSrcweir 
493cdf0e10cSrcweir }
494cdf0e10cSrcweir // -----------------------------------------------------------------------------
495cdf0e10cSrcweir // XDropCatalog
496cdf0e10cSrcweir void SAL_CALL ODriver::dropCatalog( const ::rtl::OUString& /*catalogName*/, const Sequence< PropertyValue >& /*info*/ ) throw(SQLException, NoSuchElementException, RuntimeException)
497cdf0e10cSrcweir {
498cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
499cdf0e10cSrcweir 	if (ODriver_BASE::rBHelper.bDisposed)
500cdf0e10cSrcweir 		throw DisposedException();
501cdf0e10cSrcweir 
502cdf0e10cSrcweir     ::dbtools::throwFeatureNotImplementedException( "!XDropCatalog::dropCatalog", *this );
503cdf0e10cSrcweir }
504cdf0e10cSrcweir //-----------------------------------------------------------------------------
505cdf0e10cSrcweir // ODBC Environment (gemeinsam fuer alle Connections):
506cdf0e10cSrcweir SQLHANDLE ODriver::EnvironmentHandle(::rtl::OUString &_rPath)
507cdf0e10cSrcweir {
508cdf0e10cSrcweir 	// Ist (fuer diese Instanz) bereits ein Environment erzeugt worden?
509cdf0e10cSrcweir 	if (!m_pDriverHandle)
510cdf0e10cSrcweir 	{
511cdf0e10cSrcweir 		SQLHANDLE h = SQL_NULL_HANDLE;
512cdf0e10cSrcweir 		// Environment allozieren
513cdf0e10cSrcweir 
514cdf0e10cSrcweir 		// ODBC-DLL jetzt laden:
515cdf0e10cSrcweir 		if (! LoadLibrary_ADABAS(_rPath))
516cdf0e10cSrcweir 			return SQL_NULL_HANDLE;
517cdf0e10cSrcweir 
518cdf0e10cSrcweir 		if (N3SQLAllocHandle(SQL_HANDLE_ENV,SQL_NULL_HANDLE,&h) != SQL_SUCCESS)
519cdf0e10cSrcweir 			return SQL_NULL_HANDLE;
520cdf0e10cSrcweir 
521cdf0e10cSrcweir 		// In globaler Struktur merken ...
522cdf0e10cSrcweir 		m_pDriverHandle = h;
523cdf0e10cSrcweir 		SQLRETURN nError = N3SQLSetEnvAttr(h, SQL_ATTR_ODBC_VERSION,(SQLPOINTER) SQL_OV_ODBC3, SQL_IS_INTEGER);
524cdf0e10cSrcweir         OSL_UNUSED( nError );
525cdf0e10cSrcweir 		//N3SQLSetEnvAttr(h, SQL_ATTR_CONNECTION_POOLING,(SQLPOINTER) SQL_CP_ONE_PER_HENV, SQL_IS_INTEGER);
526cdf0e10cSrcweir 	}
527cdf0e10cSrcweir 
528cdf0e10cSrcweir 	return m_pDriverHandle;
529cdf0e10cSrcweir }
530cdf0e10cSrcweir // --------------------------------------------------------------------------------
531cdf0e10cSrcweir // XDataDefinitionSupplier
532cdf0e10cSrcweir Reference< XTablesSupplier > SAL_CALL ODriver::getDataDefinitionByConnection( const Reference< ::com::sun::star::sdbc::XConnection >& connection ) throw(::com::sun::star::sdbc::SQLException, RuntimeException)
533cdf0e10cSrcweir {
534cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
535cdf0e10cSrcweir 	if (ODriver_BASE::rBHelper.bDisposed)
536cdf0e10cSrcweir 		throw DisposedException();
537cdf0e10cSrcweir 
538cdf0e10cSrcweir 	Reference< XTablesSupplier > xTab;
539cdf0e10cSrcweir 	Reference< ::com::sun::star::lang::XUnoTunnel> xTunnel(connection,UNO_QUERY);
540cdf0e10cSrcweir 	if ( xTunnel.is() )
541cdf0e10cSrcweir 	{
542cdf0e10cSrcweir 
543cdf0e10cSrcweir 		OAdabasConnection* pConnection = NULL;
544cdf0e10cSrcweir 		OAdabasConnection* pSearchConnection = reinterpret_cast< OAdabasConnection* >( xTunnel->getSomething(OAdabasConnection::getUnoTunnelImplementationId()) );
545cdf0e10cSrcweir 		for (OWeakRefArray::iterator i = m_xConnections.begin(); m_xConnections.end() != i; ++i)
546cdf0e10cSrcweir 		{
547cdf0e10cSrcweir 			if ( (OAdabasConnection*) Reference< XConnection >::query(i->get().get()).get() == pSearchConnection )
548cdf0e10cSrcweir 			{
549cdf0e10cSrcweir 				pConnection = pSearchConnection;
550cdf0e10cSrcweir 				break;
551cdf0e10cSrcweir 			}
552cdf0e10cSrcweir 		}
553cdf0e10cSrcweir 
554cdf0e10cSrcweir 
555cdf0e10cSrcweir 		if ( pConnection )
556cdf0e10cSrcweir 			xTab = pConnection->createCatalog();
557cdf0e10cSrcweir 	}
558cdf0e10cSrcweir 	return xTab;
559cdf0e10cSrcweir }
560cdf0e10cSrcweir 
561cdf0e10cSrcweir // --------------------------------------------------------------------------------
562cdf0e10cSrcweir Reference< XTablesSupplier > SAL_CALL ODriver::getDataDefinitionByURL( const ::rtl::OUString& url, const Sequence< PropertyValue >& info ) throw(::com::sun::star::sdbc::SQLException, RuntimeException)
563cdf0e10cSrcweir {
564cdf0e10cSrcweir 	if ( ! acceptsURL(url) )
565cdf0e10cSrcweir     {
566cdf0e10cSrcweir         SharedResources aResources;
567cdf0e10cSrcweir         const ::rtl::OUString sMessage = aResources.getResourceString(STR_URI_SYNTAX_ERROR);
568cdf0e10cSrcweir 		::dbtools::throwGenericSQLException(sMessage ,*this);
569cdf0e10cSrcweir     } // if ( ! acceptsURL(url) )
570cdf0e10cSrcweir 
571cdf0e10cSrcweir 	return getDataDefinitionByConnection(connect(url,info));
572cdf0e10cSrcweir }
573cdf0e10cSrcweir // -----------------------------------------------------------------------------
574cdf0e10cSrcweir void SAL_CALL ODriver::acquire() throw()
575cdf0e10cSrcweir {
576cdf0e10cSrcweir 	ODriver_BASE::acquire();
577cdf0e10cSrcweir }
578cdf0e10cSrcweir // -----------------------------------------------------------------------------
579cdf0e10cSrcweir void SAL_CALL ODriver::release() throw()
580cdf0e10cSrcweir {
581cdf0e10cSrcweir 	ODriver_BASE::release();
582cdf0e10cSrcweir }
583cdf0e10cSrcweir ODriver::~ODriver()
584cdf0e10cSrcweir {
585cdf0e10cSrcweir }
586cdf0e10cSrcweir // -----------------------------------------------------------------------------
587cdf0e10cSrcweir oslGenericFunction ODriver::getOdbcFunction(sal_Int32 _nIndex) const
588cdf0e10cSrcweir {
589cdf0e10cSrcweir 	oslGenericFunction pFunction = NULL;
590cdf0e10cSrcweir 	switch(_nIndex)
591cdf0e10cSrcweir 	{
592cdf0e10cSrcweir 		case ODBC3SQLAllocHandle:
593cdf0e10cSrcweir 			pFunction = (oslGenericFunction)pODBC3SQLAllocHandle;;
594cdf0e10cSrcweir 			break;
595cdf0e10cSrcweir 		case ODBC3SQLConnect:
596cdf0e10cSrcweir 			pFunction = (oslGenericFunction)pODBC3SQLConnect;
597cdf0e10cSrcweir 			break;
598cdf0e10cSrcweir 		case ODBC3SQLDriverConnect:
599cdf0e10cSrcweir 			pFunction = (oslGenericFunction)pODBC3SQLDriverConnect;
600cdf0e10cSrcweir 			break;
601cdf0e10cSrcweir 		case ODBC3SQLBrowseConnect:
602cdf0e10cSrcweir 			pFunction = (oslGenericFunction)pODBC3SQLBrowseConnect;
603cdf0e10cSrcweir 			break;
604cdf0e10cSrcweir 		case ODBC3SQLDataSources:
605cdf0e10cSrcweir 			pFunction = (oslGenericFunction)pODBC3SQLDataSources;
606cdf0e10cSrcweir 			break;
607cdf0e10cSrcweir 		case ODBC3SQLDrivers:
608cdf0e10cSrcweir 			pFunction = (oslGenericFunction)pODBC3SQLDrivers;
609cdf0e10cSrcweir 			break;
610cdf0e10cSrcweir 		case ODBC3SQLGetInfo:
611cdf0e10cSrcweir 
612cdf0e10cSrcweir 			pFunction = (oslGenericFunction)pODBC3SQLGetInfo;
613cdf0e10cSrcweir 			break;
614cdf0e10cSrcweir 		case ODBC3SQLGetFunctions:
615cdf0e10cSrcweir 
616cdf0e10cSrcweir 			pFunction = (oslGenericFunction)pODBC3SQLGetFunctions;
617cdf0e10cSrcweir 			break;
618cdf0e10cSrcweir 		case ODBC3SQLGetTypeInfo:
619cdf0e10cSrcweir 
620cdf0e10cSrcweir 			pFunction = (oslGenericFunction)pODBC3SQLGetTypeInfo;
621cdf0e10cSrcweir 			break;
622cdf0e10cSrcweir 		case ODBC3SQLSetConnectAttr:
623cdf0e10cSrcweir 
624cdf0e10cSrcweir 			pFunction = (oslGenericFunction)pODBC3SQLSetConnectAttr;
625cdf0e10cSrcweir 			break;
626cdf0e10cSrcweir 		case ODBC3SQLGetConnectAttr:
627cdf0e10cSrcweir 
628cdf0e10cSrcweir 			pFunction = (oslGenericFunction)pODBC3SQLGetConnectAttr;
629cdf0e10cSrcweir 			break;
630cdf0e10cSrcweir 		case ODBC3SQLSetEnvAttr:
631cdf0e10cSrcweir 
632cdf0e10cSrcweir 			pFunction = (oslGenericFunction)pODBC3SQLSetEnvAttr;
633cdf0e10cSrcweir 			break;
634cdf0e10cSrcweir 		case ODBC3SQLGetEnvAttr:
635cdf0e10cSrcweir 
636cdf0e10cSrcweir 			pFunction = (oslGenericFunction)pODBC3SQLGetEnvAttr;
637cdf0e10cSrcweir 			break;
638cdf0e10cSrcweir 		case ODBC3SQLSetStmtAttr:
639cdf0e10cSrcweir 
640cdf0e10cSrcweir 			pFunction = (oslGenericFunction)pODBC3SQLSetStmtAttr;
641cdf0e10cSrcweir 			break;
642cdf0e10cSrcweir 		case ODBC3SQLGetStmtAttr:
643cdf0e10cSrcweir 
644cdf0e10cSrcweir 			pFunction = (oslGenericFunction)pODBC3SQLGetStmtAttr;
645cdf0e10cSrcweir 			break;
646cdf0e10cSrcweir 		case ODBC3SQLPrepare:
647cdf0e10cSrcweir 
648cdf0e10cSrcweir 			pFunction = (oslGenericFunction)pODBC3SQLPrepare;
649cdf0e10cSrcweir 			break;
650cdf0e10cSrcweir 		case ODBC3SQLBindParameter:
651cdf0e10cSrcweir 
652cdf0e10cSrcweir 			pFunction = (oslGenericFunction)pODBC3SQLBindParameter;
653cdf0e10cSrcweir 			break;
654cdf0e10cSrcweir 		case ODBC3SQLSetCursorName:
655cdf0e10cSrcweir 
656cdf0e10cSrcweir 			pFunction = (oslGenericFunction)pODBC3SQLSetCursorName;
657cdf0e10cSrcweir 			break;
658cdf0e10cSrcweir 		case ODBC3SQLExecute:
659cdf0e10cSrcweir 
660cdf0e10cSrcweir 			pFunction = (oslGenericFunction)pODBC3SQLExecute;
661cdf0e10cSrcweir 			break;
662cdf0e10cSrcweir 		case ODBC3SQLExecDirect:
663cdf0e10cSrcweir 
664cdf0e10cSrcweir 			pFunction = (oslGenericFunction)pODBC3SQLExecDirect;
665cdf0e10cSrcweir 			break;
666cdf0e10cSrcweir 		case ODBC3SQLDescribeParam:
667cdf0e10cSrcweir 
668cdf0e10cSrcweir 			pFunction = (oslGenericFunction)pODBC3SQLDescribeParam;
669cdf0e10cSrcweir 			break;
670cdf0e10cSrcweir 		case ODBC3SQLNumParams:
671cdf0e10cSrcweir 
672cdf0e10cSrcweir 			pFunction = (oslGenericFunction)pODBC3SQLNumParams;
673cdf0e10cSrcweir 			break;
674cdf0e10cSrcweir 		case ODBC3SQLParamData:
675cdf0e10cSrcweir 
676cdf0e10cSrcweir 			pFunction = (oslGenericFunction)pODBC3SQLParamData;
677cdf0e10cSrcweir 			break;
678cdf0e10cSrcweir 		case ODBC3SQLPutData:
679cdf0e10cSrcweir 
680cdf0e10cSrcweir 			pFunction = (oslGenericFunction)pODBC3SQLPutData;
681cdf0e10cSrcweir 			break;
682cdf0e10cSrcweir 		case ODBC3SQLRowCount:
683cdf0e10cSrcweir 
684cdf0e10cSrcweir 			pFunction = (oslGenericFunction)pODBC3SQLRowCount;
685cdf0e10cSrcweir 			break;
686cdf0e10cSrcweir 		case ODBC3SQLNumResultCols:
687cdf0e10cSrcweir 
688cdf0e10cSrcweir 			pFunction = (oslGenericFunction)pODBC3SQLNumResultCols;
689cdf0e10cSrcweir 			break;
690cdf0e10cSrcweir 		case ODBC3SQLDescribeCol:
691cdf0e10cSrcweir 
692cdf0e10cSrcweir 			pFunction = (oslGenericFunction)pODBC3SQLDescribeCol;
693cdf0e10cSrcweir 			break;
694cdf0e10cSrcweir 		case ODBC3SQLColAttribute:
695cdf0e10cSrcweir 
696cdf0e10cSrcweir 			pFunction = (oslGenericFunction)pODBC3SQLColAttribute;
697cdf0e10cSrcweir 			break;
698cdf0e10cSrcweir 		case ODBC3SQLBindCol:
699cdf0e10cSrcweir 
700cdf0e10cSrcweir 			pFunction = (oslGenericFunction)pODBC3SQLBindCol;
701cdf0e10cSrcweir 			break;
702cdf0e10cSrcweir 		case ODBC3SQLFetch:
703cdf0e10cSrcweir 
704cdf0e10cSrcweir 			pFunction = (oslGenericFunction)pODBC3SQLFetch;
705cdf0e10cSrcweir 			break;
706cdf0e10cSrcweir 		case ODBC3SQLFetchScroll:
707cdf0e10cSrcweir 
708cdf0e10cSrcweir 			pFunction = (oslGenericFunction)pODBC3SQLFetchScroll;
709cdf0e10cSrcweir 			break;
710cdf0e10cSrcweir 		case ODBC3SQLGetData:
711cdf0e10cSrcweir 
712cdf0e10cSrcweir 			pFunction = (oslGenericFunction)pODBC3SQLGetData;
713cdf0e10cSrcweir 			break;
714cdf0e10cSrcweir 		case ODBC3SQLSetPos:
715cdf0e10cSrcweir 
716cdf0e10cSrcweir 			pFunction = (oslGenericFunction)pODBC3SQLSetPos;
717cdf0e10cSrcweir 			break;
718cdf0e10cSrcweir 		case ODBC3SQLBulkOperations:
719cdf0e10cSrcweir 
720cdf0e10cSrcweir 			pFunction = (oslGenericFunction)pODBC3SQLBulkOperations;
721cdf0e10cSrcweir 			break;
722cdf0e10cSrcweir 		case ODBC3SQLMoreResults:
723cdf0e10cSrcweir 
724cdf0e10cSrcweir 			pFunction = (oslGenericFunction)pODBC3SQLMoreResults;
725cdf0e10cSrcweir 			break;
726cdf0e10cSrcweir 		case ODBC3SQLGetDiagRec:
727cdf0e10cSrcweir 
728cdf0e10cSrcweir 			pFunction = (oslGenericFunction)pODBC3SQLGetDiagRec;
729cdf0e10cSrcweir 			break;
730cdf0e10cSrcweir 		case ODBC3SQLColumnPrivileges:
731cdf0e10cSrcweir 
732cdf0e10cSrcweir 			pFunction = (oslGenericFunction)pODBC3SQLColumnPrivileges;
733cdf0e10cSrcweir 			break;
734cdf0e10cSrcweir 		case ODBC3SQLColumns:
735cdf0e10cSrcweir 
736cdf0e10cSrcweir 			pFunction = (oslGenericFunction)pODBC3SQLColumns;
737cdf0e10cSrcweir 			break;
738cdf0e10cSrcweir 		case ODBC3SQLForeignKeys:
739cdf0e10cSrcweir 
740cdf0e10cSrcweir 			pFunction = (oslGenericFunction)pODBC3SQLForeignKeys;
741cdf0e10cSrcweir 			break;
742cdf0e10cSrcweir 		case ODBC3SQLPrimaryKeys:
743cdf0e10cSrcweir 
744cdf0e10cSrcweir 			pFunction = (oslGenericFunction)pODBC3SQLPrimaryKeys;
745cdf0e10cSrcweir 			break;
746cdf0e10cSrcweir 		case ODBC3SQLProcedureColumns:
747cdf0e10cSrcweir 
748cdf0e10cSrcweir 			pFunction = (oslGenericFunction)pODBC3SQLProcedureColumns;
749cdf0e10cSrcweir 			break;
750cdf0e10cSrcweir 		case ODBC3SQLProcedures:
751cdf0e10cSrcweir 
752cdf0e10cSrcweir 			pFunction = (oslGenericFunction)pODBC3SQLProcedures;
753cdf0e10cSrcweir 			break;
754cdf0e10cSrcweir 		case ODBC3SQLSpecialColumns:
755cdf0e10cSrcweir 
756cdf0e10cSrcweir 			pFunction = (oslGenericFunction)pODBC3SQLSpecialColumns;
757cdf0e10cSrcweir 			break;
758cdf0e10cSrcweir 		case ODBC3SQLStatistics:
759cdf0e10cSrcweir 
760cdf0e10cSrcweir 			pFunction = (oslGenericFunction)pODBC3SQLStatistics;
761cdf0e10cSrcweir 			break;
762cdf0e10cSrcweir 		case ODBC3SQLTablePrivileges:
763cdf0e10cSrcweir 
764cdf0e10cSrcweir 			pFunction = (oslGenericFunction)pODBC3SQLTablePrivileges;
765cdf0e10cSrcweir 			break;
766cdf0e10cSrcweir 		case ODBC3SQLTables:
767cdf0e10cSrcweir 
768cdf0e10cSrcweir 			pFunction = (oslGenericFunction)pODBC3SQLTables;
769cdf0e10cSrcweir 			break;
770cdf0e10cSrcweir 		case ODBC3SQLFreeStmt:
771cdf0e10cSrcweir 
772cdf0e10cSrcweir 			pFunction = (oslGenericFunction)pODBC3SQLFreeStmt;
773cdf0e10cSrcweir 			break;
774cdf0e10cSrcweir 		case ODBC3SQLCloseCursor:
775cdf0e10cSrcweir 
776cdf0e10cSrcweir 			pFunction = (oslGenericFunction)pODBC3SQLCloseCursor;
777cdf0e10cSrcweir 			break;
778cdf0e10cSrcweir 		case ODBC3SQLCancel:
779cdf0e10cSrcweir 
780cdf0e10cSrcweir 			pFunction = (oslGenericFunction)pODBC3SQLCancel;
781cdf0e10cSrcweir 			break;
782cdf0e10cSrcweir 		case ODBC3SQLEndTran:
783cdf0e10cSrcweir 
784cdf0e10cSrcweir 			pFunction = (oslGenericFunction)pODBC3SQLEndTran;
785cdf0e10cSrcweir 			break;
786cdf0e10cSrcweir 		case ODBC3SQLDisconnect:
787cdf0e10cSrcweir 
788cdf0e10cSrcweir 			pFunction = (oslGenericFunction)pODBC3SQLDisconnect;
789cdf0e10cSrcweir 			break;
790cdf0e10cSrcweir 		case ODBC3SQLFreeHandle:
791cdf0e10cSrcweir 
792cdf0e10cSrcweir 			pFunction = (oslGenericFunction)pODBC3SQLFreeHandle;
793cdf0e10cSrcweir 			break;
794cdf0e10cSrcweir 		case ODBC3SQLGetCursorName:
795cdf0e10cSrcweir 
796cdf0e10cSrcweir 			pFunction = (oslGenericFunction)pODBC3SQLGetCursorName;
797cdf0e10cSrcweir 			break;
798cdf0e10cSrcweir 		case ODBC3SQLNativeSql:
799cdf0e10cSrcweir 
800cdf0e10cSrcweir 			pFunction = (oslGenericFunction)pODBC3SQLNativeSql;
801cdf0e10cSrcweir 			break;
802cdf0e10cSrcweir 		default:
803cdf0e10cSrcweir 			OSL_ENSURE(0,"Function unknown!");
804cdf0e10cSrcweir 	}
805cdf0e10cSrcweir 	return pFunction;
806cdf0e10cSrcweir }
807cdf0e10cSrcweir // -----------------------------------------------------------------------------
808cdf0e10cSrcweir void ODriver::createNeededDirs(const ::rtl::OUString& sDBName)
809cdf0e10cSrcweir {
810cdf0e10cSrcweir 	::rtl::OUString sDbWork,sDBConfig,sTemp;
811cdf0e10cSrcweir 
812cdf0e10cSrcweir 	if(m_sDbWork.getLength())
813cdf0e10cSrcweir 	{
814cdf0e10cSrcweir 		sDbWork = m_sDbWorkURL;
815cdf0e10cSrcweir 		if(!UCBContentHelper::IsFolder(m_sDbWorkURL))
816cdf0e10cSrcweir 			UCBContentHelper::MakeFolder(m_sDbWorkURL);
817cdf0e10cSrcweir 
818cdf0e10cSrcweir 		sDbWork += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/"));
819cdf0e10cSrcweir 		sDbWork += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("wrk"));
820cdf0e10cSrcweir 		if(!UCBContentHelper::IsFolder(sDbWork))
821cdf0e10cSrcweir 			UCBContentHelper::MakeFolder(sDbWork);
822cdf0e10cSrcweir 
823cdf0e10cSrcweir 		sDbWork += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/"));
824cdf0e10cSrcweir 
825cdf0e10cSrcweir 		sTemp = sDbWork;
826cdf0e10cSrcweir 		sTemp += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("config"));
827cdf0e10cSrcweir 		if(!UCBContentHelper::IsFolder(sTemp))
828cdf0e10cSrcweir 			UCBContentHelper::MakeFolder(sTemp);
829cdf0e10cSrcweir 
830cdf0e10cSrcweir 		sTemp = sDbWork;
831cdf0e10cSrcweir 		sTemp += sDBName;
832cdf0e10cSrcweir 		if(!UCBContentHelper::IsFolder(sTemp))
833cdf0e10cSrcweir 			UCBContentHelper::MakeFolder(sTemp);
834cdf0e10cSrcweir 	}
835cdf0e10cSrcweir 
836cdf0e10cSrcweir 	if(m_sDbConfig.getLength())
837cdf0e10cSrcweir 	{
838cdf0e10cSrcweir 		sDBConfig = m_sDbConfigURL;
839cdf0e10cSrcweir 		if(!UCBContentHelper::IsFolder(sDBConfig))
840cdf0e10cSrcweir 			UCBContentHelper::MakeFolder(sDBConfig);
841cdf0e10cSrcweir 
842cdf0e10cSrcweir 		sDBConfig += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/"));
843cdf0e10cSrcweir 		sTemp = sDBConfig;
844cdf0e10cSrcweir 		sTemp += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("config"));
845cdf0e10cSrcweir 		if(!UCBContentHelper::IsFolder(sTemp))
846cdf0e10cSrcweir 			UCBContentHelper::MakeFolder(sTemp);
847cdf0e10cSrcweir 
848cdf0e10cSrcweir 		sTemp += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/"));
849cdf0e10cSrcweir 		sTemp += sDBName;
850cdf0e10cSrcweir 		if(UCBContentHelper::Exists(sTemp))
851cdf0e10cSrcweir 			UCBContentHelper::Kill(sTemp);
852cdf0e10cSrcweir 
853cdf0e10cSrcweir #if !(defined(WNT))
854cdf0e10cSrcweir 		sTemp = sDBConfig;
855cdf0e10cSrcweir 		sTemp += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("diag"));
856cdf0e10cSrcweir 		if(!UCBContentHelper::IsFolder(sTemp))
857cdf0e10cSrcweir 			UCBContentHelper::MakeFolder(sTemp);
858cdf0e10cSrcweir 
859cdf0e10cSrcweir 		sTemp = sDBConfig;
860cdf0e10cSrcweir 		sTemp += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ipc"));
861cdf0e10cSrcweir 		if(!UCBContentHelper::IsFolder(sTemp))
862cdf0e10cSrcweir 			UCBContentHelper::MakeFolder(sTemp);
863cdf0e10cSrcweir 
864cdf0e10cSrcweir 		sTemp = sDBConfig;
865cdf0e10cSrcweir 		sTemp += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("spool"));
866cdf0e10cSrcweir 		if(!UCBContentHelper::IsFolder(sTemp))
867cdf0e10cSrcweir 			UCBContentHelper::MakeFolder(sTemp);
868cdf0e10cSrcweir #endif
869cdf0e10cSrcweir 	}
870cdf0e10cSrcweir }
871cdf0e10cSrcweir // -----------------------------------------------------------------------------
872cdf0e10cSrcweir void ODriver::clearDatabase(const ::rtl::OUString& sDBName)
873cdf0e10cSrcweir { // stop the database
874cdf0e10cSrcweir 	::rtl::OUString sCommand;
875cdf0e10cSrcweir #if defined(WNT)
876cdf0e10cSrcweir 	::rtl::OUString sStop = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("stop"));
877cdf0e10cSrcweir 	OArgumentList aArgs(2,&sDBName,&sStop);
878cdf0e10cSrcweir 	sCommand =	::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("x_cons.exe"));
879cdf0e10cSrcweir #else
880cdf0e10cSrcweir 	OArgumentList aArgs(1,&sDBName);
881cdf0e10cSrcweir 	sCommand =	::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("x_clear"));
882cdf0e10cSrcweir #endif
883cdf0e10cSrcweir 
884cdf0e10cSrcweir 	OProcess aApp( sCommand,m_sDbWorkURL);
885cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
886cdf0e10cSrcweir 	OProcess::TProcessError eError =
887cdf0e10cSrcweir #endif
888cdf0e10cSrcweir         aApp.execute( (OProcess::TProcessOption) OPROCESS_ADABAS, aArgs );
889cdf0e10cSrcweir     OSL_ENSURE( eError == OProcess::E_None, "ODriver::clearDatabase: calling the executable failed!" );
890cdf0e10cSrcweir }
891cdf0e10cSrcweir // -----------------------------------------------------------------------------
892cdf0e10cSrcweir void ODriver::createDb( const TDatabaseStruct& _aInfo)
893cdf0e10cSrcweir {
894cdf0e10cSrcweir 
895cdf0e10cSrcweir 	clearDatabase(_aInfo.sDBName);
896cdf0e10cSrcweir 
897cdf0e10cSrcweir 	X_PARAM(_aInfo.sDBName,_aInfo.sControlUser,_aInfo.sControlPassword,String::CreateFromAscii("BINIT"));
898cdf0e10cSrcweir 
899cdf0e10cSrcweir 	String sTemp;
900cdf0e10cSrcweir 	LocalFileHelper::ConvertURLToPhysicalName(_aInfo.sSysDevSpace,sTemp);
901cdf0e10cSrcweir 
902cdf0e10cSrcweir 	PutParam(_aInfo.sDBName,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SYSDEVSPACE")),sTemp);
903cdf0e10cSrcweir 
904cdf0e10cSrcweir 	sTemp.Erase();
905cdf0e10cSrcweir 	LocalFileHelper::ConvertURLToPhysicalName(_aInfo.sTransLogName,sTemp);
906cdf0e10cSrcweir     PutParam(_aInfo.sDBName,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TRANSACTION_LOG")),sTemp);
907cdf0e10cSrcweir 	PutParam(_aInfo.sDBName,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MAXUSERTASKS")),::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("3")));
908cdf0e10cSrcweir 	PutParam(_aInfo.sDBName,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MAXDEVSPACES")),::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("7")));
909cdf0e10cSrcweir 	PutParam(_aInfo.sDBName,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MAXDATADEVSPACES")),::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("5")));
910cdf0e10cSrcweir 	PutParam(_aInfo.sDBName,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MAXDATAPAGES")),::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("25599")));
911cdf0e10cSrcweir 	PutParam(_aInfo.sDBName,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MAXBACKUPDEVS")),::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("1")));
912cdf0e10cSrcweir 	PutParam(_aInfo.sDBName,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MAXSERVERDB")),::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("1")));
913cdf0e10cSrcweir 	PutParam(_aInfo.sDBName,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DATA_CACHE_PAGES")),_aInfo.sCacheSize);
914cdf0e10cSrcweir 	PutParam(_aInfo.sDBName,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CONV_CACHE_PAGES")),::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("23")));
915cdf0e10cSrcweir 	PutParam(_aInfo.sDBName,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PROC_DATA_PAGES")),::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("40")));
916cdf0e10cSrcweir 	PutParam(_aInfo.sDBName,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("RUNDIRECTORY")),m_sDbRunDir);
917cdf0e10cSrcweir 	PutParam(_aInfo.sDBName,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("KERNELTRACESIZE")),::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("100")));
918cdf0e10cSrcweir 	PutParam(_aInfo.sDBName,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("LOG_QUEUE_PAGES")),::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("10")));
919cdf0e10cSrcweir 
920cdf0e10cSrcweir #if !defined(WNT)
921cdf0e10cSrcweir 	PutParam(_aInfo.sDBName,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("OPMSG1")),::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/dev/null")));
922cdf0e10cSrcweir #endif
923cdf0e10cSrcweir 
924cdf0e10cSrcweir 	X_PARAM(_aInfo.sDBName,_aInfo.sControlUser,_aInfo.sControlPassword,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("BCHECK")));
925cdf0e10cSrcweir 
926cdf0e10cSrcweir 	X_START(_aInfo.sDBName);
927cdf0e10cSrcweir 
928cdf0e10cSrcweir 	//	SHOW_STATE()
929cdf0e10cSrcweir 	//	%m_sDbRoot%\bin\xutil -d %_aInfo.sDBName% -u %CONUSR%,%CONPWD% -b %INITCMD%
930cdf0e10cSrcweir 	::rtl::OUString aBatch2 =  ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("-b "));
931cdf0e10cSrcweir 
932cdf0e10cSrcweir //	if(!bBsp && INITCMD.Len() >= 40)
933cdf0e10cSrcweir //	{
934cdf0e10cSrcweir //		DirEntry aTmp(INITCMD);
935cdf0e10cSrcweir //		aTmp.CopyTo(aInitFile, FSYS_ACTION_COPYFILE);
936cdf0e10cSrcweir //		INITCMD = aInitFile.GetFull();
937cdf0e10cSrcweir //	}
938cdf0e10cSrcweir 	// generate the init file for the database
939cdf0e10cSrcweir 	String sInitFile = getDatabaseInitFile(_aInfo);
940cdf0e10cSrcweir 
941cdf0e10cSrcweir 	LocalFileHelper::ConvertURLToPhysicalName(sInitFile,sTemp);
942cdf0e10cSrcweir 	aBatch2 += sTemp;
943cdf0e10cSrcweir 	XUTIL(aBatch2,_aInfo.sDBName,_aInfo.sControlUser,_aInfo.sControlPassword);
944cdf0e10cSrcweir #if OSL_DEBUG_LEVEL < 2
945cdf0e10cSrcweir 	if(UCBContentHelper::Exists(sInitFile))
946cdf0e10cSrcweir 		UCBContentHelper::Kill(sInitFile);
947cdf0e10cSrcweir #endif
948cdf0e10cSrcweir 
949cdf0e10cSrcweir 	// install system tables
950cdf0e10cSrcweir 	installSystemTables(_aInfo);
951cdf0e10cSrcweir 	// now we have to make our SYSDBA user "NOT EXCLUSIVE"
952cdf0e10cSrcweir 	{
953cdf0e10cSrcweir 		String sExt;
954cdf0e10cSrcweir 		sExt.AssignAscii(".sql");
955cdf0e10cSrcweir 
956cdf0e10cSrcweir 		String sWorkUrl(m_sDbWorkURL);
957cdf0e10cSrcweir 		::utl::TempFile aInitFile(String::CreateFromAscii("Init"),&sExt,&sWorkUrl);
958cdf0e10cSrcweir 		aInitFile.EnableKillingFile();
959cdf0e10cSrcweir 		{
960cdf0e10cSrcweir 			::std::auto_ptr<SvStream> pFileStream( UcbStreamHelper::CreateStream(aInitFile.GetURL(),STREAM_WRITE) );
961cdf0e10cSrcweir 			(*pFileStream)	<< "ALTER USER \""
962cdf0e10cSrcweir 							<< ::rtl::OString(_aInfo.sSysUser,_aInfo.sSysUser.getLength(),gsl_getSystemTextEncoding())
963cdf0e10cSrcweir 							<< "\" NOT EXCLUSIVE "
964cdf0e10cSrcweir 							<< sNewLine;
965cdf0e10cSrcweir 			pFileStream->Flush();
966cdf0e10cSrcweir 		}
967cdf0e10cSrcweir 		{ // just to get sure that the tempfile still lives
968cdf0e10cSrcweir 			sTemp.Erase();
969cdf0e10cSrcweir 			LocalFileHelper::ConvertURLToPhysicalName(aInitFile.GetURL(),sTemp);
970cdf0e10cSrcweir 			LoadBatch(_aInfo.sDBName,_aInfo.sSysUser,_aInfo.sSysPassword,sTemp);
971cdf0e10cSrcweir 		}
972cdf0e10cSrcweir 	}
973cdf0e10cSrcweir }
974cdf0e10cSrcweir 
975cdf0e10cSrcweir 
976cdf0e10cSrcweir //-------------------------------------------------------------------------------------------------
977cdf0e10cSrcweir int ODriver::X_PARAM(const ::rtl::OUString& _DBNAME,
978cdf0e10cSrcweir 			const ::rtl::OUString& _USR,
979cdf0e10cSrcweir 			const ::rtl::OUString& _PWD,
980cdf0e10cSrcweir 			const ::rtl::OUString& _CMD)
981cdf0e10cSrcweir {
982cdf0e10cSrcweir 	//	%XPARAM% -u %CONUSR%,%CONPWD% BINIT
983cdf0e10cSrcweir 	String sCommandFile = generateInitFile();
984cdf0e10cSrcweir 	{
985cdf0e10cSrcweir 		::std::auto_ptr<SvStream> pFileStream( UcbStreamHelper::CreateStream(sCommandFile,STREAM_STD_READWRITE));
986cdf0e10cSrcweir 		pFileStream->Seek(STREAM_SEEK_TO_END);
987cdf0e10cSrcweir 		(*pFileStream)	<< "x_param"
988cdf0e10cSrcweir #if defined(WNT)
989cdf0e10cSrcweir 						<< ".exe"
990cdf0e10cSrcweir #endif
991cdf0e10cSrcweir 						<< " -d "
992cdf0e10cSrcweir 						<< ::rtl::OString(_DBNAME,_DBNAME.getLength(),gsl_getSystemTextEncoding())
993cdf0e10cSrcweir 						<< " -u "
994cdf0e10cSrcweir 						<< ::rtl::OString(_USR,_USR.getLength(),gsl_getSystemTextEncoding())
995cdf0e10cSrcweir 						<< ","
996cdf0e10cSrcweir 						<< ::rtl::OString(_PWD,_PWD.getLength(),gsl_getSystemTextEncoding())
997cdf0e10cSrcweir 						<< " "
998cdf0e10cSrcweir 						<< ::rtl::OString(_CMD,_CMD.getLength(),gsl_getSystemTextEncoding())
999cdf0e10cSrcweir #if defined(WNT)
1000cdf0e10cSrcweir #if (OSL_DEBUG_LEVEL > 1) || defined(DBG_UTIL)
1001cdf0e10cSrcweir 						<< " >> %DBWORK%\\create.log 2>&1"
1002cdf0e10cSrcweir #endif
1003cdf0e10cSrcweir #else
1004cdf0e10cSrcweir #if (OSL_DEBUG_LEVEL > 1) || defined(DBG_UTIL)
1005cdf0e10cSrcweir 						<< " >> /tmp/kstart.log"
1006cdf0e10cSrcweir #else
1007cdf0e10cSrcweir 						<< " > /dev/null"
1008cdf0e10cSrcweir #endif
1009cdf0e10cSrcweir #endif
1010cdf0e10cSrcweir 						<< " "
1011cdf0e10cSrcweir 						<< sNewLine
1012cdf0e10cSrcweir 						<< sNewLine;
1013cdf0e10cSrcweir 
1014cdf0e10cSrcweir 		pFileStream->Flush();
1015cdf0e10cSrcweir 	}
1016cdf0e10cSrcweir 
1017cdf0e10cSrcweir 	OProcess aApp(sCommandFile ,m_sDbWorkURL);
1018cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
1019cdf0e10cSrcweir 	OProcess::TProcessError eError =
1020cdf0e10cSrcweir #endif
1021cdf0e10cSrcweir 	    aApp.execute( (OProcess::TProcessOption)(OProcess::TOption_Hidden | OProcess::TOption_Wait));
1022cdf0e10cSrcweir     OSL_ENSURE( eError == OProcess::E_None, "ODriver::X_PARAM: calling the executable failed!" );
1023cdf0e10cSrcweir #if OSL_DEBUG_LEVEL < 2
1024cdf0e10cSrcweir 	if(UCBContentHelper::Exists(sCommandFile))
1025cdf0e10cSrcweir 		UCBContentHelper::Kill(sCommandFile);
1026cdf0e10cSrcweir #endif
1027cdf0e10cSrcweir 
1028cdf0e10cSrcweir 	return 0;
1029cdf0e10cSrcweir }
1030cdf0e10cSrcweir // -----------------------------------------------------------------------------
1031cdf0e10cSrcweir sal_Int32 ODriver::CreateFiles(const TDatabaseStruct& _aInfo)
1032cdf0e10cSrcweir {
1033cdf0e10cSrcweir 	int nRet = CreateFile(_aInfo.sSysDevSpace,_aInfo.nDataSize/50) ? 0 : -9;
1034cdf0e10cSrcweir 	if(!nRet)
1035cdf0e10cSrcweir 		nRet = CreateFile(_aInfo.sTransLogName,_aInfo.nLogSize) ? 0 : -10;
1036cdf0e10cSrcweir 	if(!nRet)
1037cdf0e10cSrcweir 		nRet = CreateFile(_aInfo.sDataDevName,_aInfo.nDataSize) ? 0 : -11;
1038cdf0e10cSrcweir 
1039cdf0e10cSrcweir 	return nRet;
1040cdf0e10cSrcweir 
1041cdf0e10cSrcweir }
1042cdf0e10cSrcweir // -----------------------------------------------------------------------------
1043cdf0e10cSrcweir void ODriver::PutParam(const ::rtl::OUString& sDBName,
1044cdf0e10cSrcweir 					  const ::rtl::OUString& rWhat,
1045cdf0e10cSrcweir 					  const ::rtl::OUString& rHow)
1046cdf0e10cSrcweir {
1047cdf0e10cSrcweir 	OArgumentList aArgs(3,&sDBName,&rWhat,&rHow);
1048cdf0e10cSrcweir 	::rtl::OUString sCommand = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("putparam"));
1049cdf0e10cSrcweir #if defined(WNT)
1050cdf0e10cSrcweir 	sCommand += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".exe"));
1051cdf0e10cSrcweir #endif
1052cdf0e10cSrcweir 
1053cdf0e10cSrcweir 	OProcess aApp(sCommand,m_sDbWorkURL);
1054cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
1055cdf0e10cSrcweir 	OProcess::TProcessError eError =
1056cdf0e10cSrcweir #endif
1057cdf0e10cSrcweir 	    aApp.execute( (OProcess::TProcessOption)OPROCESS_ADABAS,aArgs );
1058cdf0e10cSrcweir     OSL_ENSURE( eError == OProcess::E_None, "ODriver::PutParam: calling the executable failed!" );
1059cdf0e10cSrcweir }
1060cdf0e10cSrcweir // -----------------------------------------------------------------------------
1061cdf0e10cSrcweir sal_Bool ODriver::CreateFile(const ::rtl::OUString &_FileName,
1062cdf0e10cSrcweir 				sal_Int32 _nSize)
1063cdf0e10cSrcweir {
1064cdf0e10cSrcweir OSL_TRACE("CreateFile %d",_nSize);
1065cdf0e10cSrcweir 	sal_Bool bOK = sal_True;
1066cdf0e10cSrcweir 	try
1067cdf0e10cSrcweir 	{
1068cdf0e10cSrcweir 		::std::auto_ptr<SvStream> pFileStream( UcbStreamHelper::CreateStream(_FileName,STREAM_WRITE));
1069cdf0e10cSrcweir 		if( !pFileStream.get())
1070cdf0e10cSrcweir 		{
1071cdf0e10cSrcweir             ::connectivity::SharedResources aResources;
1072cdf0e10cSrcweir             const ::rtl::OUString sError( aResources.getResourceStringWithSubstitution(
1073cdf0e10cSrcweir                     STR_NO_DISK_SPACE,
1074cdf0e10cSrcweir                     "$filename$",_FileName
1075cdf0e10cSrcweir                  ) );
1076cdf0e10cSrcweir 	        ::dbtools::throwGenericSQLException(sError,*this);
1077cdf0e10cSrcweir 		}
1078cdf0e10cSrcweir 		(*pFileStream).SetFiller('\0');
1079cdf0e10cSrcweir 		sal_Int32 nNewSize = 0;
1080cdf0e10cSrcweir 		sal_Int32 nCount = _nSize /2;
1081cdf0e10cSrcweir 		for(sal_Int32 i=0; bOK && i < nCount; ++i)
1082cdf0e10cSrcweir 		{
1083cdf0e10cSrcweir 			nNewSize += 8192;//4096;
1084cdf0e10cSrcweir 			bOK = (*pFileStream).SetStreamSize(nNewSize);
1085cdf0e10cSrcweir 			pFileStream->Flush();
1086cdf0e10cSrcweir 		}
1087cdf0e10cSrcweir 
1088cdf0e10cSrcweir 		bOK = bOK && static_cast<sal_Int32>(pFileStream->Seek(STREAM_SEEK_TO_END)) == nNewSize;
1089cdf0e10cSrcweir 	}
1090cdf0e10cSrcweir 	catch(Exception&)
1091cdf0e10cSrcweir 	{
1092cdf0e10cSrcweir 	OSL_TRACE("Exception");
1093cdf0e10cSrcweir 	}
1094cdf0e10cSrcweir 	if(!bOK)
1095cdf0e10cSrcweir 	{
1096cdf0e10cSrcweir         ::connectivity::SharedResources aResources;
1097cdf0e10cSrcweir         const ::rtl::OUString sError( aResources.getResourceStringWithSubstitution(
1098cdf0e10cSrcweir                 STR_NO_DISK_SPACE,
1099cdf0e10cSrcweir                 "$filename$",_FileName
1100cdf0e10cSrcweir              ) );
1101cdf0e10cSrcweir         ::dbtools::throwGenericSQLException(sError,*this);
1102cdf0e10cSrcweir 	}
1103cdf0e10cSrcweir 
1104cdf0e10cSrcweir 	return bOK;
1105cdf0e10cSrcweir 	// dd if=/dev/zero bs=4k of=$DEV_NAME count=$2
1106cdf0e10cSrcweir }
1107cdf0e10cSrcweir // -----------------------------------------------------------------------------
1108cdf0e10cSrcweir int ODriver::X_START(const ::rtl::OUString& sDBName)
1109cdf0e10cSrcweir {
1110cdf0e10cSrcweir 	::rtl::OUString sCommand;
1111cdf0e10cSrcweir #if defined(WNT)
1112cdf0e10cSrcweir 
1113cdf0e10cSrcweir 	::rtl::OUString sArg1 = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("-d"));
1114cdf0e10cSrcweir 	::rtl::OUString sArg3 = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("-NoDBService"));
1115cdf0e10cSrcweir 	::rtl::OUString sArg4 = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("-NoDBWindow"));
1116cdf0e10cSrcweir 
1117cdf0e10cSrcweir 	OArgumentList aArgs(4,&sArg1,&sDBName,&sArg3,&sArg4);
1118cdf0e10cSrcweir 	sCommand =	::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("strt.exe"));
1119cdf0e10cSrcweir #else
1120cdf0e10cSrcweir 	OArgumentList aArgs(1,&sDBName);
1121cdf0e10cSrcweir 	sCommand =	::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("x_start"));
1122cdf0e10cSrcweir #endif
1123cdf0e10cSrcweir 
1124cdf0e10cSrcweir 	OProcess aApp( sCommand ,m_sDbWorkURL);
1125cdf0e10cSrcweir 	OProcess::TProcessError eError = aApp.execute((OProcess::TProcessOption)OPROCESS_ADABAS,aArgs);
1126cdf0e10cSrcweir 
1127cdf0e10cSrcweir 	if(eError == OProcess::E_NotFound)
1128cdf0e10cSrcweir 	{
1129cdf0e10cSrcweir         ::connectivity::SharedResources aResources;
1130cdf0e10cSrcweir         const ::rtl::OUString sError( aResources.getResourceStringWithSubstitution(
1131cdf0e10cSrcweir                 STR_COMMAND_NOT_FOUND,
1132cdf0e10cSrcweir                 "$databasename$",sDBName,
1133cdf0e10cSrcweir                 "$progname$",sCommand
1134cdf0e10cSrcweir              ) );
1135cdf0e10cSrcweir         ::dbtools::throwGenericSQLException(sError,*this);
1136cdf0e10cSrcweir 	}
1137cdf0e10cSrcweir 	OSL_ASSERT(eError == OProcess::E_None);
1138cdf0e10cSrcweir 
1139cdf0e10cSrcweir 	OProcess::TProcessInfo aInfo;
1140cdf0e10cSrcweir 	if(aApp.getInfo(OProcess::TData_ExitCode,&aInfo) == OProcess::E_None && aInfo.Code)
1141cdf0e10cSrcweir 		return aInfo.Code;
1142cdf0e10cSrcweir 
1143cdf0e10cSrcweir 	return 0;
1144cdf0e10cSrcweir }
1145cdf0e10cSrcweir // -----------------------------------------------------------------------------
1146cdf0e10cSrcweir int ODriver::X_STOP(const ::rtl::OUString& sDBName)
1147cdf0e10cSrcweir {
1148cdf0e10cSrcweir 	::rtl::OUString sCommand;
1149cdf0e10cSrcweir #if defined(WNT)
1150cdf0e10cSrcweir 
1151cdf0e10cSrcweir 	::rtl::OUString sArg1 = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("-d"));
1152cdf0e10cSrcweir 	::rtl::OUString sArg2 = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("-NoDBService"));
1153cdf0e10cSrcweir 
1154cdf0e10cSrcweir 	OArgumentList aArgs(3,&sArg1,&sDBName,&sArg2);
1155cdf0e10cSrcweir 	sCommand =	::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("stp.exe"));
1156cdf0e10cSrcweir #else
1157cdf0e10cSrcweir 	OArgumentList aArgs(1,&sDBName);
1158cdf0e10cSrcweir 	sCommand = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("x_stop"));
1159cdf0e10cSrcweir #endif
1160cdf0e10cSrcweir 	OProcess aApp( sCommand ,m_sDbWorkURL);
1161cdf0e10cSrcweir 
1162cdf0e10cSrcweir 	OProcess::TProcessError eError = aApp.execute((OProcess::TProcessOption)OPROCESS_ADABAS,aArgs);
1163cdf0e10cSrcweir 
1164cdf0e10cSrcweir 
1165cdf0e10cSrcweir 	OSL_ASSERT(eError == OProcess::E_None);
1166cdf0e10cSrcweir 	if(eError != OProcess::E_None)
1167cdf0e10cSrcweir 		return 1;
1168cdf0e10cSrcweir 		OProcess::TProcessInfo aInfo;
1169cdf0e10cSrcweir 	if(aApp.getInfo(OProcess::TData_ExitCode,&aInfo) == OProcess::E_None && aInfo.Code)
1170cdf0e10cSrcweir 		return aInfo.Code;
1171cdf0e10cSrcweir 
1172cdf0e10cSrcweir 	return 0;
1173cdf0e10cSrcweir }
1174cdf0e10cSrcweir // -----------------------------------------------------------------------------
1175cdf0e10cSrcweir void ODriver::XUTIL(const ::rtl::OUString& _rParam,
1176cdf0e10cSrcweir 		   const ::rtl::OUString& _DBNAME,
1177cdf0e10cSrcweir 		   const ::rtl::OUString& _USRNAME,
1178cdf0e10cSrcweir 		   const ::rtl::OUString& _USRPWD)
1179cdf0e10cSrcweir {
1180cdf0e10cSrcweir 	String sWorkUrl(m_sDbWorkURL);
1181cdf0e10cSrcweir 	String sExt = String::CreateFromAscii(".log");
1182cdf0e10cSrcweir 	::utl::TempFile aCmdFile(String::CreateFromAscii("xutil"),&sExt,&sWorkUrl);
1183cdf0e10cSrcweir 	aCmdFile.EnableKillingFile();
1184cdf0e10cSrcweir 
1185cdf0e10cSrcweir 	String sPhysicalPath;
1186cdf0e10cSrcweir 	LocalFileHelper::ConvertURLToPhysicalName(aCmdFile.GetURL(),sPhysicalPath);
1187cdf0e10cSrcweir 
1188cdf0e10cSrcweir 	String sCommandFile = generateInitFile();
1189cdf0e10cSrcweir 
1190cdf0e10cSrcweir 	{
1191cdf0e10cSrcweir 		::std::auto_ptr<SvStream> pFileStream( UcbStreamHelper::CreateStream(sCommandFile,STREAM_STD_READWRITE));
1192cdf0e10cSrcweir 		pFileStream->Seek(STREAM_SEEK_TO_END);
1193cdf0e10cSrcweir 		(*pFileStream)	<<
1194cdf0e10cSrcweir #if defined(WNT)
1195cdf0e10cSrcweir 							"xutil.exe"
1196cdf0e10cSrcweir #else
1197cdf0e10cSrcweir 							"utility"
1198cdf0e10cSrcweir #endif
1199cdf0e10cSrcweir 						<< " -u "
1200cdf0e10cSrcweir 						<< ::rtl::OString(_USRNAME,_USRNAME.getLength(),gsl_getSystemTextEncoding())
1201cdf0e10cSrcweir 						<< ","
1202cdf0e10cSrcweir 						<< ::rtl::OString(_USRPWD,_USRPWD.getLength(),gsl_getSystemTextEncoding())
1203cdf0e10cSrcweir 						<< " -d "
1204cdf0e10cSrcweir 						<< ::rtl::OString(_DBNAME,_DBNAME.getLength(),gsl_getSystemTextEncoding())
1205cdf0e10cSrcweir 						<< " "
1206cdf0e10cSrcweir 						<< ::rtl::OString(_rParam,_rParam.getLength(),gsl_getSystemTextEncoding())
1207cdf0e10cSrcweir 						<< " > "
1208cdf0e10cSrcweir 						<< ::rtl::OString(sPhysicalPath.GetBuffer(),sPhysicalPath.Len(),gsl_getSystemTextEncoding())
1209cdf0e10cSrcweir 						<< " 2>&1"
1210cdf0e10cSrcweir 						<< sNewLine;
1211cdf0e10cSrcweir 		pFileStream->Flush();
1212cdf0e10cSrcweir 	}
1213cdf0e10cSrcweir 
1214cdf0e10cSrcweir 	OProcess aApp(sCommandFile ,m_sDbWorkURL);
1215cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
1216cdf0e10cSrcweir 	OProcess::TProcessError eError =
1217cdf0e10cSrcweir #endif
1218cdf0e10cSrcweir         aApp.execute( (OProcess::TProcessOption)(OProcess::TOption_Hidden | OProcess::TOption_Wait));
1219cdf0e10cSrcweir     OSL_ENSURE( eError == OProcess::E_None, "ODriver::XUTIL: calling the executable failed!" );
1220cdf0e10cSrcweir #if OSL_DEBUG_LEVEL < 2
1221cdf0e10cSrcweir 	if(UCBContentHelper::Exists(sCommandFile))
1222cdf0e10cSrcweir 		UCBContentHelper::Kill(sCommandFile);
1223cdf0e10cSrcweir #endif
1224cdf0e10cSrcweir }
1225cdf0e10cSrcweir // -----------------------------------------------------------------------------
1226cdf0e10cSrcweir void ODriver::LoadBatch(const ::rtl::OUString& sDBName,
1227cdf0e10cSrcweir 			   const ::rtl::OUString& _rUSR,
1228cdf0e10cSrcweir 			   const ::rtl::OUString& _rPWD,
1229cdf0e10cSrcweir 			   const ::rtl::OUString& _rBatch)
1230cdf0e10cSrcweir {
1231cdf0e10cSrcweir 	OSL_ENSURE(_rBatch.getLength(),"No batch file given!");
1232cdf0e10cSrcweir 	String sWorkUrl(m_sDbWorkURL);
1233cdf0e10cSrcweir 	String sExt = String::CreateFromAscii(".log");
1234cdf0e10cSrcweir 	::utl::TempFile aCmdFile(String::CreateFromAscii("LoadBatch"),&sExt,&sWorkUrl);
1235cdf0e10cSrcweir #if OSL_DEBUG_LEVEL < 2
1236cdf0e10cSrcweir 	aCmdFile.EnableKillingFile();
1237cdf0e10cSrcweir #endif
1238cdf0e10cSrcweir 
1239cdf0e10cSrcweir 	String sPhysicalPath;
1240cdf0e10cSrcweir 	LocalFileHelper::ConvertURLToPhysicalName(aCmdFile.GetURL(),sPhysicalPath);
1241cdf0e10cSrcweir 
1242cdf0e10cSrcweir 	String sCommandFile = generateInitFile();
1243cdf0e10cSrcweir 	{
1244cdf0e10cSrcweir 		::std::auto_ptr<SvStream> pFileStream( UcbStreamHelper::CreateStream(sCommandFile,STREAM_STD_READWRITE));
1245cdf0e10cSrcweir 		pFileStream->Seek(STREAM_SEEK_TO_END);
1246cdf0e10cSrcweir 		(*pFileStream)	<< "xload"
1247cdf0e10cSrcweir #if defined(WNT)
1248cdf0e10cSrcweir 						<< ".exe"
1249cdf0e10cSrcweir #endif
1250cdf0e10cSrcweir 						<< " -d "
1251cdf0e10cSrcweir 						<< ::rtl::OString(sDBName,sDBName.getLength(),gsl_getSystemTextEncoding())
1252cdf0e10cSrcweir 						<< " -u "
1253cdf0e10cSrcweir 						<< ::rtl::OString(_rUSR,_rUSR.getLength(),gsl_getSystemTextEncoding())
1254cdf0e10cSrcweir 						<< ","
1255cdf0e10cSrcweir 						<< ::rtl::OString(_rPWD,_rPWD.getLength(),gsl_getSystemTextEncoding());
1256cdf0e10cSrcweir 
1257cdf0e10cSrcweir 		if ( !isKernelVersion(CURRENT_DB_VERSION) )
1258cdf0e10cSrcweir 			(*pFileStream) << " -S adabas -b ";
1259cdf0e10cSrcweir 		else
1260cdf0e10cSrcweir 			(*pFileStream) << " -S NATIVE -b ";
1261cdf0e10cSrcweir 
1262cdf0e10cSrcweir 		(*pFileStream)	<< ::rtl::OString(_rBatch,_rBatch.getLength(),gsl_getSystemTextEncoding())
1263cdf0e10cSrcweir 						<< " > "
1264cdf0e10cSrcweir 						<< ::rtl::OString(sPhysicalPath.GetBuffer(),sPhysicalPath.Len(),gsl_getSystemTextEncoding())
1265cdf0e10cSrcweir 						<< " 2>&1"
1266cdf0e10cSrcweir 						<< sNewLine;
1267cdf0e10cSrcweir 
1268cdf0e10cSrcweir 		pFileStream->Flush();
1269cdf0e10cSrcweir 	}
1270cdf0e10cSrcweir 
1271cdf0e10cSrcweir 	OProcess aApp(sCommandFile ,m_sDbWorkURL);
1272cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
1273cdf0e10cSrcweir 	OProcess::TProcessError eError =
1274cdf0e10cSrcweir #endif
1275cdf0e10cSrcweir         aApp.execute( (OProcess::TProcessOption)(OProcess::TOption_Hidden | OProcess::TOption_Wait));
1276cdf0e10cSrcweir     OSL_ENSURE( eError == OProcess::E_None, "ODriver::LoadBatch: calling the executable failed!" );
1277cdf0e10cSrcweir #if OSL_DEBUG_LEVEL < 2
1278cdf0e10cSrcweir 	if(UCBContentHelper::Exists(sCommandFile))
1279cdf0e10cSrcweir 		UCBContentHelper::Kill(sCommandFile);
1280cdf0e10cSrcweir #endif
1281cdf0e10cSrcweir }
1282cdf0e10cSrcweir // -----------------------------------------------------------------------------
1283cdf0e10cSrcweir void ODriver::fillEnvironmentVariables()
1284cdf0e10cSrcweir {
1285cdf0e10cSrcweir 	// read the environment vars
1286cdf0e10cSrcweir     struct env_data
1287cdf0e10cSrcweir     {
1288cdf0e10cSrcweir         const sal_Char*     pAsciiEnvName;
1289cdf0e10cSrcweir         ::rtl::OUString*    pValue;
1290cdf0e10cSrcweir         ::rtl::OUString*    pValueURL;
1291cdf0e10cSrcweir     } EnvData[] = {
1292cdf0e10cSrcweir         { "DBWORK",     &m_sDbWork,     &m_sDbWorkURL },
1293cdf0e10cSrcweir         { "DBCONFIG",   &m_sDbConfig,   &m_sDbConfigURL },
1294cdf0e10cSrcweir         { "DBROOT",     &m_sDbRoot,     &m_sDbRootURL }
1295cdf0e10cSrcweir     };
1296cdf0e10cSrcweir 
1297cdf0e10cSrcweir     for ( size_t i = 0; i < sizeof( EnvData ) / sizeof( EnvData[0] ); ++i )
1298cdf0e10cSrcweir     {
1299cdf0e10cSrcweir 	    ::rtl::OUString sVarName = ::rtl::OUString::createFromAscii( EnvData[i].pAsciiEnvName );
1300cdf0e10cSrcweir         ::rtl::OUString sEnvValue;
1301cdf0e10cSrcweir 	    if(osl_getEnvironment( sVarName.pData, &sEnvValue.pData ) == osl_Process_E_None )
1302cdf0e10cSrcweir 	    {
1303cdf0e10cSrcweir 		    *EnvData[i].pValue = sEnvValue;
1304cdf0e10cSrcweir 		    String sURL;
1305cdf0e10cSrcweir 		    LocalFileHelper::ConvertPhysicalNameToURL( *EnvData[i].pValue, sURL );
1306cdf0e10cSrcweir 		    *EnvData[i].pValueURL = sURL;
1307cdf0e10cSrcweir 	    }
1308cdf0e10cSrcweir     }
1309cdf0e10cSrcweir 
1310cdf0e10cSrcweir 	m_sDelimit =  ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/"));
1311cdf0e10cSrcweir }
1312cdf0e10cSrcweir // -----------------------------------------------------------------------------
1313cdf0e10cSrcweir ::rtl::OUString ODriver::generateInitFile() const
1314cdf0e10cSrcweir {
1315cdf0e10cSrcweir 	String sExt;
1316cdf0e10cSrcweir #if !defined(WNT)
1317cdf0e10cSrcweir 	sExt = String::CreateFromAscii(".sh");
1318cdf0e10cSrcweir #else
1319cdf0e10cSrcweir 	sExt = String::CreateFromAscii(".bat");
1320cdf0e10cSrcweir #endif
1321cdf0e10cSrcweir 
1322cdf0e10cSrcweir 	String sWorkUrl(m_sDbWorkURL);
1323cdf0e10cSrcweir 	::utl::TempFile aCmdFile(String::CreateFromAscii("Init"),&sExt,&sWorkUrl);
1324cdf0e10cSrcweir #if !defined(WNT)
1325cdf0e10cSrcweir 	String sPhysicalPath;
1326cdf0e10cSrcweir 	LocalFileHelper::ConvertURLToPhysicalName(aCmdFile.GetURL(),sPhysicalPath);
1327cdf0e10cSrcweir 	chmod(ByteString(sPhysicalPath,gsl_getSystemTextEncoding()).GetBuffer(),S_IRUSR|S_IWUSR|S_IXUSR);
1328cdf0e10cSrcweir #endif
1329cdf0e10cSrcweir 
1330cdf0e10cSrcweir #if !defined(WNT)
1331cdf0e10cSrcweir 	SvStream* pFileStream = aCmdFile.GetStream(STREAM_WRITE);
1332cdf0e10cSrcweir 	(*pFileStream)	<< "#!/bin/sh"
1333cdf0e10cSrcweir 					<< sNewLine
1334cdf0e10cSrcweir 					<< "cd \"$DBWORK\""
1335cdf0e10cSrcweir 					<< sNewLine
1336cdf0e10cSrcweir 					<< sNewLine;
1337cdf0e10cSrcweir 	pFileStream->Flush();
1338cdf0e10cSrcweir #endif
1339cdf0e10cSrcweir 
1340cdf0e10cSrcweir 	return aCmdFile.GetURL();
1341cdf0e10cSrcweir }
1342cdf0e10cSrcweir // -----------------------------------------------------------------------------
1343cdf0e10cSrcweir ::rtl::OUString ODriver::getDatabaseInitFile(  const TDatabaseStruct& _aDBInfo)
1344cdf0e10cSrcweir {
1345cdf0e10cSrcweir 	String sExt;
1346cdf0e10cSrcweir 	sExt.AssignAscii(".ins");
1347cdf0e10cSrcweir 
1348cdf0e10cSrcweir 
1349cdf0e10cSrcweir 	String sWorkUrl(m_sDbWorkURL);
1350cdf0e10cSrcweir 	::utl::TempFile aInitFile(String::CreateFromAscii("Init"),&sExt,&sWorkUrl);
1351cdf0e10cSrcweir 	{
1352cdf0e10cSrcweir 		SvStream* pFileStream = aInitFile.GetStream(STREAM_WRITE);
1353cdf0e10cSrcweir 		(*pFileStream) << "* @(#)init.cmd  6.1.1   1994-11-10\n";
1354cdf0e10cSrcweir 		(*pFileStream) << "init config\n";
1355cdf0e10cSrcweir 		(*pFileStream) << "* default code:\n";
1356cdf0e10cSrcweir 		(*pFileStream) << "ascii\n";
1357cdf0e10cSrcweir 		(*pFileStream) << "* date time format\n";
1358cdf0e10cSrcweir 		(*pFileStream) << "internal\n";
1359cdf0e10cSrcweir 		(*pFileStream) << "* command timeout:\n";
1360cdf0e10cSrcweir 		(*pFileStream) << "900\n";
1361cdf0e10cSrcweir 		(*pFileStream) << "* lock timeout:\n";
1362cdf0e10cSrcweir 		(*pFileStream) << "360\n";
1363cdf0e10cSrcweir 		(*pFileStream) << "* request timeout:\n";
1364cdf0e10cSrcweir 		(*pFileStream) << "180\n";
1365cdf0e10cSrcweir 		(*pFileStream) << "* log mode:\n";
1366cdf0e10cSrcweir 		(*pFileStream) << "demo\n";
1367cdf0e10cSrcweir 		(*pFileStream) << "* log segment size:\n";
1368cdf0e10cSrcweir 		(*pFileStream) << "0\n";
1369cdf0e10cSrcweir 		(*pFileStream) << "* no of archive logs:\n";
1370cdf0e10cSrcweir 		(*pFileStream) << "0\n";
1371cdf0e10cSrcweir 		(*pFileStream) << "* no of data devspaces:\n";
1372cdf0e10cSrcweir 		(*pFileStream) << "1\n";
1373cdf0e10cSrcweir 		(*pFileStream) << "* mirror devspaces:\n";
1374cdf0e10cSrcweir 		(*pFileStream) << "n\n";
1375cdf0e10cSrcweir 		(*pFileStream) << "if $rc <> 0 then stop\n";
1376cdf0e10cSrcweir 		(*pFileStream) << "*---  device description ---\n";
1377cdf0e10cSrcweir 		(*pFileStream) << "* sys devspace name:\n";
1378cdf0e10cSrcweir 		{
1379cdf0e10cSrcweir 			String sTemp;
1380cdf0e10cSrcweir 			LocalFileHelper::ConvertURLToPhysicalName(_aDBInfo.sSysDevSpace,sTemp);
1381cdf0e10cSrcweir 			(*pFileStream) << ::rtl::OString(sTemp.GetBuffer(),sTemp.Len(),gsl_getSystemTextEncoding());
1382cdf0e10cSrcweir 		}
1383cdf0e10cSrcweir 		(*pFileStream) << "\n* log devspace size:\n";
1384cdf0e10cSrcweir 		(*pFileStream) << ::rtl::OString::valueOf(_aDBInfo.nLogSize);
1385cdf0e10cSrcweir 		(*pFileStream) << "\n* log devspace name:\n";
1386cdf0e10cSrcweir 		{
1387cdf0e10cSrcweir 			String sTemp;
1388cdf0e10cSrcweir 			LocalFileHelper::ConvertURLToPhysicalName(_aDBInfo.sTransLogName,sTemp);
1389cdf0e10cSrcweir 			(*pFileStream) << ::rtl::OString(sTemp.GetBuffer(),sTemp.Len(),gsl_getSystemTextEncoding());
1390cdf0e10cSrcweir 		}
1391cdf0e10cSrcweir 		(*pFileStream) << "\n* data devspace size:\n";
1392cdf0e10cSrcweir 		(*pFileStream) << ::rtl::OString::valueOf(_aDBInfo.nDataSize);
1393cdf0e10cSrcweir 		(*pFileStream) << "\n* data devspace name:\n";
1394cdf0e10cSrcweir 		{
1395cdf0e10cSrcweir 			String sTemp;
1396cdf0e10cSrcweir 			LocalFileHelper::ConvertURLToPhysicalName(_aDBInfo.sDataDevName,sTemp);
1397cdf0e10cSrcweir 			(*pFileStream) << ::rtl::OString(sTemp.GetBuffer(),sTemp.Len(),gsl_getSystemTextEncoding());
1398cdf0e10cSrcweir 		}
1399cdf0e10cSrcweir 
1400cdf0e10cSrcweir 		(*pFileStream) << "\n* END INIT CONFIG\n";
1401cdf0e10cSrcweir 		(*pFileStream) << "if $rc <> 0 then stop\n";
1402cdf0e10cSrcweir 		if(_aDBInfo.bRestoreDatabase)
1403cdf0e10cSrcweir 		{
1404cdf0e10cSrcweir 			(*pFileStream) << "RESTORE DATA QUICK FROM '";
1405cdf0e10cSrcweir 			{
1406cdf0e10cSrcweir 				String sTemp;
1407cdf0e10cSrcweir 				LocalFileHelper::ConvertURLToPhysicalName(_aDBInfo.sBackupFile,sTemp);
1408cdf0e10cSrcweir 				(*pFileStream) << ::rtl::OString(sTemp.GetBuffer(),sTemp.Len(),gsl_getSystemTextEncoding());
1409cdf0e10cSrcweir 			}
1410cdf0e10cSrcweir 			(*pFileStream) << "' BLOCKSIZE 8\n";
1411cdf0e10cSrcweir 			(*pFileStream) << "if $rc <> 0 then stop\n";
1412cdf0e10cSrcweir 			(*pFileStream) << "RESTART\n";
1413cdf0e10cSrcweir 
1414cdf0e10cSrcweir 		}
1415cdf0e10cSrcweir 		else
1416cdf0e10cSrcweir 		{
1417cdf0e10cSrcweir 			(*pFileStream) << "ACTIVATE SERVERDB SYSDBA \"";
1418cdf0e10cSrcweir 			(*pFileStream) << ::rtl::OString(_aDBInfo.sSysUser,_aDBInfo.sSysUser.getLength(),gsl_getSystemTextEncoding());
1419cdf0e10cSrcweir 			(*pFileStream) << "\" PASSWORD \"";
1420cdf0e10cSrcweir 			(*pFileStream) << ::rtl::OString(_aDBInfo.sSysPassword,_aDBInfo.sSysPassword.getLength(),gsl_getSystemTextEncoding());
1421cdf0e10cSrcweir 			(*pFileStream) << "\"\n";
1422cdf0e10cSrcweir 		}
1423cdf0e10cSrcweir 		(*pFileStream) << "if $rc <> 0 then stop\n";
1424cdf0e10cSrcweir 		(*pFileStream) << "exit\n";
1425cdf0e10cSrcweir 	}
1426cdf0e10cSrcweir 	return aInitFile.GetURL();
1427cdf0e10cSrcweir }
1428cdf0e10cSrcweir // -----------------------------------------------------------------------------
1429cdf0e10cSrcweir void ODriver::X_CONS(const ::rtl::OUString& sDBName,const ::rtl::OString& _ACTION,const ::rtl::OUString& _FILENAME)
1430cdf0e10cSrcweir {
1431cdf0e10cSrcweir 	String sPhysicalPath;
1432cdf0e10cSrcweir 	LocalFileHelper::ConvertURLToPhysicalName(_FILENAME,sPhysicalPath);
1433cdf0e10cSrcweir 
1434cdf0e10cSrcweir 	String sCommandFile = generateInitFile();
1435cdf0e10cSrcweir 	{
1436cdf0e10cSrcweir 		::std::auto_ptr<SvStream> pFileStream( UcbStreamHelper::CreateStream(sCommandFile,STREAM_STD_READWRITE));
1437cdf0e10cSrcweir 		pFileStream->Seek(STREAM_SEEK_TO_END);
1438cdf0e10cSrcweir 
1439cdf0e10cSrcweir 		(*pFileStream)	<< "x_cons"
1440cdf0e10cSrcweir #if defined(WNT)
1441cdf0e10cSrcweir 						<< ".exe"
1442cdf0e10cSrcweir #endif
1443cdf0e10cSrcweir 						<< " "
1444cdf0e10cSrcweir 						<< ::rtl::OString(sDBName,sDBName.getLength(),gsl_getSystemTextEncoding())
1445cdf0e10cSrcweir 						<< " SHOW "
1446cdf0e10cSrcweir 						<< _ACTION
1447cdf0e10cSrcweir 						<< " > "
1448cdf0e10cSrcweir 						<< ::rtl::OString(sPhysicalPath.GetBuffer(),sPhysicalPath.Len(),gsl_getSystemTextEncoding())
1449cdf0e10cSrcweir 						<< sNewLine;
1450cdf0e10cSrcweir 		pFileStream->Flush();
1451cdf0e10cSrcweir 	}
1452cdf0e10cSrcweir 
1453cdf0e10cSrcweir 	OProcess aApp(sCommandFile ,m_sDbWorkURL);
1454cdf0e10cSrcweir 	aApp.execute( (OProcess::TProcessOption)(OProcess::TOption_Hidden | OProcess::TOption_Wait));
1455cdf0e10cSrcweir #if OSL_DEBUG_LEVEL < 2
1456cdf0e10cSrcweir 	if(UCBContentHelper::Exists(sCommandFile))
1457cdf0e10cSrcweir 		UCBContentHelper::Kill(sCommandFile);
1458cdf0e10cSrcweir #endif
1459cdf0e10cSrcweir }
1460cdf0e10cSrcweir // -----------------------------------------------------------------------------
1461cdf0e10cSrcweir void ODriver::checkAndRestart(const ::rtl::OUString& sDBName,const TDatabaseStruct& _rDbInfo)
1462cdf0e10cSrcweir {
1463cdf0e10cSrcweir 	String sWorkUrl(m_sDbWorkURL);
1464cdf0e10cSrcweir 	String sExt = String::CreateFromAscii(".st");
1465cdf0e10cSrcweir 	::utl::TempFile aCmdFile(String::CreateFromAscii("State"),&sExt,&sWorkUrl);
1466cdf0e10cSrcweir 	aCmdFile.EnableKillingFile();
1467cdf0e10cSrcweir 
1468cdf0e10cSrcweir 	X_CONS(sDBName,"STATE",aCmdFile.GetURL());
1469cdf0e10cSrcweir 	SvStream* pFileStream = aCmdFile.GetStream(STREAM_SHARE_DENYALL);
1470cdf0e10cSrcweir 	if ( pFileStream )
1471cdf0e10cSrcweir 	{
1472cdf0e10cSrcweir 		ByteString sStateLine;
1473cdf0e10cSrcweir 		sal_Bool bRead = sal_True;
1474cdf0e10cSrcweir 		sal_Int32 nStart = 2;
1475cdf0e10cSrcweir 		while(bRead && !pFileStream->IsEof())
1476cdf0e10cSrcweir 		{
1477cdf0e10cSrcweir 			String aLine;
1478cdf0e10cSrcweir 			bRead = pFileStream->ReadLine(sStateLine);
1479cdf0e10cSrcweir 			if(bRead)
1480cdf0e10cSrcweir 			{
1481cdf0e10cSrcweir 				if(sStateLine.Search("WARM") != STRING_NOTFOUND)
1482cdf0e10cSrcweir 				{	// nothing to do
1483cdf0e10cSrcweir 					nStart = 0;
1484cdf0e10cSrcweir 					break;
1485cdf0e10cSrcweir 				}
1486cdf0e10cSrcweir 				else if(sStateLine.Search("COLD") != STRING_NOTFOUND)
1487cdf0e10cSrcweir 				{
1488cdf0e10cSrcweir 					nStart = 1;
1489cdf0e10cSrcweir 					break;
1490cdf0e10cSrcweir 				}
1491cdf0e10cSrcweir 			}
1492cdf0e10cSrcweir 		}
1493cdf0e10cSrcweir 		switch(nStart)
1494cdf0e10cSrcweir 		{
1495cdf0e10cSrcweir 			case 2:
1496cdf0e10cSrcweir                 clearDatabase(sDBName);
1497cdf0e10cSrcweir 				X_START(sDBName);
1498cdf0e10cSrcweir 				// don't break here
1499cdf0e10cSrcweir 			case 1:
1500cdf0e10cSrcweir 				XUTIL(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("RESTART")),sDBName,_rDbInfo.sControlUser,_rDbInfo.sControlPassword);
1501cdf0e10cSrcweir 			case 0:
1502cdf0e10cSrcweir 				break;
1503cdf0e10cSrcweir 		}
1504cdf0e10cSrcweir 	}
1505cdf0e10cSrcweir }
1506cdf0e10cSrcweir // -----------------------------------------------------------------------------
1507cdf0e10cSrcweir sal_Bool ODriver::isVersion(const ::rtl::OUString& sDBName, const char* _pVersion)
1508cdf0e10cSrcweir {
1509cdf0e10cSrcweir 	String sWorkUrl(m_sDbWorkURL);
1510cdf0e10cSrcweir 	String sExt = String::CreateFromAscii(".st");
1511cdf0e10cSrcweir 	::utl::TempFile aCmdFile(String::CreateFromAscii("DevSpaces"),&sExt,&sWorkUrl);
1512cdf0e10cSrcweir 	aCmdFile.EnableKillingFile();
1513cdf0e10cSrcweir 
1514cdf0e10cSrcweir 	String sPhysicalPath;
1515cdf0e10cSrcweir 	LocalFileHelper::ConvertURLToPhysicalName(aCmdFile.GetURL(),sPhysicalPath);
1516cdf0e10cSrcweir 
1517cdf0e10cSrcweir 	String sCommandFile = generateInitFile();
1518cdf0e10cSrcweir 	{
1519cdf0e10cSrcweir 		::std::auto_ptr<SvStream> pFileStream( UcbStreamHelper::CreateStream(sCommandFile,STREAM_STD_READWRITE));
1520cdf0e10cSrcweir 		pFileStream->Seek(STREAM_SEEK_TO_END);
1521cdf0e10cSrcweir 
1522cdf0e10cSrcweir 		(*pFileStream)	<< "getparam"
1523cdf0e10cSrcweir #if defined(WNT)
1524cdf0e10cSrcweir 						<< ".exe"
1525cdf0e10cSrcweir #endif
1526cdf0e10cSrcweir 						<< " "
1527cdf0e10cSrcweir 						<< ::rtl::OString(sDBName,sDBName.getLength(),gsl_getSystemTextEncoding())
1528cdf0e10cSrcweir 						<< " KERNELVERSION > "
1529cdf0e10cSrcweir 						<< ::rtl::OString(sPhysicalPath.GetBuffer(),sPhysicalPath.Len(),gsl_getSystemTextEncoding())
1530cdf0e10cSrcweir 						<< sNewLine;
1531cdf0e10cSrcweir 	}
1532cdf0e10cSrcweir 
1533cdf0e10cSrcweir 	OProcess aApp(sCommandFile ,m_sDbWorkURL);
1534cdf0e10cSrcweir 	aApp.execute( (OProcess::TProcessOption)OPROCESS_ADABAS);
1535cdf0e10cSrcweir #if OSL_DEBUG_LEVEL < 2
1536cdf0e10cSrcweir 	if(UCBContentHelper::Exists(sCommandFile))
1537cdf0e10cSrcweir 		UCBContentHelper::Kill(sCommandFile);
1538cdf0e10cSrcweir #endif
1539cdf0e10cSrcweir 	SvStream* pFileStream = aCmdFile.GetStream(STREAM_STD_READWRITE);
1540cdf0e10cSrcweir 	ByteString sStateLine;
1541cdf0e10cSrcweir 	sal_Bool bRead = sal_True;
1542cdf0e10cSrcweir 	sal_Bool bIsVersion = sal_False;
1543cdf0e10cSrcweir 	while ( pFileStream && bRead && !pFileStream->IsEof() )
1544cdf0e10cSrcweir 	{
1545cdf0e10cSrcweir 		bRead = pFileStream->ReadLine(sStateLine);
1546cdf0e10cSrcweir 		if ( bRead )
1547cdf0e10cSrcweir 		{
1548cdf0e10cSrcweir 			bIsVersion = sStateLine.GetToken(1,' ').Equals(_pVersion) != 0;
1549cdf0e10cSrcweir 			break;
1550cdf0e10cSrcweir 		}
1551cdf0e10cSrcweir 	}
1552cdf0e10cSrcweir 	return bIsVersion;
1553cdf0e10cSrcweir }
1554cdf0e10cSrcweir // -----------------------------------------------------------------------------
1555cdf0e10cSrcweir void ODriver::checkAndInsertNewDevSpace(const ::rtl::OUString& sDBName,
1556cdf0e10cSrcweir 										const TDatabaseStruct& _rDBInfo)
1557cdf0e10cSrcweir {
1558cdf0e10cSrcweir 	//	%DBROOT%\pgm\getparam %2 DATA_CACHE_PAGES > %3
1559cdf0e10cSrcweir 	String sWorkUrl(m_sDbWorkURL);
1560cdf0e10cSrcweir 	String sExt = String::CreateFromAscii(".st");
1561cdf0e10cSrcweir 	::utl::TempFile aCmdFile(String::CreateFromAscii("DevSpaces"),&sExt,&sWorkUrl);
1562cdf0e10cSrcweir 	aCmdFile.EnableKillingFile();
1563cdf0e10cSrcweir 
1564cdf0e10cSrcweir 	String sPhysicalPath;
1565cdf0e10cSrcweir 	LocalFileHelper::ConvertURLToPhysicalName(aCmdFile.GetURL(),sPhysicalPath);
1566cdf0e10cSrcweir 
1567cdf0e10cSrcweir 	String sCommandFile = generateInitFile();
1568cdf0e10cSrcweir 	{
1569cdf0e10cSrcweir 		::std::auto_ptr<SvStream> pFileStream( UcbStreamHelper::CreateStream(sCommandFile,STREAM_STD_READWRITE));
1570cdf0e10cSrcweir 		pFileStream->Seek(STREAM_SEEK_TO_END);
1571cdf0e10cSrcweir 
1572cdf0e10cSrcweir 		(*pFileStream)	<< "getparam"
1573cdf0e10cSrcweir #if defined(WNT)
1574cdf0e10cSrcweir 						<< ".exe"
1575cdf0e10cSrcweir #endif
1576cdf0e10cSrcweir 						<< " "
1577cdf0e10cSrcweir 						<< ::rtl::OString(sDBName,sDBName.getLength(),gsl_getSystemTextEncoding())
1578cdf0e10cSrcweir 						<< " DATA_CACHE_PAGES > "
1579cdf0e10cSrcweir 						<< ::rtl::OString(sPhysicalPath.GetBuffer(),sPhysicalPath.Len(),gsl_getSystemTextEncoding())
1580cdf0e10cSrcweir 						<< sNewLine;
1581cdf0e10cSrcweir 	}
1582cdf0e10cSrcweir 
1583cdf0e10cSrcweir 	OProcess aApp(sCommandFile ,m_sDbWorkURL);
1584cdf0e10cSrcweir 	aApp.execute( (OProcess::TProcessOption)OPROCESS_ADABAS);
1585cdf0e10cSrcweir #if OSL_DEBUG_LEVEL < 2
1586cdf0e10cSrcweir 	if(UCBContentHelper::Exists(sCommandFile))
1587cdf0e10cSrcweir 		UCBContentHelper::Kill(sCommandFile);
1588cdf0e10cSrcweir #endif
1589cdf0e10cSrcweir 	SvStream* pFileStream = aCmdFile.GetStream(STREAM_STD_READWRITE);
1590cdf0e10cSrcweir 	ByteString sStateLine;
1591cdf0e10cSrcweir 	sal_Bool bRead = sal_True;
1592cdf0e10cSrcweir 	sal_Int32 nDataPages = 0;
1593cdf0e10cSrcweir 	while(pFileStream && bRead && !pFileStream->IsEof())
1594cdf0e10cSrcweir 	{
1595cdf0e10cSrcweir 		bRead = pFileStream->ReadLine(sStateLine);
1596cdf0e10cSrcweir 		if(bRead)
1597cdf0e10cSrcweir 		{
1598cdf0e10cSrcweir 			nDataPages = sStateLine.ToInt32();
1599cdf0e10cSrcweir 			if(nDataPages && nDataPages < 100)
1600cdf0e10cSrcweir 			{
1601cdf0e10cSrcweir 				// the space isn't big enough anymore so we increment it
1602cdf0e10cSrcweir 				PutParam(sDBName,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DATA_CACHE_PAGES")),::rtl::OUString::valueOf(nDataPages));
1603cdf0e10cSrcweir 				X_PARAM(sDBName,_rDBInfo.sControlUser,_rDBInfo.sControlPassword,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("BCHECK")));
1604cdf0e10cSrcweir 			}
1605cdf0e10cSrcweir 		}
1606cdf0e10cSrcweir 	}
1607cdf0e10cSrcweir }
1608cdf0e10cSrcweir // -----------------------------------------------------------------------------
1609cdf0e10cSrcweir sal_Bool ODriver::isKernelVersion(const char* _pVersion)
1610cdf0e10cSrcweir {
1611cdf0e10cSrcweir 	::utl::TempFile aCmdFile(String::CreateFromAscii("KernelVersion"));
1612cdf0e10cSrcweir 	aCmdFile.EnableKillingFile();
1613cdf0e10cSrcweir 
1614cdf0e10cSrcweir 	String sPhysicalPath;
1615cdf0e10cSrcweir 	LocalFileHelper::ConvertURLToPhysicalName(aCmdFile.GetURL(),sPhysicalPath);
1616cdf0e10cSrcweir 
1617cdf0e10cSrcweir 	String sCommandFile = generateInitFile();
1618cdf0e10cSrcweir 	{
1619cdf0e10cSrcweir 		::std::auto_ptr<SvStream> pFileStream( UcbStreamHelper::CreateStream(sCommandFile,STREAM_STD_READWRITE));
1620cdf0e10cSrcweir 		pFileStream->Seek(STREAM_SEEK_TO_END);
1621cdf0e10cSrcweir 
1622cdf0e10cSrcweir 		(*pFileStream)	<< "dbversion"
1623cdf0e10cSrcweir 						<< " > "
1624cdf0e10cSrcweir 						<< ::rtl::OString(sPhysicalPath.GetBuffer(),sPhysicalPath.Len(),gsl_getSystemTextEncoding())
1625cdf0e10cSrcweir 						<< sNewLine;
1626cdf0e10cSrcweir 	}
1627cdf0e10cSrcweir 
1628cdf0e10cSrcweir 	OProcess aApp(sCommandFile ,m_sDbWorkURL);
1629cdf0e10cSrcweir 	aApp.execute( (OProcess::TProcessOption)OPROCESS_ADABAS);
1630cdf0e10cSrcweir #if OSL_DEBUG_LEVEL < 2
1631cdf0e10cSrcweir 	if(UCBContentHelper::Exists(sCommandFile))
1632cdf0e10cSrcweir 		UCBContentHelper::Kill(sCommandFile);
1633cdf0e10cSrcweir #endif
1634cdf0e10cSrcweir 	SvStream* pFileStream = aCmdFile.GetStream(STREAM_STD_READWRITE);
1635cdf0e10cSrcweir 	ByteString sStateLine;
1636cdf0e10cSrcweir 	sal_Bool bRead = sal_True;
1637cdf0e10cSrcweir 	sal_Bool bIsVersion = sal_True;
1638cdf0e10cSrcweir 	while ( pFileStream && bRead && !pFileStream->IsEof() )
1639cdf0e10cSrcweir 	{
1640cdf0e10cSrcweir 		bRead = pFileStream->ReadLine(sStateLine);
1641cdf0e10cSrcweir 		if ( bRead )
1642cdf0e10cSrcweir 		{
1643cdf0e10cSrcweir 			// convert a 11.02.00 to a 12.01.30 version
1644cdf0e10cSrcweir 			bIsVersion = sStateLine.GetToken(0).Equals(_pVersion) != 0;
1645cdf0e10cSrcweir 			break;
1646cdf0e10cSrcweir 		}
1647cdf0e10cSrcweir 	}
1648cdf0e10cSrcweir 	return bIsVersion;
1649cdf0e10cSrcweir }
1650cdf0e10cSrcweir // -----------------------------------------------------------------------------
1651cdf0e10cSrcweir void ODriver::installSystemTables(	const TDatabaseStruct& _aInfo)
1652cdf0e10cSrcweir {
1653cdf0e10cSrcweir #if defined(WNT)
1654cdf0e10cSrcweir 	//	xutil -d %_DBNAME% -u %_CONTROL_USER%,%_CONTROL_PWD% -b %m_sDbRoot%\env\TERMCHAR.ind
1655cdf0e10cSrcweir 	::rtl::OUString aBatch =  ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("-b "));
1656cdf0e10cSrcweir 	::rtl::OUString sTemp2 = m_sDbRootURL	+ m_sDelimit
1657cdf0e10cSrcweir 											+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("env"))
1658cdf0e10cSrcweir 											+ m_sDelimit
1659cdf0e10cSrcweir 											+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TERMCHAR.ind"));
1660cdf0e10cSrcweir 	String sTemp;
1661cdf0e10cSrcweir 	sal_Bool bOk = LocalFileHelper::ConvertURLToPhysicalName(sTemp2,sTemp);
1662cdf0e10cSrcweir 	aBatch += sTemp;
1663cdf0e10cSrcweir 
1664cdf0e10cSrcweir 	XUTIL(aBatch,_aInfo.sDBName,_aInfo.sControlUser,_aInfo.sControlPassword);
1665cdf0e10cSrcweir 
1666cdf0e10cSrcweir 	//	xutil -d %_DBNAME% -u %_CONTROL_USER%,%_CONTROL_PWD% DIAGNOSE TRIGGER OFF
1667cdf0e10cSrcweir 	XUTIL(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DIAGNOSE TRIGGER OFF")),_aInfo.sDBName,_aInfo.sControlUser,_aInfo.sControlPassword);
1668cdf0e10cSrcweir 	//	xload -d %_DBNAME% -u %_SYSDBA_USER%,%_SYSDBA_PWD% -S NATIVE -b %m_sDbRoot%\env\DBS.ins %_DOMAINPWD%
1669cdf0e10cSrcweir 	{
1670cdf0e10cSrcweir 		sTemp2 = m_sDbRootURL
1671cdf0e10cSrcweir 								+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("env"))
1672cdf0e10cSrcweir 								+ m_sDelimit
1673cdf0e10cSrcweir 								+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DBS.ins"));
1674cdf0e10cSrcweir 		sTemp.Erase();
1675cdf0e10cSrcweir 		bOk = LocalFileHelper::ConvertURLToPhysicalName(sTemp2,sTemp);
1676cdf0e10cSrcweir 		OSL_ENSURE(bOk,"File could be converted into file system path!");
1677cdf0e10cSrcweir 		sTemp.AppendAscii(" ");
1678cdf0e10cSrcweir 		sTemp += String(_aInfo.sDomainPassword);
1679cdf0e10cSrcweir 
1680cdf0e10cSrcweir 		LoadBatch(_aInfo.sDBName,_aInfo.sSysUser,_aInfo.sSysPassword,sTemp);
1681cdf0e10cSrcweir 	}
1682cdf0e10cSrcweir 	//	xload -d %_DBNAME% -u DOMAIN,%_DOMAINPWD% -S NATIVE -b %m_sDbRoot%\env\XDD.ins
1683cdf0e10cSrcweir 	{
1684cdf0e10cSrcweir 		sTemp2 = m_sDbRootURL
1685cdf0e10cSrcweir 								+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("env"))
1686cdf0e10cSrcweir 								+ m_sDelimit
1687cdf0e10cSrcweir 								+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("XDD.ins"));
1688cdf0e10cSrcweir 		sTemp.Erase();
1689cdf0e10cSrcweir 		bOk = LocalFileHelper::ConvertURLToPhysicalName(sTemp2,sTemp);
1690cdf0e10cSrcweir 		OSL_ENSURE(bOk,"File could be converted into file system path!");
1691cdf0e10cSrcweir 
1692cdf0e10cSrcweir 		LoadBatch(_aInfo.sDBName,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DOMAIN")),_aInfo.sDomainPassword,sTemp);
1693cdf0e10cSrcweir 	}
1694cdf0e10cSrcweir 	//	xload -d %_DBNAME% -u %_SYSDBA_USER%,%_SYSDBA_PWD% -S NATIVE -b %m_sDbRoot%\env\QP.ins
1695cdf0e10cSrcweir 	{
1696cdf0e10cSrcweir 		sTemp2 = m_sDbRootURL
1697cdf0e10cSrcweir 								+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("env"))
1698cdf0e10cSrcweir 								+ m_sDelimit
1699cdf0e10cSrcweir 								+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("QP.ins"));
1700cdf0e10cSrcweir 		sTemp.Erase();
1701cdf0e10cSrcweir 		bOk = LocalFileHelper::ConvertURLToPhysicalName(sTemp2,sTemp);
1702cdf0e10cSrcweir 		OSL_ENSURE(bOk,"File could be converted into file system path!");
1703cdf0e10cSrcweir 		LoadBatch(_aInfo.sDBName,_aInfo.sSysUser,_aInfo.sSysPassword,sTemp);
1704cdf0e10cSrcweir 	}
1705cdf0e10cSrcweir 	//	xload  -d %_DBNAME% -u DOMAIN,%_DOMAINPWD% -S NATIVE -b %m_sDbRoot%\env\SPROC.ins
1706cdf0e10cSrcweir 	{
1707cdf0e10cSrcweir 		sTemp2 = m_sDbRootURL
1708cdf0e10cSrcweir 								+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("env"))
1709cdf0e10cSrcweir 								+ m_sDelimit
1710cdf0e10cSrcweir 								+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SPROC.ins"));
1711cdf0e10cSrcweir 		sTemp.Erase();
1712cdf0e10cSrcweir 		bOk = LocalFileHelper::ConvertURLToPhysicalName(sTemp2,sTemp);
1713cdf0e10cSrcweir 		OSL_ENSURE(bOk,"File could be converted into file system path!");
1714cdf0e10cSrcweir 
1715cdf0e10cSrcweir 		LoadBatch(_aInfo.sDBName,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DOMAIN")),_aInfo.sDomainPassword,sTemp);
1716cdf0e10cSrcweir 	}
1717cdf0e10cSrcweir 
1718cdf0e10cSrcweir 	//	xutil -d %_DBNAME% -u %_CONTROL_USER%,%_CONTROL_PWD%  DIAGNOSE TRIGGER ON
1719cdf0e10cSrcweir 	XUTIL(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DIAGNOSE TRIGGER ON")),_aInfo.sDBName,_aInfo.sControlUser,_aInfo.sControlPassword);
1720cdf0e10cSrcweir 	//	xutil -d %_DBNAME% -u %_CONTROL_USER%,%_CONTROL_PWD%  SET NOLOG OFF
1721cdf0e10cSrcweir 	XUTIL(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SET NOLOG OFF")),_aInfo.sDBName,_aInfo.sControlUser,_aInfo.sControlPassword);
1722cdf0e10cSrcweir 	//	xutil -d %_DBNAME% -u %_CONTROL_USER%,%_CONTROL_PWD%  SHUTDOWN QUICK
1723cdf0e10cSrcweir 	XUTIL(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SHUTDOWN QUICK")),_aInfo.sDBName,_aInfo.sControlUser,_aInfo.sControlPassword);
1724cdf0e10cSrcweir 	//	xutil -d %_DBNAME% -u %_CONTROL_USER%,%_CONTROL_PWD%  RESTART
1725cdf0e10cSrcweir 	XUTIL(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("RESTART")),_aInfo.sDBName,_aInfo.sControlUser,_aInfo.sControlPassword);
1726cdf0e10cSrcweir 
1727cdf0e10cSrcweir #else // UNX
1728cdf0e10cSrcweir 	String sCommandFile = generateInitFile();
1729cdf0e10cSrcweir 	{
1730cdf0e10cSrcweir 		::std::auto_ptr<SvStream> pFileStream( UcbStreamHelper::CreateStream(sCommandFile,STREAM_STD_READWRITE));
1731cdf0e10cSrcweir 		pFileStream->Seek(STREAM_SEEK_TO_END);
1732cdf0e10cSrcweir 		(*pFileStream)	<< "x_dbinst"
1733cdf0e10cSrcweir 						<< " -d "
1734cdf0e10cSrcweir 						<< ::rtl::OString(_aInfo.sDBName,_aInfo.sDBName.getLength(),gsl_getSystemTextEncoding())
1735cdf0e10cSrcweir 						<< " -u "
1736cdf0e10cSrcweir 						<< ::rtl::OString(_aInfo.sSysUser,_aInfo.sSysUser.getLength(),gsl_getSystemTextEncoding())
1737cdf0e10cSrcweir 						<< ","
1738cdf0e10cSrcweir 						<< ::rtl::OString(_aInfo.sSysPassword,_aInfo.sSysPassword.getLength(),gsl_getSystemTextEncoding())
1739cdf0e10cSrcweir 						<< " -w "
1740cdf0e10cSrcweir 						<< ::rtl::OString(_aInfo.sDomainPassword,_aInfo.sDomainPassword.getLength(),gsl_getSystemTextEncoding())
1741cdf0e10cSrcweir 						<< " -b ";
1742cdf0e10cSrcweir 
1743cdf0e10cSrcweir 		if ( isKernelVersion(ADABAS_KERNEL_11) )
1744cdf0e10cSrcweir 			(*pFileStream) << "-i all";
1745cdf0e10cSrcweir 		(*pFileStream)
1746cdf0e10cSrcweir #if (OSL_DEBUG_LEVEL > 1) || defined(DBG_UTIL)
1747cdf0e10cSrcweir 					<< " >> /tmp/kstart.log"
1748cdf0e10cSrcweir #else
1749cdf0e10cSrcweir 					<< " > /dev/null"
1750cdf0e10cSrcweir #endif
1751cdf0e10cSrcweir 						<< sNewLine
1752cdf0e10cSrcweir 						<< sNewLine;
1753cdf0e10cSrcweir 		pFileStream->Flush();
1754cdf0e10cSrcweir 	}
1755cdf0e10cSrcweir 	// now execute the command
1756cdf0e10cSrcweir 	OProcess aApp(sCommandFile ,m_sDbWorkURL);
1757cdf0e10cSrcweir 	aApp.execute( (OProcess::TProcessOption)(OProcess::TOption_Hidden | OProcess::TOption_Wait));
1758cdf0e10cSrcweir #if OSL_DEBUG_LEVEL < 2
1759cdf0e10cSrcweir 	if(UCBContentHelper::Exists(sCommandFile))
1760cdf0e10cSrcweir 		UCBContentHelper::Kill(sCommandFile);
1761cdf0e10cSrcweir #endif
1762cdf0e10cSrcweir 
1763cdf0e10cSrcweir #endif //WNT,UNX
1764cdf0e10cSrcweir }
1765cdf0e10cSrcweir // -----------------------------------------------------------------------------
1766cdf0e10cSrcweir void ODriver::convertOldVersion(const ::rtl::OUString& sDBName,const TDatabaseStruct& _rDbInfo)
1767cdf0e10cSrcweir {
1768cdf0e10cSrcweir 	// first we have to check if this databse is a old version and we have to update the system tables
1769cdf0e10cSrcweir 	if ( !isVersion(sDBName,CURRENT_DB_VERSION) && isKernelVersion(CURRENT_DB_VERSION) )
1770cdf0e10cSrcweir 	{
1771cdf0e10cSrcweir 		if (	!_rDbInfo.sControlUser.getLength()
1772cdf0e10cSrcweir 			||	!_rDbInfo.sControlPassword.getLength())
1773cdf0e10cSrcweir 		{
1774cdf0e10cSrcweir             ::connectivity::SharedResources aResources;
1775cdf0e10cSrcweir             const ::rtl::OUString sError( aResources.getResourceString(STR_DATABASE_NEEDS_CONVERTING) );
1776cdf0e10cSrcweir             ::dbtools::throwGenericSQLException(sError,*this);
1777cdf0e10cSrcweir 		}
1778cdf0e10cSrcweir 		String sCommandFile = m_sDbWorkURL;
1779cdf0e10cSrcweir 		sCommandFile += String::CreateFromAscii("/xparam.prt");
1780cdf0e10cSrcweir 		if ( UCBContentHelper::Exists(sCommandFile) )
1781cdf0e10cSrcweir 			UCBContentHelper::Kill(sCommandFile);
1782cdf0e10cSrcweir 		X_PARAM(sDBName,_rDbInfo.sControlUser,_rDbInfo.sControlPassword,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("BCHECK")));
1783cdf0e10cSrcweir 
1784cdf0e10cSrcweir 		if ( UCBContentHelper::Exists(sCommandFile) )
1785cdf0e10cSrcweir 		{
1786cdf0e10cSrcweir 			{
1787cdf0e10cSrcweir 				::std::auto_ptr<SvStream> pFileStream( UcbStreamHelper::CreateStream(sCommandFile,STREAM_STD_READ) );
1788cdf0e10cSrcweir 				ByteString sStateLine;
1789cdf0e10cSrcweir 				sal_Bool bRead = sal_True;
1790cdf0e10cSrcweir 				static ByteString s_ErrorId("-21100");
1791cdf0e10cSrcweir 				while ( pFileStream.get() && bRead && !pFileStream->IsEof() )
1792cdf0e10cSrcweir 				{
1793cdf0e10cSrcweir 					bRead = pFileStream->ReadLine(sStateLine);
1794cdf0e10cSrcweir 					if ( bRead && s_ErrorId == sStateLine.GetToken(0,' ') )
1795cdf0e10cSrcweir 					{
1796cdf0e10cSrcweir 						UCBContentHelper::Kill(sCommandFile);
1797cdf0e10cSrcweir 						::rtl::OUString sError(::rtl::OUString::createFromAscii(sStateLine.GetBuffer()));
1798cdf0e10cSrcweir 						throw SQLException(sError,*this,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("S1000")),1000,Any());
1799cdf0e10cSrcweir 					}
1800cdf0e10cSrcweir 				}
1801cdf0e10cSrcweir 			}
1802cdf0e10cSrcweir 
1803cdf0e10cSrcweir 			UCBContentHelper::Kill(sCommandFile);
1804cdf0e10cSrcweir 		}
1805cdf0e10cSrcweir 	}
1806cdf0e10cSrcweir }
1807cdf0e10cSrcweir // -----------------------------------------------------------------------------
1808cdf0e10cSrcweir // -----------------------------------------------------------------------------
1809cdf0e10cSrcweir 	} // namespace adabas
1810cdf0e10cSrcweir }// namespace connectivity
1811cdf0e10cSrcweir // -----------------------------------------------------------------------------
1812cdf0e10cSrcweir 
1813cdf0e10cSrcweir 
1814cdf0e10cSrcweir 
1815cdf0e10cSrcweir 
1816