diff options
Diffstat (limited to 'src/core/xbmemo4.cpp')
-rwxr-xr-x | src/core/xbmemo4.cpp | 245 |
1 files changed, 104 insertions, 141 deletions
diff --git a/src/core/xbmemo4.cpp b/src/core/xbmemo4.cpp index 4f92d2b..d02df99 100755 --- a/src/core/xbmemo4.cpp +++ b/src/core/xbmemo4.cpp @@ -53,11 +53,11 @@ xbInt16 xbMemoDbt4::Abort(){ xbUInt32 ulNodeCnt = llNewBlocks.GetNodeCnt(); for( xbUInt32 l = 0; l < ulNodeCnt; l++ ){ if(( rc = llNewBlocks.RemoveFromFront( ulBlockNo )) != XB_NO_ERROR ){ - iErrorStop = 10; + iErrorStop = 100; throw rc; } if(( rc = FreeMemoBlockChain( ulBlockNo )) != XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 110; throw rc; } } @@ -89,11 +89,11 @@ xbInt16 xbMemoDbt4::Commit(){ xbUInt32 ulNodeCnt = llOldBlocks.GetNodeCnt(); for( xbUInt32 l = 0; l < ulNodeCnt; l++ ){ if(( rc = llOldBlocks.RemoveFromFront( ulBlockNo )) != XB_NO_ERROR ){ - iErrorStop = 10; + iErrorStop = 100; throw rc; } if(( rc = FreeMemoBlockChain( ulBlockNo )) != XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 110; throw rc; } } @@ -121,14 +121,14 @@ xbInt16 xbMemoDbt4::CreateMemoFile(){ try{ if(( rc = xbFopen( "w+b", dbf->GetShareMode() )) != XB_NO_ERROR ){ - iErrorStop = 10; + iErrorStop = 100; throw rc; } ulHdrNextBlock = 1L; ePutUInt32( cBuf, ulHdrNextBlock ); if(( rc = xbFwrite( cBuf, 4, 1 ))!= XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 110; xbFclose(); throw rc; } @@ -145,7 +145,7 @@ xbInt16 xbMemoDbt4::CreateMemoFile(){ ePutInt16( cBuf, GetBlockSize()); if(( rc = xbFwrite( cBuf, 2, 1 ))!= XB_NO_ERROR ){ - iErrorStop = 60; + iErrorStop = 120; xbFclose(); throw rc; } @@ -153,7 +153,7 @@ xbInt16 xbMemoDbt4::CreateMemoFile(){ xbFputc( 0x00 ); if(( mbb = (void *) malloc( GetBlockSize())) == NULL ){ rc = XB_NO_MEMORY; - iErrorStop = 80; + iErrorStop = 130; return XB_NO_MEMORY; } } @@ -181,11 +181,11 @@ xbInt16 xbMemoDbt4::DumpMemoFreeChain() try{ if(( rc = ReadDbtHeader(1)) != XB_NO_ERROR ){ - iErrorStop = 10; + iErrorStop = 100; throw rc; } if(( rc = CalcLastDataBlock( ulLastDataBlock )) != XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 110; throw rc; } @@ -196,7 +196,7 @@ xbInt16 xbMemoDbt4::DumpMemoFreeChain() while( ulCurBlock < ulLastDataBlock ){ if(( rc = ReadBlockHeader( ulCurBlock, 2 )) != XB_NO_ERROR ){ - iErrorStop = 30; + iErrorStop = 120; throw rc; } std::cout << "**********************************" << std::endl; @@ -245,6 +245,8 @@ xbInt16 xbMemoDbt4::DumpMemoInternals() { return XB_NO_ERROR; } +#endif // XB_DEBUG_SUPPORT + /***********************************************************************/ //! @brief Dump memo file header. /*! @@ -266,7 +268,6 @@ xbInt16 xbMemoDbt4::DumpMemoHeader(){ std::cout << "Last Data Block = " << ulLastDataBlock << std::endl; return rc; } -#endif // XB_DEBUG_SUPPORT /************************************************************************/ //! @brief Find an empty set of blocks in the free block chain @@ -295,7 +296,7 @@ xbInt16 xbMemoDbt4::FindBlockSetInChain( xbUInt32 ulBlocksNeeded, if( ulLastDataBlock == 0 ){ /* Determine last good data block */ if(( rc = CalcLastDataBlock( ulLastDataBlock )) != XB_NO_ERROR ){ - iErrorStop = 10; + iErrorStop = 100; throw rc; } } @@ -303,14 +304,14 @@ xbInt16 xbMemoDbt4::FindBlockSetInChain( xbUInt32 ulBlocksNeeded, ulCurNode = ulHdrNextBlock; if(( rc = ReadBlockHeader( ulHdrNextBlock, 2 )) != XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 110; throw rc; } while( ulBlocksNeeded > ulFreeBlockCnt && ulNextFreeBlock < ulLastDataBlock ){ ulPrevNode = ulCurNode; ulCurNode = ulNextFreeBlock; if(( rc = ReadBlockHeader( ulNextFreeBlock, 2 )) != XB_NO_ERROR ){ - iErrorStop = 30; + iErrorStop = 120; throw rc; } } @@ -373,14 +374,14 @@ xbInt16 xbMemoDbt4::FreeMemoBlockChain( xbUInt32 ulBlockNo, xbUInt32 &ulLastData try{ if( ulBlockNo <= 0 ){ - iErrorStop = 10; + iErrorStop = 100; rc =XB_INVALID_BLOCK_NO; throw rc; } /* Load the first block */ if(( rc = ReadBlockHeader( ulBlockNo, 1 )) != XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 110; throw rc; } @@ -391,12 +392,12 @@ xbInt16 xbMemoDbt4::FreeMemoBlockChain( xbUInt32 ulBlockNo, xbUInt32 &ulLastData /* Determine last good data block */ if(( rc = CalcLastDataBlock( ulLastDataBlock )) != XB_NO_ERROR ){ - iErrorStop = 30; + iErrorStop = 120; throw rc; } if(( rc = ReadDbtHeader( 0 )) != XB_NO_ERROR ){ - iErrorStop = 40; + iErrorStop = 130; throw rc; } @@ -406,7 +407,7 @@ xbInt16 xbMemoDbt4::FreeMemoBlockChain( xbUInt32 ulBlockNo, xbUInt32 &ulLastData ulLastFreeBlock = ulNextFreeBlock; if(( rc = ReadBlockHeader( ulNextFreeBlock, 2 )) != XB_NO_ERROR ){ - iErrorStop = 50; + iErrorStop = 140; return rc; } ulLastFreeBlockCnt = ulFreeBlockCnt; @@ -421,7 +422,7 @@ xbInt16 xbMemoDbt4::FreeMemoBlockChain( xbUInt32 ulBlockNo, xbUInt32 &ulLastData ulSaveNextFreeBlock = ulNextFreeBlock; if(( ulBlockNo + ulNoOfFreedBlocks ) == ulNextFreeBlock && ulNextFreeBlock < ulLastDataBlock ){ if(( rc = ReadBlockHeader( ulNextFreeBlock, 2 )) != XB_NO_ERROR ){ - iErrorStop = 60; + iErrorStop = 150; throw rc; } ulNoOfFreedBlocks += ulFreeBlockCnt; @@ -438,13 +439,13 @@ xbInt16 xbMemoDbt4::FreeMemoBlockChain( xbUInt32 ulBlockNo, xbUInt32 &ulLastData ePutUInt32( (char *) mbb, ulSaveNextFreeBlock ); ePutUInt32( (char *) mbb+4, ulNoOfFreedBlocks ); if(( rc = WriteBlock( ulBlockNo, 8, mbb )) != XB_NO_ERROR ){ - iErrorStop = 70; + iErrorStop = 160; throw rc; } ulHdrNextBlock = ulBlockNo; if(( rc = UpdateHeadNextNode()) != XB_NO_ERROR ){ - iErrorStop = 80; + iErrorStop = 170; throw rc; } return XB_NO_ERROR; @@ -452,9 +453,8 @@ xbInt16 xbMemoDbt4::FreeMemoBlockChain( xbUInt32 ulBlockNo, xbUInt32 &ulLastData /* determine if this block set should be added to the previous set */ if(( ulLastFreeBlockCnt + ulLastFreeBlock ) == ulBlockNo ){ - if(( rc = ReadBlockHeader( ulLastFreeBlock, 2 )) != XB_NO_ERROR ){ - iErrorStop = 90; + iErrorStop = 180; throw rc; } ulFreeBlockCnt += ulNoOfFreedBlocks; @@ -462,7 +462,7 @@ xbInt16 xbMemoDbt4::FreeMemoBlockChain( xbUInt32 ulBlockNo, xbUInt32 &ulLastData ePutUInt32( (char *) mbb, ulSaveNextFreeBlock ); ePutUInt32( (char *) mbb+4, ulFreeBlockCnt ); if(( rc = WriteBlock( ulLastFreeBlock, 8, mbb )) != XB_NO_ERROR ){ - iErrorStop = 100; + iErrorStop = 190; throw rc; } return XB_NO_ERROR; @@ -478,34 +478,29 @@ xbInt16 xbMemoDbt4::FreeMemoBlockChain( xbUInt32 ulBlockNo, xbUInt32 &ulLastData ePutUInt32( (char *) mbb, ulSaveNextFreeBlock ); ePutUInt32( (char *) mbb+4, ulNoOfFreedBlocks ); if(( rc = WriteBlock( ulBlockNo, 8, mbb )) != XB_NO_ERROR ){ - iErrorStop = 110; + iErrorStop = 200; throw rc; } if(( rc = ReadBlockHeader( ulLastFreeBlock, 2 )) != XB_NO_ERROR ){ - iErrorStop = 120; + iErrorStop = 210; throw rc; } ePutUInt32( (char *) mbb, ulBlockNo ); if(( rc = WriteBlock( ulLastFreeBlock, 8, mbb )) != XB_NO_ERROR ){ - iErrorStop = 130; + iErrorStop = 220; throw rc; } - } - catch (xbInt16 rc ){ xbString sMsg; sMsg.Sprintf( "xbMemoDbt4::DeleteMemoField() Exception Caught. Error Stop = [%d] rc = [%d]", iErrorStop, rc ); xbase->WriteLogMessage( sMsg.Str() ); xbase->WriteLogMessage( GetErrorMessage( rc )); } - return rc; } - - /************************************************************************/ //! @brief Get a set of blocks from the free block chain. /*! @@ -520,9 +515,7 @@ xbInt16 xbMemoDbt4::FreeMemoBlockChain( xbUInt32 ulBlockNo, xbUInt32 &ulLastData xbInt16 xbMemoDbt4::GetBlockSetFromChain( xbUInt32 ulBlocksNeeded, xbUInt32 ulLocation, xbUInt32 ulPrevNode ) - { - xbInt16 rc = XB_NO_ERROR; xbInt16 iErrorStop = 0; xbUInt32 ulNextFreeBlock2; @@ -531,7 +524,7 @@ xbInt16 xbMemoDbt4::GetBlockSetFromChain( xbUInt32 ulBlocksNeeded, try{ if(( rc = ReadBlockHeader( ulLocation, 2 )) != XB_NO_ERROR ){ - iErrorStop = 10; + iErrorStop = 100; throw rc; } @@ -539,7 +532,7 @@ xbInt16 xbMemoDbt4::GetBlockSetFromChain( xbUInt32 ulBlocksNeeded, if( ulPrevNode == 0 ){ // first in the chain ulHdrNextBlock = ulNextFreeBlock; if(( rc = UpdateHeadNextNode()) != XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 110; throw rc; } } @@ -547,12 +540,12 @@ xbInt16 xbMemoDbt4::GetBlockSetFromChain( xbUInt32 ulBlocksNeeded, { ulNextFreeBlock2 = ulNextFreeBlock; if(( rc = ReadBlockHeader( ulPrevNode, 2 )) != XB_NO_ERROR ){ - iErrorStop = 30; + iErrorStop = 120; throw rc; } ulNextFreeBlock = ulNextFreeBlock2; if(( rc = WriteBlockHeader( ulPrevNode, 2 )) != XB_NO_ERROR ){ - iErrorStop = 40; + iErrorStop = 130; throw rc; } } @@ -560,36 +553,33 @@ xbInt16 xbMemoDbt4::GetBlockSetFromChain( xbUInt32 ulBlocksNeeded, if( ulPrevNode == 0 ){ // first in the set ulHdrNextBlock = ulLocation + ulBlocksNeeded; if(( rc = UpdateHeadNextNode()) != XB_NO_ERROR ){ - iErrorStop = 50; + iErrorStop = 140; throw rc; } ulFreeBlockCnt -= ulBlocksNeeded; if(( rc = WriteBlockHeader( ulHdrNextBlock, 2 )) != XB_NO_ERROR ){ - iErrorStop = 60; + iErrorStop = 150; throw rc; } - } else { // remove out of the middle or end - ulNewFreeBlocks = ulFreeBlockCnt - ulBlocksNeeded; ulSaveNextFreeBlock = ulNextFreeBlock; ulNextFreeBlock2 = ulLocation + ulBlocksNeeded; if(( rc = ReadBlockHeader( ulPrevNode, 2 )) != XB_NO_ERROR ){ - iErrorStop = 70; + iErrorStop = 160; throw rc; } - ulNextFreeBlock = ulNextFreeBlock2; if(( rc = WriteBlockHeader( ulPrevNode, 2 )) != XB_NO_ERROR ){ - iErrorStop = 80; + iErrorStop = 170; throw rc; } ulFreeBlockCnt = ulNewFreeBlocks; ulNextFreeBlock = ulSaveNextFreeBlock; if(( rc = WriteBlockHeader( ulNextFreeBlock2, 2 )) != XB_NO_ERROR ){ - iErrorStop = 90; + iErrorStop = 180; throw rc; } } @@ -603,7 +593,6 @@ xbInt16 xbMemoDbt4::GetBlockSetFromChain( xbUInt32 ulBlocksNeeded, } return rc; } - /***********************************************************************/ //! @brief Get a memo field for a given field number. /*! @@ -622,9 +611,8 @@ xbInt16 xbMemoDbt4::GetMemoField( xbInt16 iFieldNo, xbString & sMemoData ){ char *p = NULL; try{ - if(( rc = GetMemoFieldLen( iFieldNo, ulMemoFieldLen, ulBlockNo )) != XB_NO_ERROR ){ - iErrorStop = 10; + iErrorStop = 100; throw rc; } @@ -634,7 +622,7 @@ xbInt16 xbMemoDbt4::GetMemoField( xbInt16 iFieldNo, xbString & sMemoData ){ ulMemoFieldDataLen = ulMemoFieldLen - 8; if(( p = (char *)calloc(1, ulMemoFieldDataLen+1)) == NULL ){ - iErrorStop = 20; + iErrorStop = 110; rc = XB_NO_MEMORY; xbString sMsg; sMsg.Sprintf( "xbMemoDbt4::GetMemoField() lBlockNo = %ld Data Len = [%ld]", ulBlockNo, ulMemoFieldDataLen + 1 ); @@ -644,18 +632,17 @@ xbInt16 xbMemoDbt4::GetMemoField( xbInt16 iFieldNo, xbString & sMemoData ){ // go to the first block of the memo field, skip past the first 8 bytes if(( xbFseek( ( ulBlockNo * GetBlockSize() + 8 ), SEEK_SET )) != XB_NO_ERROR ){ - iErrorStop = 30; + iErrorStop = 120; rc = XB_SEEK_ERROR; throw rc; } // read the memo file data into buffer pointed to by "p" if(( rc = xbFread( p, ulMemoFieldDataLen, 1 )) != XB_NO_ERROR ){ - iErrorStop = 40; + iErrorStop = 130; rc = XB_READ_ERROR; throw rc; } - // null terminate the string char *p2; p2 = p + ulMemoFieldDataLen; @@ -665,7 +652,6 @@ xbInt16 xbMemoDbt4::GetMemoField( xbInt16 iFieldNo, xbString & sMemoData ){ sMemoData.Set( p, ulMemoFieldDataLen + 1 ); free( p ); } - } catch (xbInt16 rc ){ xbString sMsg; @@ -708,30 +694,27 @@ xbInt16 xbMemoDbt4::GetMemoFieldLen( xbInt16 iFieldNo, xbUInt32 &ulMemoFieldLen, try{ if(( rc = dbf->GetFieldType( iFieldNo, cFieldType )) != XB_NO_ERROR ){ - iErrorStop = 10; + iErrorStop = 100; throw rc; } if( cFieldType != 'M' ){ - iErrorStop = 20; + iErrorStop = 110; rc = XB_INVALID_MEMO_FIELD; throw rc; } if(( rc = dbf->GetULongField( iFieldNo, ulBlockNo )) < XB_NO_ERROR ){ - iErrorStop = 30; + iErrorStop = 120; throw rc; } - if( ulBlockNo < 1 ){ ulMemoFieldLen = 0; return XB_NO_ERROR; } - if(( rc = ReadBlockHeader( ulBlockNo, 1 )) != XB_NO_ERROR ){ - iErrorStop = 40; + iErrorStop = 130; throw rc; } ulMemoFieldLen = ulFieldLen; - } catch (xbInt16 rc ){ xbString sMsg; @@ -741,7 +724,6 @@ xbInt16 xbMemoDbt4::GetMemoFieldLen( xbInt16 iFieldNo, xbUInt32 &ulMemoFieldLen, } return rc; } - /***********************************************************************/ //! @brief Open memo file. /*! @@ -755,16 +737,16 @@ xbInt16 xbMemoDbt4::OpenMemoFile() { try{ if(( rc = xbFopen( dbf->GetOpenMode(), dbf->GetShareMode())) != XB_NO_ERROR ){ - iErrorStop = 10; + iErrorStop = 100; throw rc; } if(( rc = ReadDbtHeader( 1 )) != XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 110; throw rc; } if(( mbb = (void *) malloc( GetBlockSize())) == NULL ){ xbFclose(); - iErrorStop = 30; + iErrorStop = 120; rc = XB_NO_MEMORY; throw rc; } @@ -792,23 +774,21 @@ xbInt16 xbMemoDbt4::PackMemo( void (*memoStatusFunc ) ( xbUInt32 ulItemNum, xbUI char * cBlock = NULL; #ifdef XB_LOCKING_SUPPORT - xbInt16 iAutoLock = dbf->GetAutoLock(); xbBool bTableLocked = xbFalse; xbBool bMemoLocked = xbFalse; #endif try{ - #ifdef XB_LOCKING_SUPPORT - if( iAutoLock && !dbf->GetTableLocked() ){ + if( dbf->GetAutoLock() && !dbf->GetTableLocked() ){ if(( iRc = dbf->LockTable( XB_LOCK )) != XB_NO_ERROR ){ - iErrorStop = 10; + iErrorStop = 100; throw iRc; } else { bTableLocked = xbTrue; } if(( iRc = LockMemo( XB_LOCK )) != XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 110; throw iRc; } else { bMemoLocked = xbTrue; @@ -819,20 +799,20 @@ xbInt16 xbMemoDbt4::PackMemo( void (*memoStatusFunc ) ( xbUInt32 ulItemNum, xbUI // create temp file xbString sTempMemoName; if(( iRc = CreateUniqueFileName( GetDirectory(), "dbt", sTempMemoName )) != XB_NO_ERROR ){ - iErrorStop = 10; + iErrorStop = 120; throw iRc; } xbMemoDbt4 *pMemo = new xbMemoDbt4( dbf, sTempMemoName ); if(( iRc = pMemo->CreateMemoFile()) != XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 130; throw iRc; } // for dbase III, block size is always 512, don't need to reset it // for each record in dbf xbUInt32 ulRecCnt; if(( iRc = dbf->GetRecordCnt( ulRecCnt)) != XB_NO_ERROR ){ - iErrorStop = 30; + iErrorStop = 140; throw iRc; } xbInt32 lFldCnt = dbf->GetFieldCnt(); @@ -841,7 +821,7 @@ xbInt16 xbMemoDbt4::PackMemo( void (*memoStatusFunc ) ( xbUInt32 ulItemNum, xbUI for( xbUInt32 ulI = 1; ulI <= ulRecCnt; ulI++ ){ if(( iRc = dbf->GetRecord( ulI )) != XB_NO_ERROR ){ - iErrorStop = 40; + iErrorStop = 150; throw iRc; } @@ -851,18 +831,18 @@ xbInt16 xbMemoDbt4::PackMemo( void (*memoStatusFunc ) ( xbUInt32 ulItemNum, xbUI // for each memo field for( xbInt32 lFc = 0; lFc < lFldCnt; lFc++ ){ if(( iRc = dbf->GetFieldType( lFc, cFldType )) != XB_NO_ERROR ){ - iErrorStop = 50; + iErrorStop = 160; throw iRc; } if( cFldType == 'M' ){ // copy it to work field if(( iRc = dbf->GetMemoField( lFc, sMemoFldData )) != XB_NO_ERROR ){ - iErrorStop = 60; + iErrorStop = 170; throw iRc; } // write it to new field if(( iRc = pMemo->UpdateMemoField( lFc, sMemoFldData )) != XB_NO_ERROR ){ - iErrorStop = 70; + iErrorStop = 180; throw iRc; } } @@ -873,25 +853,25 @@ xbInt16 xbMemoDbt4::PackMemo( void (*memoStatusFunc ) ( xbUInt32 ulItemNum, xbUI xbUInt32 ulBlkSize = GetBlockSize(); xbUInt64 ullFileSize; if(( iRc = pMemo->GetFileSize( ullFileSize )) != XB_NO_ERROR ){ - iErrorStop = 80; + iErrorStop = 190; throw iRc; } // file size should be evenly divisible by block size xbUInt32 ulBlkCnt; if( ullFileSize % ulBlkSize ){ - iErrorStop = 90; + iErrorStop = 200; throw iRc; } else { ulBlkCnt = (xbUInt32) (ullFileSize / ulBlkSize); } if(( iRc = xbTruncate( 0 )) != XB_NO_ERROR ){ - iErrorStop = 100; + iErrorStop = 210; throw iRc; } if(( cBlock = (char *) malloc( ulBlkSize )) == NULL ){ - iErrorStop = 110; + iErrorStop = 220; throw iRc; } @@ -900,17 +880,17 @@ xbInt16 xbMemoDbt4::PackMemo( void (*memoStatusFunc ) ( xbUInt32 ulItemNum, xbUI for( xbUInt32 ulBc = 0; ulBc < ulBlkCnt; ulBc++ ){ if(( iRc = pMemo->ReadBlock( ulBc, ulBlkSize, cBlock )) != XB_NO_ERROR ){ - iErrorStop = 120; + iErrorStop = 230; throw iRc; } if(( iRc = WriteBlock( ulBc, ulBlkSize, cBlock )) != XB_NO_ERROR ){ - iErrorStop = 130; + iErrorStop = 240; throw iRc; } } if(( xbFseek( 8, SEEK_SET )) != XB_NO_ERROR ){ - iErrorStop = 140; + iErrorStop = 250; iRc = XB_SEEK_ERROR; throw iRc; } @@ -920,44 +900,31 @@ xbInt16 xbMemoDbt4::PackMemo( void (*memoStatusFunc ) ( xbUInt32 ulItemNum, xbUI //close and delete target if(( iRc = pMemo->xbFclose()) != XB_NO_ERROR ){ - iErrorStop = 150; + iErrorStop = 260; throw iRc; } if(( iRc = pMemo->xbRemove()) != XB_NO_ERROR ){ - iErrorStop = 160; + iErrorStop = 270; throw iRc; } free( cBlock ); delete pMemo; - #ifdef XB_LOCKING_SUPPORT - if( iAutoLock && !dbf->GetTableLocked() ){ - if(( iRc = dbf->LockTable( XB_UNLOCK )) != XB_NO_ERROR ){ - iErrorStop = 200; - throw iRc; - } - if(( iRc = LockMemo( XB_UNLOCK )) != XB_NO_ERROR ){ - iErrorStop = 210; - throw iRc; - } - } - #endif } catch (xbInt16 iRc ){ free( cBlock ); - #ifdef XB_LOCKING_SUPPORT - if( bTableLocked ) - dbf->LockTable( XB_UNLOCK ); - if( bMemoLocked ) - LockMemo( XB_UNLOCK ); - #endif - xbString sMsg; sMsg.Sprintf( "xbMemoDbt4::PackMemo() Exception Caught. Error Stop = [%d] rc = [%d]", iErrorStop, iRc ); xbase->WriteLogMessage( sMsg.Str() ); xbase->WriteLogMessage( GetErrorMessage( iRc )); } + #ifdef XB_LOCKING_SUPPORT + if( bTableLocked ) + dbf->LockTable( XB_UNLOCK ); + if( bMemoLocked ) + LockMemo( XB_UNLOCK ); + #endif return iRc; } /***********************************************************************/ @@ -977,7 +944,7 @@ xbInt16 xbMemoDbt4::ReadBlockHeader( xbUInt32 ulBlockNo, xbInt16 iOption ) { try{ if(( rc = ReadBlock( ulBlockNo, 8, mbb )) != XB_NO_ERROR ){ - iErrorStop = 10; + iErrorStop = 100; rc = XB_READ_ERROR; } if( iOption == 1 ){ @@ -990,7 +957,7 @@ xbInt16 xbMemoDbt4::ReadBlockHeader( xbUInt32 ulBlockNo, xbInt16 iOption ) { ulFreeBlockCnt = eGetUInt32((char *) mbb+4 ); } else{ - iErrorStop = 20; + iErrorStop = 110; rc = XB_INVALID_OPTION; throw rc; } @@ -1021,12 +988,12 @@ xbInt16 xbMemoDbt4::ReadDbtHeader( xbInt16 iOption ) { try{ if( !FileIsOpen() ){ - iErrorStop = 10; + iErrorStop = 100; rc = XB_NOT_OPEN; throw rc; } if( xbFseek( 0, SEEK_SET )){ - iErrorStop = 20; + iErrorStop = 110; rc = XB_SEEK_ERROR; throw rc; } @@ -1036,7 +1003,7 @@ xbInt16 xbMemoDbt4::ReadDbtHeader( xbInt16 iOption ) { iReadLen = 4; if(( xbFread( &MemoBlock, (size_t) iReadLen, 1 )) != XB_NO_ERROR ){ - iErrorStop = 30; + iErrorStop = 120; rc = XB_READ_ERROR; throw rc; } @@ -1104,13 +1071,13 @@ xbInt16 xbMemoDbt4::UpdateHeaderName() { try{ if(( rc = xbFseek( 8, SEEK_SET )) != XB_NO_ERROR ){ - iErrorStop = 10; + iErrorStop = 100; throw rc; } for( int i = 1; i < 9; i++ ){ if(( rc = xbFputc( sDbfFileNameWoExt[i] )) != XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 110; throw rc; } } @@ -1140,7 +1107,7 @@ xbInt16 xbMemoDbt4::UpdateMemoField( xbInt16 iFieldNo, const xbString & sMemoDat try{ if(( rc = dbf->GetULongField( iFieldNo, ulBlockNo )) < XB_NO_ERROR ){ - iErrorStop = 10; + iErrorStop = 100; throw rc; } @@ -1155,26 +1122,24 @@ xbInt16 xbMemoDbt4::UpdateMemoField( xbInt16 iFieldNo, const xbString & sMemoDat // Since it won't be needed in either a Commmit() or Abort(), can be freed immediately if( llNewBlocks.SearchFor( ulBlockNo ) > 0 ){ if(( rc = FreeMemoBlockChain( ulBlockNo )) != XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 110; throw rc; } if(( llNewBlocks.RemoveByVal( ulBlockNo )) < XB_NO_ERROR ){ - iErrorStop = 30; + iErrorStop = 120; throw rc; } } else { // first revision, save what it was in case of Abort() command if(( llOldBlocks.InsertAtFront( ulBlockNo )) != XB_NO_ERROR ){ - iErrorStop = 40; + iErrorStop = 130; throw rc; } } - if(( rc = dbf->PutField( iFieldNo, "" )) != XB_NO_ERROR ){ - iErrorStop = 50; + iErrorStop = 140; throw rc; } - } } else { // free up the old space @@ -1184,13 +1149,13 @@ xbInt16 xbMemoDbt4::UpdateMemoField( xbInt16 iFieldNo, const xbString & sMemoDat if( llNewBlocks.SearchFor( ulBlockNo ) > 0 ){ if(( rc = FreeMemoBlockChain( ulBlockNo, ulLastDataBlock )) != XB_NO_ERROR ){ - iErrorStop = 60; + iErrorStop = 150; throw rc; } } else { // first revision, save what it was in case of Abort() command if(( rc = llOldBlocks.InsertAtFront( ulBlockNo )) != XB_NO_ERROR ){ - iErrorStop = 70; + iErrorStop = 160; throw rc; } } @@ -1207,7 +1172,7 @@ xbInt16 xbMemoDbt4::UpdateMemoField( xbInt16 iFieldNo, const xbString & sMemoDat xbUInt32 ulHeadBlock; xbUInt32 ulPrevNode; if(( rc = FindBlockSetInChain( ulBlocksNeeded, ulLastDataBlock, ulHeadBlock, ulPrevNode, bUsedBlockFound )) != XB_NO_ERROR ){ - iErrorStop = 80; + iErrorStop = 170; throw rc; } iField1 = -1; @@ -1217,34 +1182,33 @@ xbInt16 xbMemoDbt4::UpdateMemoField( xbInt16 iFieldNo, const xbString & sMemoDat if( bUsedBlockFound ){ if(( rc = GetBlockSetFromChain( ulBlocksNeeded, ulHeadBlock, ulPrevNode )) != XB_NO_ERROR ){ - iErrorStop = 90; + iErrorStop = 180; throw rc; } if(( rc = WriteBlockHeader( ulHeadBlock, 1 )) != XB_NO_ERROR ){ - iErrorStop = 100; + iErrorStop = 190; throw rc; } if(( rc = xbFwrite( sMemoData.Str(), sMemoData.Len(), 1 )) != XB_NO_ERROR ){ - iErrorStop = 110; + iErrorStop = 200; throw rc; } - } else { // append to the end if(( rc = WriteBlockHeader( ulLastDataBlock, 1 )) != XB_NO_ERROR ){ - iErrorStop = 120; + iErrorStop = 220; throw rc; } if(( rc = xbFwrite( sMemoData.Str(), sMemoData.Len(), 1 )) != XB_NO_ERROR ){ - iErrorStop = 130; + iErrorStop = 230; throw rc; } if(( rc = xbFputc( 0x00, (xbInt32)((ulBlocksNeeded * GetBlockSize()) - (sMemoData.Len() + 8)))) != XB_NO_ERROR ){ - iErrorStop = 140; + iErrorStop = 240; throw rc; } @@ -1252,7 +1216,7 @@ xbInt16 xbMemoDbt4::UpdateMemoField( xbInt16 iFieldNo, const xbString & sMemoDat ulHdrNextBlock += ulBlocksNeeded; ulHeadBlock = ulLastDataBlock; if(( rc = UpdateHeadNextNode()) != XB_NO_ERROR ){ - iErrorStop = 150; + iErrorStop = 250; throw rc; } @@ -1261,18 +1225,18 @@ xbInt16 xbMemoDbt4::UpdateMemoField( xbInt16 iFieldNo, const xbString & sMemoDat ulNextFreeBlock = ulLastDataBlock + ulBlocksNeeded; ulHeadBlock = ulLastDataBlock; if(( rc = WriteBlockHeader( ulPrevNode, 2 )) != XB_NO_ERROR ){ - iErrorStop = 160; + iErrorStop = 260; throw rc; } } } if(( rc = llNewBlocks.InsertAtFront( ulHeadBlock )) != XB_NO_ERROR ){ // In case of Abort(), this block needs to be freed - iErrorStop = 170; + iErrorStop = 270; throw rc; } if(( rc = dbf->PutLongField( iFieldNo, (xbInt32) ulHeadBlock )) != XB_NO_ERROR ){ - iErrorStop = 180; + iErrorStop = 280; throw rc; } } @@ -1284,7 +1248,6 @@ xbInt16 xbMemoDbt4::UpdateMemoField( xbInt16 iFieldNo, const xbString & sMemoDat xbase->WriteLogMessage( sMsg.Str() ); xbase->WriteLogMessage( GetErrorMessage( rc )); } - return rc; } /***********************************************************************/ @@ -1312,13 +1275,13 @@ xbInt16 xbMemoDbt4::WriteBlockHeader( xbUInt32 ulBlockNo, xbInt16 iOption ) { ePutUInt32((char *) mbb+4, ulFreeBlockCnt ); } else{ - iErrorStop = 10; + iErrorStop = 100; rc = XB_INVALID_OPTION; throw rc; } if(( rc = WriteBlock( ulBlockNo, 8, mbb )) != XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 110; rc = XB_READ_ERROR; } } @@ -1345,15 +1308,15 @@ xbInt16 xbMemoDbt4::Zap(){ ePutUInt32( cBuf, ulHdrNextBlock ); if(( iRc != xbFseek( 0, SEEK_SET )) != XB_NO_ERROR ){ - iErrorStop = 10; + iErrorStop = 100; throw iRc; } if(( iRc != xbFwrite( cBuf, 4, 1 ))!= XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 110; throw iRc; } if(( iRc != xbTruncate( GetBlockSize())) != XB_NO_ERROR ){ - iErrorStop = 30; + iErrorStop = 120; throw iRc; } } |