diff options
Diffstat (limited to 'src/core/xbdbf.cpp')
-rwxr-xr-x | src/core/xbdbf.cpp | 154 |
1 files changed, 140 insertions, 14 deletions
diff --git a/src/core/xbdbf.cpp b/src/core/xbdbf.cpp index 3d13369..4033ef9 100755 --- a/src/core/xbdbf.cpp +++ b/src/core/xbdbf.cpp @@ -2,7 +2,7 @@ XBase64 Software Library -Copyright (c) 1997,2003,2014,2022 Gary A Kunkel +Copyright (c) 1997,2003,2014,2022,2023 Gary A Kunkel The xb64 software library is covered under the terms of the GPL Version 3, 2007 license. @@ -24,10 +24,16 @@ namespace xb{ \param x Pointer to xbXbase */ xbDbf::xbDbf( xbXBase * x ) : xbFile( x ){ - xbase = x; - SchemaPtr = NULL; - RecBuf = NULL; - RecBuf2 = NULL; + xbase = x; + SchemaPtr = NULL; + RecBuf = NULL; + RecBuf2 = NULL; + + #ifdef XB_BLOCKREAD_SUPPORT + pRb = NULL; + bBlockReadEnabled = xbFalse; // batch read switch, if xbTrue, then ON + #endif // XB_BLOCKREAD_SUPPORT + InitVars(); } /************************************************************************/ @@ -77,7 +83,7 @@ void xbDbf::InitVars() #ifdef XB_INF_SUPPORT llInfData.Clear(); - #endif // XB_INF_SUPPORT + #endif // XB_INF_SUPPORT } /************************************************************************/ @@ -104,6 +110,16 @@ xbDbf::~xbDbf(){ free( RecBuf2 ); RecBuf2 = NULL; } + if( RecBuf ){ + free( RecBuf ); + RecBuf = NULL; + } + + #ifdef XB_BLOCKREAD_SUPPORT + if( bBlockReadEnabled ) + DisableBlockReadProcessing(); + #endif // XB_BLOCKREAD_SUPPORT + Close(); } /************************************************************************/ @@ -1952,6 +1968,18 @@ xbInt16 xbDbf::GetFirstKey(){ } /************************************************************************/ +//! @brief GetHeaderLen for dbf +/*! + + Returns the length of the header portion of the dbf file + \returns Length of header protion of dbf file + +*/ +xbUInt16 xbDbf::GetHeaderLen() const { + return uiHeaderLen; +} + +/************************************************************************/ //! @brief GetLastKey for tag. /*! @@ -2054,6 +2082,32 @@ xbInt16 xbDbf::Find( xbDouble &dKey ){ #endif // XB_INDEX_SUPPORT /************************************************************************/ +//! @brief Return true if dbf file empty or positioned to the first record +/*! + \returns Returns true if dbf file is empty or positioned on the first record. +*/ +xbBool xbDbf::GetBof() { +/* + if( GetRecordCount() == 0 || GetCurRecNo() == 1 ) + return xbTrue; + else + */ + return xbFalse; +} +/************************************************************************/ +//! @brief Return true if dbf file empty or positioned to the last record +/*! + \returns Returns true if dbf file is empty or positioned on the last record. +*/ +xbBool xbDbf::GetEof() { + xbUInt32 ulRecCnt = GetRecordCount(); + + if( ulRecCnt == 0 || GetCurRecNo() == ulRecCnt ) + return xbTrue; + else + return xbFalse; +} +/************************************************************************/ //! @brief Return the current record number. /*! \returns Returns the current record number. @@ -2428,15 +2482,23 @@ xbInt16 xbDbf::GetRecord( xbUInt32 ulRecNo ){ iErrorStop = 120; throw iRc; } - } - } + } + } + + // std::cout << "xbdbf::GetRecord: " << ulRecNo << " " << ulNoOfRecs << "\n"; if( ulRecNo > ulNoOfRecs || ulRecNo == 0L ){ iErrorStop = 130; iRc = XB_INVALID_RECORD; throw iRc; } + #ifdef XB_BLOCKREAD_SUPPORT + if( bBlockReadEnabled ) + return pRb->GetRecord( ulRecNo ); + #endif // XB_BLOCK_READ_SUPPORT + + if(( xbFseek( (uiHeaderLen+(( (xbInt64) ulRecNo-1L ) * uiRecordLen )), SEEK_SET )) != XB_NO_ERROR ){ iErrorStop = 140; iRc = XB_SEEK_ERROR; @@ -2475,9 +2537,6 @@ char * xbDbf::GetRecordBuf( xbInt16 iOpt ) const { return RecBuf; } - - - /************************************************************************/ //! @brief Get the current number of records in the dbf data file. /*! @@ -3211,12 +3270,12 @@ xbInt16 xbDbf::Open( const xbString & sTableName, const xbString & sAlias ){ xbLinkListNode<xbString> * llN = llInfData.GetHeadNode(); for( xbUInt32 i = 0; i < llNodeCnt; i++ ){ s2 = llN->GetKey(); - #ifdef XB_NDX_SUPPORT + #ifdef XB_NDX_SUPPORT if(( iRc = OpenIndex( "NDX", s2 )) != XB_NO_ERROR ){ iErrorStop = 120; throw iRc ; } - #endif // XB_NDX_SUPPORT + #endif // XB_NDX_SUPPORT llN = llN->GetNextNode(); } } @@ -3270,7 +3329,6 @@ xbInt16 xbDbf::OpenIndex( const xbString &sIxType, const xbString &sFileName ){ #ifdef XB_MDX_SUPPORT } else if( sType == "MDX" ){ - pIx = new xbIxMdx( this ); if(( iRc = pIx->Open( sFileName )) != XB_NO_ERROR ){ iErrorStop = 120; @@ -4209,4 +4267,72 @@ xbInt16 xbDbf::Zap(){ return iRc; } /************************************************************************/ +#ifdef XB_BLOCKREAD_SUPPORT +// block read processing is designed to provide a way to rapidly retrieve +// all the records from a .DBF file in sequential order. + +// It is not designed for doing any read/write processing or data retrieval based on a tag sort. +// It is designed for doing a fast sequentil block read out of a table + + +xbInt16 xbDbf::DisableBlockReadProcessing(){ + + if( bBlockReadEnabled ){ + bBlockReadEnabled = xbFalse; + delete pRb; + pRb = NULL; + } + return XB_NO_ERROR; +} + +xbBool xbDbf::GetBlockReadStatus() const { + return bBlockReadEnabled; +} + +xbInt16 xbDbf::EnableBlockReadProcessing(){ + + xbInt16 iRc = 0; + xbInt16 iErrorStop = 0; + + try{ + + if( !bBlockReadEnabled ){ + if( iDbfStatus == XB_UPDATED ){ + if( GetAutoCommit() == 1 ){ + if(( iRc = Commit()) != XB_NO_ERROR ){ + iErrorStop = 100; + throw iRc; + } + } else { + if(( iRc = Abort()) != XB_NO_ERROR ){ + iErrorStop = 110; + throw iRc; + } + } + } + pRb = new xbBlockRead( this ); + if( !pRb ){ + iErrorStop = 120; + iRc = XB_NO_MEMORY; + throw iRc; + } + if(( iRc = pRb->Init()) != XB_NO_ERROR ){ + iErrorStop = 130; + throw iRc; + } + + bBlockReadEnabled = xbTrue; + } + + } catch( xbInt16 iRc ){ + xbString sMsg; + sMsg.Sprintf( "xbdbf::EnableBlockReadProcessing() Exception Caught. Error Stop = [%d] iRc = [%d]", iErrorStop, iRc ); + xbase->WriteLogMessage( sMsg.Str() ); + xbase->WriteLogMessage( GetErrorMessage( iRc )); + } + return iRc; +} + +#endif // XB_BLOCKREAD_SUPPORT +/************************************************************************/ } /* namespace */
\ No newline at end of file |