update dev300-m58
[ooovba.git] / connectivity / source / drivers / adabas / BDriver.cxx
blobbcdd09cb7efa19dfcfd92be051a401ffbd64e090
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: BDriver.cxx,v $
10 * $Revision: 1.24.56.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_connectivity.hxx"
33 #include <unotools/tempfile.hxx>
34 #include "adabas/BDriver.hxx"
35 #include "adabas/BConnection.hxx"
36 #include "odbc/OFunctions.hxx"
37 #include <com/sun/star/lang/DisposedException.hpp>
38 #include "odbc/OTools.hxx"
39 #include "connectivity/dbexception.hxx"
40 #include "TConnection.hxx"
41 #include "diagnose_ex.h"
42 #include <vos/process.hxx>
43 #include <osl/process.h>
44 #include <unotools/ucbhelper.hxx>
45 #include <unotools/ucbstreamhelper.hxx>
46 #include <unotools/localfilehelper.hxx>
47 #include "resource/adabas_res.hrc"
48 #include "resource/sharedresources.hxx"
51 #include <memory>
52 #include <sys/stat.h>
54 #if defined(MAC)
55 const char sNewLine = '\015';
56 #elif defined(UNX)
57 const char sNewLine = '\012';
58 #else
59 const char sNewLine[] = "\015\012"; // \015\012 and not \n
60 #endif
61 #define ADABAS_DB_11 "11.02.00"
62 #define ADABAS_KERNEL_11 "11.02"
63 #define ADABAS_DB_12 "12.01.00"
64 #define ADABAS_KERNEL_12 "12.01"
65 #define CURRENT_DB_VERSION "13.01.00"
66 #define CURRENT_KERNEL_VERSION "13.01"
68 #define OPROCESS_ADABAS (OProcess::TOption_Hidden | OProcess::TOption_Wait | OProcess::TOption_SearchPath)
69 #define OPROCESS_ADABAS_DBG (OProcess::TOption_Wait | OProcess::TOption_SearchPath)
72 using namespace connectivity;
73 namespace connectivity
75 namespace adabas
77 // extern declaration of the function pointer
78 extern T3SQLAllocHandle pODBC3SQLAllocHandle;
79 extern T3SQLConnect pODBC3SQLConnect;
80 extern T3SQLDriverConnect pODBC3SQLDriverConnect;
81 extern T3SQLBrowseConnect pODBC3SQLBrowseConnect;
82 extern T3SQLDataSources pODBC3SQLDataSources;
83 extern T3SQLDrivers pODBC3SQLDrivers;
84 extern T3SQLGetInfo pODBC3SQLGetInfo;
85 extern T3SQLGetFunctions pODBC3SQLGetFunctions;
86 extern T3SQLGetTypeInfo pODBC3SQLGetTypeInfo;
87 extern T3SQLSetConnectAttr pODBC3SQLSetConnectAttr;
88 extern T3SQLGetConnectAttr pODBC3SQLGetConnectAttr;
89 extern T3SQLSetEnvAttr pODBC3SQLSetEnvAttr;
90 extern T3SQLGetEnvAttr pODBC3SQLGetEnvAttr;
91 extern T3SQLSetStmtAttr pODBC3SQLSetStmtAttr;
92 extern T3SQLGetStmtAttr pODBC3SQLGetStmtAttr;
93 //extern T3SQLSetDescField pODBC3SQLSetDescField;
94 //extern T3SQLGetDescField pODBC3SQLGetDescField;
95 //extern T3SQLGetDescRec pODBC3SQLGetDescRec;
96 //extern T3SQLSetDescRec pODBC3SQLSetDescRec;
97 extern T3SQLPrepare pODBC3SQLPrepare;
98 extern T3SQLBindParameter pODBC3SQLBindParameter;
99 //extern T3SQLGetCursorName pODBC3SQLGetCursorName;
100 extern T3SQLSetCursorName pODBC3SQLSetCursorName;
101 extern T3SQLExecute pODBC3SQLExecute;
102 extern T3SQLExecDirect pODBC3SQLExecDirect;
103 //extern T3SQLNativeSql pODBC3SQLNativeSql;
104 extern T3SQLDescribeParam pODBC3SQLDescribeParam;
105 extern T3SQLNumParams pODBC3SQLNumParams;
106 extern T3SQLParamData pODBC3SQLParamData;
107 extern T3SQLPutData pODBC3SQLPutData;
108 extern T3SQLRowCount pODBC3SQLRowCount;
109 extern T3SQLNumResultCols pODBC3SQLNumResultCols;
110 extern T3SQLDescribeCol pODBC3SQLDescribeCol;
111 extern T3SQLColAttribute pODBC3SQLColAttribute;
112 extern T3SQLBindCol pODBC3SQLBindCol;
113 extern T3SQLFetch pODBC3SQLFetch;
114 extern T3SQLFetchScroll pODBC3SQLFetchScroll;
115 extern T3SQLGetData pODBC3SQLGetData;
116 extern T3SQLSetPos pODBC3SQLSetPos;
117 extern T3SQLBulkOperations pODBC3SQLBulkOperations;
118 extern T3SQLMoreResults pODBC3SQLMoreResults;
119 //extern T3SQLGetDiagField pODBC3SQLGetDiagField;
120 extern T3SQLGetDiagRec pODBC3SQLGetDiagRec;
121 extern T3SQLColumnPrivileges pODBC3SQLColumnPrivileges;
122 extern T3SQLColumns pODBC3SQLColumns;
123 extern T3SQLForeignKeys pODBC3SQLForeignKeys;
124 extern T3SQLPrimaryKeys pODBC3SQLPrimaryKeys;
125 extern T3SQLProcedureColumns pODBC3SQLProcedureColumns;
126 extern T3SQLProcedures pODBC3SQLProcedures;
127 extern T3SQLSpecialColumns pODBC3SQLSpecialColumns;
128 extern T3SQLStatistics pODBC3SQLStatistics;
129 extern T3SQLTablePrivileges pODBC3SQLTablePrivileges;
130 extern T3SQLTables pODBC3SQLTables;
131 extern T3SQLFreeStmt pODBC3SQLFreeStmt;
132 extern T3SQLCloseCursor pODBC3SQLCloseCursor;
133 extern T3SQLCancel pODBC3SQLCancel;
134 extern T3SQLEndTran pODBC3SQLEndTran;
135 extern T3SQLDisconnect pODBC3SQLDisconnect;
136 extern T3SQLFreeHandle pODBC3SQLFreeHandle;
137 extern T3SQLGetCursorName pODBC3SQLGetCursorName;
138 extern T3SQLNativeSql pODBC3SQLNativeSql;
140 using namespace ::com::sun::star::uno;
141 using namespace ::com::sun::star::beans;
142 using namespace ::com::sun::star::sdbcx;
143 using namespace ::com::sun::star::sdbc;
144 using namespace ::com::sun::star::container;
145 using namespace ::com::sun::star::lang;
146 using namespace utl;
147 using namespace osl;
148 using namespace vos;
149 using namespace ::dbtools;
151 sal_Bool LoadFunctions(oslModule pODBCso);
152 sal_Bool LoadLibrary_ADABAS(::rtl::OUString &_rPath);
153 // --------------------------------------------------------------------------------
154 void ODriver::fillInfo(const Sequence< PropertyValue >& info, TDatabaseStruct& _rDBInfo)
156 const PropertyValue* pIter = info.getConstArray();
157 const PropertyValue* pEnd = pIter + info.getLength();
158 for(;pIter != pEnd;++pIter)
160 if(pIter->Name.equalsIgnoreAsciiCase(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DatabaseName"))))
162 pIter->Value >>= _rDBInfo.sDBName;
164 else if(pIter->Name.equalsIgnoreAsciiCase(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ControlUser"))))
166 pIter->Value >>= _rDBInfo.sControlUser;
168 else if(pIter->Name.equalsIgnoreAsciiCase(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ControlPassword"))))
170 pIter->Value >>= _rDBInfo.sControlPassword;
172 else if(pIter->Name.equalsIgnoreAsciiCase(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DataCacheSizeIncrement"))))
173 pIter->Value >>= _rDBInfo.nDataIncrement;
174 else if(pIter->Name.equalsIgnoreAsciiCase(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ShutdownDatabase"))))
175 pIter->Value >>= _rDBInfo.bShutDown;
176 else if(pIter->Name.equalsIgnoreAsciiCase(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("User"))))
178 pIter->Value >>= _rDBInfo.sSysUser;
180 else if(pIter->Name.equalsIgnoreAsciiCase(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Password"))))
182 pIter->Value >>= _rDBInfo.sSysPassword;
184 else if(pIter->Name.equalsIgnoreAsciiCase(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DomainPassword"))))
186 pIter->Value >>= _rDBInfo.sDomainPassword;
188 else if(pIter->Name.equalsIgnoreAsciiCase(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CacheSize"))))
190 pIter->Value >>= _rDBInfo.sCacheSize;
192 else if(pIter->Name.equalsIgnoreAsciiCase(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("RestoreDatabase"))))
194 pIter->Value >>= _rDBInfo.bRestoreDatabase;
196 else if(pIter->Name.equalsIgnoreAsciiCase(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Backup"))))
198 pIter->Value >>= _rDBInfo.sBackupFile;
200 else if(pIter->Name.equalsIgnoreAsciiCase(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DataDevSpace"))))
202 pIter->Value >>= _rDBInfo.sDataDevName;
204 else if(pIter->Name.equalsIgnoreAsciiCase(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SYSDEVSPACE"))))
206 pIter->Value >>= _rDBInfo.sSysDevSpace;
208 else if(pIter->Name.equalsIgnoreAsciiCase(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TRANSACTION_LOG"))))
210 pIter->Value >>= _rDBInfo.sTransLogName;
212 else if(pIter->Name.equalsIgnoreAsciiCase(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DataDevSize"))))
214 pIter->Value >>= _rDBInfo.nDataSize;
216 else if(pIter->Name.equalsIgnoreAsciiCase(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("LogDevSize"))))
218 pIter->Value >>= _rDBInfo.nLogSize;
224 // --------------------------------------------------------------------------------
225 ODriver::ODriver(const Reference< XMultiServiceFactory >& _rxFactory) : ODBCDriver(_rxFactory)
227 osl_incrementInterlockedCount(&m_refCount);
228 fillEnvironmentVariables();
229 Reference< XComponent > xComponent(m_xORB, UNO_QUERY);
230 if (xComponent.is())
232 Reference< ::com::sun::star::lang::XEventListener> xEvtL((::cppu::OWeakObject*)this,UNO_QUERY);
233 xComponent->addEventListener(xEvtL);
235 osl_decrementInterlockedCount(&m_refCount);
237 //------------------------------------------------------------------------------
238 void ODriver::disposing()
240 ::osl::MutexGuard aGuard(m_aMutex);
241 ODriver_BASE::disposing();
242 Reference< XComponent > xComponent(m_xORB, UNO_QUERY);
243 if (xComponent.is())
245 Reference< XEventListener> xEvtL((::cppu::OWeakObject*)this,UNO_QUERY);
246 xComponent->removeEventListener(xEvtL);
248 m_xORB.clear();
251 // static ServiceInfo
252 //------------------------------------------------------------------------------
253 rtl::OUString ODriver::getImplementationName_Static( ) throw(RuntimeException)
255 return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.sdbcx.adabas.ODriver"));
257 //------------------------------------------------------------------------------
258 Sequence< ::rtl::OUString > ODriver::getSupportedServiceNames_Static( ) throw (RuntimeException)
260 Sequence< ::rtl::OUString > aSNS( 2 );
261 aSNS[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdbc.Driver"));
262 aSNS[1] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdbcx.Driver"));
263 return aSNS;
265 //------------------------------------------------------------------
266 ::rtl::OUString SAL_CALL ODriver::getImplementationName( ) throw(RuntimeException)
268 return getImplementationName_Static();
271 //------------------------------------------------------------------
272 sal_Bool SAL_CALL ODriver::supportsService( const ::rtl::OUString& _rServiceName ) throw(RuntimeException)
274 const Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames());
275 const ::rtl::OUString* pSupported = aSupported.getConstArray();
276 const ::rtl::OUString* pEnd = pSupported + aSupported.getLength();
277 for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported)
280 return pSupported != pEnd;
282 //------------------------------------------------------------------
283 Sequence< ::rtl::OUString > SAL_CALL ODriver::getSupportedServiceNames( ) throw(RuntimeException)
285 return getSupportedServiceNames_Static();
287 //------------------------------------------------------------------
288 Any SAL_CALL ODriver::queryInterface( const Type & rType ) throw(RuntimeException)
290 Any aRet = ::cppu::queryInterface(rType, static_cast<XDataDefinitionSupplier*>(this));
291 if ( !aRet.hasValue() )
292 aRet = ODriver_BASE::queryInterface(rType);
293 return aRet.hasValue() ? aRet : ODriver_BASE2::queryInterface(rType);
295 //------------------------------------------------------------------
296 Reference< XInterface > SAL_CALL ODriver_CreateInstance(const Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFac) throw( Exception )
298 return *(new ODriver(_rxFac));
300 // -----------------------------------------------------------------------------
301 void SAL_CALL ODriver::disposing( const EventObject& Source ) throw(RuntimeException)
303 ::osl::MutexGuard aGuard( m_aMutex );
305 if(m_xORB.is() && Reference< XMultiServiceFactory >(Source.Source,UNO_QUERY) == m_xORB)
307 TDatabaseMap::iterator aIter = m_aDatabaseMap.begin();
308 for(;aIter != m_aDatabaseMap.end();++aIter)
310 if(aIter->second.bShutDown)
312 ::rtl::OUString sName;
313 if(getDBName(aIter->first,sName))
315 XUTIL(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SHUTDOWN QUICK")),sName,aIter->second.sControlUser,aIter->second.sControlPassword);
316 X_STOP(sName);
320 m_xORB.clear();
323 // --------------------------------------------------------------------------------
324 Reference< XConnection > SAL_CALL ODriver::connect( const ::rtl::OUString& url, const Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException)
326 if ( ! acceptsURL(url) )
327 return NULL;
329 ::osl::MutexGuard aGuard( m_aMutex );
330 if (ODriver_BASE::rBHelper.bDisposed)
331 throw DisposedException();
333 TDatabaseStruct aDBInfo;
334 aDBInfo.bShutDown = sal_False;
335 fillInfo(info,aDBInfo);
336 aDBInfo.sControlUser = aDBInfo.sControlUser.toAsciiUpperCase();
337 aDBInfo.sControlPassword = aDBInfo.sControlPassword.toAsciiUpperCase();
338 aDBInfo.sSysUser = aDBInfo.sSysUser.toAsciiUpperCase();
339 aDBInfo.sSysPassword = aDBInfo.sSysPassword.toAsciiUpperCase();
342 TDatabaseMap::iterator aFind = m_aDatabaseMap.find(url);
343 if(aFind == m_aDatabaseMap.end()) // only when not found yet
344 m_aDatabaseMap[url] = aDBInfo;
345 else
347 if(aFind->second.bShutDown != aDBInfo.bShutDown)
348 aFind->second.bShutDown &= aDBInfo.bShutDown;
351 ::rtl::OUString sName;
352 if(aDBInfo.sControlPassword.getLength() && aDBInfo.sControlUser.getLength() && getDBName(url,sName))
354 // check if we have to add a new data dev space
355 checkAndInsertNewDevSpace(sName,aDBInfo);
357 convertOldVersion(sName,aDBInfo);
358 // check if we must restart the database
359 checkAndRestart(sName,aDBInfo);
363 if(!m_pDriverHandle)
365 ::rtl::OUString aPath;
366 if(!EnvironmentHandle(aPath))
367 throw SQLException(aPath,*this,::rtl::OUString(),1000,Any());
369 OAdabasConnection* pCon = new OAdabasConnection(m_pDriverHandle,this);
370 Reference< XConnection > xCon = pCon;
371 SQLRETURN nSQLRETURN = pCon->Construct(url,info);
373 if (nSQLRETURN == SQL_ERROR || nSQLRETURN == SQL_NO_DATA)
375 odbc::OTools::ThrowException(pCon,nSQLRETURN,pCon->getConnection(),SQL_HANDLE_DBC,*this);
378 m_xConnections.push_back(WeakReferenceHelper(*pCon));
380 return xCon;
382 // -----------------------------------------------------------------------------
383 sal_Bool ODriver::getDBName(const ::rtl::OUString& _rName,::rtl::OUString& sDBName) const
385 sDBName = ::rtl::OUString();
386 ::rtl::OUString sName = _rName.copy(12);
387 sal_Int32 nPos = sName.indexOf(':');
388 if(nPos != -1 && nPos < 1)
389 sDBName = sName.copy(1);
390 return (nPos != -1 && nPos < 1);
392 // --------------------------------------------------------------------------------
393 sal_Bool SAL_CALL ODriver::acceptsURL( const ::rtl::OUString& url )
394 throw(SQLException, RuntimeException)
396 return (!url.compareTo(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:adabas:")),12));
398 // --------------------------------------------------------------------------------
399 Sequence< DriverPropertyInfo > SAL_CALL ODriver::getPropertyInfo( const ::rtl::OUString& url, const Sequence< PropertyValue >& /*info*/) throw(SQLException, RuntimeException)
401 if ( acceptsURL(url) )
403 ::std::vector< DriverPropertyInfo > aDriverInfo;
405 aDriverInfo.push_back(DriverPropertyInfo(
406 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ShutdownDatabase"))
407 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Shut down service when closing."))
408 ,sal_False
409 ,::rtl::OUString()
410 ,Sequence< ::rtl::OUString >())
412 aDriverInfo.push_back(DriverPropertyInfo(
413 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ControlUser"))
414 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Control user name."))
415 ,sal_False
416 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("0"))
417 ,Sequence< ::rtl::OUString >())
419 aDriverInfo.push_back(DriverPropertyInfo(
420 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ControlPassword"))
421 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Control password."))
422 ,sal_False
423 ,::rtl::OUString()
424 ,Sequence< ::rtl::OUString >())
426 aDriverInfo.push_back(DriverPropertyInfo(
427 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DataCacheSizeIncrement"))
428 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Data increment (MB)."))
429 ,sal_False
430 ,::rtl::OUString()
431 ,Sequence< ::rtl::OUString >())
433 aDriverInfo.push_back(DriverPropertyInfo(
434 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CharSet"))
435 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CharSet of the database."))
436 ,sal_False
437 ,::rtl::OUString()
438 ,Sequence< ::rtl::OUString >())
440 return Sequence< DriverPropertyInfo >(&aDriverInfo[0],aDriverInfo.size());
443 SharedResources aResources;
444 const ::rtl::OUString sMessage = aResources.getResourceString(STR_URI_SYNTAX_ERROR);
445 ::dbtools::throwGenericSQLException(sMessage ,*this);
446 return Sequence< DriverPropertyInfo >();
448 // --------------------------------------------------------------------------------
449 sal_Int32 SAL_CALL ODriver::getMajorVersion( ) throw(RuntimeException)
451 return 1;
453 // --------------------------------------------------------------------------------
454 sal_Int32 SAL_CALL ODriver::getMinorVersion( ) throw(RuntimeException)
456 return 0;
458 // -----------------------------------------------------------------------------
459 // XCreateCatalog
460 void SAL_CALL ODriver::createCatalog( const Sequence< PropertyValue >& info ) throw(SQLException, ElementExistException, RuntimeException)
462 ::osl::MutexGuard aGuard( m_aMutex );
463 if (ODriver_BASE::rBHelper.bDisposed)
464 throw DisposedException();
468 TDatabaseStruct aDBInfo;
469 fillInfo(info,aDBInfo);
470 static char envName[] = "DBSERVICE=0";
471 putenv( envName );
473 m_sDbRunDir = m_sDbWorkURL + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/wrk/")) + aDBInfo.sDBName;
474 String sTemp;
475 LocalFileHelper::ConvertURLToPhysicalName(m_sDbRunDir,sTemp);
476 m_sDbRunDir = sTemp;
478 createNeededDirs(aDBInfo.sDBName);
479 if(CreateFiles(aDBInfo))
481 ::connectivity::SharedResources aResources;
482 const ::rtl::OUString sError( aResources.getResourceStringWithSubstitution(
483 STR_NO_DISK_SPACE,
484 "$filename$",aDBInfo.sDBName
485 ) );
486 ::dbtools::throwGenericSQLException(sError,*this);
487 } // if(CreateFiles(aDBInfo))
489 createDb(aDBInfo);
491 catch( SQLException&)
493 throw;
495 catch(Exception&)
497 throw SQLException();
501 // -----------------------------------------------------------------------------
502 // XDropCatalog
503 void SAL_CALL ODriver::dropCatalog( const ::rtl::OUString& /*catalogName*/, const Sequence< PropertyValue >& /*info*/ ) throw(SQLException, NoSuchElementException, RuntimeException)
505 ::osl::MutexGuard aGuard( m_aMutex );
506 if (ODriver_BASE::rBHelper.bDisposed)
507 throw DisposedException();
509 ::dbtools::throwFeatureNotImplementedException( "!XDropCatalog::dropCatalog", *this );
511 //-----------------------------------------------------------------------------
512 // ODBC Environment (gemeinsam fuer alle Connections):
513 SQLHANDLE ODriver::EnvironmentHandle(::rtl::OUString &_rPath)
515 // Ist (fuer diese Instanz) bereits ein Environment erzeugt worden?
516 if (!m_pDriverHandle)
518 SQLHANDLE h = SQL_NULL_HANDLE;
519 // Environment allozieren
521 // ODBC-DLL jetzt laden:
522 if (! LoadLibrary_ADABAS(_rPath))
523 return SQL_NULL_HANDLE;
525 if (N3SQLAllocHandle(SQL_HANDLE_ENV,SQL_NULL_HANDLE,&h) != SQL_SUCCESS)
526 return SQL_NULL_HANDLE;
528 // In globaler Struktur merken ...
529 m_pDriverHandle = h;
530 SQLRETURN nError = N3SQLSetEnvAttr(h, SQL_ATTR_ODBC_VERSION,(SQLPOINTER) SQL_OV_ODBC3, SQL_IS_INTEGER);
531 OSL_UNUSED( nError );
532 //N3SQLSetEnvAttr(h, SQL_ATTR_CONNECTION_POOLING,(SQLPOINTER) SQL_CP_ONE_PER_HENV, SQL_IS_INTEGER);
535 return m_pDriverHandle;
537 // --------------------------------------------------------------------------------
538 // XDataDefinitionSupplier
539 Reference< XTablesSupplier > SAL_CALL ODriver::getDataDefinitionByConnection( const Reference< ::com::sun::star::sdbc::XConnection >& connection ) throw(::com::sun::star::sdbc::SQLException, RuntimeException)
541 ::osl::MutexGuard aGuard( m_aMutex );
542 if (ODriver_BASE::rBHelper.bDisposed)
543 throw DisposedException();
545 Reference< XTablesSupplier > xTab;
546 Reference< ::com::sun::star::lang::XUnoTunnel> xTunnel(connection,UNO_QUERY);
547 if ( xTunnel.is() )
550 OAdabasConnection* pConnection = NULL;
551 OAdabasConnection* pSearchConnection = reinterpret_cast< OAdabasConnection* >( xTunnel->getSomething(OAdabasConnection::getUnoTunnelImplementationId()) );
552 for (OWeakRefArray::iterator i = m_xConnections.begin(); m_xConnections.end() != i; ++i)
554 if ( (OAdabasConnection*) Reference< XConnection >::query(i->get().get()).get() == pSearchConnection )
556 pConnection = pSearchConnection;
557 break;
562 if ( pConnection )
563 xTab = pConnection->createCatalog();
565 return xTab;
568 // --------------------------------------------------------------------------------
569 Reference< XTablesSupplier > SAL_CALL ODriver::getDataDefinitionByURL( const ::rtl::OUString& url, const Sequence< PropertyValue >& info ) throw(::com::sun::star::sdbc::SQLException, RuntimeException)
571 if ( ! acceptsURL(url) )
573 SharedResources aResources;
574 const ::rtl::OUString sMessage = aResources.getResourceString(STR_URI_SYNTAX_ERROR);
575 ::dbtools::throwGenericSQLException(sMessage ,*this);
576 } // if ( ! acceptsURL(url) )
578 return getDataDefinitionByConnection(connect(url,info));
580 // -----------------------------------------------------------------------------
581 void SAL_CALL ODriver::acquire() throw()
583 ODriver_BASE::acquire();
585 // -----------------------------------------------------------------------------
586 void SAL_CALL ODriver::release() throw()
588 ODriver_BASE::release();
590 ODriver::~ODriver()
593 // -----------------------------------------------------------------------------
594 oslGenericFunction ODriver::getOdbcFunction(sal_Int32 _nIndex) const
596 oslGenericFunction pFunction = NULL;
597 switch(_nIndex)
599 case ODBC3SQLAllocHandle:
600 pFunction = (oslGenericFunction)pODBC3SQLAllocHandle;;
601 break;
602 case ODBC3SQLConnect:
603 pFunction = (oslGenericFunction)pODBC3SQLConnect;
604 break;
605 case ODBC3SQLDriverConnect:
606 pFunction = (oslGenericFunction)pODBC3SQLDriverConnect;
607 break;
608 case ODBC3SQLBrowseConnect:
609 pFunction = (oslGenericFunction)pODBC3SQLBrowseConnect;
610 break;
611 case ODBC3SQLDataSources:
612 pFunction = (oslGenericFunction)pODBC3SQLDataSources;
613 break;
614 case ODBC3SQLDrivers:
615 pFunction = (oslGenericFunction)pODBC3SQLDrivers;
616 break;
617 case ODBC3SQLGetInfo:
619 pFunction = (oslGenericFunction)pODBC3SQLGetInfo;
620 break;
621 case ODBC3SQLGetFunctions:
623 pFunction = (oslGenericFunction)pODBC3SQLGetFunctions;
624 break;
625 case ODBC3SQLGetTypeInfo:
627 pFunction = (oslGenericFunction)pODBC3SQLGetTypeInfo;
628 break;
629 case ODBC3SQLSetConnectAttr:
631 pFunction = (oslGenericFunction)pODBC3SQLSetConnectAttr;
632 break;
633 case ODBC3SQLGetConnectAttr:
635 pFunction = (oslGenericFunction)pODBC3SQLGetConnectAttr;
636 break;
637 case ODBC3SQLSetEnvAttr:
639 pFunction = (oslGenericFunction)pODBC3SQLSetEnvAttr;
640 break;
641 case ODBC3SQLGetEnvAttr:
643 pFunction = (oslGenericFunction)pODBC3SQLGetEnvAttr;
644 break;
645 case ODBC3SQLSetStmtAttr:
647 pFunction = (oslGenericFunction)pODBC3SQLSetStmtAttr;
648 break;
649 case ODBC3SQLGetStmtAttr:
651 pFunction = (oslGenericFunction)pODBC3SQLGetStmtAttr;
652 break;
653 case ODBC3SQLPrepare:
655 pFunction = (oslGenericFunction)pODBC3SQLPrepare;
656 break;
657 case ODBC3SQLBindParameter:
659 pFunction = (oslGenericFunction)pODBC3SQLBindParameter;
660 break;
661 case ODBC3SQLSetCursorName:
663 pFunction = (oslGenericFunction)pODBC3SQLSetCursorName;
664 break;
665 case ODBC3SQLExecute:
667 pFunction = (oslGenericFunction)pODBC3SQLExecute;
668 break;
669 case ODBC3SQLExecDirect:
671 pFunction = (oslGenericFunction)pODBC3SQLExecDirect;
672 break;
673 case ODBC3SQLDescribeParam:
675 pFunction = (oslGenericFunction)pODBC3SQLDescribeParam;
676 break;
677 case ODBC3SQLNumParams:
679 pFunction = (oslGenericFunction)pODBC3SQLNumParams;
680 break;
681 case ODBC3SQLParamData:
683 pFunction = (oslGenericFunction)pODBC3SQLParamData;
684 break;
685 case ODBC3SQLPutData:
687 pFunction = (oslGenericFunction)pODBC3SQLPutData;
688 break;
689 case ODBC3SQLRowCount:
691 pFunction = (oslGenericFunction)pODBC3SQLRowCount;
692 break;
693 case ODBC3SQLNumResultCols:
695 pFunction = (oslGenericFunction)pODBC3SQLNumResultCols;
696 break;
697 case ODBC3SQLDescribeCol:
699 pFunction = (oslGenericFunction)pODBC3SQLDescribeCol;
700 break;
701 case ODBC3SQLColAttribute:
703 pFunction = (oslGenericFunction)pODBC3SQLColAttribute;
704 break;
705 case ODBC3SQLBindCol:
707 pFunction = (oslGenericFunction)pODBC3SQLBindCol;
708 break;
709 case ODBC3SQLFetch:
711 pFunction = (oslGenericFunction)pODBC3SQLFetch;
712 break;
713 case ODBC3SQLFetchScroll:
715 pFunction = (oslGenericFunction)pODBC3SQLFetchScroll;
716 break;
717 case ODBC3SQLGetData:
719 pFunction = (oslGenericFunction)pODBC3SQLGetData;
720 break;
721 case ODBC3SQLSetPos:
723 pFunction = (oslGenericFunction)pODBC3SQLSetPos;
724 break;
725 case ODBC3SQLBulkOperations:
727 pFunction = (oslGenericFunction)pODBC3SQLBulkOperations;
728 break;
729 case ODBC3SQLMoreResults:
731 pFunction = (oslGenericFunction)pODBC3SQLMoreResults;
732 break;
733 case ODBC3SQLGetDiagRec:
735 pFunction = (oslGenericFunction)pODBC3SQLGetDiagRec;
736 break;
737 case ODBC3SQLColumnPrivileges:
739 pFunction = (oslGenericFunction)pODBC3SQLColumnPrivileges;
740 break;
741 case ODBC3SQLColumns:
743 pFunction = (oslGenericFunction)pODBC3SQLColumns;
744 break;
745 case ODBC3SQLForeignKeys:
747 pFunction = (oslGenericFunction)pODBC3SQLForeignKeys;
748 break;
749 case ODBC3SQLPrimaryKeys:
751 pFunction = (oslGenericFunction)pODBC3SQLPrimaryKeys;
752 break;
753 case ODBC3SQLProcedureColumns:
755 pFunction = (oslGenericFunction)pODBC3SQLProcedureColumns;
756 break;
757 case ODBC3SQLProcedures:
759 pFunction = (oslGenericFunction)pODBC3SQLProcedures;
760 break;
761 case ODBC3SQLSpecialColumns:
763 pFunction = (oslGenericFunction)pODBC3SQLSpecialColumns;
764 break;
765 case ODBC3SQLStatistics:
767 pFunction = (oslGenericFunction)pODBC3SQLStatistics;
768 break;
769 case ODBC3SQLTablePrivileges:
771 pFunction = (oslGenericFunction)pODBC3SQLTablePrivileges;
772 break;
773 case ODBC3SQLTables:
775 pFunction = (oslGenericFunction)pODBC3SQLTables;
776 break;
777 case ODBC3SQLFreeStmt:
779 pFunction = (oslGenericFunction)pODBC3SQLFreeStmt;
780 break;
781 case ODBC3SQLCloseCursor:
783 pFunction = (oslGenericFunction)pODBC3SQLCloseCursor;
784 break;
785 case ODBC3SQLCancel:
787 pFunction = (oslGenericFunction)pODBC3SQLCancel;
788 break;
789 case ODBC3SQLEndTran:
791 pFunction = (oslGenericFunction)pODBC3SQLEndTran;
792 break;
793 case ODBC3SQLDisconnect:
795 pFunction = (oslGenericFunction)pODBC3SQLDisconnect;
796 break;
797 case ODBC3SQLFreeHandle:
799 pFunction = (oslGenericFunction)pODBC3SQLFreeHandle;
800 break;
801 case ODBC3SQLGetCursorName:
803 pFunction = (oslGenericFunction)pODBC3SQLGetCursorName;
804 break;
805 case ODBC3SQLNativeSql:
807 pFunction = (oslGenericFunction)pODBC3SQLNativeSql;
808 break;
809 default:
810 OSL_ENSURE(0,"Function unknown!");
812 return pFunction;
814 // -----------------------------------------------------------------------------
815 void ODriver::createNeededDirs(const ::rtl::OUString& sDBName)
817 ::rtl::OUString sDbWork,sDBConfig,sTemp;
819 if(m_sDbWork.getLength())
821 sDbWork = m_sDbWorkURL;
822 if(!UCBContentHelper::IsFolder(m_sDbWorkURL))
823 UCBContentHelper::MakeFolder(m_sDbWorkURL);
825 sDbWork += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/"));
826 sDbWork += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("wrk"));
827 if(!UCBContentHelper::IsFolder(sDbWork))
828 UCBContentHelper::MakeFolder(sDbWork);
830 sDbWork += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/"));
832 sTemp = sDbWork;
833 sTemp += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("config"));
834 if(!UCBContentHelper::IsFolder(sTemp))
835 UCBContentHelper::MakeFolder(sTemp);
837 sTemp = sDbWork;
838 sTemp += sDBName;
839 if(!UCBContentHelper::IsFolder(sTemp))
840 UCBContentHelper::MakeFolder(sTemp);
843 if(m_sDbConfig.getLength())
845 sDBConfig = m_sDbConfigURL;
846 if(!UCBContentHelper::IsFolder(sDBConfig))
847 UCBContentHelper::MakeFolder(sDBConfig);
849 sDBConfig += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/"));
850 sTemp = sDBConfig;
851 sTemp += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("config"));
852 if(!UCBContentHelper::IsFolder(sTemp))
853 UCBContentHelper::MakeFolder(sTemp);
855 sTemp += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/"));
856 sTemp += sDBName;
857 if(UCBContentHelper::Exists(sTemp))
858 UCBContentHelper::Kill(sTemp);
860 #if !(defined(WIN) || defined(WNT))
861 sTemp = sDBConfig;
862 sTemp += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("diag"));
863 if(!UCBContentHelper::IsFolder(sTemp))
864 UCBContentHelper::MakeFolder(sTemp);
866 sTemp = sDBConfig;
867 sTemp += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ipc"));
868 if(!UCBContentHelper::IsFolder(sTemp))
869 UCBContentHelper::MakeFolder(sTemp);
871 sTemp = sDBConfig;
872 sTemp += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("spool"));
873 if(!UCBContentHelper::IsFolder(sTemp))
874 UCBContentHelper::MakeFolder(sTemp);
875 #endif
878 // -----------------------------------------------------------------------------
879 void ODriver::clearDatabase(const ::rtl::OUString& sDBName)
880 { // stop the database
881 ::rtl::OUString sCommand;
882 #if defined(WIN) || defined(WNT)
883 ::rtl::OUString sStop = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("stop"));
884 OArgumentList aArgs(2,&sDBName,&sStop);
885 sCommand = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("x_cons.exe"));
886 #else
887 OArgumentList aArgs(1,&sDBName);
888 sCommand = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("x_clear"));
889 #endif
891 OProcess aApp( sCommand,m_sDbWorkURL);
892 #if OSL_DEBUG_LEVEL > 0
893 OProcess::TProcessError eError =
894 #endif
895 aApp.execute( (OProcess::TProcessOption) OPROCESS_ADABAS, aArgs );
896 OSL_ENSURE( eError == OProcess::E_None, "ODriver::clearDatabase: calling the executable failed!" );
898 // -----------------------------------------------------------------------------
899 void ODriver::createDb( const TDatabaseStruct& _aInfo)
902 clearDatabase(_aInfo.sDBName);
904 X_PARAM(_aInfo.sDBName,_aInfo.sControlUser,_aInfo.sControlPassword,String::CreateFromAscii("BINIT"));
906 String sTemp;
907 LocalFileHelper::ConvertURLToPhysicalName(_aInfo.sSysDevSpace,sTemp);
909 PutParam(_aInfo.sDBName,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SYSDEVSPACE")),sTemp);
911 sTemp.Erase();
912 LocalFileHelper::ConvertURLToPhysicalName(_aInfo.sTransLogName,sTemp);
913 PutParam(_aInfo.sDBName,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TRANSACTION_LOG")),sTemp);
914 PutParam(_aInfo.sDBName,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MAXUSERTASKS")),::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("3")));
915 PutParam(_aInfo.sDBName,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MAXDEVSPACES")),::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("7")));
916 PutParam(_aInfo.sDBName,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MAXDATADEVSPACES")),::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("5")));
917 PutParam(_aInfo.sDBName,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MAXDATAPAGES")),::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("25599")));
918 PutParam(_aInfo.sDBName,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MAXBACKUPDEVS")),::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("1")));
919 PutParam(_aInfo.sDBName,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MAXSERVERDB")),::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("1")));
920 PutParam(_aInfo.sDBName,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DATA_CACHE_PAGES")),_aInfo.sCacheSize);
921 PutParam(_aInfo.sDBName,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CONV_CACHE_PAGES")),::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("23")));
922 PutParam(_aInfo.sDBName,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PROC_DATA_PAGES")),::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("40")));
923 PutParam(_aInfo.sDBName,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("RUNDIRECTORY")),m_sDbRunDir);
924 PutParam(_aInfo.sDBName,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("KERNELTRACESIZE")),::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("100")));
925 PutParam(_aInfo.sDBName,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("LOG_QUEUE_PAGES")),::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("10")));
927 #if !(defined(WIN) || defined(WNT))
928 PutParam(_aInfo.sDBName,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("OPMSG1")),::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/dev/null")));
929 #endif
931 X_PARAM(_aInfo.sDBName,_aInfo.sControlUser,_aInfo.sControlPassword,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("BCHECK")));
933 X_START(_aInfo.sDBName);
935 // SHOW_STATE()
936 // %m_sDbRoot%\bin\xutil -d %_aInfo.sDBName% -u %CONUSR%,%CONPWD% -b %INITCMD%
937 ::rtl::OUString aBatch2 = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("-b "));
939 // if(!bBsp && INITCMD.Len() >= 40)
940 // {
941 // DirEntry aTmp(INITCMD);
942 // aTmp.CopyTo(aInitFile, FSYS_ACTION_COPYFILE);
943 // INITCMD = aInitFile.GetFull();
944 // }
945 // generate the init file for the database
946 String sInitFile = getDatabaseInitFile(_aInfo);
948 LocalFileHelper::ConvertURLToPhysicalName(sInitFile,sTemp);
949 aBatch2 += sTemp;
950 XUTIL(aBatch2,_aInfo.sDBName,_aInfo.sControlUser,_aInfo.sControlPassword);
951 #if OSL_DEBUG_LEVEL < 2
952 if(UCBContentHelper::Exists(sInitFile))
953 UCBContentHelper::Kill(sInitFile);
954 #endif
956 // install system tables
957 installSystemTables(_aInfo);
958 // now we have to make our SYSDBA user "NOT EXCLUSIVE"
960 String sExt;
961 sExt.AssignAscii(".sql");
963 String sWorkUrl(m_sDbWorkURL);
964 ::utl::TempFile aInitFile(String::CreateFromAscii("Init"),&sExt,&sWorkUrl);
965 aInitFile.EnableKillingFile();
967 ::std::auto_ptr<SvStream> pFileStream( UcbStreamHelper::CreateStream(aInitFile.GetURL(),STREAM_WRITE) );
968 (*pFileStream) << "ALTER USER \""
969 << ::rtl::OString(_aInfo.sSysUser,_aInfo.sSysUser.getLength(),gsl_getSystemTextEncoding())
970 << "\" NOT EXCLUSIVE "
971 << sNewLine;
972 pFileStream->Flush();
974 { // just to get sure that the tempfile still lives
975 sTemp.Erase();
976 LocalFileHelper::ConvertURLToPhysicalName(aInitFile.GetURL(),sTemp);
977 LoadBatch(_aInfo.sDBName,_aInfo.sSysUser,_aInfo.sSysPassword,sTemp);
983 //-------------------------------------------------------------------------------------------------
984 int ODriver::X_PARAM(const ::rtl::OUString& _DBNAME,
985 const ::rtl::OUString& _USR,
986 const ::rtl::OUString& _PWD,
987 const ::rtl::OUString& _CMD)
989 // %XPARAM% -u %CONUSR%,%CONPWD% BINIT
990 String sCommandFile = generateInitFile();
992 ::std::auto_ptr<SvStream> pFileStream( UcbStreamHelper::CreateStream(sCommandFile,STREAM_STD_READWRITE));
993 pFileStream->Seek(STREAM_SEEK_TO_END);
994 (*pFileStream) << "x_param"
995 #if defined(WIN) || defined(WNT)
996 << ".exe"
997 #endif
998 << " -d "
999 << ::rtl::OString(_DBNAME,_DBNAME.getLength(),gsl_getSystemTextEncoding())
1000 << " -u "
1001 << ::rtl::OString(_USR,_USR.getLength(),gsl_getSystemTextEncoding())
1002 << ","
1003 << ::rtl::OString(_PWD,_PWD.getLength(),gsl_getSystemTextEncoding())
1004 << " "
1005 << ::rtl::OString(_CMD,_CMD.getLength(),gsl_getSystemTextEncoding())
1006 #if (defined(WIN) || defined(WNT))
1007 #if (OSL_DEBUG_LEVEL > 1) || defined(DBG_UTIL)
1008 << " >> %DBWORK%\\create.log 2>&1"
1009 #endif
1010 #else
1011 #if (OSL_DEBUG_LEVEL > 1) || defined(DBG_UTIL)
1012 << " >> /tmp/kstart.log"
1013 #else
1014 << " > /dev/null"
1015 #endif
1016 #endif
1017 << " "
1018 << sNewLine
1019 << sNewLine;
1021 pFileStream->Flush();
1024 OProcess aApp(sCommandFile ,m_sDbWorkURL);
1025 #if OSL_DEBUG_LEVEL > 0
1026 OProcess::TProcessError eError =
1027 #endif
1028 aApp.execute( (OProcess::TProcessOption)(OProcess::TOption_Hidden | OProcess::TOption_Wait));
1029 OSL_ENSURE( eError == OProcess::E_None, "ODriver::X_PARAM: calling the executable failed!" );
1030 #if OSL_DEBUG_LEVEL < 2
1031 if(UCBContentHelper::Exists(sCommandFile))
1032 UCBContentHelper::Kill(sCommandFile);
1033 #endif
1035 return 0;
1037 // -----------------------------------------------------------------------------
1038 sal_Int32 ODriver::CreateFiles(const TDatabaseStruct& _aInfo)
1040 int nRet = CreateFile(_aInfo.sSysDevSpace,_aInfo.nDataSize/50) ? 0 : -9;
1041 if(!nRet)
1042 nRet = CreateFile(_aInfo.sTransLogName,_aInfo.nLogSize) ? 0 : -10;
1043 if(!nRet)
1044 nRet = CreateFile(_aInfo.sDataDevName,_aInfo.nDataSize) ? 0 : -11;
1046 return nRet;
1049 // -----------------------------------------------------------------------------
1050 void ODriver::PutParam(const ::rtl::OUString& sDBName,
1051 const ::rtl::OUString& rWhat,
1052 const ::rtl::OUString& rHow)
1054 OArgumentList aArgs(3,&sDBName,&rWhat,&rHow);
1055 ::rtl::OUString sCommand = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("putparam"));
1056 #if defined(WIN) || defined(WNT)
1057 sCommand += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".exe"));
1058 #endif
1060 OProcess aApp(sCommand,m_sDbWorkURL);
1061 #if OSL_DEBUG_LEVEL > 0
1062 OProcess::TProcessError eError =
1063 #endif
1064 aApp.execute( (OProcess::TProcessOption)OPROCESS_ADABAS,aArgs );
1065 OSL_ENSURE( eError == OProcess::E_None, "ODriver::PutParam: calling the executable failed!" );
1067 // -----------------------------------------------------------------------------
1068 sal_Bool ODriver::CreateFile(const ::rtl::OUString &_FileName,
1069 sal_Int32 _nSize)
1071 OSL_TRACE("CreateFile %d",_nSize);
1072 sal_Bool bOK = sal_True;
1075 ::std::auto_ptr<SvStream> pFileStream( UcbStreamHelper::CreateStream(_FileName,STREAM_WRITE));
1076 if( !pFileStream.get())
1078 ::connectivity::SharedResources aResources;
1079 const ::rtl::OUString sError( aResources.getResourceStringWithSubstitution(
1080 STR_NO_DISK_SPACE,
1081 "$filename$",_FileName
1082 ) );
1083 ::dbtools::throwGenericSQLException(sError,*this);
1085 (*pFileStream).SetFiller('\0');
1086 sal_Int32 nNewSize = 0;
1087 sal_Int32 nCount = _nSize /2;
1088 for(sal_Int32 i=0; bOK && i < nCount; ++i)
1090 nNewSize += 8192;//4096;
1091 bOK = (*pFileStream).SetStreamSize(nNewSize);
1092 pFileStream->Flush();
1095 bOK = bOK && static_cast<sal_Int32>(pFileStream->Seek(STREAM_SEEK_TO_END)) == nNewSize;
1097 catch(Exception&)
1099 OSL_TRACE("Exception");
1101 if(!bOK)
1103 ::connectivity::SharedResources aResources;
1104 const ::rtl::OUString sError( aResources.getResourceStringWithSubstitution(
1105 STR_NO_DISK_SPACE,
1106 "$filename$",_FileName
1107 ) );
1108 ::dbtools::throwGenericSQLException(sError,*this);
1111 return bOK;
1112 // dd if=/dev/zero bs=4k of=$DEV_NAME count=$2
1114 // -----------------------------------------------------------------------------
1115 int ODriver::X_START(const ::rtl::OUString& sDBName)
1117 ::rtl::OUString sCommand;
1118 #if defined(WIN) || defined(WNT)
1120 ::rtl::OUString sArg1 = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("-d"));
1121 ::rtl::OUString sArg3 = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("-NoDBService"));
1122 ::rtl::OUString sArg4 = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("-NoDBWindow"));
1124 OArgumentList aArgs(4,&sArg1,&sDBName,&sArg3,&sArg4);
1125 sCommand = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("strt.exe"));
1126 #else
1127 OArgumentList aArgs(1,&sDBName);
1128 sCommand = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("x_start"));
1129 #endif
1131 OProcess aApp( sCommand ,m_sDbWorkURL);
1132 OProcess::TProcessError eError = aApp.execute((OProcess::TProcessOption)OPROCESS_ADABAS,aArgs);
1134 if(eError == OProcess::E_NotFound)
1136 ::connectivity::SharedResources aResources;
1137 const ::rtl::OUString sError( aResources.getResourceStringWithSubstitution(
1138 STR_COMMAND_NOT_FOUND,
1139 "$databasename$",sDBName,
1140 "$progname$",sCommand
1141 ) );
1142 ::dbtools::throwGenericSQLException(sError,*this);
1144 OSL_ASSERT(eError == OProcess::E_None);
1146 OProcess::TProcessInfo aInfo;
1147 if(aApp.getInfo(OProcess::TData_ExitCode,&aInfo) == OProcess::E_None && aInfo.Code)
1148 return aInfo.Code;
1150 return 0;
1152 // -----------------------------------------------------------------------------
1153 int ODriver::X_STOP(const ::rtl::OUString& sDBName)
1155 ::rtl::OUString sCommand;
1156 #if defined(WIN) || defined(WNT)
1158 ::rtl::OUString sArg1 = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("-d"));
1159 ::rtl::OUString sArg2 = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("-NoDBService"));
1161 OArgumentList aArgs(3,&sArg1,&sDBName,&sArg2);
1162 sCommand = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("stp.exe"));
1163 #else
1164 OArgumentList aArgs(1,&sDBName);
1165 sCommand = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("x_stop"));
1166 #endif
1167 OProcess aApp( sCommand ,m_sDbWorkURL);
1169 OProcess::TProcessError eError = aApp.execute((OProcess::TProcessOption)OPROCESS_ADABAS,aArgs);
1172 OSL_ASSERT(eError == OProcess::E_None);
1173 if(eError != OProcess::E_None)
1174 return 1;
1175 OProcess::TProcessInfo aInfo;
1176 if(aApp.getInfo(OProcess::TData_ExitCode,&aInfo) == OProcess::E_None && aInfo.Code)
1177 return aInfo.Code;
1179 return 0;
1181 // -----------------------------------------------------------------------------
1182 void ODriver::XUTIL(const ::rtl::OUString& _rParam,
1183 const ::rtl::OUString& _DBNAME,
1184 const ::rtl::OUString& _USRNAME,
1185 const ::rtl::OUString& _USRPWD)
1187 String sWorkUrl(m_sDbWorkURL);
1188 String sExt = String::CreateFromAscii(".log");
1189 ::utl::TempFile aCmdFile(String::CreateFromAscii("xutil"),&sExt,&sWorkUrl);
1190 aCmdFile.EnableKillingFile();
1192 String sPhysicalPath;
1193 LocalFileHelper::ConvertURLToPhysicalName(aCmdFile.GetURL(),sPhysicalPath);
1195 String sCommandFile = generateInitFile();
1198 ::std::auto_ptr<SvStream> pFileStream( UcbStreamHelper::CreateStream(sCommandFile,STREAM_STD_READWRITE));
1199 pFileStream->Seek(STREAM_SEEK_TO_END);
1200 (*pFileStream) <<
1201 #if defined(WIN) || defined(WNT)
1202 "xutil.exe"
1203 #else
1204 "utility"
1205 #endif
1206 << " -u "
1207 << ::rtl::OString(_USRNAME,_USRNAME.getLength(),gsl_getSystemTextEncoding())
1208 << ","
1209 << ::rtl::OString(_USRPWD,_USRPWD.getLength(),gsl_getSystemTextEncoding())
1210 << " -d "
1211 << ::rtl::OString(_DBNAME,_DBNAME.getLength(),gsl_getSystemTextEncoding())
1212 << " "
1213 << ::rtl::OString(_rParam,_rParam.getLength(),gsl_getSystemTextEncoding())
1214 << " > "
1215 << ::rtl::OString(sPhysicalPath.GetBuffer(),sPhysicalPath.Len(),gsl_getSystemTextEncoding())
1216 << " 2>&1"
1217 << sNewLine;
1218 pFileStream->Flush();
1221 OProcess aApp(sCommandFile ,m_sDbWorkURL);
1222 #if OSL_DEBUG_LEVEL > 0
1223 OProcess::TProcessError eError =
1224 #endif
1225 aApp.execute( (OProcess::TProcessOption)(OProcess::TOption_Hidden | OProcess::TOption_Wait));
1226 OSL_ENSURE( eError == OProcess::E_None, "ODriver::XUTIL: calling the executable failed!" );
1227 #if OSL_DEBUG_LEVEL < 2
1228 if(UCBContentHelper::Exists(sCommandFile))
1229 UCBContentHelper::Kill(sCommandFile);
1230 #endif
1232 // -----------------------------------------------------------------------------
1233 void ODriver::LoadBatch(const ::rtl::OUString& sDBName,
1234 const ::rtl::OUString& _rUSR,
1235 const ::rtl::OUString& _rPWD,
1236 const ::rtl::OUString& _rBatch)
1238 OSL_ENSURE(_rBatch.getLength(),"No batch file given!");
1239 String sWorkUrl(m_sDbWorkURL);
1240 String sExt = String::CreateFromAscii(".log");
1241 ::utl::TempFile aCmdFile(String::CreateFromAscii("LoadBatch"),&sExt,&sWorkUrl);
1242 #if OSL_DEBUG_LEVEL < 2
1243 aCmdFile.EnableKillingFile();
1244 #endif
1246 String sPhysicalPath;
1247 LocalFileHelper::ConvertURLToPhysicalName(aCmdFile.GetURL(),sPhysicalPath);
1249 String sCommandFile = generateInitFile();
1251 ::std::auto_ptr<SvStream> pFileStream( UcbStreamHelper::CreateStream(sCommandFile,STREAM_STD_READWRITE));
1252 pFileStream->Seek(STREAM_SEEK_TO_END);
1253 (*pFileStream) << "xload"
1254 #if defined(WIN) || defined(WNT)
1255 << ".exe"
1256 #endif
1257 << " -d "
1258 << ::rtl::OString(sDBName,sDBName.getLength(),gsl_getSystemTextEncoding())
1259 << " -u "
1260 << ::rtl::OString(_rUSR,_rUSR.getLength(),gsl_getSystemTextEncoding())
1261 << ","
1262 << ::rtl::OString(_rPWD,_rPWD.getLength(),gsl_getSystemTextEncoding());
1264 if ( !isKernelVersion(CURRENT_DB_VERSION) )
1265 (*pFileStream) << " -S adabas -b ";
1266 else
1267 (*pFileStream) << " -S NATIVE -b ";
1269 (*pFileStream) << ::rtl::OString(_rBatch,_rBatch.getLength(),gsl_getSystemTextEncoding())
1270 << " > "
1271 << ::rtl::OString(sPhysicalPath.GetBuffer(),sPhysicalPath.Len(),gsl_getSystemTextEncoding())
1272 << " 2>&1"
1273 << sNewLine;
1275 pFileStream->Flush();
1278 OProcess aApp(sCommandFile ,m_sDbWorkURL);
1279 #if OSL_DEBUG_LEVEL > 0
1280 OProcess::TProcessError eError =
1281 #endif
1282 aApp.execute( (OProcess::TProcessOption)(OProcess::TOption_Hidden | OProcess::TOption_Wait));
1283 OSL_ENSURE( eError == OProcess::E_None, "ODriver::LoadBatch: calling the executable failed!" );
1284 #if OSL_DEBUG_LEVEL < 2
1285 if(UCBContentHelper::Exists(sCommandFile))
1286 UCBContentHelper::Kill(sCommandFile);
1287 #endif
1289 // -----------------------------------------------------------------------------
1290 void ODriver::fillEnvironmentVariables()
1292 // read the environment vars
1293 struct env_data
1295 const sal_Char* pAsciiEnvName;
1296 ::rtl::OUString* pValue;
1297 ::rtl::OUString* pValueURL;
1298 } EnvData[] = {
1299 { "DBWORK", &m_sDbWork, &m_sDbWorkURL },
1300 { "DBCONFIG", &m_sDbConfig, &m_sDbConfigURL },
1301 { "DBROOT", &m_sDbRoot, &m_sDbRootURL }
1304 for ( size_t i = 0; i < sizeof( EnvData ) / sizeof( EnvData[0] ); ++i )
1306 ::rtl::OUString sVarName = ::rtl::OUString::createFromAscii( EnvData[i].pAsciiEnvName );
1307 ::rtl::OUString sEnvValue;
1308 if(osl_getEnvironment( sVarName.pData, &sEnvValue.pData ) == osl_Process_E_None )
1310 *EnvData[i].pValue = sEnvValue;
1311 String sURL;
1312 LocalFileHelper::ConvertPhysicalNameToURL( *EnvData[i].pValue, sURL );
1313 *EnvData[i].pValueURL = sURL;
1317 m_sDelimit = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/"));
1319 // -----------------------------------------------------------------------------
1320 ::rtl::OUString ODriver::generateInitFile() const
1322 String sExt;
1323 #if !(defined(WIN) || defined(WNT))
1324 sExt = String::CreateFromAscii(".sh");
1325 #else
1326 sExt = String::CreateFromAscii(".bat");
1327 #endif
1329 String sWorkUrl(m_sDbWorkURL);
1330 ::utl::TempFile aCmdFile(String::CreateFromAscii("Init"),&sExt,&sWorkUrl);
1331 #if !(defined(WIN) || defined(WNT))
1332 String sPhysicalPath;
1333 LocalFileHelper::ConvertURLToPhysicalName(aCmdFile.GetURL(),sPhysicalPath);
1334 chmod(ByteString(sPhysicalPath,gsl_getSystemTextEncoding()).GetBuffer(),S_IRUSR|S_IWUSR|S_IXUSR);
1335 #endif
1337 #if !(defined(WIN) || defined(WNT))
1338 SvStream* pFileStream = aCmdFile.GetStream(STREAM_WRITE);
1339 (*pFileStream) << "#!/bin/sh"
1340 << sNewLine
1341 << "cd \"$DBWORK\""
1342 << sNewLine
1343 << sNewLine;
1344 pFileStream->Flush();
1345 #endif
1347 return aCmdFile.GetURL();
1349 // -----------------------------------------------------------------------------
1350 ::rtl::OUString ODriver::getDatabaseInitFile( const TDatabaseStruct& _aDBInfo)
1352 String sExt;
1353 sExt.AssignAscii(".ins");
1356 String sWorkUrl(m_sDbWorkURL);
1357 ::utl::TempFile aInitFile(String::CreateFromAscii("Init"),&sExt,&sWorkUrl);
1359 SvStream* pFileStream = aInitFile.GetStream(STREAM_WRITE);
1360 (*pFileStream) << "* @(#)init.cmd 6.1.1 1994-11-10\n";
1361 (*pFileStream) << "init config\n";
1362 (*pFileStream) << "* default code:\n";
1363 (*pFileStream) << "ascii\n";
1364 (*pFileStream) << "* date time format\n";
1365 (*pFileStream) << "internal\n";
1366 (*pFileStream) << "* command timeout:\n";
1367 (*pFileStream) << "900\n";
1368 (*pFileStream) << "* lock timeout:\n";
1369 (*pFileStream) << "360\n";
1370 (*pFileStream) << "* request timeout:\n";
1371 (*pFileStream) << "180\n";
1372 (*pFileStream) << "* log mode:\n";
1373 (*pFileStream) << "demo\n";
1374 (*pFileStream) << "* log segment size:\n";
1375 (*pFileStream) << "0\n";
1376 (*pFileStream) << "* no of archive logs:\n";
1377 (*pFileStream) << "0\n";
1378 (*pFileStream) << "* no of data devspaces:\n";
1379 (*pFileStream) << "1\n";
1380 (*pFileStream) << "* mirror devspaces:\n";
1381 (*pFileStream) << "n\n";
1382 (*pFileStream) << "if $rc <> 0 then stop\n";
1383 (*pFileStream) << "*--- device description ---\n";
1384 (*pFileStream) << "* sys devspace name:\n";
1386 String sTemp;
1387 LocalFileHelper::ConvertURLToPhysicalName(_aDBInfo.sSysDevSpace,sTemp);
1388 (*pFileStream) << ::rtl::OString(sTemp.GetBuffer(),sTemp.Len(),gsl_getSystemTextEncoding());
1390 (*pFileStream) << "\n* log devspace size:\n";
1391 (*pFileStream) << ::rtl::OString::valueOf(_aDBInfo.nLogSize);
1392 (*pFileStream) << "\n* log devspace name:\n";
1394 String sTemp;
1395 LocalFileHelper::ConvertURLToPhysicalName(_aDBInfo.sTransLogName,sTemp);
1396 (*pFileStream) << ::rtl::OString(sTemp.GetBuffer(),sTemp.Len(),gsl_getSystemTextEncoding());
1398 (*pFileStream) << "\n* data devspace size:\n";
1399 (*pFileStream) << ::rtl::OString::valueOf(_aDBInfo.nDataSize);
1400 (*pFileStream) << "\n* data devspace name:\n";
1402 String sTemp;
1403 LocalFileHelper::ConvertURLToPhysicalName(_aDBInfo.sDataDevName,sTemp);
1404 (*pFileStream) << ::rtl::OString(sTemp.GetBuffer(),sTemp.Len(),gsl_getSystemTextEncoding());
1407 (*pFileStream) << "\n* END INIT CONFIG\n";
1408 (*pFileStream) << "if $rc <> 0 then stop\n";
1409 if(_aDBInfo.bRestoreDatabase)
1411 (*pFileStream) << "RESTORE DATA QUICK FROM '";
1413 String sTemp;
1414 LocalFileHelper::ConvertURLToPhysicalName(_aDBInfo.sBackupFile,sTemp);
1415 (*pFileStream) << ::rtl::OString(sTemp.GetBuffer(),sTemp.Len(),gsl_getSystemTextEncoding());
1417 (*pFileStream) << "' BLOCKSIZE 8\n";
1418 (*pFileStream) << "if $rc <> 0 then stop\n";
1419 (*pFileStream) << "RESTART\n";
1422 else
1424 (*pFileStream) << "ACTIVATE SERVERDB SYSDBA \"";
1425 (*pFileStream) << ::rtl::OString(_aDBInfo.sSysUser,_aDBInfo.sSysUser.getLength(),gsl_getSystemTextEncoding());
1426 (*pFileStream) << "\" PASSWORD \"";
1427 (*pFileStream) << ::rtl::OString(_aDBInfo.sSysPassword,_aDBInfo.sSysPassword.getLength(),gsl_getSystemTextEncoding());
1428 (*pFileStream) << "\"\n";
1430 (*pFileStream) << "if $rc <> 0 then stop\n";
1431 (*pFileStream) << "exit\n";
1433 return aInitFile.GetURL();
1435 // -----------------------------------------------------------------------------
1436 void ODriver::X_CONS(const ::rtl::OUString& sDBName,const ::rtl::OString& _ACTION,const ::rtl::OUString& _FILENAME)
1438 String sPhysicalPath;
1439 LocalFileHelper::ConvertURLToPhysicalName(_FILENAME,sPhysicalPath);
1441 String sCommandFile = generateInitFile();
1443 ::std::auto_ptr<SvStream> pFileStream( UcbStreamHelper::CreateStream(sCommandFile,STREAM_STD_READWRITE));
1444 pFileStream->Seek(STREAM_SEEK_TO_END);
1446 (*pFileStream) << "x_cons"
1447 #if defined(WIN) || defined(WNT)
1448 << ".exe"
1449 #endif
1450 << " "
1451 << ::rtl::OString(sDBName,sDBName.getLength(),gsl_getSystemTextEncoding())
1452 << " SHOW "
1453 << _ACTION
1454 << " > "
1455 << ::rtl::OString(sPhysicalPath.GetBuffer(),sPhysicalPath.Len(),gsl_getSystemTextEncoding())
1456 << sNewLine;
1457 pFileStream->Flush();
1460 OProcess aApp(sCommandFile ,m_sDbWorkURL);
1461 aApp.execute( (OProcess::TProcessOption)(OProcess::TOption_Hidden | OProcess::TOption_Wait));
1462 #if OSL_DEBUG_LEVEL < 2
1463 if(UCBContentHelper::Exists(sCommandFile))
1464 UCBContentHelper::Kill(sCommandFile);
1465 #endif
1467 // -----------------------------------------------------------------------------
1468 void ODriver::checkAndRestart(const ::rtl::OUString& sDBName,const TDatabaseStruct& _rDbInfo)
1470 String sWorkUrl(m_sDbWorkURL);
1471 String sExt = String::CreateFromAscii(".st");
1472 ::utl::TempFile aCmdFile(String::CreateFromAscii("State"),&sExt,&sWorkUrl);
1473 aCmdFile.EnableKillingFile();
1475 X_CONS(sDBName,"STATE",aCmdFile.GetURL());
1476 SvStream* pFileStream = aCmdFile.GetStream(STREAM_SHARE_DENYALL);
1477 if ( pFileStream )
1479 ByteString sStateLine;
1480 sal_Bool bRead = sal_True;
1481 sal_Int32 nStart = 2;
1482 while(bRead && !pFileStream->IsEof())
1484 String aLine;
1485 bRead = pFileStream->ReadLine(sStateLine);
1486 if(bRead)
1488 if(sStateLine.Search("WARM") != STRING_NOTFOUND)
1489 { // nothing to do
1490 nStart = 0;
1491 break;
1493 else if(sStateLine.Search("COLD") != STRING_NOTFOUND)
1495 nStart = 1;
1496 break;
1500 switch(nStart)
1502 case 2:
1503 clearDatabase(sDBName);
1504 X_START(sDBName);
1505 // don't break here
1506 case 1:
1507 XUTIL(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("RESTART")),sDBName,_rDbInfo.sControlUser,_rDbInfo.sControlPassword);
1508 case 0:
1509 break;
1513 // -----------------------------------------------------------------------------
1514 sal_Bool ODriver::isVersion(const ::rtl::OUString& sDBName, const char* _pVersion)
1516 String sWorkUrl(m_sDbWorkURL);
1517 String sExt = String::CreateFromAscii(".st");
1518 ::utl::TempFile aCmdFile(String::CreateFromAscii("DevSpaces"),&sExt,&sWorkUrl);
1519 aCmdFile.EnableKillingFile();
1521 String sPhysicalPath;
1522 LocalFileHelper::ConvertURLToPhysicalName(aCmdFile.GetURL(),sPhysicalPath);
1524 String sCommandFile = generateInitFile();
1526 ::std::auto_ptr<SvStream> pFileStream( UcbStreamHelper::CreateStream(sCommandFile,STREAM_STD_READWRITE));
1527 pFileStream->Seek(STREAM_SEEK_TO_END);
1529 (*pFileStream) << "getparam"
1530 #if defined(WIN) || defined(WNT)
1531 << ".exe"
1532 #endif
1533 << " "
1534 << ::rtl::OString(sDBName,sDBName.getLength(),gsl_getSystemTextEncoding())
1535 << " KERNELVERSION > "
1536 << ::rtl::OString(sPhysicalPath.GetBuffer(),sPhysicalPath.Len(),gsl_getSystemTextEncoding())
1537 << sNewLine;
1540 OProcess aApp(sCommandFile ,m_sDbWorkURL);
1541 aApp.execute( (OProcess::TProcessOption)OPROCESS_ADABAS);
1542 #if OSL_DEBUG_LEVEL < 2
1543 if(UCBContentHelper::Exists(sCommandFile))
1544 UCBContentHelper::Kill(sCommandFile);
1545 #endif
1546 SvStream* pFileStream = aCmdFile.GetStream(STREAM_STD_READWRITE);
1547 ByteString sStateLine;
1548 sal_Bool bRead = sal_True;
1549 sal_Bool bIsVersion = sal_False;
1550 while ( pFileStream && bRead && !pFileStream->IsEof() )
1552 bRead = pFileStream->ReadLine(sStateLine);
1553 if ( bRead )
1555 bIsVersion = sStateLine.GetToken(1,' ').Equals(_pVersion) != 0;
1556 break;
1559 return bIsVersion;
1561 // -----------------------------------------------------------------------------
1562 void ODriver::checkAndInsertNewDevSpace(const ::rtl::OUString& sDBName,
1563 const TDatabaseStruct& _rDBInfo)
1565 // %DBROOT%\pgm\getparam %2 DATA_CACHE_PAGES > %3
1566 String sWorkUrl(m_sDbWorkURL);
1567 String sExt = String::CreateFromAscii(".st");
1568 ::utl::TempFile aCmdFile(String::CreateFromAscii("DevSpaces"),&sExt,&sWorkUrl);
1569 aCmdFile.EnableKillingFile();
1571 String sPhysicalPath;
1572 LocalFileHelper::ConvertURLToPhysicalName(aCmdFile.GetURL(),sPhysicalPath);
1574 String sCommandFile = generateInitFile();
1576 ::std::auto_ptr<SvStream> pFileStream( UcbStreamHelper::CreateStream(sCommandFile,STREAM_STD_READWRITE));
1577 pFileStream->Seek(STREAM_SEEK_TO_END);
1579 (*pFileStream) << "getparam"
1580 #if defined(WIN) || defined(WNT)
1581 << ".exe"
1582 #endif
1583 << " "
1584 << ::rtl::OString(sDBName,sDBName.getLength(),gsl_getSystemTextEncoding())
1585 << " DATA_CACHE_PAGES > "
1586 << ::rtl::OString(sPhysicalPath.GetBuffer(),sPhysicalPath.Len(),gsl_getSystemTextEncoding())
1587 << sNewLine;
1590 OProcess aApp(sCommandFile ,m_sDbWorkURL);
1591 aApp.execute( (OProcess::TProcessOption)OPROCESS_ADABAS);
1592 #if OSL_DEBUG_LEVEL < 2
1593 if(UCBContentHelper::Exists(sCommandFile))
1594 UCBContentHelper::Kill(sCommandFile);
1595 #endif
1596 SvStream* pFileStream = aCmdFile.GetStream(STREAM_STD_READWRITE);
1597 ByteString sStateLine;
1598 sal_Bool bRead = sal_True;
1599 sal_Int32 nDataPages = 0;
1600 while(pFileStream && bRead && !pFileStream->IsEof())
1602 bRead = pFileStream->ReadLine(sStateLine);
1603 if(bRead)
1605 nDataPages = sStateLine.ToInt32();
1606 if(nDataPages && nDataPages < 100)
1608 // the space isn't big enough anymore so we increment it
1609 PutParam(sDBName,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DATA_CACHE_PAGES")),::rtl::OUString::valueOf(nDataPages));
1610 X_PARAM(sDBName,_rDBInfo.sControlUser,_rDBInfo.sControlPassword,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("BCHECK")));
1615 // -----------------------------------------------------------------------------
1616 sal_Bool ODriver::isKernelVersion(const char* _pVersion)
1618 ::utl::TempFile aCmdFile(String::CreateFromAscii("KernelVersion"));
1619 aCmdFile.EnableKillingFile();
1621 String sPhysicalPath;
1622 LocalFileHelper::ConvertURLToPhysicalName(aCmdFile.GetURL(),sPhysicalPath);
1624 String sCommandFile = generateInitFile();
1626 ::std::auto_ptr<SvStream> pFileStream( UcbStreamHelper::CreateStream(sCommandFile,STREAM_STD_READWRITE));
1627 pFileStream->Seek(STREAM_SEEK_TO_END);
1629 (*pFileStream) << "dbversion"
1630 << " > "
1631 << ::rtl::OString(sPhysicalPath.GetBuffer(),sPhysicalPath.Len(),gsl_getSystemTextEncoding())
1632 << sNewLine;
1635 OProcess aApp(sCommandFile ,m_sDbWorkURL);
1636 aApp.execute( (OProcess::TProcessOption)OPROCESS_ADABAS);
1637 #if OSL_DEBUG_LEVEL < 2
1638 if(UCBContentHelper::Exists(sCommandFile))
1639 UCBContentHelper::Kill(sCommandFile);
1640 #endif
1641 SvStream* pFileStream = aCmdFile.GetStream(STREAM_STD_READWRITE);
1642 ByteString sStateLine;
1643 sal_Bool bRead = sal_True;
1644 sal_Bool bIsVersion = sal_True;
1645 while ( pFileStream && bRead && !pFileStream->IsEof() )
1647 bRead = pFileStream->ReadLine(sStateLine);
1648 if ( bRead )
1650 // convert a 11.02.00 to a 12.01.30 version
1651 bIsVersion = sStateLine.GetToken(0).Equals(_pVersion) != 0;
1652 break;
1655 return bIsVersion;
1657 // -----------------------------------------------------------------------------
1658 void ODriver::installSystemTables( const TDatabaseStruct& _aInfo)
1660 #if defined(WIN) || defined(WNT)
1661 // xutil -d %_DBNAME% -u %_CONTROL_USER%,%_CONTROL_PWD% -b %m_sDbRoot%\env\TERMCHAR.ind
1662 ::rtl::OUString aBatch = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("-b "));
1663 ::rtl::OUString sTemp2 = m_sDbRootURL + m_sDelimit
1664 + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("env"))
1665 + m_sDelimit
1666 + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TERMCHAR.ind"));
1667 String sTemp;
1668 sal_Bool bOk = LocalFileHelper::ConvertURLToPhysicalName(sTemp2,sTemp);
1669 aBatch += sTemp;
1671 XUTIL(aBatch,_aInfo.sDBName,_aInfo.sControlUser,_aInfo.sControlPassword);
1673 // xutil -d %_DBNAME% -u %_CONTROL_USER%,%_CONTROL_PWD% DIAGNOSE TRIGGER OFF
1674 XUTIL(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DIAGNOSE TRIGGER OFF")),_aInfo.sDBName,_aInfo.sControlUser,_aInfo.sControlPassword);
1675 // xload -d %_DBNAME% -u %_SYSDBA_USER%,%_SYSDBA_PWD% -S NATIVE -b %m_sDbRoot%\env\DBS.ins %_DOMAINPWD%
1677 sTemp2 = m_sDbRootURL
1678 + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("env"))
1679 + m_sDelimit
1680 + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DBS.ins"));
1681 sTemp.Erase();
1682 bOk = LocalFileHelper::ConvertURLToPhysicalName(sTemp2,sTemp);
1683 OSL_ENSURE(bOk,"File could be converted into file system path!");
1684 sTemp.AppendAscii(" ");
1685 sTemp += String(_aInfo.sDomainPassword);
1687 LoadBatch(_aInfo.sDBName,_aInfo.sSysUser,_aInfo.sSysPassword,sTemp);
1689 // xload -d %_DBNAME% -u DOMAIN,%_DOMAINPWD% -S NATIVE -b %m_sDbRoot%\env\XDD.ins
1691 sTemp2 = m_sDbRootURL
1692 + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("env"))
1693 + m_sDelimit
1694 + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("XDD.ins"));
1695 sTemp.Erase();
1696 bOk = LocalFileHelper::ConvertURLToPhysicalName(sTemp2,sTemp);
1697 OSL_ENSURE(bOk,"File could be converted into file system path!");
1699 LoadBatch(_aInfo.sDBName,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DOMAIN")),_aInfo.sDomainPassword,sTemp);
1701 // xload -d %_DBNAME% -u %_SYSDBA_USER%,%_SYSDBA_PWD% -S NATIVE -b %m_sDbRoot%\env\QP.ins
1703 sTemp2 = m_sDbRootURL
1704 + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("env"))
1705 + m_sDelimit
1706 + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("QP.ins"));
1707 sTemp.Erase();
1708 bOk = LocalFileHelper::ConvertURLToPhysicalName(sTemp2,sTemp);
1709 OSL_ENSURE(bOk,"File could be converted into file system path!");
1710 LoadBatch(_aInfo.sDBName,_aInfo.sSysUser,_aInfo.sSysPassword,sTemp);
1712 // xload -d %_DBNAME% -u DOMAIN,%_DOMAINPWD% -S NATIVE -b %m_sDbRoot%\env\SPROC.ins
1714 sTemp2 = m_sDbRootURL
1715 + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("env"))
1716 + m_sDelimit
1717 + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SPROC.ins"));
1718 sTemp.Erase();
1719 bOk = LocalFileHelper::ConvertURLToPhysicalName(sTemp2,sTemp);
1720 OSL_ENSURE(bOk,"File could be converted into file system path!");
1722 LoadBatch(_aInfo.sDBName,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DOMAIN")),_aInfo.sDomainPassword,sTemp);
1725 // xutil -d %_DBNAME% -u %_CONTROL_USER%,%_CONTROL_PWD% DIAGNOSE TRIGGER ON
1726 XUTIL(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DIAGNOSE TRIGGER ON")),_aInfo.sDBName,_aInfo.sControlUser,_aInfo.sControlPassword);
1727 // xutil -d %_DBNAME% -u %_CONTROL_USER%,%_CONTROL_PWD% SET NOLOG OFF
1728 XUTIL(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SET NOLOG OFF")),_aInfo.sDBName,_aInfo.sControlUser,_aInfo.sControlPassword);
1729 // xutil -d %_DBNAME% -u %_CONTROL_USER%,%_CONTROL_PWD% SHUTDOWN QUICK
1730 XUTIL(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SHUTDOWN QUICK")),_aInfo.sDBName,_aInfo.sControlUser,_aInfo.sControlPassword);
1731 // xutil -d %_DBNAME% -u %_CONTROL_USER%,%_CONTROL_PWD% RESTART
1732 XUTIL(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("RESTART")),_aInfo.sDBName,_aInfo.sControlUser,_aInfo.sControlPassword);
1734 #else // UNX
1735 String sCommandFile = generateInitFile();
1737 ::std::auto_ptr<SvStream> pFileStream( UcbStreamHelper::CreateStream(sCommandFile,STREAM_STD_READWRITE));
1738 pFileStream->Seek(STREAM_SEEK_TO_END);
1739 (*pFileStream) << "x_dbinst"
1740 << " -d "
1741 << ::rtl::OString(_aInfo.sDBName,_aInfo.sDBName.getLength(),gsl_getSystemTextEncoding())
1742 << " -u "
1743 << ::rtl::OString(_aInfo.sSysUser,_aInfo.sSysUser.getLength(),gsl_getSystemTextEncoding())
1744 << ","
1745 << ::rtl::OString(_aInfo.sSysPassword,_aInfo.sSysPassword.getLength(),gsl_getSystemTextEncoding())
1746 << " -w "
1747 << ::rtl::OString(_aInfo.sDomainPassword,_aInfo.sDomainPassword.getLength(),gsl_getSystemTextEncoding())
1748 << " -b ";
1750 if ( isKernelVersion(ADABAS_KERNEL_11) )
1751 (*pFileStream) << "-i all";
1752 (*pFileStream)
1753 #if (OSL_DEBUG_LEVEL > 1) || defined(DBG_UTIL)
1754 << " >> /tmp/kstart.log"
1755 #else
1756 << " > /dev/null"
1757 #endif
1758 << sNewLine
1759 << sNewLine;
1760 pFileStream->Flush();
1762 // now execute the command
1763 OProcess aApp(sCommandFile ,m_sDbWorkURL);
1764 aApp.execute( (OProcess::TProcessOption)(OProcess::TOption_Hidden | OProcess::TOption_Wait));
1765 #if OSL_DEBUG_LEVEL < 2
1766 if(UCBContentHelper::Exists(sCommandFile))
1767 UCBContentHelper::Kill(sCommandFile);
1768 #endif
1770 #endif //WNT,UNX
1772 // -----------------------------------------------------------------------------
1773 void ODriver::convertOldVersion(const ::rtl::OUString& sDBName,const TDatabaseStruct& _rDbInfo)
1775 // first we have to check if this databse is a old version and we have to update the system tables
1776 if ( !isVersion(sDBName,CURRENT_DB_VERSION) && isKernelVersion(CURRENT_DB_VERSION) )
1778 if ( !_rDbInfo.sControlUser.getLength()
1779 || !_rDbInfo.sControlPassword.getLength())
1781 ::connectivity::SharedResources aResources;
1782 const ::rtl::OUString sError( aResources.getResourceString(STR_DATABASE_NEEDS_CONVERTING) );
1783 ::dbtools::throwGenericSQLException(sError,*this);
1785 String sCommandFile = m_sDbWorkURL;
1786 sCommandFile += String::CreateFromAscii("/xparam.prt");
1787 if ( UCBContentHelper::Exists(sCommandFile) )
1788 UCBContentHelper::Kill(sCommandFile);
1789 X_PARAM(sDBName,_rDbInfo.sControlUser,_rDbInfo.sControlPassword,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("BCHECK")));
1791 if ( UCBContentHelper::Exists(sCommandFile) )
1794 ::std::auto_ptr<SvStream> pFileStream( UcbStreamHelper::CreateStream(sCommandFile,STREAM_STD_READ) );
1795 ByteString sStateLine;
1796 sal_Bool bRead = sal_True;
1797 static ByteString s_ErrorId("-21100");
1798 while ( pFileStream.get() && bRead && !pFileStream->IsEof() )
1800 bRead = pFileStream->ReadLine(sStateLine);
1801 if ( bRead && s_ErrorId == sStateLine.GetToken(0,' ') )
1803 UCBContentHelper::Kill(sCommandFile);
1804 ::rtl::OUString sError(::rtl::OUString::createFromAscii(sStateLine.GetBuffer()));
1805 throw SQLException(sError,*this,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("S1000")),1000,Any());
1810 UCBContentHelper::Kill(sCommandFile);
1814 // -----------------------------------------------------------------------------
1815 // -----------------------------------------------------------------------------
1816 } // namespace adabas
1817 }// namespace connectivity
1818 // -----------------------------------------------------------------------------