diff options
author | Ocke Janssen <oj@openoffice.org> | 2001-03-30 13:01:50 +0000 |
---|---|---|
committer | Ocke Janssen <oj@openoffice.org> | 2001-03-30 13:01:50 +0000 |
commit | 2c7d09b02814986e858d37e34eef123bf913b208 (patch) | |
tree | 7ca478b935ba6318c07d344867771b2e9fe6c522 /connectivity/source/drivers | |
parent | 6388eec544b14749fcce25123f1d4d315431cc4b (diff) |
#85298##85297# correct index impl
Diffstat (limited to 'connectivity/source/drivers')
-rw-r--r-- | connectivity/source/drivers/dbase/DColumns.cxx | 6 | ||||
-rw-r--r-- | connectivity/source/drivers/dbase/DDatabaseMetaData.cxx | 30 | ||||
-rw-r--r-- | connectivity/source/drivers/dbase/DIndex.cxx | 407 | ||||
-rw-r--r-- | connectivity/source/drivers/dbase/DIndexes.cxx | 60 | ||||
-rw-r--r-- | connectivity/source/drivers/dbase/DTables.cxx | 6 | ||||
-rw-r--r-- | connectivity/source/drivers/dbase/dindexnode.cxx | 25 |
6 files changed, 279 insertions, 255 deletions
diff --git a/connectivity/source/drivers/dbase/DColumns.cxx b/connectivity/source/drivers/dbase/DColumns.cxx index 248f7e8188e7..00e610b82bf8 100644 --- a/connectivity/source/drivers/dbase/DColumns.cxx +++ b/connectivity/source/drivers/dbase/DColumns.cxx @@ -2,9 +2,9 @@ * * $RCSfile: DColumns.cxx,v $ * - * $Revision: 1.5 $ + * $Revision: 1.6 $ * - * last change: $Author: oj $ $Date: 2001-03-28 11:31:44 $ + * last change: $Author: oj $ $Date: 2001-03-30 13:57:18 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -133,7 +133,7 @@ void SAL_CALL ODbaseColumns::dropByIndex( sal_Int32 index ) throw(SQLException, { ::osl::MutexGuard aGuard(m_rMutex); if (index < 0 || index >= getCount()) - throw IndexOutOfBoundsException(); + throw IndexOutOfBoundsException(::rtl::OUString::valueOf(index),*this); if(!m_pTable->isNew()) { diff --git a/connectivity/source/drivers/dbase/DDatabaseMetaData.cxx b/connectivity/source/drivers/dbase/DDatabaseMetaData.cxx index 21bc450f341e..b66d283609d6 100644 --- a/connectivity/source/drivers/dbase/DDatabaseMetaData.cxx +++ b/connectivity/source/drivers/dbase/DDatabaseMetaData.cxx @@ -2,9 +2,9 @@ * * $RCSfile: DDatabaseMetaData.cxx,v $ * - * $Revision: 1.17 $ + * $Revision: 1.18 $ * - * last change: $Author: oj $ $Date: 2001-03-28 11:31:44 $ + * last change: $Author: oj $ $Date: 2001-03-30 13:57:18 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -108,14 +108,14 @@ #endif using namespace connectivity::dbase; -using namespace connectivity::file; +using namespace connectivity; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::beans; using namespace ::com::sun::star::sdbcx; using namespace ::com::sun::star::sdbc; using namespace ::com::sun::star::container; -ODbaseDatabaseMetaData::ODbaseDatabaseMetaData(OConnection* _pCon) :ODatabaseMetaData(_pCon) +ODbaseDatabaseMetaData::ODbaseDatabaseMetaData(::connectivity::file::OConnection* _pCon) :ODatabaseMetaData(_pCon) { } // ------------------------------------------------------------------------- @@ -127,7 +127,7 @@ Reference< XResultSet > SAL_CALL ODbaseDatabaseMetaData::getTypeInfo( ) throw(S { ::osl::MutexGuard aGuard( m_aMutex ); - ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(); + ::connectivity::ODatabaseMetaDataResultSet* pResult = new ::connectivity::ODatabaseMetaDataResultSet(); Reference< XResultSet > xRef = pResult; pResult->setTypeInfoMap(); ORows aRows; @@ -211,7 +211,7 @@ Reference< XResultSet > SAL_CALL ODbaseDatabaseMetaData::getColumnPrivileges( { ::osl::MutexGuard aGuard( m_aMutex ); - ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(); + ::connectivity::ODatabaseMetaDataResultSet* pResult = new ::connectivity::ODatabaseMetaDataResultSet(); Reference< XResultSet > xRef = pResult; pResult->setColumnPrivilegesMap(); return xRef; @@ -310,7 +310,7 @@ Reference< XResultSet > SAL_CALL ODbaseDatabaseMetaData::getColumns( } } - ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(); + ::connectivity::ODatabaseMetaDataResultSet* pResult = new ::connectivity::ODatabaseMetaDataResultSet(); Reference< XResultSet > xRef = pResult; pResult->setColumnsMap(); pResult->setRows(aRows); @@ -323,7 +323,7 @@ Reference< XResultSet > SAL_CALL ODbaseDatabaseMetaData::getVersionColumns( { ::osl::MutexGuard aGuard( m_aMutex ); - ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(); + ::connectivity::ODatabaseMetaDataResultSet* pResult = new ::connectivity::ODatabaseMetaDataResultSet(); Reference< XResultSet > xRef = pResult; pResult->setVersionColumnsMap(); return xRef; @@ -334,8 +334,8 @@ Reference< XResultSet > SAL_CALL ODbaseDatabaseMetaData::getExportedKeys( { ::osl::MutexGuard aGuard( m_aMutex ); - ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(); - Reference< XResultSet > xRef = pResult; + ::connectivity::ODatabaseMetaDataResultSet* pResult = new ::connectivity::ODatabaseMetaDataResultSet(); + Reference< XResultSet > xRef = pResult; pResult->setExportedKeysMap(); return xRef; } @@ -345,7 +345,7 @@ Reference< XResultSet > SAL_CALL ODbaseDatabaseMetaData::getImportedKeys( { ::osl::MutexGuard aGuard( m_aMutex ); - ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(); + ::connectivity::ODatabaseMetaDataResultSet* pResult = new ::connectivity::ODatabaseMetaDataResultSet(); Reference< XResultSet > xRef = pResult; pResult->setImportedKeysMap(); return xRef; @@ -356,7 +356,7 @@ Reference< XResultSet > SAL_CALL ODbaseDatabaseMetaData::getPrimaryKeys( { ::osl::MutexGuard aGuard( m_aMutex ); - ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(); + ::connectivity::ODatabaseMetaDataResultSet* pResult = new ::connectivity::ODatabaseMetaDataResultSet(); Reference< XResultSet > xRef = pResult; pResult->setPrimaryKeysMap(); return xRef; @@ -437,7 +437,7 @@ Reference< XResultSet > SAL_CALL ODbaseDatabaseMetaData::getIndexInfo( } } - ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(); + ::connectivity::ODatabaseMetaDataResultSet* pResult = new ::connectivity::ODatabaseMetaDataResultSet(); Reference< XResultSet > xRef = pResult; pResult->setIndexInfoMap(); pResult->setRows(aRows); @@ -450,7 +450,7 @@ Reference< XResultSet > SAL_CALL ODbaseDatabaseMetaData::getBestRowIdentifier( { ::osl::MutexGuard aGuard( m_aMutex ); - ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(); + ::connectivity::ODatabaseMetaDataResultSet* pResult = new ::connectivity::ODatabaseMetaDataResultSet(); Reference< XResultSet > xRef = pResult; pResult->setBestRowIdentifierMap(); return xRef; @@ -463,7 +463,7 @@ Reference< XResultSet > SAL_CALL ODbaseDatabaseMetaData::getCrossReference( { ::osl::MutexGuard aGuard( m_aMutex ); - ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(); + ::connectivity::ODatabaseMetaDataResultSet* pResult = new ::connectivity::ODatabaseMetaDataResultSet(); Reference< XResultSet > xRef = pResult; pResult->setCrossReferenceMap(); return xRef; diff --git a/connectivity/source/drivers/dbase/DIndex.cxx b/connectivity/source/drivers/dbase/DIndex.cxx index f7725eb40f40..564a079b130d 100644 --- a/connectivity/source/drivers/dbase/DIndex.cxx +++ b/connectivity/source/drivers/dbase/DIndex.cxx @@ -2,9 +2,9 @@ * * $RCSfile: DIndex.cxx,v $ * - * $Revision: 1.12 $ + * $Revision: 1.13 $ * - * last change: $Author: jl $ $Date: 2001-03-21 13:41:12 $ + * last change: $Author: oj $ $Date: 2001-03-30 13:57:18 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -105,6 +105,21 @@ #ifndef _COMPHELPER_EXTRACT_HXX_ #include <comphelper/extract.hxx> #endif +#ifndef _UNOTOOLS_LOCALFILEHELPER_HXX +#include <unotools/localfilehelper.hxx> +#endif +#ifndef _UNOTOOLS_UCBHELPER_HXX +#include <unotools/ucbhelper.hxx> +#endif +#ifndef _UNTOOLS_UCBSTREAMHELPER_HXX +#include <unotools/ucbstreamhelper.hxx> +#endif +#ifndef _COMPHELPER_TYPES_HXX_ +#include <comphelper/types.hxx> +#endif +#ifndef _DBHELPER_DBEXCEPTION_HXX_ +#include <connectivity/dbexception.hxx> +#endif // define the properties of this lib // this file includes the properties for this dll namespace connectivity @@ -119,6 +134,7 @@ namespace connectivity // ------------------------------------------------------------------------- using namespace connectivity; using namespace ucb; +using namespace utl; using namespace cppu; using namespace connectivity::file; using namespace connectivity::sdbcx; @@ -133,7 +149,10 @@ IMPLEMENT_SERVICE_INFO(ODbaseIndex,"com.sun.star.sdbcx.driver.dbase.Index","com. // ------------------------------------------------------------------------- ODbaseIndex::ODbaseIndex(ODbaseTable* _pTable) : OIndex(_pTable->getConnection()->getMetaData()->storesMixedCaseQuotedIdentifiers()) , m_pTable(_pTable) + ,m_pFileStream(NULL) { + m_aHeader.db_maxkeys = m_aHeader.db_maxkeys = m_aHeader.db_keylen = m_aHeader.db_pagecount = m_aHeader.db_rootpage = 0; + m_aHeader.db_name[0] = '\0'; construct(); } // ------------------------------------------------------------------------- @@ -143,16 +162,27 @@ ODbaseIndex::ODbaseIndex( ODbaseTable* _pTable, : OIndex(_rName,::rtl::OUString(),_rHeader.db_unique,sal_False,sal_False,_pTable->getConnection()->getMetaData()->storesMixedCaseQuotedIdentifiers()) , m_aHeader(_rHeader) , m_pTable(_pTable) + ,m_pFileStream(NULL) { construct(); } +// ----------------------------------------------------------------------------- +ODbaseIndex::~ODbaseIndex() +{ + closeImpl(); +} // ------------------------------------------------------------------------- void ODbaseIndex::refreshColumns() { ::osl::MutexGuard aGuard( m_aMutex ); ::std::vector< ::rtl::OUString> aVector; - aVector.push_back(::rtl::OUString::createFromAscii(m_aHeader.db_name)); + if(!isNew()) + { + OSL_ENSURE(m_pFileStream,"FileStream is not opened!"); + OSL_ENSURE(m_aHeader.db_name[0] != '\0',"Invalid name for the column!"); + aVector.push_back(::rtl::OUString::createFromAscii(m_aHeader.db_name)); + } if(m_pColumns) delete m_pColumns; @@ -198,32 +228,34 @@ ONDXPagePtr ODbaseIndex::getRoot() //------------------------------------------------------------------ sal_Bool ODbaseIndex::openIndexFile() { - if(!m_aFileStream.IsOpen()) + if(!m_pFileStream) { - INetURLObject aURL; - - aURL.SetSmartProtocol(INET_PROT_FILE); - aURL.SetSmartURL(m_pTable->getEntry(), INetURLObject::ENCODE_ALL); - - aURL.setName(m_Name); - aURL.setExtension(String::CreateFromAscii("ndx")); - - // Dir* pDir = m_pTable->getConnection()->getDir(); - // String aPath = pDir->GetName(); - // aPath += m_Name.getStr(); - // DirEntry aEntry(aPath); - // aEntry.setExtension(String::CreateFromAscii("ndx")); - m_aFileStream.Open(aURL.getFSysPath(INetURLObject::FSYS_DETECT), STREAM_READWRITE | STREAM_NOCREATE | STREAM_SHARE_DENYWRITE); - - m_aFileStream.SetNumberFormatInt(NUMBERFORMAT_INT_LITTLEENDIAN); - m_aFileStream.SetBufferSize(512); + ::rtl::OUString sFile = getCompletePath(); + if(UCBContentHelper::Exists(sFile)) + { + m_pFileStream = UcbStreamHelper::CreateStream(sFile,STREAM_READWRITE | STREAM_NOCREATE | STREAM_SHARE_DENYWRITE); + if(!m_pFileStream) + m_pFileStream = UcbStreamHelper::CreateStream(sFile,STREAM_READ | STREAM_NOCREATE | STREAM_SHARE_DENYNONE ); + if(m_pFileStream) + { + m_pFileStream->SetNumberFormatInt(NUMBERFORMAT_INT_LITTLEENDIAN); + m_pFileStream->SetBufferSize(512); + (*m_pFileStream) >> *this; + } + } + if(!m_pFileStream) + { + ::rtl::OUString sErrMsg = ::rtl::OUString::createFromAscii("Could not open index: "); + sErrMsg += sFile; + throw SQLException(sErrMsg,*this,SQLSTATE_GENERAL,1000,Any()); + } } - return m_aFileStream.IsOpen(); + return m_pFileStream != NULL; } //------------------------------------------------------------------ OIndexIterator* ODbaseIndex::createIterator(OBoolOperator* pOp, - const OOperand* pOperand) + const OOperand* pOperand) { openIndexFile(); return new OIndexIterator(this, pOp, pOperand); @@ -231,7 +263,7 @@ OIndexIterator* ODbaseIndex::createIterator(OBoolOperator* pOp, //------------------------------------------------------------------ BOOL ODbaseIndex::ConvertToKey(ONDXKey* rKey, sal_uInt32 nRec, const ORowSetValue& rValue) { - OSL_ENSURE(m_aFileStream.IsOpen(),"FileStream is not opened!"); + OSL_ENSURE(m_pFileStream,"FileStream is not opened!"); // Sucht ein bestimmten Wert im Index // Wenn der Index Unique ist, interssiert der Key nicht, sonst ja try @@ -248,8 +280,9 @@ BOOL ODbaseIndex::ConvertToKey(ONDXKey* rKey, sal_uInt32 nRec, const ORowSetValu *rKey = ONDXKey(rValue.getDouble(), nRec ); } } - catch (...) + catch (Exception&) { + OSL_ASSERT(0); return FALSE; } return TRUE; @@ -259,7 +292,7 @@ BOOL ODbaseIndex::ConvertToKey(ONDXKey* rKey, sal_uInt32 nRec, const ORowSetValu BOOL ODbaseIndex::Find(sal_uInt32 nRec, const ORowSetValue& rValue) { openIndexFile(); - OSL_ENSURE(m_aFileStream.IsOpen(),"FileStream is not opened!"); + OSL_ENSURE(m_pFileStream,"FileStream is not opened!"); // Sucht ein bestimmten Wert im Index // Wenn der Index Unique ist, interssiert der Key nicht, sonst ja ONDXKey aKey; @@ -270,7 +303,7 @@ BOOL ODbaseIndex::Find(sal_uInt32 nRec, const ORowSetValue& rValue) BOOL ODbaseIndex::Insert(sal_uInt32 nRec, const ORowSetValue& rValue) { openIndexFile(); - OSL_ENSURE(m_aFileStream.IsOpen(),"FileStream is not opened!"); + OSL_ENSURE(m_pFileStream,"FileStream is not opened!"); ONDXKey aKey; // Existiert der Wert bereits @@ -295,7 +328,7 @@ BOOL ODbaseIndex::Update(sal_uInt32 nRec, const ORowSetValue& rOldValue, const ORowSetValue& rNewValue) { openIndexFile(); - OSL_ENSURE(m_aFileStream.IsOpen(),"FileStream is not opened!"); + OSL_ENSURE(m_pFileStream,"FileStream is not opened!"); ONDXKey aKey; if (!ConvertToKey(&aKey, nRec, rNewValue) || (isUnique() && getRoot()->Find(aKey))) return FALSE; @@ -307,7 +340,7 @@ BOOL ODbaseIndex::Update(sal_uInt32 nRec, const ORowSetValue& rOldValue, BOOL ODbaseIndex::Delete(sal_uInt32 nRec, const ORowSetValue& rValue) { openIndexFile(); - OSL_ENSURE(m_aFileStream.IsOpen(),"FileStream is not opened!"); + OSL_ENSURE(m_pFileStream,"FileStream is not opened!"); // Existiert der Wert bereits // Find immer verwenden um das aktuelle Blatt zu bestimmen ONDXKey aKey; @@ -328,9 +361,12 @@ BOOL ODbaseIndex::Delete(sal_uInt32 nRec, const ORowSetValue& rValue) //------------------------------------------------------------------ void ODbaseIndex::Collect(ONDXPage* pPage) { - OSL_ENSURE(m_aFileStream.IsOpen(),"FileStream is not opened!"); + OSL_ENSURE(m_pFileStream,"FileStream is not opened!"); if (pPage) + { + pPage->acquire(); m_aCollector.push_back(pPage); + } } //------------------------------------------------------------------ void ODbaseIndex::Release(BOOL bSave) @@ -362,15 +398,26 @@ void ODbaseIndex::Release(BOOL bSave) { m_aHeader.db_rootpage = m_nRootPage; m_aHeader.db_pagecount = m_nPageCount; - m_aFileStream << *this; + (*m_pFileStream) << *this; } m_nRootPage = m_nPageCount = 0; m_nCurNode = NODE_NOTFOUND; + + closeImpl(); +} +// ----------------------------------------------------------------------------- +void ODbaseIndex::closeImpl() +{ + if(m_pFileStream) + { + delete m_pFileStream; + m_pFileStream = NULL; + } } //------------------------------------------------------------------ ONDXPage* ODbaseIndex::CreatePage(sal_uInt32 nPagePos, ONDXPage* pParent, BOOL bLoad) { - OSL_ENSURE(m_aFileStream.IsOpen(),"FileStream is not opened!"); + OSL_ENSURE(m_pFileStream,"FileStream is not opened!"); ONDXPage* pPage; if (m_aCollector.size()) @@ -384,7 +431,7 @@ ONDXPage* ODbaseIndex::CreatePage(sal_uInt32 nPagePos, ONDXPage* pParent, BOOL b pPage = new ONDXPage(*this, nPagePos, pParent); if (bLoad) - m_aFileStream >> *pPage; + (*m_pFileStream) >> *pPage; return pPage; } @@ -417,24 +464,30 @@ SvStream& connectivity::dbase::operator << (SvStream &rStream, ODbaseIndex& rInd return rStream; } // ------------------------------------------------------------------------- -INetURLObject ODbaseIndex::getEntry() +::rtl::OUString ODbaseIndex::getCompletePath() { - INetURLObject aDir = m_pTable->getEntry(); - aDir.setName(m_Name); - return aDir; + ::rtl::OUString sDir = m_pTable->getConnection()->getURL(); + sDir += STR_DELIMITER; + sDir += m_Name; + sDir += ::rtl::OUString::createFromAscii(".ndx"); + return sDir; } //------------------------------------------------------------------ void ODbaseIndex::createINFEntry() { // inf Datei abgleichen - String aNDX; - INetURLObject aEntry(getEntry()); - aEntry.setExtension(String::CreateFromAscii("ndx")); + String sEntry = m_Name; + sEntry += String::CreateFromAscii(".ndx"); - INetURLObject aInfEntry(m_pTable->getEntry()); - aInfEntry.setExtension(String::CreateFromAscii("inf")); + ::rtl::OUString sCfgFile(m_pTable->getConnection()->getURL()); + sCfgFile += STR_DELIMITER; + sCfgFile += m_pTable->getName(); + sCfgFile += ::rtl::OUString::createFromAscii(".inf"); - Config aInfFile(aInfEntry.getFSysPath(INetURLObject::FSYS_DETECT)); + String sPhysicalPath; + LocalFileHelper::ConvertURLToPhysicalName(sCfgFile,sPhysicalPath); + + Config aInfFile(sPhysicalPath); aInfFile.SetGroup(dBASE_III_GROUP); USHORT nSuffix = aInfFile.GetKeyCount(); @@ -454,56 +507,47 @@ void ODbaseIndex::createINFEntry() } } } - aInfFile.WriteKey(aNewEntry,ByteString(aEntry.GetName(),m_pTable->getConnection()->getTextEncoding())); + aInfFile.WriteKey(aNewEntry,ByteString(sEntry,m_pTable->getConnection()->getTextEncoding())); } // ------------------------------------------------------------------------- BOOL ODbaseIndex::DropImpl() { - if (m_aFileStream.IsOpen()) - m_aFileStream.Close(); - - INetURLObject aIndexEntry(getEntry()); - aIndexEntry.setExtension(String::CreateFromAscii("ndx")); + closeImpl(); - try + ::rtl::OUString sPath = getCompletePath(); + if(UCBContentHelper::Exists(sPath)) { - Content aContent(aIndexEntry.GetMainURL(),Reference<XCommandEnvironment>()); - aContent.executeCommand( rtl::OUString::createFromAscii( "delete" ),bool2any( sal_True ) ); + if(!UCBContentHelper::Kill(sPath)) + throw SQLException(::rtl::OUString::createFromAscii("Could not delete index!"),*m_pTable,SQLSTATE_GENERAL,1000,Any()); } - catch(Exception&) // a execption is thrown when no file exists - { - } - -// ULONG nErrorCode = aIndexEntry.Kill(); -// if (nErrorCode != SVSTREAM_OK && nErrorCode != SVSTREAM_FILE_NOT_FOUND) -// { -// // aStatus.SetError(nErrorCode,INDEX,aName); -// return FALSE; -// } // InfDatei abgleichen - String aNDX; - INetURLObject aEntry( m_pTable->getEntry()); - aEntry.setExtension(String::CreateFromAscii("inf")); - Config aInfFile(aEntry.getFSysPath(INetURLObject::FSYS_DETECT)); + ::rtl::OUString sCfgFile(m_pTable->getConnection()->getURL()); + sCfgFile += STR_DELIMITER; + sCfgFile += m_pTable->getName(); + sCfgFile += ::rtl::OUString::createFromAscii(".inf"); + + String sPhysicalPath; + String sNDX(sCfgFile); + sal_Bool bOk = LocalFileHelper::ConvertURLToPhysicalName(sNDX,sPhysicalPath); + OSL_ENSURE(bOk,"Can not convert Config Filename into Physical Name!"); + + Config aInfFile(sPhysicalPath); aInfFile.SetGroup(dBASE_III_GROUP); USHORT nKeyCnt = aInfFile.GetKeyCount(); ByteString aKeyName; + String sEntry = m_Name; + sEntry += String::CreateFromAscii(".ndx"); - INetURLObject aEntryToComp(getEntry()); - aEntryToComp.setExtension(String::CreateFromAscii("ndx")); - + // delete entries from the inf file for (USHORT nKey = 0; nKey < nKeyCnt; nKey++) { // Verweist der Key auf ein Indexfile?... aKeyName = aInfFile.GetKeyName( nKey ); - //...wenn ja, Indexliste der Tabelle hinzufuegen - if (aEntry.IsCaseSensitive() ? aKeyName.Copy(0,3) == "NDX" : aKeyName.Copy(0,3).EqualsIgnoreCaseAscii("NDX")) + if (aKeyName.Copy(0,3) == "ndx") { - aEntryToComp.setName(String(aInfFile.ReadKey(aKeyName),m_pTable->getConnection()->getTextEncoding())); - aEntryToComp.setExtension(String::CreateFromAscii("ndx")); - if (aEntryToComp == aIndexEntry) + if(sEntry == String(aInfFile.ReadKey(aKeyName),m_pTable->getConnection()->getTextEncoding())) { aInfFile.DeleteKey(aKeyName); break; @@ -517,44 +561,20 @@ BOOL ODbaseIndex::DropImpl() BOOL ODbaseIndex::CreateImpl() { // Anlegen des Index - INetURLObject aEntry(getEntry()); - aEntry.setExtension(String::CreateFromAscii("ndx")); - - Content aContent(aEntry.GetMainURL(),Reference<XCommandEnvironment>()); - try - { - if (aContent.isDocument()) - { - // aStatus.SetError(ERRCODE_IO_ALREADYEXISTS,INDEX,aEntry.GetFull()); - return FALSE; - } - } - catch(Exception&) // a execption is thrown when no file exists - { - } + ::rtl::OUString sFile = getCompletePath(); + if(UCBContentHelper::Exists(sFile)) + throw SQLException(::rtl::OUString::createFromAscii("Object already exists!"),*this,SQLSTATE_SEQUENCE,1000,Any()); // Index ist nur einstufig - if (m_pColumns->getCount() != 2) - { - // aStatus.SetDriverNotCapableError(); - return FALSE; - } + if (m_pColumns->getCount() > 1) + throw SQLException(::rtl::OUString::createFromAscii("Not capable! Only one column per index."),*this,SQLSTATE_SEQUENCE,1000,Any()); Reference<XFastPropertySet> xCol; - ::cppu::extractInterface(xCol,m_pColumns->getByIndex(1)); + ::cppu::extractInterface(xCol,m_pColumns->getByIndex(0)); // ist die Spalte schon indiziert ? if (!xCol.is()) - { -// String aText = String(OResId(STR_STAT_INDEX_COLUMN_NOT_FOUND)); -// aText.SearchAndReplace(String::CreateFromAscii("#"),pColumn->GetName()); -// aText.SearchAndReplace(String::CreateFromAscii("%"),GetTable()->Name()); -// aStatus.Set(SDB_STAT_ERROR, -// String::CreateFromAscii("01000"), -// aStatus.CreateErrorMessage(aText), -// 0, String() ); - return FALSE; - } + throw ::dbtools::FunctionSequenceException(*this); // else if (pColumn && pColumn->IsIndexed()) // { // String aText = String(OResId(STR_STAT_INDEX_COLUMN_ALREADY_INDEXED)); @@ -566,67 +586,81 @@ BOOL ODbaseIndex::CreateImpl() // return FALSE; // } - // Anlegen des Indexfiles - m_aFileStream.Open(aEntry.getFSysPath(INetURLObject::FSYS_DETECT), STREAM_READWRITE | STREAM_SHARE_DENYWRITE | STREAM_TRUNC); - if (!m_aFileStream.IsOpen()) - return FALSE; + // create the index file + m_pFileStream = UcbStreamHelper::CreateStream(sFile,STREAM_READWRITE | STREAM_SHARE_DENYWRITE | STREAM_TRUNC); + if (!m_pFileStream) + throw SQLException(::rtl::OUString::createFromAscii("Could not access index file!"),*this,SQLSTATE_SEQUENCE,1000,Any()); - m_aFileStream.SetNumberFormatInt(NUMBERFORMAT_INT_LITTLEENDIAN); - m_aFileStream.SetBufferSize(512); + m_pFileStream->SetNumberFormatInt(NUMBERFORMAT_INT_LITTLEENDIAN); + m_pFileStream->SetBufferSize(512); // Zunchst mu das Ergebnis sortiert sein - Reference<XStatement> xStmt = m_pTable->getConnection()->createStatement(); - - String aName(getString(xCol->getFastPropertyValue(PROPERTY_ID_NAME))); - - String aQuote(m_pTable->getConnection()->getMetaData()->getIdentifierQuoteString()); - String aStatement; - aStatement.AssignAscii("SELECT "); - aStatement += aQuote; - aStatement += aName; - aStatement += aQuote; - aStatement.AppendAscii(" FROM "); - aStatement += aQuote; - aStatement += m_pTable->getName().getStr(); - aStatement += aQuote; - aStatement.AppendAscii(" ORDER BY "); - aStatement += aQuote; - aStatement += aName; - aStatement += aQuote; - - if (!m_IsUnique) // zusaetzlich sortierung mit der bookmarkspalte + Reference<XStatement> xStmt; + Reference<XResultSet> xSet; + String aName; + try { - aStatement.AppendAscii(" ,"); + xStmt = m_pTable->getConnection()->createStatement(); + + aName = getString(xCol->getFastPropertyValue(PROPERTY_ID_NAME)); + + String aQuote(m_pTable->getConnection()->getMetaData()->getIdentifierQuoteString()); + String aStatement; + aStatement.AssignAscii("SELECT "); aStatement += aQuote; - aStatement.AppendAscii("[BOOKMARK]"); // this is a special column + aStatement += aName; aStatement += aQuote; - } + aStatement.AppendAscii(" FROM "); + aStatement += aQuote; + aStatement += m_pTable->getName().getStr(); + aStatement += aQuote; + aStatement.AppendAscii(" ORDER BY "); + aStatement += aQuote; + aStatement += aName; + aStatement += aQuote; + +// if (!m_IsUnique) // zusaetzlich sortierung mit der bookmarkspalte +// { +// aStatement.AppendAscii(" ,"); +// aStatement += aQuote; +// aStatement.AppendAscii("[BOOKMARK]"); // this is a special column +// aStatement += aQuote; +// } - Reference<XResultSet> xSet = xStmt->executeQuery(aStatement); + xSet = xStmt->executeQuery(aStatement); + } + catch(Exception& e) + { + closeImpl(); + if(UCBContentHelper::Exists(sFile)) + UCBContentHelper::Kill(sFile); + throw SQLException(::rtl::OUString::createFromAscii("Could not create index!"),*this,SQLSTATE_SEQUENCE,1000,makeAny(e)); + } if (!xSet.is()) { - m_aFileStream.Close(); - try - { - aContent.executeCommand( rtl::OUString::createFromAscii( "delete" ),bool2any( sal_True ) ); - } - catch(Exception&) // a execption is thrown when no file exists - { - } - return FALSE; + + closeImpl(); + if(UCBContentHelper::Exists(sFile)) + UCBContentHelper::Kill(sFile); + throw SQLException(::rtl::OUString::createFromAscii("Could not create index!"),*this,SQLSTATE_SEQUENCE,1000,Any()); } // Setzen der Headerinfo memset(&m_aHeader,0,sizeof(m_aHeader)); - m_aFileStream.SetStreamSize(512); + m_pFileStream->SetStreamSize(512); sal_Int32 nType = 0; - xCol->getFastPropertyValue(PROPERTY_ID_TYPE) >>= nType; + ::vos::ORef<OSQLColumns> aCols = m_pTable->getTableColumns(); + + Reference< XPropertySet > xTableCol(*find(aCols->begin(),aCols->end(),aName,::comphelper::UStringMixEqual(isCaseSensitive()))); + + xTableCol->getPropertyValue(PROPERTY_TYPE) >>= nType; m_aHeader.db_keytype = (nType == DataType::VARCHAR || nType == DataType::CHAR) ? 0 : 1; - m_aHeader.db_keylen = (m_aHeader.db_keytype) ? 8 : (USHORT)getINT32(xCol->getFastPropertyValue(PROPERTY_ID_PRECISION)); + m_aHeader.db_keylen = (m_aHeader.db_keytype) ? 8 : (USHORT)getINT32(xTableCol->getPropertyValue(PROPERTY_PRECISION)); m_aHeader.db_maxkeys = (512 - 8) / (8 + m_aHeader.db_keylen); + ByteString aCol(aName,m_pTable->getConnection()->getTextEncoding()); strcpy(m_aHeader.db_name,aCol.GetBuffer()); m_aHeader.db_unique = m_IsUnique ? 1: 0; @@ -647,61 +681,48 @@ BOOL ODbaseIndex::CreateImpl() // ULONG nRowsLeft = pCursor->RowCount(); Reference<XRow> xRow(xSet,UNO_QUERY); - xSet->last(); - sal_Int32 nRowsLeft = xSet->getRow(); - xSet->beforeFirst(); - - // Erzeugen der Indexstruktur - while (xSet->next()) + if(xSet->last()) { - // ODbRow& rRow = *pCursor->GetRow(); - // ueberpruefen auf doppelten eintrag - if (m_IsUnique && m_nCurNode != NODE_NOTFOUND) + sal_Int32 nRowsLeft = xSet->getRow(); + xSet->beforeFirst(); + + // Erzeugen der Indexstruktur + while (xSet->next()) { - ONDXKey aKey(m_aHeader.db_keytype ? ORowSetValue(xRow->getDouble(1)) : ORowSetValue(xRow->getString(1)), nType, 0); - if (aKey == (*m_aCurLeaf)[m_nCurNode].GetKey()) + // ODbRow& rRow = *pCursor->GetRow(); + // ueberpruefen auf doppelten eintrag + if (m_IsUnique && m_nCurNode != NODE_NOTFOUND) { -// String aText = String(OResId(STR_STAT_INDEX_NOT_UNIQUE)); -// aText.SearchAndReplace(String::CreateFromAscii("#"),aName); -// aStatus.Set(SDB_STAT_ERROR, -// String::CreateFromAscii("01000"), -// aStatus.CreateErrorMessage(aText), -// 0, String() ); - break; + ONDXKey aKey(m_aHeader.db_keytype ? ORowSetValue(xRow->getDouble(1)) : ORowSetValue(xRow->getString(1)), nType, 0); + if (aKey == (*m_aCurLeaf)[m_nCurNode].GetKey()) + { + + closeImpl(); + if(UCBContentHelper::Exists(sFile)) + UCBContentHelper::Kill(sFile); + throw SQLException(::rtl::OUString::createFromAscii("Can not create index values are not unique!"),*this,SQLSTATE_GENERAL,1000,Any()); + } } + ONDXKey aKey(m_aHeader.db_keytype ? ORowSetValue(xRow->getDouble(1)) : ORowSetValue(xRow->getString(1)), nType, xSet->getRow()); + ONDXNode aNewNode(aKey); + if (!m_aCurLeaf->Insert(aNewNode, --nRowsLeft)) + break; + + #ifdef DEBUG + //DBG_TRACE1("SDB: %s", (const char*)pCursor->Variable(1)->GetString()); + // PrintTree(); + #endif } - ONDXKey aKey(m_aHeader.db_keytype ? ORowSetValue(xRow->getDouble(1)) : ORowSetValue(xRow->getString(1)), nType, xSet->getRow()); - ONDXNode aNewNode(aKey); - if (!m_aCurLeaf->Insert(aNewNode, --nRowsLeft)) - break; - -#ifdef DEBUG - //DBG_TRACE1("SDB: %s", (const char*)pCursor->Variable(1)->GetString()); - // PrintTree(); -#endif } + xRow = NULL; + ::comphelper::disposeComponent(xSet); + ::comphelper::disposeComponent(xStmt); -// BOOL bResult = !pCursor->IsInRange(); -// if (!bResult) -// { -// m_aFileStream.Close(); -// aEntry.Kill(); -// Release(FALSE); -// } -// else -// { - - Release(); -// m_aFileStream.Close(); - // den FielStream NICHT schliessen, da per definitionem ein OObject nach dem Kreieren offen ist - - // inf Datei abgleichen - createINFEntry(); -// } -// - // pCursor->ReleaseRef(); + Release(); + createINFEntry(); return sal_True; } +// ----------------------------------------------------------------------------- diff --git a/connectivity/source/drivers/dbase/DIndexes.cxx b/connectivity/source/drivers/dbase/DIndexes.cxx index edb84ff2bc4b..c3774c6df4bd 100644 --- a/connectivity/source/drivers/dbase/DIndexes.cxx +++ b/connectivity/source/drivers/dbase/DIndexes.cxx @@ -2,9 +2,9 @@ * * $RCSfile: DIndexes.cxx,v $ * - * $Revision: 1.5 $ + * $Revision: 1.6 $ * - * last change: $Author: oj $ $Date: 2000-11-03 14:17:57 $ + * last change: $Author: oj $ $Date: 2001-03-30 13:57:18 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -68,8 +68,14 @@ #ifndef _CONNECTIVITY_PROPERTYIDS_HXX_ #include "propertyids.hxx" #endif +#ifndef _UNTOOLS_UCBSTREAMHELPER_HXX +#include <unotools/ucbstreamhelper.hxx> +#endif +#ifndef _UNOTOOLS_UCBHELPER_HXX +#include <unotools/ucbhelper.hxx> +#endif - +using namespace utl; using namespace connectivity::dbase; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::beans; @@ -85,26 +91,31 @@ Reference< XNamed > ODbaseIndexes::createObject(const ::rtl::OUString& _rName) // Dir* pDir = m_pTable->getConnection()->getDir(); // String aPath = pDir->GetName(); // aPath += _rName.getStr(); - INetURLObject aEntry(m_pTable->getEntry()); - aEntry.setName(_rName); - aEntry.setExtension(String::CreateFromAscii("ndx")); - SvFileStream aFileStream; - aFileStream.Open(aEntry.getFSysPath(INetURLObject::FSYS_DETECT), STREAM_READ | STREAM_NOCREATE| STREAM_SHARE_DENYWRITE); - - - // Anlegen des Indexfiles - // aFileStream.Open(aEntry.GetFull(), STREAM_READWRITE | STREAM_NOCREATE| STREAM_SHARE_DENYWRITE); - - aFileStream.SetNumberFormatInt(NUMBERFORMAT_INT_LITTLEENDIAN); - aFileStream.SetBufferSize(512); - ODbaseIndex::NDXHeader aHeader; - - aFileStream.Seek(0); - aFileStream.Read(&aHeader,512); + ::rtl::OUString sFile = m_pTable->getConnection()->getURL(); + sFile += STR_DELIMITER; + sFile += _rName; + sFile += ::rtl::OUString::createFromAscii(".ndx"); + if(!UCBContentHelper::Exists(sFile)) + throw SQLException(::rtl::OUString::createFromAscii("Index file doesn't exists!"),*m_pTable,SQLSTATE_GENERAL,1000,Any()); + + Reference< XNamed > xRet; + SvStream* pFileStream = UcbStreamHelper::CreateStream(sFile,STREAM_READ | STREAM_NOCREATE| STREAM_SHARE_DENYWRITE); + if(pFileStream) + { + pFileStream->SetNumberFormatInt(NUMBERFORMAT_INT_LITTLEENDIAN); + pFileStream->SetBufferSize(512); + ODbaseIndex::NDXHeader aHeader; - ODbaseIndex* pIndex = new ODbaseIndex(m_pTable,aHeader,_rName); + pFileStream->Seek(0); + pFileStream->Read(&aHeader,512); + delete pFileStream; - Reference< XNamed > xRet = pIndex; + ODbaseIndex* pIndex = new ODbaseIndex(m_pTable,aHeader,_rName); + xRet = pIndex; + pIndex->openIndexFile(); + } + else + throw SQLException(::rtl::OUString::createFromAscii("Could not open index file"),*m_pTable,SQLSTATE_GENERAL,1000,Any()); return xRet; } // ------------------------------------------------------------------------- @@ -137,7 +148,7 @@ void SAL_CALL ODbaseIndexes::appendByDescriptor( const Reference< XPropertySet > { ODbaseIndex* pIndex = (ODbaseIndex*)xTunnel->getSomething(ODbaseIndex::getUnoTunnelImplementationId()); if(pIndex && pIndex->CreateImpl()) - ODbaseIndexes_BASE::appendByDescriptor(descriptor); + ODbaseIndexes_BASE::appendByDescriptor(Reference< XPropertySet >(createObject(aName),UNO_QUERY)); } } // ------------------------------------------------------------------------- @@ -150,6 +161,9 @@ void SAL_CALL ODbaseIndexes::dropByName( const ::rtl::OUString& elementName ) th if( aIter == m_aNameMap.end()) throw NoSuchElementException(elementName,*this); + if(!aIter->second.is()) + aIter->second = createObject(elementName); + Reference< XUnoTunnel> xTunnel(aIter->second.get(),UNO_QUERY); if(xTunnel.is()) { @@ -164,7 +178,7 @@ void SAL_CALL ODbaseIndexes::dropByIndex( sal_Int32 index ) throw(SQLException, { ::osl::MutexGuard aGuard(m_rMutex); if (index < 0 || index >= getCount()) - throw IndexOutOfBoundsException(); + throw IndexOutOfBoundsException(::rtl::OUString::valueOf(index),*this); dropByName((*m_aElements[index]).first); } diff --git a/connectivity/source/drivers/dbase/DTables.cxx b/connectivity/source/drivers/dbase/DTables.cxx index ec79921decc5..82b34f7af9e7 100644 --- a/connectivity/source/drivers/dbase/DTables.cxx +++ b/connectivity/source/drivers/dbase/DTables.cxx @@ -2,9 +2,9 @@ * * $RCSfile: DTables.cxx,v $ * - * $Revision: 1.10 $ + * $Revision: 1.11 $ * - * last change: $Author: oj $ $Date: 2001-03-28 11:32:43 $ + * last change: $Author: oj $ $Date: 2001-03-30 13:57:18 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -186,7 +186,7 @@ void SAL_CALL ODbaseTables::dropByIndex( sal_Int32 index ) throw(SQLException, I { ::osl::MutexGuard aGuard(m_rMutex); if (index < 0 || index >= getCount()) - throw IndexOutOfBoundsException(); + throw IndexOutOfBoundsException(::rtl::OUString::valueOf(index),*this); dropByName((*m_aElements[index]).first); } diff --git a/connectivity/source/drivers/dbase/dindexnode.cxx b/connectivity/source/drivers/dbase/dindexnode.cxx index d71881c4ac0c..b6bf532b717b 100644 --- a/connectivity/source/drivers/dbase/dindexnode.cxx +++ b/connectivity/source/drivers/dbase/dindexnode.cxx @@ -2,9 +2,9 @@ * * $RCSfile: dindexnode.cxx,v $ * - * $Revision: 1.4 $ + * $Revision: 1.5 $ * - * last change: $Author: oj $ $Date: 2001-02-05 12:26:39 $ + * last change: $Author: oj $ $Date: 2001-03-30 13:57:18 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -108,17 +108,14 @@ ONDXPage::~ONDXPage() void ONDXPage::release() { if (! osl_decrementInterlockedCount( &m_refCount )) - { QueryDelete(); - delete this; - } } //------------------------------------------------------------------ void ONDXPage::QueryDelete() { // Ablegen im GarbageCollector if (IsModified()) - rIndex.m_aFileStream << *this; + (*rIndex.m_pFileStream) << *this; bModified = FALSE; if (rIndex.UseCollector()) @@ -139,6 +136,8 @@ void ONDXPage::QueryDelete() (*aParent).Clear(); rIndex.Collect(this); } + else + delete this; // else // SvRefBase::QueryDelete(); } @@ -927,18 +926,8 @@ void ONDXNode::Write(SvStream &rStream, const ONDXPage& rPage) const memset(aNodeData.aData,0x20,rIndex.getHeader().db_keylen); if (aKey.getValue().hasValue()) { - // ODBFConnection *pCon = rIndex.GetDBFConnection(); - if (NULL) - { - ByteString aText(getString(aKey.getValue()).getStr(), rIndex.m_pTable->getConnection()->getTextEncoding()); - strncpy(aNodeData.aData,aText.GetBuffer(),min(rIndex.getHeader().db_keylen, aText.Len())); - } - else - { - DBG_ERROR("No Connection"); - ByteString aText(getString(aKey.getValue()).getStr(), rIndex.m_pTable->getConnection()->getTextEncoding()); - strncpy(aNodeData.aData,aText.GetBuffer(),min(rIndex.getHeader().db_keylen, aText.Len())); - } + ByteString aText(getString(aKey.getValue()).getStr(), rIndex.m_pTable->getConnection()->getTextEncoding()); + strncpy(aNodeData.aData,aText.GetBuffer(),min(rIndex.getHeader().db_keylen, aText.Len())); } rStream.Write((BYTE*)aNodeData.aData,rIndex.getHeader().db_keylen); } |