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