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