diff options
Diffstat (limited to 'src/core/xbixmdx.cpp')
-rwxr-xr-x | src/core/xbixmdx.cpp | 259 |
1 files changed, 15 insertions, 244 deletions
diff --git a/src/core/xbixmdx.cpp b/src/core/xbixmdx.cpp index 135cde8..0eef64b 100755 --- a/src/core/xbixmdx.cpp +++ b/src/core/xbixmdx.cpp @@ -92,11 +92,7 @@ xbInt16 xbIxMdx::AddKey( void * vpTag, xbUInt32 ulRecNo ){ iErrorStop = 100; throw iRc; } - xbInt32 lKeyCnt = GetKeyCount( npTag->npCurNode ); - - // std::cout << "xbIxMdx::AddKeys() lKeyCnt = " << lKeyCnt << " KeysPerBlock = " << npTag->iKeysPerBlock << " npBlockNo = " << npTag->npCurNode->ulBlockNo << "\n"; - if( lKeyCnt < npTag->iKeysPerBlock ){ // Section A - add key to appropriate position if space available // std::cout << "AddKey Section A begin\n"; @@ -104,12 +100,8 @@ xbInt16 xbIxMdx::AddKey( void * vpTag, xbUInt32 ulRecNo ){ iErrorStop = 110; throw iRc; } - //std::cout << "AddKey Section A end\n"; } else { - // land here with a full leaf node - // std::cout << "Section B begin split leaf node\n"; - iHeadNodeUpdateOpt = 1; npRightNode = AllocateIxNode( npTag, GetBlockSize() + (xbUInt32) npTag->iKeyItemLen, npTag->npCurNode->ulBlockNo * (xbUInt32) iBlockFactor ); if( !npRightNode ){ @@ -122,26 +114,14 @@ xbInt16 xbIxMdx::AddKey( void * vpTag, xbUInt32 ulRecNo ){ ulNewRightChild = npRightNode->ulBlockNo * (xbUInt32) iBlockFactor; } - // std::cout << "ulNewRightChild = " << ulNewRightChild << "\n"; - if(( iRc = xbIxMdx::SplitNodeL( npTag, npTag->npCurNode, npRightNode, npTag->npCurNode->iCurKeyNo, npTag->cpKeyBuf, ulRecNo )) != XB_NO_ERROR ){ iErrorStop = 130; throw iRc; } xbUInt32 ulTempBlockNo = npRightNode->ulBlockNo; - - //std::cout << "ulTempBlockNo = " << ulTempBlockNo << "\n"; - //std::cout << "key count left block " << GetKeyCount( npTag->npCurNode ) << "\n"; - //std::cout << "key count right block " << GetKeyCount( npRightNode ) << "\n"; - - - //std::cout << "Section B end\n"; - // section C - go up the tree, splitting nodes as necessary xbIxNode * npParent = npTag->npCurNode->npPrev; - - while( npParent && GetKeyCount( npParent ) >= npTag->iKeysPerBlock ){ //std::cout << "Section C begin interior node is full\n"; npRightNode = FreeNodeChain( npRightNode ); @@ -165,23 +145,15 @@ xbInt16 xbIxMdx::AddKey( void * vpTag, xbUInt32 ulRecNo ){ npParent = npParent->npPrev; } - // std::cout << "Past Section C Cur Node Block No = " << npTag->npCurNode->ulBlockNo << " root page = " << npTag->ulRootPage << "\n"; // section D - if cur node is split root, create new root - if(( npTag->npCurNode->ulBlockNo * (xbUInt32) iBlockFactor ) == npTag->ulRootPage ){ - - // std::cout << "Section D begin right node = " << npRightNode << "\n"; - if(( iRc = AddKeyNewRoot( npTag, npTag->npCurNode, npRightNode )) != XB_NO_ERROR ){ iErrorStop = 160; throw iRc; } - if( npRightNode ) npRightNode = FreeNodeChain( npRightNode ); - // std::cout << "Section D end\n"; - } else { // std::cout << "Section E, put key in parent\n"; @@ -213,8 +185,6 @@ xbInt16 xbIxMdx::AddKey( void * vpTag, xbUInt32 ulRecNo ){ if( ulNewRightChild > 0 ){ -// std::cout << "ulRightChild was = " << npTag->ulRightChild << " changed to " << ulNewRightChild << "\n"; - char cBuf[4]; ePutUInt32( cBuf, ulNewRightChild ); if(( iRc = xbFseek( ((npTag->ulTagHdrPageNo * 512) + 252), SEEK_SET )) != XB_NO_ERROR ){ @@ -225,7 +195,6 @@ xbInt16 xbIxMdx::AddKey( void * vpTag, xbUInt32 ulRecNo ){ iErrorStop = 220; throw iRc; } -// std::cout << "setting right child\n"; npTag->ulRightChild = ulNewRightChild; } @@ -243,7 +212,6 @@ xbInt16 xbIxMdx::AddKey( void * vpTag, xbUInt32 ulRecNo ){ } return iRc; } - /***********************************************************************/ void xbIxMdx::AppendNodeChain( void *vpTag, xbIxNode * npNode ){ xbMdxTag * mdxTag = (xbMdxTag *) vpTag; @@ -282,11 +250,6 @@ xbInt16 xbIxMdx::AddKeyNewRoot( xbMdxTag *npTag, xbIxNode *npLeft, xbIxNode *np } npTag->ulRootPage = npRoot->ulBlockNo; - // std::cout << "AddKeyNewRoot - RootBlock = " << npRoot->ulBlockNo << "\n"; - // std::cout << "AddKeyNewRoot - LeftBlock = " << npLeft->ulBlockNo << "\n"; - // std::cout << "AddKeyNewRoot - RightBlock = " << npRight->ulBlockNo << "\n"; - - pLastKey = (char *) malloc( (size_t) npTag->iKeyLen ); if(( iRc = GetLastKeyForBlockNo( npTag, npLeft->ulBlockNo, pLastKey )) != XB_NO_ERROR ){ iErrorStop = 110; @@ -303,17 +266,8 @@ xbInt16 xbIxMdx::AddKeyNewRoot( xbMdxTag *npTag, xbIxNode *npLeft, xbIxNode *np // set the key pTrg+= 4; - // std::cout << "AddKeyNewRoot - key [" << pLastKey << "] len = [" << strlen( pLastKey) << "]\n"; memcpy( pTrg, pLastKey, (size_t) npTag->iKeyLen ); - - // set the right node number - //pTrg+= (npTag->iKeyLen); - // pTrg+= (npTag->iKeyItemLen)-4; - pTrg+= npTag->iKeyItemLen - 4; - - //pTrg-=4; - ePutUInt32( pTrg, npRight->ulBlockNo * (xbUInt32) iBlockFactor ); // write out the new block @@ -326,8 +280,6 @@ xbInt16 xbIxMdx::AddKeyNewRoot( xbMdxTag *npTag, xbIxNode *npLeft, xbIxNode *np // position the file xbUInt32 ulPagePos = npTag->ulTagHdrPageNo * 512; - // std::cout << "ulPagePos = " << ulPagePos << " root block no = " << npRoot->ulBlockNo << " \n"; - // save the number to a buffer char cBuf[4]; ePutUInt32( cBuf, npRoot->ulBlockNo * ((xbUInt32) iBlockFactor )); @@ -375,9 +327,6 @@ xbIxNode * xbIxMdx::AllocateIxNode( xbMdxTag * mpTag, xbUInt32 ulBufSize, xbUInt xbIxNode *n = NULL; try{ - - // std::cout << "xbIxMdx::AllocateIxNode()\n"; - if(( n = xbIx::AllocateIxNode( ulBufSize )) == NULL ){ iRc = XB_NO_MEMORY; iErrorStop = 100; @@ -387,10 +336,7 @@ xbIxNode * xbIxMdx::AllocateIxNode( xbMdxTag * mpTag, xbUInt32 ulBufSize, xbUInt p += 4; if( ulFirstFreePage > 0 && bReuseEmptyNodes ){ - // we have an empty node we can reuse - - // std::cout << "Reusing node " << ulFirstFreePage << "\n"; - + // have an empty node we can reuse n->ulBlockNo = PageToBlock( ulFirstFreePage ); if(( iRc = ReadBlock( n->ulBlockNo, GetBlockSize(), n->cpBlockData )) != XB_NO_ERROR ){ iRc = 110; @@ -409,7 +355,6 @@ xbIxNode * xbIxMdx::AllocateIxNode( xbMdxTag * mpTag, xbUInt32 ulBufSize, xbUInt // memset cpBlockData to zeroes memset( n->cpBlockData, 0x00, GetBlockSize()); - } else { n->ulBlockNo = ulPageCnt / (xbUInt32) iBlockFactor; ulPageCnt += (xbUInt32) iBlockFactor; @@ -419,9 +364,6 @@ xbIxNode * xbIxMdx::AllocateIxNode( xbMdxTag * mpTag, xbUInt32 ulBufSize, xbUInt if( ulBlock2 > 0 ){ ePutUInt32( p, ulBlock2 ); } - - // std::cout << "AllocateIxNode incremented the block to " << ulPageCnt << "\n"; - // std::cout << "AllocateIxNode new block number = " << n->ulBlockNo << "\n"; } catch( xbInt16 iRc ){ xbString sMsg; @@ -431,9 +373,7 @@ xbIxNode * xbIxMdx::AllocateIxNode( xbMdxTag * mpTag, xbUInt32 ulBufSize, xbUInt if( n ) n = FreeNodeChain( n ); } - return n; - } /***********************************************************************/ //! @brief Calculate B-tree pointers. @@ -496,8 +436,6 @@ void xbIxMdx::CalcBtreePointers(){ xbString s; xbMdxTag *mpTag = mdxTagTbl; for( xbInt16 i = 0; i < iTagUseCnt; i++ ){ -// s.Sprintf( "tag = [%d] parent = [%d] left = [%d] right = [%d]\n", i, iaParent[i], iaLeftChild[i], iaRightChild[i]); -// std::cout << s; mpTag->cLeftChild = (char ) iaLeftChild[i]; mpTag->cRightChild = (char ) iaRightChild[i]; mpTag->cParent = (char ) iaParent[i]; @@ -597,9 +535,7 @@ xbInt16 xbIxMdx::CheckTagIntegrity( void *vpTag, xbInt16 iOpt ){ xbBool bLocked = xbFalse; #endif - try{ -// xbase->WriteLogMessage( "xbIxMdx::CheckTagIntegrity()", iOpt ); #ifdef XB_LOCKING_SUPPORT if( dbf->GetAutoLock() && !dbf->GetTableLocked() ){ @@ -612,7 +548,6 @@ xbInt16 xbIxMdx::CheckTagIntegrity( void *vpTag, xbInt16 iOpt ){ #endif memset( npTag->cpKeyBuf2, 0x00, (size_t) npTag->iKeyLen ); - // memset( npTag->cpKeyBuf2, 0x00, (size_t) npTag->iKeyItemLen ); cKeyType = GetKeyType( vpTag ); pPrevKeyBuf = (char *) calloc( 1, (size_t) npTag->iKeyLen ); @@ -716,10 +651,8 @@ xbInt16 xbIxMdx::CheckTagIntegrity( void *vpTag, xbInt16 iOpt ){ xbase->WriteLogMessage( sMsg, iOpt ); } - if( pPrevKeyBuf ) free( pPrevKeyBuf ); - } catch (xbInt16 iRc ){ xbString sMsg; @@ -734,7 +667,6 @@ xbInt16 xbIxMdx::CheckTagIntegrity( void *vpTag, xbInt16 iOpt ){ xbase->WriteLogMessage( sMsg, iOpt ); } } - #ifdef XB_LOCKING_SUPPORT if( bLocked ){ dbf->LockTable( XB_UNLOCK ); @@ -795,7 +727,6 @@ xbInt16 xbIxMdx::Close(){ return iRc; } - /***********************************************************************/ //! @brief Create key. /*! @@ -830,9 +761,6 @@ xbInt16 xbIxMdx::CreateKey( void *vpTag, xbInt16 iOpt ){ xbMdxTag *npTag = (xbMdxTag *) vpTag; npTag->iKeySts = 0; - // char *p0 = dbf->GetRecordBuf(0); - // char *p1 = dbf->GetRecordBuf(1); - // do tag filter logic if( npTag->cHasFilter ){ if(( iRc = npTag->filter->ProcessExpression( 0 )) != XB_NO_ERROR ){ @@ -843,8 +771,6 @@ xbInt16 xbIxMdx::CreateKey( void *vpTag, xbInt16 iOpt ){ iErrorStop = 110; throw iRc; } - // std::cout << "cp1 f0 = " << bFilter0 << "\n"; - // printf( "del byte 0 [%x] 1 [%x]\n", *p0, *p1 ); } else { bFilter0 = xbTrue; } @@ -922,10 +848,6 @@ xbInt16 xbIxMdx::CreateKey( void *vpTag, xbInt16 iOpt ){ npTag->iKeySts = XB_ADD_KEY; } } - -// std::cout << "xbIxMdx::CreateKey key sts = " << npTag->iKeySts << " iOpt = " << iOpt << " type = " << npTag->exp->GetReturnType() << " name = " << npTag->cTagName; -// std::cout << " f0 = " << bFilter0 << " f1 = " << bFilter1 << "\n"; - } catch (xbInt16 iRc ){ xbString sMsg; @@ -933,16 +855,15 @@ xbInt16 xbIxMdx::CreateKey( void *vpTag, xbInt16 iOpt ){ xbase->WriteLogMessage( sMsg.Str() ); xbase->WriteLogMessage( GetErrorMessage( iRc )); } - return iRc; } - /***********************************************************************/ //! @brief Create new tag. /*! This routine creates a new tag. When complete, sets the cur tag pointer to the newly created tag. + \param sName Tag Name, including .MDX suffix \param sKey Key Expression \param sFilter Filter expression. @@ -960,11 +881,6 @@ xbInt16 xbIxMdx::CreateTag( const xbString &sName, const xbString &sKey, const xbInt16 iErrorStop = 0; xbMdxTag *tte = NULL; - - // std::cout << "CreateTag() name=[" << sName.Str() << "] key=[" << sKey.Str() << "] sFilter=[" << sFilter.Str() << "]\n"; - // std::cout << "TagUseCnt = " << iTagUseCnt << std::endl; - - try{ // verify room for new tag if( !( iTagUseCnt < 47 )){ @@ -1016,8 +932,6 @@ xbInt16 xbIxMdx::CreateTag( const xbString &sName, const xbString &sKey, const throw iRc; } - // tte->filter->DumpTree( 1 ); - if((tte->filter->GetReturnType()) != 'L' ){ iRc = XB_INVALID_TAG; iErrorStop = 160; @@ -1042,7 +956,7 @@ xbInt16 xbIxMdx::CreateTag( const xbString &sName, const xbString &sKey, const } xbDate d; - + d.Sysdate(); if( iTagUseCnt == 0 ){ // first tag, new mdx file // create the file name @@ -1132,11 +1046,6 @@ xbInt16 xbIxMdx::CreateTag( const xbString &sName, const xbString &sKey, const tte->cpKeyBuf = (char *) malloc( (size_t) tte->iKeyLen + 1 ); tte->cpKeyBuf2 = (char *) malloc( (size_t) tte->iKeyLen + 1 ); -// if( 0 ){ -// printf( "ulTagHdrPageNo=[%d] cTagName=[%-11s], cLeftChild=[%d] cRightChild=[%d] cParent=[%d] cKeyType=[%c]\n\n", -// tte->ulTagHdrPageNo, tte->cTagName, tte->cLeftChild, tte->cRightChild, tte->cParent, tte->cKeyType ); -// } - // write the new tte entry here char tteBuf[21]; memset( tteBuf, 0x00, 21 ); @@ -1158,7 +1067,6 @@ xbInt16 xbIxMdx::CreateTag( const xbString &sName, const xbString &sKey, const throw iRc; } - // Begin Tag Header tte->ulRootPage = ulPageCnt; tte->ulTagSize = (xbUInt32) iBlockFactor; @@ -1185,15 +1093,8 @@ xbInt16 xbIxMdx::CreateTag( const xbString &sName, const xbString &sKey, const while(( tte->iKeyItemLen % 4 ) != 0 ) tte->iKeyItemLen++; tte->iKeysPerBlock = (xbInt16) (GetBlockSize() - 12) / tte->iKeyItemLen; - - //std::cout << "-------------- create tag info\n"; - //std::cout << "keylen=" << tte->iKeyLen << " iKeyItemLen = " << tte->iKeyItemLen << " keys per block calc = " << tte->iKeysPerBlock << "\n"; - tte->cKeyFmt3 = CalcTagKeyFmt( *tte->exp ); -// printf( "ulRootPage=[%d] cKeyFmt2=[%d] cKeyType2=[%d] iKeyLen=[%d]iKeysPerBlock=[%d]\n", tte->ulRootPage, tte->cKeyFmt2, tte->cKeyType2, tte->iKeyLen, tte->iKeysPerBlock ); -// printf( "iSecKeyType=[%d] iKeyItemLen=[%d] cUnique=[%d] \n", tte->iSecKeyType, tte->iKeyItemLen, tte->cUnique ); - char *pBuf; if(( pBuf = (char *) calloc( 1, (size_t) GetBlockSize())) == NULL ){ iErrorStop = 230; @@ -1280,7 +1181,6 @@ xbInt16 xbIxMdx::CreateTag( const xbString &sName, const xbString &sKey, const iTagUseCnt++; cNextTag++; - if(( iRc = WriteHeadBlock( 1 )) != XB_NO_ERROR ){ iErrorStop = 270; throw iRc; @@ -1350,9 +1250,6 @@ xbInt16 xbIxMdx::CreateTag( const xbString &sName, const xbString &sKey, const tteWork = tteWork->next; } free( pBuf ); - -// xbIx::SetCurTag( ( void *) tte ); - } catch (xbInt16 iRc ){ @@ -1447,13 +1344,6 @@ xbInt16 xbIxMdx::DeleteFromNode( void *vpTag, xbIxNode * npNode, xbInt16 iSlotNo throw iRc; } - // do any empty node processing here -// if( bReuseEmptyNodes ){ -// if( bLeaf && lKeyCnt == 1 ){ -// std::cout << "Empty node ready for reuse\n"; -// } -// } - } catch (xbInt16 iRc ){ xbString sMsg; @@ -1486,8 +1376,6 @@ xbInt16 xbIxMdx::DeleteKey( void *vpTag ){ npTag->npNodeChain = NULL; xbIxNode * npSaveCurNode = npTag->npCurNode; - // std::cout << "xbIxMdx::DeleteKey()\n"; - try{ xbString sMsg; @@ -1502,7 +1390,6 @@ xbInt16 xbIxMdx::DeleteKey( void *vpTag ){ // as prev key, ascend 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; @@ -1591,7 +1478,7 @@ xbInt16 xbIxMdx::DeleteKey( void *vpTag ){ } /***********************************************************************/ -//! @brief Dump a given block for a tag +//! @brief Delete a given tag /*! \param vpTag Input tag ptr for tag to be deleted<br> \returns <a href="xbretcod_8h.html">Return Codes</a><br> @@ -2100,8 +1987,6 @@ xbInt16 xbIxMdx::DumpHeader( xbInt16 iOpt, xbInt16 iFmtOpt ) if(( iRc = ReadHeadBlock( 1 )) != XB_NO_ERROR ) return iRc; -// std::cout << "xbIxMdx::DumpHeader options - " << iDestOpt << " fmtopt = " << iFmtOpt << "\n"; - char c, tfv, cDisplayMask = 1; cDisplayMask = cDisplayMask << 7; if( iFmtOpt != 2 && iFmtOpt != 4 ){ @@ -2116,9 +2001,6 @@ xbInt16 xbIxMdx::DumpHeader( xbInt16 iOpt, xbInt16 iFmtOpt ) } xbase->WriteLogMessage( s, iOpt ); - -// std::cout << std::endl; -// std::cout << s.Sprintf( "Create Date = %d/%d/%d", (int) cCreateMM, (int) cCreateDD, (int) cCreateYY % 100 ); xbase->WriteLogMessage( s, iOpt ); @@ -2724,9 +2606,6 @@ xbInt16 xbIxMdx::GetFirstKey( void *vpTag, xbInt16 iRetrieveSw = 0 ){ throw iRc; } } - // else { - // throw iRc; - // } } catch (xbInt16 iRc ){ xbString sMsg; @@ -2766,23 +2645,16 @@ xbString &xbIxMdx::GetKeyFilter( const void * vpTag ) const{ xbMdxTag * mpTag = (xbMdxTag *) vpTag; - // std::cout << "GetKeyFilter() "; if( mpTag->sFiltExp ) return *mpTag->sFiltExp; -// std::cout << " not null\n"; else return sNullString; - // std::cout << " null\n"; - -// next line causes seg faults -// return *mpTag->sFiltExp; } /**************************************************************************************************/ xbInt16 xbIxMdx::GetKeyPtr( void *vpTag, xbInt16 iKeyNo, xbIxNode *np, xbUInt32 &ulKeyPtr ) const { xbInt16 iRc = XB_NO_ERROR; - xbInt16 iErrorStop = 0; try{ @@ -3339,15 +3211,9 @@ xbInt16 xbIxMdx::HarvestEmptyNode( xbMdxTag *mpTag, xbIxNode *npNode, xbInt16 iO try{ -// std::cout << "xbIxMdx::HarvestEmptyNode() page= " << BlockToPage( npNode->ulBlockNo ); -// std::cout << " block = " << npNode->ulBlockNo << "\n"; - if( mpTag->ulRootPage == BlockToPage( npNode->ulBlockNo ) && !bHarvestRoot ){ bRootPage = xbTrue; - -// std::cout << "special root page processing *****************\n"; } - memset( npNode->cpBlockData, 0x00, GetBlockSize()); char *pTrg = npNode->cpBlockData; @@ -3356,7 +3222,6 @@ xbInt16 xbIxMdx::HarvestEmptyNode( xbMdxTag *mpTag, xbIxNode *npNode, xbInt16 iO ePutUInt32( pTrg, ulFirstFreePage ); } - if( bRootPage ){ if( mpTag->cHasKeys ){ @@ -3374,7 +3239,6 @@ xbInt16 xbIxMdx::HarvestEmptyNode( xbMdxTag *mpTag, xbIxNode *npNode, xbInt16 iO // might need to update left sibling and right sibling here. // Fields don't seem to be updated consistently by other xbase tools, // for now, not updating - } } else { @@ -3393,7 +3257,6 @@ xbInt16 xbIxMdx::HarvestEmptyNode( xbMdxTag *mpTag, xbIxNode *npNode, xbInt16 iO iErrorStop = 130; throw iRc; } - } if( iOpt == 1 ){ @@ -3418,8 +3281,6 @@ xbInt16 xbIxMdx::HarvestEmptyNode( xbMdxTag *mpTag, xbIxNode *npNode, xbInt16 iO return iRc; } - - /***********************************************************************/ //! @brief Harvest Tag Nodes. /*! @@ -3523,9 +3384,7 @@ xbInt16 xbIxMdx::InsertNodeI( void *vpTag, xbIxNode *npNode, xbInt16 iSlotNo, xb xbInt16 iCopyLen; xbInt16 iNewKeyPos = 8; - try{ - xbInt32 lKeyCnt = GetKeyCount( npNode ); iNewKeyPos += (iSlotNo * npTag->iKeyItemLen); char *pSrc = npNode->cpBlockData; @@ -3642,12 +3501,6 @@ xbInt16 xbIxMdx::InsertNodeL( void *vpTag, xbIxNode *npNode, xbInt16 iSlotNo, ch try{ xbInt32 lKeyCnt = GetKeyCount( npNode ); - -// std::cout << "InsertNodeL Keycount = " << lKeyCnt << "\n"; -// next line is correct, this aligns with db7 -// "4" is the four byte record number stored to the left of the key -// xbInt16 iKeyPos = 4 + iSlotNo * npTag->iKeyItemLen; - iNewKeyPos += (iSlotNo * npTag->iKeyItemLen); // length of number of keys that need to be moved to the right @@ -3657,24 +3510,18 @@ xbInt16 xbIxMdx::InsertNodeL( void *vpTag, xbIxNode *npNode, xbInt16 iSlotNo, ch iCopyLen = 0; // +8 is to include the first two 4 byte fields in the block - // xbUInt32 ulRqdBufSize = (xbUInt32) (iKeyPos + (npTag->iKeyItemLen * 2) + iCopyLen + 8); xbUInt32 ulRqdBufSize = (xbUInt32) ((lKeyCnt + 1) * npTag->iKeyItemLen) + 8; -/* - std::cout << "InsertNodeL CopyLen = " << iCopyLen << "\n"; - std::cout << "InsertNodeL iNewKeyPos = " << iNewKeyPos << "\n"; - std::cout << "InsertNodeL SlotNo = " << iSlotNo << "\n"; - std::cout << "InsertNodeL lKeyCnt = " << lKeyCnt << "\n"; - std::cout << "InsertNodeL node buf size = " << npNode->ulBufSize << "\n"; - std::cout << "InsertNodeL key item len = " << npTag->iKeyItemLen << "\n"; - std::cout << "InsertNodeL key len = " << npTag->iKeyLen << "\n"; - std::cout << "required buf size = " << ulRqdBufSize << "\n"; - std::cout << "InsertNodeL key buf strlen = " << strlen( npTag->cpKeyBuf ) << "\n"; -*/ - if( ulRqdBufSize > npNode->ulBufSize ){ + npNode->ulBufSize += (xbUInt32) npTag->iKeyItemLen; npNode->cpBlockData = (char *) realloc( npNode->cpBlockData, (size_t) npNode->ulBufSize ); + + // init the newly acquired buffer space + char *p = npNode->cpBlockData; + p += (npNode->ulBufSize - (xbUInt32) npTag->iKeyItemLen); + memset( p, 0x00, (size_t) npTag->iKeyItemLen ); + if( !npNode->cpBlockData ){ iErrorStop = 100; iRc = XB_NO_MEMORY; @@ -3688,10 +3535,6 @@ xbInt16 xbIxMdx::InsertNodeL( void *vpTag, xbIxNode *npNode, xbInt16 iSlotNo, ch pNewKeyPos += iNewKeyPos; if( iSlotNo < lKeyCnt ) { - // pKeyPos = npNode->cpBlockData; - // pKeyPos += iKeyPos; - // pKeyPos += iNewKeyPos; - // pTrg = pKeyPos; pTrg = pNewKeyPos; pTrg += npTag->iKeyItemLen; memmove( pTrg, pNewKeyPos, (size_t) iCopyLen ); @@ -3710,14 +3553,11 @@ xbInt16 xbIxMdx::InsertNodeL( void *vpTag, xbIxNode *npNode, xbInt16 iSlotNo, ch // update number of keys on the node ePutInt32( npNode->cpBlockData, ++lKeyCnt ); -// std::cout << "lKeyCntA = " << GetKeyCount( npNode ) << "\n"; - // determine length of node, zap everything to the right of it xbUInt32 iStartPos = 8 + ((xbUInt32) lKeyCnt * (xbUInt32) npTag->iKeyItemLen ); xbUInt32 iClearLen = npNode->ulBufSize - iStartPos; -// std::cout << "InsertNodeL SP = " << iStartPos << " clear len = " << iClearLen << " ulBufsize = " << npNode->ulBufSize << "\n"; char *p = npNode->cpBlockData; p += iStartPos; memset( p, 0x00, iClearLen ); @@ -3727,10 +3567,6 @@ xbInt16 xbIxMdx::InsertNodeL( void *vpTag, xbIxNode *npNode, xbInt16 iSlotNo, ch iErrorStop = 100; throw iRc; } - -// std::cout << "lKeyCntB = " << GetKeyCount( npNode ) << "\n"; - - } catch (xbInt16 iRc ){ xbString sMsg; @@ -3754,8 +3590,6 @@ inline xbBool xbIxMdx::IsLeaf( void *vpTag, xbIxNode *npNode ) const{ p+=8; p+= mTag->iKeyItemLen * lNoOfKeys; - // printf( "IsLeaf p = [%d] b1 = [%x] keylen = [%d]\n", eGetUInt32( p ), *p, mTag->iKeyItemLen ); - if( eGetUInt32( p ) == 0 ){ // std::cout << "leaf node\n"; return true; @@ -3773,8 +3607,6 @@ xbInt16 xbIxMdx::KeyExists( void * vpTag ) xbMdxTag *mpTag = (xbMdxTag *) vpTag; xbInt16 iRc = FindKey( vpTag, mpTag->cpKeyBuf, mpTag->iKeyLen, 0 ); - // iRc == 0 ? return 1 : return 0; - if( iRc == 0 ) return 1; else @@ -3940,8 +3772,6 @@ xbInt16 xbIxMdx::LoadTagDetail( xbInt16 iOption, xbMdxTag *tte ){ // option 1 - Load the entire tag detail // option 2 - Load the dynamic variables only - // std::cout << "LoadTagDetail() iOption = " << iOption << "\n"; - xbInt16 iRc = XB_NO_ERROR; xbInt16 iErrorStop = 0; size_t iReadSize; @@ -4020,10 +3850,6 @@ xbInt16 xbIxMdx::LoadTagDetail( xbInt16 iOption, xbMdxTag *tte ){ p+=221; tte->cKeyFmt3 = *p; -//for( int i = 0; i < 5; i++ ) -// printf( "%d [%x]\n", i, *p++ ); -// p+=2; - if( tte->cHasFilter ){ p+=282; tte->sFiltExp = new xbString(); @@ -4135,7 +3961,6 @@ xbInt16 xbIxMdx::LoadTagTable() ttel->next = tte; else mdxTagTbl = tte; - // tte->sKeyExp = new xbString(); ttel = tte; tte->next = NULL; @@ -4268,13 +4093,9 @@ xbInt16 xbIxMdx::PrintKey( void *vpTag, xbIxNode *npNode, xbInt16 iKeyNo, xbInt1 xbInt16 xbIxMdx::ReadHeadBlock( xbInt16 iOpt ) { - - xbInt16 iRc = XB_NO_ERROR; xbInt16 iErrorStop = 0; -// std::cout << "ReadHeadBlock() option = " << iOpt << "\n"; - try{ if( !FileIsOpen()){ iRc = XB_NOT_OPEN; @@ -4367,8 +4188,6 @@ xbInt16 xbIxMdx::ReadHeadBlock( xbInt16 iOpt ) cUpdateMM = *p++; cUpdateDD = *p; } - - } catch (xbInt16 iRc ){ xbString sMsg; @@ -4425,7 +4244,7 @@ xbInt16 xbIxMdx::Reindex( void **vpTag ){ iErrorStop = 100; throw iRc; } - bLocked = xbTrue; + bLocked = xbTrue; } #endif @@ -4476,13 +4295,6 @@ xbInt16 xbIxMdx::Reindex( void **vpTag ){ // create new file & add the tags while( p ){ - //std::cout << "Reindex() linked list extract\n"; - //std::cout << "Tag Name = [" << p->sTagName << "]\n"; - //std::cout << "Key Exp = [" << p->sKeyExp->Str() << "]\n"; - //std::cout << "Filt Exp = [" << p->sFiltExp->Str() << "]\n"; - //std::cout << "bDesc = [" << p->bDesc << "]\n"; - //std::cout << "bUnique = [" << p->bUnique << "]\n"; - if(( iRc = CreateTag( p->sTagName, p->sKeyExp->Str(), p->sFiltExp->Str(), p->bDesc, p->bUnique, xbTrue, vpTag )) != XB_NO_ERROR ){ iErrorStop = 120; throw iRc; @@ -4550,6 +4362,7 @@ xbInt16 xbIxMdx::Reindex( void **vpTag ){ sMsg.Sprintf( "xbIxMdx::ReIndex() Exception Caught. Error Stop = [%d] iRc = [%d]", iErrorStop, iRc ); xbase->WriteLogMessage( sMsg.Str() ); xbase->WriteLogMessage( GetErrorMessage( iRc )); + this->DeleteTag( mpTag ); } #ifdef XB_LOCKING_SUPPORT @@ -4594,39 +4407,6 @@ void xbIxMdx::SetReuseEmptyNodesSw( xbBool bEmptyNodesSw ) { } /***********************************************************************/ -//! @brief Set Tag Pointer. -/*! - Set binary tree pointer value. The MDX tags are stored with binary - tree positions. This routine sets the value in memory. - \param cPtr L - Left child.<br> - R - Right child.<br> - P - Parent. - \param iWhich - Which tag to update - \param cVal - Value to set. - \returns void -*/ - -/* -void xbIxMdx::SetTagPtr( char cPtr, xbInt16 iWhich, char cVal ){ - - xbMdxTag *mpTag = (xbMdxTag *) GetTag( iWhich ); - if( mpTag ){ - switch( cPtr ){ - case 'L': - mpTag->cLeftChild = cVal; - break; - case 'R': - mpTag->cRightChild = cVal; - break; - case 'P': - mpTag->cParent = cVal; - break; - } - } -} -*/ - -/***********************************************************************/ //! @brief Split an interior node /*! @@ -4662,7 +4442,6 @@ xbInt16 xbIxMdx::SplitNodeI( void *vpTag, xbIxNode * npLeft, xbIxNode *npRight, char *pSrc; char *pTrg; - try{ xbInt32 lKeyCnt = GetKeyCount( npLeft ); xbInt32 lNewLeftKeyCnt = (xbInt32) ((lKeyCnt + 1) * dSplitFactor); @@ -4816,11 +4595,8 @@ xbInt16 xbIxMdx::TagSerialNo( xbInt16 iOption, xbMdxTag * mpTag ){ xbInt16 iErrorStop = 0; try{ - xbInt64 lPos = (mpTag->ulTagHdrPageNo * 512) + 20; -// std::cout << "UpdateSerialNo offset = " << lPos << " option = " << iOption << "\n"; - if( iOption != 2 ){ if(( iRc = xbFseek( lPos, SEEK_SET )) != XB_NO_ERROR ){ iErrorStop = 100; @@ -4845,7 +4621,6 @@ xbInt16 xbIxMdx::TagSerialNo( xbInt16 iOption, xbMdxTag * mpTag ){ throw iRc; } } - } catch (xbInt16 iRc ){ xbString sMsg; @@ -4856,7 +4631,6 @@ xbInt16 xbIxMdx::TagSerialNo( xbInt16 iOption, xbMdxTag * mpTag ){ return iRc; } - /***********************************************************************/ //! @brief UpdateTagKey /*! @@ -4881,9 +4655,6 @@ xbInt16 xbIxMdx::UpdateTagKey( char cAction, void *vpTag, xbUInt32 ulRecNo ){ try{ // save off any needed fields for updating xbUInt32 ulTagSizeSave = npTag->ulTagSize; - // std::cout << "old size = " << ulTagSizeSave << " new size = " << npTag->ulTagSize << "\n"; - //std::cout << "UpdateTagKey - tag size was updated need to do something here - test \n"; - if( cAction == 'D' || cAction == 'R' ){ // std::cout << "UpdateTagKey-delete going to DeleteKey \n"; @@ -4891,7 +4662,6 @@ xbInt16 xbIxMdx::UpdateTagKey( char cAction, void *vpTag, xbUInt32 ulRecNo ){ iErrorStop = 100; throw iRc; } - //std::cout << "UpdateTagKey-delete back from DeleteKey \n"; } if( cAction == 'A' || cAction == 'R' ){ @@ -4941,7 +4711,8 @@ xbInt16 xbIxMdx::WriteHeadBlock( xbInt16 iOption ){ xbInt16 iErrorStop = 0; try{ - xbDate d; // default is system date, today + xbDate d; + d.Sysdate(); // set to system date, today cUpdateYY = (char) d.YearOf() - 1900; cUpdateMM = (char) d.MonthOf(); cUpdateDD = (char) d.DayOf( XB_FMT_MONTH ); |