1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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"
55 const char sNewLine
= '\015';
57 const char sNewLine
= '\012';
59 const char sNewLine
[] = "\015\012"; // \015\012 and not \n
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
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
;
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
);
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
);
245 Reference
< XEventListener
> xEvtL((::cppu::OWeakObject
*)this,UNO_QUERY
);
246 xComponent
->removeEventListener(xEvtL
);
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"));
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
);
323 // --------------------------------------------------------------------------------
324 Reference
< XConnection
> SAL_CALL
ODriver::connect( const ::rtl::OUString
& url
, const Sequence
< PropertyValue
>& info
) throw(SQLException
, RuntimeException
)
326 if ( ! acceptsURL(url
) )
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
;
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
);
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
));
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."))
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."))
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."))
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)."))
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."))
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
)
453 // --------------------------------------------------------------------------------
454 sal_Int32 SAL_CALL
ODriver::getMinorVersion( ) throw(RuntimeException
)
458 // -----------------------------------------------------------------------------
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";
473 m_sDbRunDir
= m_sDbWorkURL
+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/wrk/")) + aDBInfo
.sDBName
;
475 LocalFileHelper::ConvertURLToPhysicalName(m_sDbRunDir
,sTemp
);
478 createNeededDirs(aDBInfo
.sDBName
);
479 if(CreateFiles(aDBInfo
))
481 ::connectivity::SharedResources aResources
;
482 const ::rtl::OUString
sError( aResources
.getResourceStringWithSubstitution(
484 "$filename$",aDBInfo
.sDBName
486 ::dbtools::throwGenericSQLException(sError
,*this);
487 } // if(CreateFiles(aDBInfo))
491 catch( SQLException
&)
497 throw SQLException();
501 // -----------------------------------------------------------------------------
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 ...
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
);
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
;
563 xTab
= pConnection
->createCatalog();
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();
593 // -----------------------------------------------------------------------------
594 oslGenericFunction
ODriver::getOdbcFunction(sal_Int32 _nIndex
) const
596 oslGenericFunction pFunction
= NULL
;
599 case ODBC3SQLAllocHandle
:
600 pFunction
= (oslGenericFunction
)pODBC3SQLAllocHandle
;;
602 case ODBC3SQLConnect
:
603 pFunction
= (oslGenericFunction
)pODBC3SQLConnect
;
605 case ODBC3SQLDriverConnect
:
606 pFunction
= (oslGenericFunction
)pODBC3SQLDriverConnect
;
608 case ODBC3SQLBrowseConnect
:
609 pFunction
= (oslGenericFunction
)pODBC3SQLBrowseConnect
;
611 case ODBC3SQLDataSources
:
612 pFunction
= (oslGenericFunction
)pODBC3SQLDataSources
;
614 case ODBC3SQLDrivers
:
615 pFunction
= (oslGenericFunction
)pODBC3SQLDrivers
;
617 case ODBC3SQLGetInfo
:
619 pFunction
= (oslGenericFunction
)pODBC3SQLGetInfo
;
621 case ODBC3SQLGetFunctions
:
623 pFunction
= (oslGenericFunction
)pODBC3SQLGetFunctions
;
625 case ODBC3SQLGetTypeInfo
:
627 pFunction
= (oslGenericFunction
)pODBC3SQLGetTypeInfo
;
629 case ODBC3SQLSetConnectAttr
:
631 pFunction
= (oslGenericFunction
)pODBC3SQLSetConnectAttr
;
633 case ODBC3SQLGetConnectAttr
:
635 pFunction
= (oslGenericFunction
)pODBC3SQLGetConnectAttr
;
637 case ODBC3SQLSetEnvAttr
:
639 pFunction
= (oslGenericFunction
)pODBC3SQLSetEnvAttr
;
641 case ODBC3SQLGetEnvAttr
:
643 pFunction
= (oslGenericFunction
)pODBC3SQLGetEnvAttr
;
645 case ODBC3SQLSetStmtAttr
:
647 pFunction
= (oslGenericFunction
)pODBC3SQLSetStmtAttr
;
649 case ODBC3SQLGetStmtAttr
:
651 pFunction
= (oslGenericFunction
)pODBC3SQLGetStmtAttr
;
653 case ODBC3SQLPrepare
:
655 pFunction
= (oslGenericFunction
)pODBC3SQLPrepare
;
657 case ODBC3SQLBindParameter
:
659 pFunction
= (oslGenericFunction
)pODBC3SQLBindParameter
;
661 case ODBC3SQLSetCursorName
:
663 pFunction
= (oslGenericFunction
)pODBC3SQLSetCursorName
;
665 case ODBC3SQLExecute
:
667 pFunction
= (oslGenericFunction
)pODBC3SQLExecute
;
669 case ODBC3SQLExecDirect
:
671 pFunction
= (oslGenericFunction
)pODBC3SQLExecDirect
;
673 case ODBC3SQLDescribeParam
:
675 pFunction
= (oslGenericFunction
)pODBC3SQLDescribeParam
;
677 case ODBC3SQLNumParams
:
679 pFunction
= (oslGenericFunction
)pODBC3SQLNumParams
;
681 case ODBC3SQLParamData
:
683 pFunction
= (oslGenericFunction
)pODBC3SQLParamData
;
685 case ODBC3SQLPutData
:
687 pFunction
= (oslGenericFunction
)pODBC3SQLPutData
;
689 case ODBC3SQLRowCount
:
691 pFunction
= (oslGenericFunction
)pODBC3SQLRowCount
;
693 case ODBC3SQLNumResultCols
:
695 pFunction
= (oslGenericFunction
)pODBC3SQLNumResultCols
;
697 case ODBC3SQLDescribeCol
:
699 pFunction
= (oslGenericFunction
)pODBC3SQLDescribeCol
;
701 case ODBC3SQLColAttribute
:
703 pFunction
= (oslGenericFunction
)pODBC3SQLColAttribute
;
705 case ODBC3SQLBindCol
:
707 pFunction
= (oslGenericFunction
)pODBC3SQLBindCol
;
711 pFunction
= (oslGenericFunction
)pODBC3SQLFetch
;
713 case ODBC3SQLFetchScroll
:
715 pFunction
= (oslGenericFunction
)pODBC3SQLFetchScroll
;
717 case ODBC3SQLGetData
:
719 pFunction
= (oslGenericFunction
)pODBC3SQLGetData
;
723 pFunction
= (oslGenericFunction
)pODBC3SQLSetPos
;
725 case ODBC3SQLBulkOperations
:
727 pFunction
= (oslGenericFunction
)pODBC3SQLBulkOperations
;
729 case ODBC3SQLMoreResults
:
731 pFunction
= (oslGenericFunction
)pODBC3SQLMoreResults
;
733 case ODBC3SQLGetDiagRec
:
735 pFunction
= (oslGenericFunction
)pODBC3SQLGetDiagRec
;
737 case ODBC3SQLColumnPrivileges
:
739 pFunction
= (oslGenericFunction
)pODBC3SQLColumnPrivileges
;
741 case ODBC3SQLColumns
:
743 pFunction
= (oslGenericFunction
)pODBC3SQLColumns
;
745 case ODBC3SQLForeignKeys
:
747 pFunction
= (oslGenericFunction
)pODBC3SQLForeignKeys
;
749 case ODBC3SQLPrimaryKeys
:
751 pFunction
= (oslGenericFunction
)pODBC3SQLPrimaryKeys
;
753 case ODBC3SQLProcedureColumns
:
755 pFunction
= (oslGenericFunction
)pODBC3SQLProcedureColumns
;
757 case ODBC3SQLProcedures
:
759 pFunction
= (oslGenericFunction
)pODBC3SQLProcedures
;
761 case ODBC3SQLSpecialColumns
:
763 pFunction
= (oslGenericFunction
)pODBC3SQLSpecialColumns
;
765 case ODBC3SQLStatistics
:
767 pFunction
= (oslGenericFunction
)pODBC3SQLStatistics
;
769 case ODBC3SQLTablePrivileges
:
771 pFunction
= (oslGenericFunction
)pODBC3SQLTablePrivileges
;
775 pFunction
= (oslGenericFunction
)pODBC3SQLTables
;
777 case ODBC3SQLFreeStmt
:
779 pFunction
= (oslGenericFunction
)pODBC3SQLFreeStmt
;
781 case ODBC3SQLCloseCursor
:
783 pFunction
= (oslGenericFunction
)pODBC3SQLCloseCursor
;
787 pFunction
= (oslGenericFunction
)pODBC3SQLCancel
;
789 case ODBC3SQLEndTran
:
791 pFunction
= (oslGenericFunction
)pODBC3SQLEndTran
;
793 case ODBC3SQLDisconnect
:
795 pFunction
= (oslGenericFunction
)pODBC3SQLDisconnect
;
797 case ODBC3SQLFreeHandle
:
799 pFunction
= (oslGenericFunction
)pODBC3SQLFreeHandle
;
801 case ODBC3SQLGetCursorName
:
803 pFunction
= (oslGenericFunction
)pODBC3SQLGetCursorName
;
805 case ODBC3SQLNativeSql
:
807 pFunction
= (oslGenericFunction
)pODBC3SQLNativeSql
;
810 OSL_ENSURE(0,"Function unknown!");
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("/"));
833 sTemp
+= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("config"));
834 if(!UCBContentHelper::IsFolder(sTemp
))
835 UCBContentHelper::MakeFolder(sTemp
);
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("/"));
851 sTemp
+= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("config"));
852 if(!UCBContentHelper::IsFolder(sTemp
))
853 UCBContentHelper::MakeFolder(sTemp
);
855 sTemp
+= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/"));
857 if(UCBContentHelper::Exists(sTemp
))
858 UCBContentHelper::Kill(sTemp
);
860 #if !(defined(WIN) || defined(WNT))
862 sTemp
+= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("diag"));
863 if(!UCBContentHelper::IsFolder(sTemp
))
864 UCBContentHelper::MakeFolder(sTemp
);
867 sTemp
+= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ipc"));
868 if(!UCBContentHelper::IsFolder(sTemp
))
869 UCBContentHelper::MakeFolder(sTemp
);
872 sTemp
+= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("spool"));
873 if(!UCBContentHelper::IsFolder(sTemp
))
874 UCBContentHelper::MakeFolder(sTemp
);
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"));
887 OArgumentList
aArgs(1,&sDBName
);
888 sCommand
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("x_clear"));
891 OProcess
aApp( sCommand
,m_sDbWorkURL
);
892 #if OSL_DEBUG_LEVEL > 0
893 OProcess::TProcessError eError
=
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"));
907 LocalFileHelper::ConvertURLToPhysicalName(_aInfo
.sSysDevSpace
,sTemp
);
909 PutParam(_aInfo
.sDBName
,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SYSDEVSPACE")),sTemp
);
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")));
931 X_PARAM(_aInfo
.sDBName
,_aInfo
.sControlUser
,_aInfo
.sControlPassword
,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("BCHECK")));
933 X_START(_aInfo
.sDBName
);
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)
941 // DirEntry aTmp(INITCMD);
942 // aTmp.CopyTo(aInitFile, FSYS_ACTION_COPYFILE);
943 // INITCMD = aInitFile.GetFull();
945 // generate the init file for the database
946 String sInitFile
= getDatabaseInitFile(_aInfo
);
948 LocalFileHelper::ConvertURLToPhysicalName(sInitFile
,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
);
956 // install system tables
957 installSystemTables(_aInfo
);
958 // now we have to make our SYSDBA user "NOT EXCLUSIVE"
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 "
972 pFileStream
->Flush();
974 { // just to get sure that the tempfile still lives
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)
999 << ::rtl::OString(_DBNAME
,_DBNAME
.getLength(),gsl_getSystemTextEncoding())
1001 << ::rtl::OString(_USR
,_USR
.getLength(),gsl_getSystemTextEncoding())
1003 << ::rtl::OString(_PWD
,_PWD
.getLength(),gsl_getSystemTextEncoding())
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"
1011 #if (OSL_DEBUG_LEVEL > 1) || defined(DBG_UTIL)
1012 << " >> /tmp/kstart.log"
1021 pFileStream
->Flush();
1024 OProcess
aApp(sCommandFile
,m_sDbWorkURL
);
1025 #if OSL_DEBUG_LEVEL > 0
1026 OProcess::TProcessError eError
=
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
);
1037 // -----------------------------------------------------------------------------
1038 sal_Int32
ODriver::CreateFiles(const TDatabaseStruct
& _aInfo
)
1040 int nRet
= CreateFile(_aInfo
.sSysDevSpace
,_aInfo
.nDataSize
/50) ? 0 : -9;
1042 nRet
= CreateFile(_aInfo
.sTransLogName
,_aInfo
.nLogSize
) ? 0 : -10;
1044 nRet
= CreateFile(_aInfo
.sDataDevName
,_aInfo
.nDataSize
) ? 0 : -11;
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"));
1060 OProcess
aApp(sCommand
,m_sDbWorkURL
);
1061 #if OSL_DEBUG_LEVEL > 0
1062 OProcess::TProcessError eError
=
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
,
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(
1081 "$filename$",_FileName
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
;
1099 OSL_TRACE("Exception");
1103 ::connectivity::SharedResources aResources
;
1104 const ::rtl::OUString
sError( aResources
.getResourceStringWithSubstitution(
1106 "$filename$",_FileName
1108 ::dbtools::throwGenericSQLException(sError
,*this);
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"));
1127 OArgumentList
aArgs(1,&sDBName
);
1128 sCommand
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("x_start"));
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
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
)
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"));
1164 OArgumentList
aArgs(1,&sDBName
);
1165 sCommand
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("x_stop"));
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
)
1175 OProcess::TProcessInfo aInfo
;
1176 if(aApp
.getInfo(OProcess::TData_ExitCode
,&aInfo
) == OProcess::E_None
&& aInfo
.Code
)
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
);
1201 #if defined(WIN) || defined(WNT)
1207 << ::rtl::OString(_USRNAME
,_USRNAME
.getLength(),gsl_getSystemTextEncoding())
1209 << ::rtl::OString(_USRPWD
,_USRPWD
.getLength(),gsl_getSystemTextEncoding())
1211 << ::rtl::OString(_DBNAME
,_DBNAME
.getLength(),gsl_getSystemTextEncoding())
1213 << ::rtl::OString(_rParam
,_rParam
.getLength(),gsl_getSystemTextEncoding())
1215 << ::rtl::OString(sPhysicalPath
.GetBuffer(),sPhysicalPath
.Len(),gsl_getSystemTextEncoding())
1218 pFileStream
->Flush();
1221 OProcess
aApp(sCommandFile
,m_sDbWorkURL
);
1222 #if OSL_DEBUG_LEVEL > 0
1223 OProcess::TProcessError eError
=
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
);
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();
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)
1258 << ::rtl::OString(sDBName
,sDBName
.getLength(),gsl_getSystemTextEncoding())
1260 << ::rtl::OString(_rUSR
,_rUSR
.getLength(),gsl_getSystemTextEncoding())
1262 << ::rtl::OString(_rPWD
,_rPWD
.getLength(),gsl_getSystemTextEncoding());
1264 if ( !isKernelVersion(CURRENT_DB_VERSION
) )
1265 (*pFileStream
) << " -S adabas -b ";
1267 (*pFileStream
) << " -S NATIVE -b ";
1269 (*pFileStream
) << ::rtl::OString(_rBatch
,_rBatch
.getLength(),gsl_getSystemTextEncoding())
1271 << ::rtl::OString(sPhysicalPath
.GetBuffer(),sPhysicalPath
.Len(),gsl_getSystemTextEncoding())
1275 pFileStream
->Flush();
1278 OProcess
aApp(sCommandFile
,m_sDbWorkURL
);
1279 #if OSL_DEBUG_LEVEL > 0
1280 OProcess::TProcessError eError
=
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
);
1289 // -----------------------------------------------------------------------------
1290 void ODriver::fillEnvironmentVariables()
1292 // read the environment vars
1295 const sal_Char
* pAsciiEnvName
;
1296 ::rtl::OUString
* pValue
;
1297 ::rtl::OUString
* pValueURL
;
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
;
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
1323 #if !(defined(WIN) || defined(WNT))
1324 sExt
= String::CreateFromAscii(".sh");
1326 sExt
= String::CreateFromAscii(".bat");
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
);
1337 #if !(defined(WIN) || defined(WNT))
1338 SvStream
* pFileStream
= aCmdFile
.GetStream(STREAM_WRITE
);
1339 (*pFileStream
) << "#!/bin/sh"
1344 pFileStream
->Flush();
1347 return aCmdFile
.GetURL();
1349 // -----------------------------------------------------------------------------
1350 ::rtl::OUString
ODriver::getDatabaseInitFile( const TDatabaseStruct
& _aDBInfo
)
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";
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";
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";
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 '";
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";
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)
1451 << ::rtl::OString(sDBName
,sDBName
.getLength(),gsl_getSystemTextEncoding())
1455 << ::rtl::OString(sPhysicalPath
.GetBuffer(),sPhysicalPath
.Len(),gsl_getSystemTextEncoding())
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
);
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
);
1479 ByteString sStateLine
;
1480 sal_Bool bRead
= sal_True
;
1481 sal_Int32 nStart
= 2;
1482 while(bRead
&& !pFileStream
->IsEof())
1485 bRead
= pFileStream
->ReadLine(sStateLine
);
1488 if(sStateLine
.Search("WARM") != STRING_NOTFOUND
)
1493 else if(sStateLine
.Search("COLD") != STRING_NOTFOUND
)
1503 clearDatabase(sDBName
);
1507 XUTIL(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("RESTART")),sDBName
,_rDbInfo
.sControlUser
,_rDbInfo
.sControlPassword
);
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)
1534 << ::rtl::OString(sDBName
,sDBName
.getLength(),gsl_getSystemTextEncoding())
1535 << " KERNELVERSION > "
1536 << ::rtl::OString(sPhysicalPath
.GetBuffer(),sPhysicalPath
.Len(),gsl_getSystemTextEncoding())
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
);
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
);
1555 bIsVersion
= sStateLine
.GetToken(1,' ').Equals(_pVersion
) != 0;
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)
1584 << ::rtl::OString(sDBName
,sDBName
.getLength(),gsl_getSystemTextEncoding())
1585 << " DATA_CACHE_PAGES > "
1586 << ::rtl::OString(sPhysicalPath
.GetBuffer(),sPhysicalPath
.Len(),gsl_getSystemTextEncoding())
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
);
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
);
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"
1631 << ::rtl::OString(sPhysicalPath
.GetBuffer(),sPhysicalPath
.Len(),gsl_getSystemTextEncoding())
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
);
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
);
1650 // convert a 11.02.00 to a 12.01.30 version
1651 bIsVersion
= sStateLine
.GetToken(0).Equals(_pVersion
) != 0;
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"))
1666 + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TERMCHAR.ind"));
1668 sal_Bool bOk
= LocalFileHelper::ConvertURLToPhysicalName(sTemp2
,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"))
1680 + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DBS.ins"));
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"))
1694 + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("XDD.ins"));
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"))
1706 + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("QP.ins"));
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"))
1717 + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SPROC.ins"));
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
);
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"
1741 << ::rtl::OString(_aInfo
.sDBName
,_aInfo
.sDBName
.getLength(),gsl_getSystemTextEncoding())
1743 << ::rtl::OString(_aInfo
.sSysUser
,_aInfo
.sSysUser
.getLength(),gsl_getSystemTextEncoding())
1745 << ::rtl::OString(_aInfo
.sSysPassword
,_aInfo
.sSysPassword
.getLength(),gsl_getSystemTextEncoding())
1747 << ::rtl::OString(_aInfo
.sDomainPassword
,_aInfo
.sDomainPassword
.getLength(),gsl_getSystemTextEncoding())
1750 if ( isKernelVersion(ADABAS_KERNEL_11
) )
1751 (*pFileStream
) << "-i all";
1753 #if (OSL_DEBUG_LEVEL > 1) || defined(DBG_UTIL)
1754 << " >> /tmp/kstart.log"
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
);
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 // -----------------------------------------------------------------------------