From 517ad9d4b6eae320b708d03a9340a22893b0cab7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Sun, 29 Jan 2023 15:45:51 +0100 Subject: New upstream version 4.0.3 --- src/core/xbixndx.cpp | 251 ++++++++++++++++++++++++--------------------------- 1 file changed, 116 insertions(+), 135 deletions(-) (limited to 'src/core/xbixndx.cpp') diff --git a/src/core/xbixndx.cpp b/src/core/xbixndx.cpp index 097bd22..dcec5f9 100755 --- a/src/core/xbixndx.cpp +++ b/src/core/xbixndx.cpp @@ -85,7 +85,7 @@ xbInt16 xbIxNdx::AddKey( void * vpTag, xbUInt32 ulRecNo ){ if( lKeyCnt < npTag->iKeysPerBlock ){ // Section A - add key to appropriate position if space available if(( iRc = InsertNodeL( npTag, npTag->npCurNode, npTag->npCurNode->iCurKeyNo, npTag->cpKeyBuf, ulRecNo )) != XB_NO_ERROR ){ - iErrorStop = 200; + iErrorStop = 110; throw iRc; } @@ -95,12 +95,12 @@ xbInt16 xbIxNdx::AddKey( void * vpTag, xbUInt32 ulRecNo ){ // section B - split the leaf node xbIxNode * npRightNode = AllocateIxNode( GetBlockSize() + (xbUInt32) npTag->iKeyItemLen, 1 ); if( !npRightNode ){ - iErrorStop = 100; + iErrorStop = 120; iRc = XB_NO_MEMORY; throw iRc; } if(( iRc = SplitNodeL( npTag, npTag->npCurNode, npRightNode, npTag->npCurNode->iCurKeyNo, npTag->cpKeyBuf, ulRecNo )) != XB_NO_ERROR ){ - iErrorStop = 110; + iErrorStop = 130; throw iRc; } xbUInt32 ulTempBlockNo = npRightNode->ulBlockNo; @@ -111,12 +111,12 @@ xbInt16 xbIxNdx::AddKey( void * vpTag, xbUInt32 ulRecNo ){ npRightNode = FreeNodeChain( npRightNode ); npRightNode = AllocateIxNode( GetBlockSize() + (xbUInt32) npTag->iKeyItemLen, 1 ); if( !npRightNode ){ - iErrorStop = 200; + iErrorStop = 140; iRc = XB_NO_MEMORY; throw iRc; } if(( iRc = SplitNodeI( npTag, npParent, npRightNode, npParent->iCurKeyNo, ulTempBlockNo )) != XB_NO_ERROR ){ - iErrorStop = 210; + iErrorStop = 150; throw iRc; } ulTempBlockNo = npRightNode->ulBlockNo; @@ -128,7 +128,7 @@ xbInt16 xbIxNdx::AddKey( void * vpTag, xbUInt32 ulRecNo ){ if( npTag->npCurNode->ulBlockNo == npTag->ulRootBlock ){ // xbase->WriteLogMessage( "Section d" ); if(( iRc = AddKeyNewRoot( npTag, npTag->npCurNode, npRightNode )) != XB_NO_ERROR ){ - iErrorStop = 300; + iErrorStop = 160; throw iRc; } npRightNode = FreeNodeChain( npRightNode ); @@ -136,7 +136,7 @@ xbInt16 xbIxNdx::AddKey( void * vpTag, xbUInt32 ulRecNo ){ } else { // else section E, put key in parent if(( iRc = InsertNodeI( vpTag, npParent, npParent->iCurKeyNo, npRightNode->ulBlockNo )) != XB_NO_ERROR ){ - iErrorStop = 400; + iErrorStop = 170; throw iRc; } npRightNode = FreeNodeChain( npRightNode ); @@ -145,7 +145,7 @@ xbInt16 xbIxNdx::AddKey( void * vpTag, xbUInt32 ulRecNo ){ // update the header if(( iRc = WriteHeadBlock( iHeadNodeUpdateOpt )) != XB_NO_ERROR ){ - iErrorStop = 130; + iErrorStop = 180; throw iRc; } @@ -327,21 +327,22 @@ xbInt16 xbIxNdx::CheckTagIntegrity( void *vpTag, xbInt16 iOpt ){ xbString sMsg; char cKeyType; char *pPrevKeyBuf = NULL; - xbInt16 iAutoLock = xbFalse; + + #ifdef XB_LOCKING_SUPPORT + xbBool bLocked = xbFalse; + #endif xbNdxTag * npTag; vpTag ? npTag = (xbNdxTag *) vpTag : npTag = ndxTag; try{ -// xbase->WriteLogMessage( "xbIxNdx::CheckTagIntegrity()", iOpt ); - #ifdef XB_LOCKING_SUPPORT - iAutoLock = dbf->GetAutoLock(); - if( iAutoLock && !dbf->GetTableLocked() ){ + if( dbf->GetAutoLock() && !dbf->GetTableLocked() ){ if(( iRc = dbf->LockTable( XB_LOCK )) != XB_NO_ERROR ){ - iErrorStop = 10; + iErrorStop = 100; throw iRc; } + bLocked = xbTrue; } #endif @@ -366,21 +367,21 @@ xbInt16 xbIxNdx::CheckTagIntegrity( void *vpTag, xbInt16 iOpt ){ if( iRc2 < 0 ){ sMsg.Sprintf( "Key sequence error at key number [%ld].", ulIxCnt ); xbase->WriteLogMessage( sMsg, iOpt ); - iErrorStop = 100; + iErrorStop = 110; iRc = XB_INVALID_INDEX; throw iRc; } ulThisRecNo = 0; if(( iRc3 = GetDbfPtr( vpTag, npTag->npCurNode->iCurKeyNo, npTag->npCurNode, ulThisRecNo )) != XB_NO_ERROR ){ - iErrorStop = 110; + iErrorStop = 120; throw iRc3; } if( iRc2 == 0 && (ulThisRecNo <= ulPrevRecNo )){ sMsg.Sprintf( "Dbf record number sequence error at key number [%ld].", iOpt ); xbase->WriteLogMessage( sMsg, iOpt ); - iErrorStop = 120; + iErrorStop = 130; iRc = XB_INVALID_INDEX; throw iRc; } @@ -393,7 +394,7 @@ xbInt16 xbIxNdx::CheckTagIntegrity( void *vpTag, xbInt16 iOpt ){ // verify the index count matches the tag count xbUInt32 ulDbfCnt = 0; if(( iRc = dbf->GetRecordCnt( ulDbfCnt )) != XB_NO_ERROR ){ - iErrorStop = 130; + iErrorStop = 140; throw iRc; } @@ -403,7 +404,7 @@ xbInt16 xbIxNdx::CheckTagIntegrity( void *vpTag, xbInt16 iOpt ){ if( ulDbfCnt != ulIxCnt ){ sMsg.Sprintf( "CheckTagIntegrity() Index entry count [%ld] does not match dbf record count [%ld]", ulIxCnt, ulDbfCnt ); xbase->WriteLogMessage( sMsg, iOpt ); - iErrorStop = 140; + iErrorStop = 150; iRc = XB_INVALID_INDEX; throw iRc; } @@ -412,29 +413,19 @@ xbInt16 xbIxNdx::CheckTagIntegrity( void *vpTag, xbInt16 iOpt ){ xbUInt32 j = 0; while( j < ulDbfCnt ){ if(( iRc = dbf->GetRecord( ++j )) != XB_NO_ERROR ){ - iErrorStop = 150; + iErrorStop = 160; throw iRc; } if(( iRc = FindKeyForCurRec( vpTag )) != XB_NO_ERROR ){ ulThisRecNo = j; - iErrorStop = 160; + iErrorStop = 170; throw iRc; } } sMsg.Sprintf( "CheckTagIntegrity() Index entry count [%ld] matches dbf record count [%ld]", ulIxCnt, ulDbfCnt ); xbase->WriteLogMessage( sMsg, iOpt ); } - - #ifdef XB_LOCKING_SUPPORT - if( iAutoLock && !dbf->GetTableLocked() ){ - if(( iRc = dbf->LockTable( XB_UNLOCK )) != XB_NO_ERROR ){ - iErrorStop = 200; - throw iRc; - } - } - #endif - - + if( pPrevKeyBuf ) free( pPrevKeyBuf ); @@ -447,11 +438,17 @@ xbInt16 xbIxNdx::CheckTagIntegrity( void *vpTag, xbInt16 iOpt ){ if( pPrevKeyBuf ) free( pPrevKeyBuf ); - if( iErrorStop == 160 ){ + if( iErrorStop == 170 ){ sMsg.Sprintf( "xbIxNdx::CheckTagIntegrity() Missing index entry for record [%d]", ulThisRecNo ); xbase->WriteLogMessage( sMsg, iOpt ); } } + + #ifdef XB_LOCKING_SUPPORT + if( bLocked ){ + dbf->LockTable( XB_UNLOCK ); + } + #endif return iRc; } @@ -476,7 +473,7 @@ xbInt16 xbIxNdx::CreateKey( void * vpTag, xbInt16 iOpt ){ vpTag ? npTag = (xbNdxTag *) vpTag : npTag = ndxTag; if(( iRc = npTag->exp->ProcessExpression( 0 )) != XB_NO_ERROR ){ - iErrorStop = 10; + iErrorStop = 100; throw iRc; } if( npTag->exp->GetReturnType() == XB_EXP_CHAR ){ @@ -499,7 +496,7 @@ xbInt16 xbIxNdx::CreateKey( void * vpTag, xbInt16 iOpt ){ else if( iOpt == 2 ){ if(( iRc = npTag->exp->ProcessExpression( 1 )) != XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 110; throw iRc; } if( npTag->exp->GetReturnType() == XB_EXP_CHAR ){ @@ -512,7 +509,6 @@ xbInt16 xbIxNdx::CreateKey( void * vpTag, xbInt16 iOpt ){ if( memcmp( npTag->cpKeyBuf, npTag->cpKeyBuf2, (size_t) npTag->iKeyLen )) npTag->iKeySts = XB_UPD_KEY; } - } catch (xbInt16 iRc ){ xbString sMsg; @@ -555,11 +551,11 @@ xbInt16 xbIxNdx::CreateTag( const xbString &sName, const xbString &sKey, if( FileIsOpen()){ if(( iRc = xbTruncate(0)) != XB_NO_ERROR ){ - iErrorStop = 10; + iErrorStop = 100; throw iRc; } if(( iRc = xbFclose()) != XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 110; throw iRc; } npTag->npNodeChain = FreeNodeChain( npTag->npNodeChain ); @@ -575,16 +571,15 @@ xbInt16 xbIxNdx::CreateTag( const xbString &sName, const xbString &sKey, npTag->cpKeyBuf2 = NULL; } } - if(( iRc = xbFopen( "w+b", dbf->GetShareMode())) != XB_NO_ERROR ){ - iErrorStop = 30; + iErrorStop = 120; throw iRc; } //set up the key expression npTag->exp = new xbExp( dbf->GetXbasePtr()); if(( iRc = npTag->exp->ParseExpression( dbf, sKey )) != XB_NO_ERROR ){ - iErrorStop = 40; + iErrorStop = 130; throw iRc; } @@ -608,20 +603,20 @@ xbInt16 xbIxNdx::CreateTag( const xbString &sName, const xbString &sKey, break; default: - iErrorStop = 50; + iErrorStop = 140; iRc = XB_INVALID_INDEX; throw iRc; } npTag->iUnique = iUnique; npTag->ulRootBlock = 1L; - npTag->ulTotalBlocks = 2l; + npTag->ulTotalBlocks = 2l; npTag->sKeyExpression = sKey; GetFileNamePart( npTag->sTagName ); if( npTag->iKeyLen > 100 ){ - iErrorStop = 60; + iErrorStop = 150; throw iRc; } @@ -633,7 +628,7 @@ xbInt16 xbIxNdx::CreateTag( const xbString &sName, const xbString &sKey, ndxTag->cpKeyBuf2 = (char *) malloc( (size_t) ndxTag->iKeyLen ); if(( iRc = WriteHeadBlock(0)) != XB_NO_ERROR ){ - iErrorStop = 70; + iErrorStop = 160; throw iRc; } @@ -641,10 +636,9 @@ xbInt16 xbIxNdx::CreateTag( const xbString &sName, const xbString &sKey, char buf[512]; memset( buf, 0x00, 512 ); if(( iRc = xbFwrite( buf, 1, 512 )) != XB_NO_ERROR ){ - iErrorStop = 80; + iErrorStop = 170; throw iRc; } - } catch (xbInt16 iRc ){ xbString sMsg; @@ -741,7 +735,6 @@ xbInt16 xbIxNdx::DeleteKey( void *vpTag ){ // 2 - if the last key on a node is deleted, and the key value is not the same as the prev key value // go up the tree looking for an interior node needing updated key value - xbInt32 lOrigKeyCnt = GetKeyCount( npTag->npCurNode ); if(( iRc = DeleteFromNode( npTag, npTag->npCurNode, npTag->npCurNode->iCurKeyNo )) != XB_NO_ERROR ){ iErrorStop = 110; @@ -873,8 +866,6 @@ xbInt16 xbIxNdx::DeleteTag( void * ){ \returns void */ -//xbInt16 xbIxNdx::DumpTagBlocks( xbInt16 iOpt, void *vpTag ){ - xbInt16 xbIxNdx::DumpTagBlocks( xbInt16 iOpt, void * ){ xbInt16 iRc = 0; @@ -887,7 +878,7 @@ xbInt16 xbIxNdx::DumpTagBlocks( xbInt16 iOpt, void * ){ try{ if( !FileIsOpen()){ iRc = XB_NOT_OPEN; - iErrorStop = 10; + iErrorStop = 100; throw iRc; } @@ -900,7 +891,7 @@ xbInt16 xbIxNdx::DumpTagBlocks( xbInt16 iOpt, void * ){ memset( cNodeBuf, 0x00, XB_NDX_BLOCK_SIZE ); if(( iRc = ReadBlock( lBlk, XB_NDX_BLOCK_SIZE, cNodeBuf )) != XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 110; throw iRc; } p = cNodeBuf; @@ -1060,7 +1051,7 @@ void xbIxNdx::DumpIxNodeChain( void *vpTag, xbInt16 iOpt ) const 0 = stdout
1 = Syslog
2 = Both
- \returns XB_NVALID_OBJECT
XB_NO_ERROR + \returns XB_INVALID_OBJECT
XB_NO_ERROR */ xbInt16 xbIxNdx::DumpNode( void *vpTag, xbIxNode *pNode, xbInt16 iOpt ) const @@ -1149,12 +1140,12 @@ xbInt16 xbIxNdx::FindKey( void *vpTag, const void *vpKey, xbInt32 lSearchKeyLen, if( dbf->GetDbfStatus() == XB_UPDATED ){ if( dbf->GetAutoCommit() == 1 ){ if(( iRc = dbf->Commit()) != XB_NO_ERROR ){ - iErrorStop = 10; + iErrorStop = 100; throw iRc; } } else { if(( iRc = dbf->Abort()) != XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 110; throw iRc; } } @@ -1171,18 +1162,18 @@ xbInt16 xbIxNdx::FindKey( void *vpTag, const void *vpKey, xbInt32 lSearchKeyLen, // determine if the index has been updated since the last time it was used time_t tFileTs; if(( iRc = GetFileMtime( tFileTs )) != XB_NO_ERROR ){ - iErrorStop = 30; + iErrorStop = 120; throw iRc; } if( npTag->tNodeChainTs < tFileTs ){ npTag->npNodeChain = FreeNodeChain( npTag->npNodeChain ); npTag->npCurNode = NULL; if(( iRc = ReadHeadBlock( 1 )) != XB_NO_ERROR ){ - iErrorStop = 40; + iErrorStop = 130; throw iRc; } if(( iRc = GetBlock( npTag, (npTag->ulRootBlock ), 1, (xbUInt32) npTag->iKeyItemLen )) != XB_NO_ERROR ){ - iErrorStop = 50; + iErrorStop = 140; throw iRc; } } else { @@ -1212,7 +1203,7 @@ xbInt16 xbIxNdx::FindKey( void *vpTag, const void *vpKey, xbInt32 lSearchKeyLen, } } else { if(( iRc = GetBlock( npTag, (npTag->ulRootBlock ), 1, (xbUInt32) npTag->iKeyItemLen )) != XB_NO_ERROR ){ - iErrorStop = 60; + iErrorStop = 150; throw iRc; } } @@ -1252,12 +1243,12 @@ xbInt16 xbIxNdx::FindKey( void *vpTag, const void *vpKey, xbInt32 lSearchKeyLen, } if(( iRc = GetKeyPtr( npTag, npTag->npCurNode->iCurKeyNo, npTag->npCurNode, ulKeyPtr )) != XB_NO_ERROR ){ - iErrorStop = 80; + iErrorStop = 160; throw iRc; } if(( iRc = GetBlock( npTag, ulKeyPtr, 1, (xbUInt32) npTag->iKeyItemLen )) != XB_NO_ERROR ){ - iErrorStop = 90; + iErrorStop = 170; throw iRc; } } @@ -1289,11 +1280,11 @@ xbInt16 xbIxNdx::FindKey( void *vpTag, const void *vpKey, xbInt32 lSearchKeyLen, ulKey--; if(( iRc = GetDbfPtr( vpTag, ulKey, npTag->npCurNode, ulKeyPtr )) != XB_NO_ERROR ){ - iErrorStop = 100; + iErrorStop = 180; throw iRc; } if(( iRc = dbf->GetRecord( ulKeyPtr )) != XB_NO_ERROR ){ - iErrorStop = 110; + iErrorStop = 190; throw iRc; } } @@ -1335,7 +1326,7 @@ xbInt16 xbIxNdx::FindKeyForCurRec( void * vpTag ) try{ if(( iRc = CreateKey( vpTag, 0 )) < XB_NO_ERROR ){ - iErrorStop = 10; + iErrorStop = 100; throw iRc; } @@ -1345,7 +1336,7 @@ xbInt16 xbIxNdx::FindKeyForCurRec( void * vpTag ) return iRc; if( iRc != XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 110; throw iRc; } @@ -1361,7 +1352,7 @@ xbInt16 xbIxNdx::FindKeyForCurRec( void * vpTag ) char cKeyType = GetKeyType( vpTag ); if(( iRc = GetDbfPtr( vpTag, npTag->npCurNode->iCurKeyNo, npTag->npCurNode, ulIxRecNo )) != XB_NO_ERROR ){ - iErrorStop = 30; + iErrorStop = 120; throw iRc; } if( ulIxRecNo == ulDbfRecNo ) @@ -1371,7 +1362,7 @@ xbInt16 xbIxNdx::FindKeyForCurRec( void * vpTag ) while( !bCurRecsMatch && bKeysMatch ){ if(( iRc = GetNextKey( vpTag, 0 )) != XB_NO_ERROR ){ - iErrorStop = 40; + iErrorStop = 130; throw iRc; } @@ -1381,7 +1372,7 @@ xbInt16 xbIxNdx::FindKeyForCurRec( void * vpTag ) bKeysMatch = false; else{ if(( iRc = GetDbfPtr( vpTag, npTag->npCurNode->iCurKeyNo, npTag->npCurNode, ulIxRecNo )) != XB_NO_ERROR ){ - iErrorStop = 50; + iErrorStop = 140; throw iRc; } if( ulIxRecNo == ulDbfRecNo ) @@ -1417,7 +1408,7 @@ xbInt16 xbIxNdx::GetDbfPtr( void *vpTag, xbInt16 iKeyNo, xbIxNode *np, xbUInt32 // turn this off in production mode for better performance xbUInt32 ulNoOfKeys = eGetUInt32 ( np->cpBlockData ); if( iKeyNo < 0 || iKeyNo > (xbInt16) --ulNoOfKeys ){ - iErrorStop = 10; + iErrorStop = 100; throw XB_INVALID_KEYNO; } #endif @@ -1458,12 +1449,12 @@ xbInt16 xbIxNdx::GetFirstKey( void *vpTag, xbInt16 iRetrieveSw ){ npTag->npCurNode = NULL; } if(( iRc = ReadHeadBlock( 1 )) != XB_NO_ERROR ){ - iErrorStop = 10; + iErrorStop = 100; throw iRc; } // lRootBlock is now available if(( iRc = GetBlock( npTag, npTag->ulRootBlock, 1, (xbUInt32) npTag->iKeyItemLen )) != XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 110; throw iRc; } // if no keys on this node, and it's a leaf node then the index is empty @@ -1475,21 +1466,21 @@ xbInt16 xbIxNdx::GetFirstKey( void *vpTag, xbInt16 iRetrieveSw ){ while( !IsLeaf( npTag, npTag->npCurNode )) // go down the chain looking for a leaf node { if(( iRc = GetKeyPtr( npTag, 0, npTag->npCurNode, ulKeyPtr )) != XB_NO_ERROR ){ - iErrorStop = 30; + iErrorStop = 120; throw iRc; } if(( iRc = GetBlock( npTag, ulKeyPtr, 1, (xbUInt32) npTag->iKeyItemLen )) != XB_NO_ERROR ){ - iErrorStop = 40; + iErrorStop = 130; throw iRc; } } if( iRetrieveSw ){ if(( iRc = GetDbfPtr( npTag, 0, npTag->npCurNode, ulKeyPtr )) != XB_NO_ERROR ){ - iErrorStop = 50; + iErrorStop = 140; throw iRc; } if(( iRc = dbf->GetRecord( ulKeyPtr )) != XB_NO_ERROR ){ - iErrorStop = 60; + iErrorStop = 150; throw iRc; } } @@ -1556,7 +1547,7 @@ xbInt16 xbIxNdx::GetKeyPtr( void *vpTag, xbInt16 iKeyNo, xbIxNode *np, xbUInt32 // turn this off in production mode for better performance xbUInt32 ulNoOfKeys = eGetUInt32 ( np->cpBlockData ); if( iKeyNo < 0 || iKeyNo > (xbInt16) ulNoOfKeys ){ - iErrorStop = 10; + iErrorStop = 100; throw XB_INVALID_KEYNO; } #endif @@ -1653,17 +1644,17 @@ xbInt16 xbIxNdx::GetLastKey( xbUInt32 ulNodeNo, void *vpTag, xbInt16 iRetrieveSw } if( ulNodeNo == 0 ){ if(( iRc = ReadHeadBlock( 1 )) != XB_NO_ERROR ){ - iErrorStop = 10; + iErrorStop = 100; throw iRc; } // lRootBlock is now available if(( iRc = GetBlock( npTag, npTag->ulRootBlock, 1, (xbUInt32) npTag->iKeyItemLen )) != XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 110; throw iRc; } } else { if(( iRc = GetBlock( npTag, ulNodeNo, 1, (xbUInt32) npTag->iKeyItemLen )) != XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 120; throw iRc; } } @@ -1677,11 +1668,11 @@ xbInt16 xbIxNdx::GetLastKey( xbUInt32 ulNodeNo, void *vpTag, xbInt16 iRetrieveSw while( !IsLeaf( npTag, npTag->npCurNode ) ){ // go down the chain looking for a leaf node npTag->npCurNode->iCurKeyNo = eGetUInt32( npTag->npCurNode->cpBlockData ); if(( iRc = GetKeyPtr( npTag, npTag->npCurNode->iCurKeyNo, npTag->npCurNode, ulKeyPtr )) != XB_NO_ERROR ){ - iErrorStop = 40; + iErrorStop = 130; throw iRc; } if(( iRc = GetBlock( npTag, ulKeyPtr, 1, (xbUInt32) npTag->iKeyItemLen )) != XB_NO_ERROR ){ - iErrorStop = 50; + iErrorStop = 140; throw iRc; } ulNoOfKeys = eGetUInt32( npTag->npCurNode->cpBlockData ); @@ -1692,11 +1683,11 @@ xbInt16 xbIxNdx::GetLastKey( xbUInt32 ulNodeNo, void *vpTag, xbInt16 iRetrieveSw if( iRetrieveSw ){ ulNoOfKeys = eGetUInt32( npTag->npCurNode->cpBlockData ); if(( iRc = GetDbfPtr( npTag, ulNoOfKeys - 1, npTag->npCurNode, ulKeyPtr )) != XB_NO_ERROR ){ - iErrorStop = 60; + iErrorStop = 150; throw iRc; } if(( iRc = dbf->GetRecord( ulKeyPtr )) != XB_NO_ERROR ){ - iErrorStop = 70; + iErrorStop = 160; throw iRc; } } @@ -1778,12 +1769,12 @@ xbInt16 xbIxNdx::GetNextKey( void * vpTag, xbInt16 iRetrieveSw ){ if((eGetUInt32( npTag->npCurNode->cpBlockData ) -1) > npTag->npCurNode->iCurKeyNo ){ npTag->npCurNode->iCurKeyNo++; if(( iRc = GetDbfPtr( npTag, npTag->npCurNode->iCurKeyNo, npTag->npCurNode, ulKeyPtr )) != XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 100; throw iRc; } if( iRetrieveSw ){ if(( iRc = dbf->GetRecord( ulKeyPtr )) != XB_NO_ERROR ){ - iErrorStop = 30; + iErrorStop = 110; throw iRc; } else { return iRc; @@ -1817,32 +1808,32 @@ xbInt16 xbIxNdx::GetNextKey( void * vpTag, xbInt16 iRetrieveSw ){ npTag->npCurNode->iCurKeyNo++; if(( iRc = GetKeyPtr( npTag, npTag->npCurNode->iCurKeyNo, npTag->npCurNode, ulKeyPtr )) != XB_NO_ERROR ){ - iErrorStop = 40; + iErrorStop = 120; throw iRc; } if(( iRc = GetBlock( npTag, ulKeyPtr, 1, (xbUInt32) npTag->iKeyItemLen )) != XB_NO_ERROR ){ - iErrorStop = 50; + iErrorStop = 130; throw iRc; } while( !IsLeaf( npTag, npTag->npCurNode )) // go down the chain looking for a leaf node { if(( iRc = GetKeyPtr( npTag, 0, npTag->npCurNode, ulKeyPtr )) != XB_NO_ERROR ){ - iErrorStop = 60; + iErrorStop = 140; throw iRc; } if(( iRc = GetBlock( npTag, ulKeyPtr, 1, (xbUInt32) npTag->iKeyItemLen )) != XB_NO_ERROR ){ - iErrorStop = 70; + iErrorStop = 150; throw iRc; } } if( iRetrieveSw ){ if(( iRc = GetDbfPtr( npTag, 0, npTag->npCurNode, ulKeyPtr )) != XB_NO_ERROR ){ - iErrorStop = 80; + iErrorStop = 160; throw iRc; } if(( iRc = dbf->GetRecord( ulKeyPtr )) != XB_NO_ERROR ){ - iErrorStop = 90; + iErrorStop = 170; throw iRc; } } @@ -1882,12 +1873,12 @@ xbInt16 xbIxNdx::GetPrevKey( void * vpTag, xbInt16 iRetrieveSw ){ npTag->npCurNode->iCurKeyNo--; if(( iRc = GetDbfPtr( npTag, npTag->npCurNode->iCurKeyNo, npTag->npCurNode, ulKeyPtr )) != XB_NO_ERROR ){ - iErrorStop = 10; + iErrorStop = 100; throw iRc; } if( iRetrieveSw ){ if(( iRc = dbf->GetRecord( ulKeyPtr )) != XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 110; throw iRc; } else { return iRc; @@ -1923,23 +1914,23 @@ xbInt16 xbIxNdx::GetPrevKey( void * vpTag, xbInt16 iRetrieveSw ){ npTag->npCurNode->iCurKeyNo--; if(( iRc = GetKeyPtr( npTag, npTag->npCurNode->iCurKeyNo, npTag->npCurNode, ulKeyPtr )) != XB_NO_ERROR ){ - iErrorStop = 30; + iErrorStop = 120; throw iRc; } if(( iRc = GetBlock( npTag, ulKeyPtr, 1, (xbUInt32) npTag->iKeyItemLen )) != XB_NO_ERROR ){ - iErrorStop = 40; + iErrorStop = 130; throw iRc; } while( !IsLeaf( npTag, npTag->npCurNode )){ // go down the chain looking for a leaf node npTag->npCurNode->iCurKeyNo = eGetUInt32( npTag->npCurNode->cpBlockData ); if(( iRc = GetKeyPtr( npTag, npTag->npCurNode->iCurKeyNo, npTag->npCurNode, ulKeyPtr )) != XB_NO_ERROR ){ - iErrorStop = 60; + iErrorStop = 140; throw iRc; } if(( iRc = GetBlock( npTag, ulKeyPtr, 1, (xbUInt32) npTag->iKeyItemLen )) != XB_NO_ERROR ){ - iErrorStop = 70; + iErrorStop = 150; throw iRc; } } @@ -1947,11 +1938,11 @@ xbInt16 xbIxNdx::GetPrevKey( void * vpTag, xbInt16 iRetrieveSw ){ npTag->npCurNode->iCurKeyNo = eGetUInt32( npTag->npCurNode->cpBlockData ) - 1; if( iRetrieveSw ){ if(( iRc = GetDbfPtr( npTag, npTag->npCurNode->iCurKeyNo, npTag->npCurNode, ulKeyPtr )) != XB_NO_ERROR ){ - iErrorStop = 80; + iErrorStop = 160; throw iRc; } if(( iRc = dbf->GetRecord( ulKeyPtr )) != XB_NO_ERROR ){ - iErrorStop = 90; + iErrorStop = 170; throw iRc; } } @@ -2096,7 +2087,7 @@ xbInt16 xbIxNdx::InsertNodeI( void *vpTag, xbIxNode *npNode, xbInt16 iSlotNo, xb // write out the updated block to disk if(( iRc = WriteBlock( npNode->ulBlockNo, GetBlockSize(), npNode->cpBlockData )) != XB_NO_ERROR ){ - iErrorStop = 10; + iErrorStop = 120; throw iRc; } if( pLastKey ) @@ -2166,7 +2157,7 @@ xbInt16 xbIxNdx::InsertNodeL( void *vpTag, xbIxNode *npNode, xbInt16 iSlotNo, // write out the updated block to disk if(( iRc = WriteBlock( npNode->ulBlockNo, GetBlockSize(), npNode->cpBlockData )) != XB_NO_ERROR ){ - iErrorStop = 10; + iErrorStop = 100; throw iRc; } } @@ -2233,14 +2224,14 @@ xbInt16 xbIxNdx::KeySetPosAdd( xbNdxTag *npTag, xbUInt32 ulAddRecNo ){ return XB_NO_ERROR; // good position else if( iRc != XB_NO_ERROR ){ - iErrorStop = 10; + iErrorStop = 100; throw iRc; } // get here if key was found, get the right most instance of any non unique key for append, find correct spot for update if( GetUnique() == 0 ){ xbUInt32 ulCurRecNo; if(( iRc = GetDbfPtr( npTag, npTag->npCurNode->iCurKeyNo, npTag->npCurNode, ulCurRecNo )) != XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 110; throw iRc; } xbBool bKeysMatch = xbTrue; @@ -2250,7 +2241,7 @@ xbInt16 xbIxNdx::KeySetPosAdd( xbNdxTag *npTag, xbUInt32 ulAddRecNo ){ bKeysMatch = xbFalse; else{ if(( iRc = GetDbfPtr( npTag, npTag->npCurNode->iCurKeyNo, npTag->npCurNode, ulCurRecNo )) != XB_NO_ERROR ){ - iErrorStop = 30; + iErrorStop = 120; throw iRc; } } @@ -2296,18 +2287,18 @@ xbInt16 xbIxNdx::KeySetPosDel( xbNdxTag *npTag ){ if( iRc == XB_NOT_FOUND || iRc == XB_EMPTY ) return XB_NO_ERROR; // good position else if( iRc != XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 100; throw iRc; } xbUInt32 ulIxRecNo; if(( iRc = GetDbfPtr( npTag, npTag->npCurNode->iCurKeyNo, npTag->npCurNode, ulIxRecNo )) != XB_NO_ERROR ){ - iErrorStop = 30; + iErrorStop = 110; throw iRc; } if( ulIxRecNo == dbf->GetCurRecNo()) return XB_NO_ERROR; if( GetUnique() == 1 ){ - iErrorStop = 40; + iErrorStop = 120; iRc = XB_NOT_FOUND; throw iRc; } @@ -2315,14 +2306,14 @@ xbInt16 xbIxNdx::KeySetPosDel( xbNdxTag *npTag ){ xbBool bKeysMatch = xbTrue; while( bKeysMatch && !bFound && iRc == XB_NO_ERROR ){ if(( iRc = GetNextKey( npTag, 0 )) != XB_NO_ERROR ){ - iErrorStop = 50; + iErrorStop = 130; throw iRc; } if( memcmp( GetKeyData( npTag->npCurNode, npTag->npCurNode->iCurKeyNo, npTag->iKeyItemLen ), npTag->cpKeyBuf2, (size_t) npTag->iKeyLen )){ bKeysMatch = xbFalse; } else { if(( iRc = GetDbfPtr( npTag, npTag->npCurNode->iCurKeyNo, npTag->npCurNode, ulIxRecNo )) != XB_NO_ERROR ){ - iErrorStop = 60; + iErrorStop = 140; throw iRc; } if( ulIxRecNo == dbf->GetCurRecNo()) @@ -2368,14 +2359,14 @@ xbInt16 xbIxNdx::ReadHeadBlock( xbInt16 iOpt = 0 ) { try{ if( !FileIsOpen()){ iRc = XB_NOT_OPEN; - iErrorStop = 10; + iErrorStop = 100; throw iRc; } xbInt16 iLen; iOpt == 0 ? iLen = 512 : iLen = 21; if(( iRc = ReadBlock( (xbUInt32) 0, (size_t) iLen, cNodeBuf )) != XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 110; throw iRc; } char *p = cNodeBuf; @@ -2396,7 +2387,7 @@ xbInt16 xbIxNdx::ReadHeadBlock( xbInt16 iOpt = 0 ) { ndxTag->exp = new xbExp( xbase, dbf ); if(( iRc = ndxTag->exp->ParseExpression( ndxTag->sKeyExpression.Str() )) != XB_NO_ERROR ){ - iErrorStop = 30; + iErrorStop = 120; throw iRc; } @@ -2448,24 +2439,24 @@ xbInt16 xbIxNdx::Reindex( void **vpTag ){ void *vpTag2; if(( iRc = CreateTag( sFileName, sKey, sFilter, 0, iUnique, xbTrue, &vpTag2 )) != XB_NO_ERROR ){ - iErrorStop = 10; + iErrorStop = 100; throw iRc; } xbUInt32 ulRecCnt = 0; if(( iRc = dbf->GetRecordCnt( ulRecCnt )) != XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 110; throw iRc; } for( xbUInt32 l = 1; l <= ulRecCnt; l++ ){ if(( iRc = dbf->GetRecord( l )) != XB_NO_ERROR ){ - iErrorStop = 30; + iErrorStop = 120; throw iRc; } if(( iRc = CreateKey( vpTag2, 1 )) != XB_NO_ERROR ){ - iErrorStop = 40; + iErrorStop = 130; throw iRc; } @@ -2473,7 +2464,7 @@ xbInt16 xbIxNdx::Reindex( void **vpTag ){ iRc = CheckForDupKey( vpTag2 ); if( iRc != 0 ){ if( iRc < 0 ){ - iErrorStop = 50; + iErrorStop = 140; throw iRc; } return XB_KEY_NOT_UNIQUE; @@ -2481,7 +2472,7 @@ xbInt16 xbIxNdx::Reindex( void **vpTag ){ } if(( iRc = AddKey( vpTag2, l )) != XB_NO_ERROR ){ - iErrorStop = 60; + iErrorStop = 150; throw iRc; } } @@ -2493,11 +2484,8 @@ xbInt16 xbIxNdx::Reindex( void **vpTag ){ xbase->WriteLogMessage( sMsg.Str() ); xbase->WriteLogMessage( GetErrorMessage( iRc )); } - return iRc; } - - /***********************************************************************/ //! @brief Set current tag. /*! @@ -2593,12 +2581,12 @@ xbInt16 xbIxNdx::SplitNodeI( void *vpTag, xbIxNode * npLeft, xbIxNode *npRight, // write out the block if(( iRc = WriteBlock( npLeft->ulBlockNo, GetBlockSize(), npLeft->cpBlockData )) != XB_NO_ERROR ){ - iErrorStop = 100; + iErrorStop = 110; throw iRc; } // write out the block if(( iRc = WriteBlock( npRight->ulBlockNo, GetBlockSize(), npRight->cpBlockData )) != XB_NO_ERROR ){ - iErrorStop = 200; + iErrorStop = 120; throw iRc; } } @@ -2675,18 +2663,16 @@ xbInt16 xbIxNdx::SplitNodeL( void *vpTag, xbIxNode * npLeft, xbIxNode *npRight, pTrg = npRight->cpBlockData; ePutInt32( pTrg, lNewRightKeyCnt ); - // write out the block + // write out the left block if(( iRc = WriteBlock( npLeft->ulBlockNo, GetBlockSize(), npLeft->cpBlockData )) != XB_NO_ERROR ){ iErrorStop = 110; throw iRc; } - - // write out the block + // write out the right block if(( iRc = WriteBlock( npRight->ulBlockNo, GetBlockSize(), npRight->cpBlockData )) != XB_NO_ERROR ){ iErrorStop = 120; throw iRc; } - } catch (xbInt16 iRc ){ xbString sMsg; @@ -2734,16 +2720,12 @@ xbInt16 xbIxNdx::UpdateTagKey( char cAction, void *vpTag, xbUInt32 ulRecNo ){ } if( cAction == 'A' || cAction == 'R' ){ -// std::cout << "UpdateTagKey add\n"; if(( iRc = AddKey( vpTag, ulRecNo )) != XB_NO_ERROR ){ - iErrorStop = 200; + iErrorStop = 110; throw iRc; } } -// if( ulTagSizeSave != mpTag->ulTagSize ){ -// std::cout << "UpdateTagKey - tag size was updated need to do something here\n"; -// } } catch (xbInt16 iRc ){ xbString sMsg; @@ -2753,7 +2735,6 @@ xbInt16 xbIxNdx::UpdateTagKey( char cAction, void *vpTag, xbUInt32 ulRecNo ){ } return iRc; } - /***********************************************************************/ //! @brief Write head block. /*! @@ -2792,7 +2773,7 @@ xbInt16 xbIxNdx::WriteHeadBlock( xbInt16 iOpt ){ ePutUInt32( &buf[0], ndxTag->ulRootBlock ); ePutUInt32( &buf[4], ndxTag->ulTotalBlocks ); if(( iRc = xbFwrite( buf, 8, 1 )) != XB_NO_ERROR ){ - iErrorStop = 200; + iErrorStop = 120; throw iRc; } return WriteHeadBlock( 2 ); @@ -2816,7 +2797,7 @@ xbInt16 xbIxNdx::WriteHeadBlock( xbInt16 iOpt ){ xbRewind(); if(( iRc = xbFwrite( buf, 512, 1 )) != XB_NO_ERROR ){ - iErrorStop = 300; + iErrorStop = 130; throw iRc; } } else { -- cgit v1.2.3