diff options
Diffstat (limited to 'src/core')
-rwxr-xr-x | src/core/xbbcd.cpp | 39 | ||||
-rwxr-xr-x | src/core/xbdbf.cpp | 770 | ||||
-rwxr-xr-x | src/core/xbdbf3.cpp | 272 | ||||
-rwxr-xr-x | src/core/xbdbf4.cpp | 357 | ||||
-rwxr-xr-x | src/core/xbexp.cpp | 125 | ||||
-rwxr-xr-x | src/core/xbfields.cpp | 56 | ||||
-rwxr-xr-x | src/core/xbfile.cpp | 103 | ||||
-rwxr-xr-x | src/core/xbfilter.cpp | 111 | ||||
-rwxr-xr-x | src/core/xbixbase.cpp | 17 | ||||
-rwxr-xr-x | src/core/xbixmdx.cpp | 64 | ||||
-rwxr-xr-x | src/core/xbixndx.cpp | 251 | ||||
-rwxr-xr-x | src/core/xbmemo.cpp | 12 | ||||
-rwxr-xr-x | src/core/xbmemo3.cpp | 109 | ||||
-rwxr-xr-x | src/core/xbmemo4.cpp | 245 | ||||
-rwxr-xr-x | src/core/xbssv.cpp | 2 | ||||
-rwxr-xr-x | src/core/xbstring.cpp | 55 | ||||
-rwxr-xr-x | src/core/xbtblmgr.cpp | 31 | ||||
-rwxr-xr-x | src/core/xbxbase.cpp | 53 |
18 files changed, 1505 insertions, 1167 deletions
diff --git a/src/core/xbbcd.cpp b/src/core/xbbcd.cpp index 4855e80..ff64110 100755 --- a/src/core/xbbcd.cpp +++ b/src/core/xbbcd.cpp @@ -142,37 +142,6 @@ void xbBcd::StringToBcd( const xbString &sIn ) if( bSign ) bcd.cEncDigits = bcd.cEncDigits | 0x80; - -/* - std::cout << "num in = " << sIn.Str() << "\n"; - unsigned char bW[12]; - memcpy( bW, &bcd, 12 ); - std::cout << "bx "; - for( int i = 0; i < 12; i++ ){ - bcdBitDump( bW[i] ); - std::cout << " "; - } - std::cout << "\n"; - - unsigned char cSign = bcd.cEncDigits >> 7; - std::cout << "bs "; - bcdBitDump( cSign ); - std::cout << "\n"; - - std::cout << "test = "; - bcdBitDump( cEdc ); - std::cout << " "; - bcdBitDump( GetEncDigitsNoSign() ); - std::cout << "\n"; - bcdBitDump( bcd.cEncDigits ); - - unsigned char c = bcd.cEncDigits; - c = c << 1; - c = c >> 3; - std::cout << " "; - bcdBitDump( c ); - std::cout << "\n"; -*/ } /***********************************************************************/ void xbBcd::ToChar( char * cOut ){ @@ -268,20 +237,20 @@ xbInt16 xbBcd::Compare( const xbBcd &bcdIn ){ // if( bcd.Sign != bcdIn.GetSign() ){ // bcd.Sign > 0 ? iRc = -1 : iRc = 1; - if( (bcd.cEncDigits >> 7 ) != bcdIn.GetSign() ){ + if( (unsigned)(bcd.cEncDigits >> 7 ) != bcdIn.GetSign() ){ (bcd.cEncDigits >> 7 ) > 0 ? iRc = -1 : iRc = 1; return iRc; } - if( bcd.cSigDigits != bcdIn.GetSigDigits()){ + if( (unsigned) bcd.cSigDigits != bcdIn.GetSigDigits()){ // if( !bcd.Sign ){ // positive numbers if( !(bcd.cEncDigits >> 7 )){ // positive numbers - if( bcd.cSigDigits > bcdIn.GetSigDigits()) + if( (unsigned) bcd.cSigDigits > bcdIn.GetSigDigits()) return 1; else return -1; } else { // negative numbers - if( bcd.cSigDigits > bcdIn.GetSigDigits()) + if( (unsigned) bcd.cSigDigits > bcdIn.GetSigDigits()) return -1; else return 1; diff --git a/src/core/xbdbf.cpp b/src/core/xbdbf.cpp index 8e020fb..3d13369 100755 --- a/src/core/xbdbf.cpp +++ b/src/core/xbdbf.cpp @@ -61,7 +61,7 @@ void xbDbf::InitVars() ulAppendLocked = 0; SetAutoLock( -1 ); lloRecLocks.SetDupKeys( xbFalse ); - #endif + #endif // XB_LOCKING_SUPPORT #ifdef XB_INDEX_SUPPORT ixList = NULL; @@ -69,10 +69,15 @@ void xbDbf::InitVars() vpCurIxTag = NULL; sCurIxType = ""; ClearTagList(); - #endif - #ifdef XB_NDXINF_SUPPORT - llNdxInfData.Clear(); - #endif + #endif // XB_INDEX_SUPPORT + + #ifdef XB_MEMO_SUPPORT + Memo = NULL; + #endif // XB_MEMO_SUPPORT + + #ifdef XB_INF_SUPPORT + llInfData.Clear(); + #endif // XB_INF_SUPPORT } /************************************************************************/ @@ -116,7 +121,7 @@ xbInt16 xbDbf::Abort(){ #ifdef XB_MEMO_SUPPORT if( MemoFieldsExist()){ if(( iRc = Memo->Abort()) != XB_NO_ERROR ){ - iErrorStop = 10; + iErrorStop = 100; throw iRc; } } @@ -214,7 +219,7 @@ xbInt16 xbDbf::AppendRecord(){ // std::cout << "xbDbf::CreateKeys(x)\n"; if(( iRc = ixList->ix->CreateKeys( 1 )) != XB_NO_ERROR ){ - iErrorStop = 10; + iErrorStop = 100; throw iRc; } @@ -224,14 +229,12 @@ xbInt16 xbDbf::AppendRecord(){ // lock everything up for an update #ifdef XB_LOCKING_SUPPORT - // xbInt16 iAutoLock = GetAutoLock(); - if( iAutoLock ){ - + if( iAutoLock && !bTableLocked ){ if(( iRc = LockHeader( XB_LOCK )) != XB_NO_ERROR ){ if( iRc == XB_LOCK_FAILED ) { return iRc; } else { - iErrorStop = 20; + iErrorStop = 110; throw iRc; } } @@ -240,14 +243,14 @@ xbInt16 xbDbf::AppendRecord(){ LockHeader( XB_UNLOCK ); return iRc; } else { - iErrorStop = 30; + iErrorStop = 120; throw iRc; } } #ifdef XB_INDEX_SUPPORT if(( iRc = LockIndices( XB_LOCK )) != XB_NO_ERROR ){ - iErrorStop = 40; + iErrorStop = 130; throw iRc; } #endif // XB_INDEX_SUPPORT @@ -255,7 +258,7 @@ xbInt16 xbDbf::AppendRecord(){ } #endif // XB_LOCKING_SUPPORT if(( iRc = ReadHeader( 1, 1 )) != XB_NO_ERROR ){ - iErrorStop = 50; + iErrorStop = 140; throw iRc; } #ifdef XB_INDEX_SUPPORT @@ -264,7 +267,7 @@ xbInt16 xbDbf::AppendRecord(){ while( ixList ){ if(( iRc = ixList->ix->CheckForDupKeys()) != 0 ){ if( iRc < 0 ){ - iErrorStop = 60; + iErrorStop = 150; throw iRc; } return XB_KEY_NOT_UNIQUE; @@ -289,7 +292,7 @@ xbInt16 xbDbf::AppendRecord(){ ixList = GetIxList(); while( ixList ){ if(( iRc = ixList->ix->AddKeys( ulCurRec )) != XB_NO_ERROR ){ - iErrorStop = 50; + iErrorStop = 160; throw iRc; } ixList = ixList->next; @@ -298,7 +301,7 @@ xbInt16 xbDbf::AppendRecord(){ #ifdef XB_LOCKING_SUPPORT if( iAutoLock ){ if(( iRc = LockIndices( XB_UNLOCK )) != XB_NO_ERROR ){ - iErrorStop = 60; + iErrorStop = 170; throw iRc; } } @@ -307,14 +310,14 @@ xbInt16 xbDbf::AppendRecord(){ // rewrite the header record if(( iRc = WriteHeader( 1, 1 )) != XB_NO_ERROR ){ - iErrorStop = 60; + iErrorStop = 180; throw iRc; } #ifdef XB_LOCKING_SUPPORT if( iAutoLock ){ if(( iRc = LockHeader( XB_UNLOCK )) != XB_NO_ERROR ){ - iErrorStop = 70; + iErrorStop = 190; throw iRc; } } @@ -322,25 +325,25 @@ xbInt16 xbDbf::AppendRecord(){ // write the last record if(( iRc = xbFseek( (uiHeaderLen+((xbInt64)(ulNoOfRecs-1)*uiRecordLen)), 0 )) != XB_NO_ERROR ){ - iErrorStop = 80; + iErrorStop = 200; throw iRc; } if(( iRc = xbFwrite( RecBuf, uiRecordLen, 1 )) != XB_NO_ERROR ){ - iErrorStop = 90; + iErrorStop = 210; throw iRc; } // write the end of file marker if(( iRc = xbFputc( XB_CHAREOF )) != XB_NO_ERROR ){ - iErrorStop = 100; + iErrorStop = 220; throw iRc; } #ifdef XB_LOCKING_SUPPORT if( iAutoLock ){ if(( iRc = LockAppend( XB_UNLOCK )) != XB_NO_ERROR ){ - iErrorStop = 110; + iErrorStop = 230; throw( iRc ); } } @@ -376,7 +379,7 @@ xbInt16 xbDbf::AppendRecord(){ } /************************************************************************/ -#ifdef XB_NDXINF_SUPPORT +#ifdef XB_INF_SUPPORT //! @brief Asscoiate a non production index to a DBF file. /*! @@ -385,7 +388,7 @@ xbInt16 xbDbf::AppendRecord(){ indices are not. This method is specific to the Xbas64 library and providex a means to link non production NDX index files to the DBF file so they will be opened automatically when the DBF file is opened.<br> - This routine requires NDXINF support be enabled when building the library.<br> + This routine requires INF support be enabled when building the library.<br> This routine creates a file with the same name as the DBF file, but with an extension of INF.<br> @@ -412,13 +415,13 @@ xbInt16 xbDbf::AssociateIndex( const xbString &sIxType, const xbString &sIxName, if( sIxTypeIn != "NDX" || sIxName == "" ) return XB_INVALID_INDEX; - if(( iRc = LoadNdxInfData()) != XB_NO_ERROR ){ - iErrorStop = 10; + if(( iRc = LoadInfData()) != XB_NO_ERROR ){ + iErrorStop = 100; throw iRc; } // check if entry exists - xbLinkListNode<xbString> * llN = llNdxInfData.GetHeadNode(); + xbLinkListNode<xbString> * llN = llInfData.GetHeadNode(); xbBool bFound = xbFalse; xbString s; @@ -434,17 +437,17 @@ xbInt16 xbDbf::AssociateIndex( const xbString &sIxType, const xbString &sIxName, xbBool bUpdated = xbFalse; if( iOpt == 0 && !bFound ){ s.Sprintf( "%s%c%c", sIxName.Str(), 0x0d, 0x0a ); - llNdxInfData.InsertAtEnd( s ); + llInfData.InsertAtEnd( s ); bUpdated = xbTrue; } else if( iOpt == 1 && bFound ){ - llNdxInfData.RemoveByVal( s ); + llInfData.RemoveByVal( s ); bUpdated = xbTrue; } if( bUpdated ){ - if(( iRc = SaveNdxInfData()) != XB_NO_ERROR ){ - iErrorStop = 20; + if(( iRc = SaveInfData()) != XB_NO_ERROR ){ + iErrorStop = 110; throw iRc; } } @@ -457,7 +460,7 @@ xbInt16 xbDbf::AssociateIndex( const xbString &sIxType, const xbString &sIxName, } return iRc; } -#endif // XB_NDXINF_SUPPORT +#endif // XB_INF_SUPPORT /************************************************************************/ //! @brief Blank the record buffer. @@ -477,7 +480,7 @@ xbInt16 xbDbf::BlankRecord() try{ if( iDbfStatus == XB_CLOSED ){ - iErrorStop = 10; + iErrorStop = 100; iRc = XB_NOT_OPEN; throw iRc; } @@ -485,12 +488,12 @@ xbInt16 xbDbf::BlankRecord() if( iDbfStatus == XB_UPDATED ){ if( GetAutoCommit() == 1 ){ if(( iRc = Commit()) != XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 110; throw iRc; } } else { if(( iRc = Abort()) != XB_NO_ERROR ){ - iErrorStop = 30; + iErrorStop = 120; throw iRc; } } @@ -511,9 +514,6 @@ xbInt16 xbDbf::BlankRecord() } /************************************************************************/ #ifdef XB_INDEX_SUPPORT - -#ifdef XB_DEBUG_SUPPORT - /*! This method is used to check an index tag's intgerity. @@ -533,9 +533,6 @@ xbInt16 xbDbf::CheckTagIntegrity( xbInt16 iTagOpt, xbInt16 iOutputOpt ){ xbInt16 iErrorStop = 0; try{ - -// std::cout << "CheckTagIntegrity()\n"; - if( iTagOpt == 0 ){ if( pCurIx ) return pCurIx->CheckTagIntegrity( vpCurIxTag, iOutputOpt ); @@ -550,7 +547,7 @@ xbInt16 xbDbf::CheckTagIntegrity( xbInt16 iTagOpt, xbInt16 iOutputOpt ){ while( llN ){ pTag = llN->GetKey(); if(( iRc = pTag->GetIx()->CheckTagIntegrity( pTag->GetVpTag(), iOutputOpt )) != XB_NO_ERROR ){ - iErrorStop = 100; + iErrorStop = 110; throw iRc; } llN = llN->GetNextNode(); @@ -563,12 +560,9 @@ xbInt16 xbDbf::CheckTagIntegrity( xbInt16 iTagOpt, xbInt16 iOutputOpt ){ xbase->WriteLogMessage( sMsg.Str() ); xbase->WriteLogMessage( GetErrorMessage( iRc )); } - return iRc; } -#endif // XB_DEBUG_SUPPORT - /************************************************************************/ /*! This method is used to reindex / rebuild index tag. @@ -588,24 +582,14 @@ xbInt16 xbDbf::Reindex( xbInt16 iTagOpt ){ if( iTagOpt == 0 ){ if( pCurIx ){ - // - // xbString = save current tag name - // - iRc = pCurIx->Reindex( &vpCurIxTag ); if( iRc != XB_NO_ERROR ){ iErrorStop = 100; throw iRc; } - // - // restore current tag name - // return iRc; - } else { - return XB_INVALID_TAG; - } } else { @@ -617,13 +601,11 @@ xbInt16 xbDbf::Reindex( xbInt16 iTagOpt ){ pTag = llN->GetKey(); vp = pTag->GetVpTag(); if(( iRc = pTag->GetIx()->Reindex( &vp )) != XB_NO_ERROR ){ - iErrorStop = 100; + iErrorStop = 110; throw iRc; } llN = llN->GetNextNode(); } - - } } catch (xbInt16 iRc ){ @@ -632,7 +614,6 @@ xbInt16 xbDbf::Reindex( xbInt16 iTagOpt ){ xbase->WriteLogMessage( sMsg.Str() ); xbase->WriteLogMessage( GetErrorMessage( iRc )); } - return iRc; } @@ -680,12 +661,12 @@ xbInt16 xbDbf::Close(){ if( GetAutoCommit() == 1 ){ if(( iRc = Commit()) != XB_NO_ERROR ){ - iErrorStop = 10; + iErrorStop = 100; throw iRc; } } else { if(( iRc = Abort()) != XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 110; throw iRc; } } @@ -704,7 +685,6 @@ xbInt16 xbDbf::Close(){ RecBuf2 = NULL; } - #ifdef XB_MEMO_SUPPORT if( iMemoFieldCnt > 0 ){ Memo->CloseMemoFile(); @@ -721,24 +701,15 @@ xbInt16 xbDbf::Close(){ } #endif - #ifdef XB_LOCKING_ON - if( xblfh ){ - fclose( xblfh ); - xblfh = NULL; - } - #endif - if(( iRc = xbase->RemoveTblFromTblList( this )) != XB_NO_ERROR ){ xbString sMsg; sMsg.Sprintf( "Alias = [%s]", sAlias.Str()); xbase->WriteLogMessage( sMsg.Str() ); - iErrorStop = 30; + iErrorStop = 120; throw iRc; } - xbFclose(); InitVars(); - } catch (xbInt16 iRc ){ xbString sMsg; @@ -749,7 +720,6 @@ xbInt16 xbDbf::Close(){ return iRc; } - /************************************************************************/ #ifdef XB_INDEX_SUPPORT //! @brief Close an open index file @@ -778,35 +748,30 @@ xbInt16 xbDbf::CloseIndexFile( xbIx *pIx ){ p = p->next; } if( !bFound ){ - iErrorStop = 10; + iErrorStop = 100; iRc = XB_NOT_OPEN; throw iRc; } - // close it if(( iRc = pIx->Close()) != XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 110; throw iRc; } - // remove it from the list if(( iRc = RemoveIndex( pIx )) != XB_NO_ERROR ){ - iErrorStop = 30; + iErrorStop = 120; throw iRc; } - // refresh the tag list if(( iRc = UpdateTagList()) != XB_NO_ERROR ){ - iErrorStop = 40; + iErrorStop = 130; throw iRc; } - if( pIx == pCurIx ){ pCurIx = NULL; vpCurIxTag = NULL; sCurIxType = ""; } - } catch (xbInt16 iRc ){ xbString sMsg; @@ -836,12 +801,12 @@ xbInt16 xbDbf::Commit(){ if( iDbfStatus == XB_UPDATED ){ if( ulCurRec == 0 ){ if(( iRc = AppendRecord()) != XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 100; throw iRc; } } else { if(( iRc = PutRecord( ulCurRec )) != XB_NO_ERROR ){ - iErrorStop = 30; + iErrorStop = 110; throw iRc; } } @@ -858,7 +823,6 @@ xbInt16 xbDbf::Commit(){ return iRc; } - /************************************************************************/ //! @brief Copy table (dbf) file structure. /*! @@ -891,13 +855,13 @@ xbInt16 xbDbf::CopyDbfStructure( xbDbf * dNewTable, const xbString &sNewTableNam try{ if( iDbfStatus == XB_CLOSED ){ - iErrorStop = 10; + iErrorStop = 100; iRc = XB_DBF_FILE_NOT_OPEN; throw iRc; } if( !dNewTable ){ - iErrorStop = 20; + iErrorStop = 110; iRc = XB_INVALID_OBJECT; throw iRc; } @@ -907,7 +871,7 @@ xbInt16 xbDbf::CopyDbfStructure( xbDbf * dNewTable, const xbString &sNewTableNam // Allocate a Schema = No Of Fields + 1 if((newTableSchema=(xbSchema *)malloc( (size_t) lSchemaRecCnt * sizeof(xbSchema)))==NULL){ - iErrorStop = 30; + iErrorStop = 120; iRc = XB_NO_MEMORY; throw iRc; } @@ -937,7 +901,7 @@ xbInt16 xbDbf::CopyDbfStructure( xbDbf * dNewTable, const xbString &sNewTableNam // Call the create a table function if(( iRc = dNewTable->CreateTable( sNewTableName, sNewTableAlias, newTableSchema, iOverlay, iShareMode )) != XB_NO_ERROR ){ - iErrorStop = 40; + iErrorStop = 130; throw iRc; } } @@ -955,7 +919,6 @@ xbInt16 xbDbf::CopyDbfStructure( xbDbf * dNewTable, const xbString &sNewTableNam return iRc; } - /************************************************************************/ #ifdef XB_INDEX_SUPPORT //! @brief Create a new tag (index) for this dbf file (table). @@ -984,16 +947,19 @@ xbInt16 xbDbf::CreateTag( const xbString &sIxType, const xbString &sName, const xbInt16 iErrorStop = 0; xbInt16 iRc = XB_NO_ERROR; + + #ifdef XB_LOCKING_SUPPORT xbBool bLocked = xbFalse; + #endif try{ xbString sType = sIxType; sType.ToUpperCase(); #ifdef XB_LOCKING_SUPPORT - if( !bTableLocked ){ + if( iAutoLock && !bTableLocked ){ if(( iRc = LockTable( XB_LOCK )) != XB_NO_ERROR ){ - iErrorStop = 10; + iErrorStop = 100; throw( iRc ); } bLocked = xbTrue; @@ -1001,7 +967,7 @@ xbInt16 xbDbf::CreateTag( const xbString &sIxType, const xbString &sName, const #endif // XB_LOCKING_SUPPORT if( sIxType == "" ){ - iErrorStop = 100; + iErrorStop = 110; iRc = XB_INVALID_OPTION; throw iRc; @@ -1010,12 +976,12 @@ xbInt16 xbDbf::CreateTag( const xbString &sIxType, const xbString &sName, const xbIxNdx *ixNdx = new xbIxNdx( this ); if(( iRc = ixNdx->CreateTag( sName, sKey, sFilter, iDescending, iUnique, iOverLay, vpTagOut )) != XB_NO_ERROR ){ - iErrorStop = 110; + iErrorStop = 120; throw iRc; } if(( iRc = AddIndex( ixNdx, sIxType )) != XB_NO_ERROR ){ - iErrorStop = 120; + iErrorStop = 130; throw iRc; } *pIxOut = ixNdx; @@ -1033,7 +999,7 @@ xbInt16 xbDbf::CreateTag( const xbString &sIxType, const xbString &sName, const } else if( sIxType == "MDX" ){ if( GetVersion() == 3 ){ // MDX indexes were version 4 and higher - iErrorStop = 200; + iErrorStop = 140; iRc = XB_INVALID_INDEX; throw iRc; } @@ -1055,19 +1021,19 @@ xbInt16 xbDbf::CreateTag( const xbString &sIxType, const xbString &sName, const ixMdx = new xbIxMdx( this ); if(( iRc = ixMdx->CreateTag( sName, sKey, sFilter, iDescending, iUnique, iOverLay, vpTagOut )) != XB_NO_ERROR ){ - iErrorStop = 210; + iErrorStop = 150; throw iRc; } if( !bMdxFound ){ if(( iRc = AddIndex( ixMdx, "MDX" )) != XB_NO_ERROR ){ - iErrorStop = 220; + iErrorStop = 160; throw iRc; } cIndexFlag = 0x01; if(( iRc = WriteHeader( 1, 0 )) != XB_NO_ERROR ){ - iErrorStop = 230; + iErrorStop = 170; throw iRc; } } @@ -1106,7 +1072,6 @@ xbInt16 xbDbf::CreateTag( const xbString &sIxType, const xbString &sName, const LockTable( XB_UNLOCK ); #endif // XB_LOCKING_SUPPORT - return iRc; } #endif // XB_INDEX_SUPPORT @@ -1131,27 +1096,35 @@ xbInt16 xbDbf::DeleteAll( xbInt16 iOption ) try{ if(( iRc = GetRecordCnt( ulRecCnt )) != XB_NO_ERROR ){ - iErrorStop = 10; + iErrorStop = 100; throw iRc; } if( ulRecCnt == 0 ) return XB_NO_ERROR; for( xbUInt32 ul = 0; ul < ulRecCnt; ul++ ){ if(( iRc = GetRecord( ul+1 )) != XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 110; throw iRc; } if( iOption == 0 ){ /* delete all option */ if( !RecordDeleted()){ if(( iRc = DeleteRecord()) != XB_NO_ERROR ){ - iErrorStop = 30; + iErrorStop = 120; + throw iRc; + } + if(( iRc = Commit()) != XB_NO_ERROR ){ + iErrorStop = 130; throw iRc; } } } else { /* undelete all option */ if( RecordDeleted()){ if(( iRc = UndeleteRecord()) != XB_NO_ERROR ){ - iErrorStop = 40; + iErrorStop = 140; + throw iRc; + } + if(( iRc = Commit()) != XB_NO_ERROR ){ + iErrorStop = 150; throw iRc; } } @@ -1181,17 +1154,20 @@ xbInt16 xbDbf::DeleteAllIndexFiles(){ xbInt16 iRc = 0; xbInt16 iErrorStop = 0; + + #ifdef XB_LOCKING_SUPPORT xbBool bLocked = xbFalse; + #endif // XB_LOCKING_SUPPORT - #ifdef XB_NDXINF_SUPPORT + #ifdef XB_INF_SUPPORT xbString sIxName; - #endif // XB_NDXINF_SUPPORT + #endif // XB_INF_SUPPORT try{ #ifdef XB_LOCKING_SUPPORT - if( !bTableLocked ){ + if( iAutoLock && !bTableLocked ){ if(( iRc = LockTable( XB_LOCK )) != XB_NO_ERROR ){ - iErrorStop = 10; + iErrorStop = 100; throw( iRc ); } bLocked = xbTrue; @@ -1202,15 +1178,15 @@ xbInt16 xbDbf::DeleteAllIndexFiles(){ while( ixList ){ ixList->ix->Close(); ixList->ix->xbRemove(); - #ifdef XB_NDXINF_SUPPORT - // if XB_NDXINF_SUPPORT is enabled, all open non prod indices should be in here + #ifdef XB_INF_SUPPORT + // if XB_INF_SUPPORT is enabled, all open non prod indices should be in here if( *ixList->sFmt != "MDX" ){ // production indices not stored in .INF dataset if(( iRc = ixList->ix->GetFileNamePart( sIxName )) != XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 110; throw iRc; } if(( iRc = AssociateIndex( *ixList->sFmt, sIxName, 1 )) != XB_NO_ERROR ){ - iErrorStop = 30; + iErrorStop = 120; throw iRc; } } @@ -1244,7 +1220,7 @@ xbInt16 xbDbf::DeleteAllRecords(){ } /************************************************************************/ -#ifdef XB_NDXINF_SUPPORT +#ifdef XB_INF_SUPPORT //! @brief Delete .INF File /*! The original Dbase (TM) software supported non production indices (NDX) and production indices (MDX). @@ -1252,45 +1228,44 @@ xbInt16 xbDbf::DeleteAllRecords(){ indices are not. This method is specific to the Xbas64 library and providex a means to link non production NDX index files to the DBF file so they will be opened automatically when the DBF file is opened.<br> - This routine requires NDXINF support be enabled when building the library.<br> + This routine requires INF support be enabled when building the library.<br> This routine deletes the .INF file.<br> \returns <a href="xbretcod_8h.html">Return Codes</a> */ -xbInt16 xbDbf::DeleteNdxInfData(){ +xbInt16 xbDbf::DeleteInfData(){ xbInt16 iRc = 0; xbInt16 iErrorStop = 0; try{ - xbString sNdxInfFileName; - if(( iRc = GetNdxInfFileName( sNdxInfFileName )) != XB_NO_ERROR ){ - iErrorStop = 10; + xbString sInfFileName; + if(( iRc = GetInfFileName( sInfFileName )) != XB_NO_ERROR ){ + iErrorStop = 100; throw iRc; } xbFile f( xbase ); - f.SetFileName( sNdxInfFileName ); + f.SetFileName( sInfFileName ); if( f.FileExists()){ if(( iRc = f.xbRemove()) != XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 110; throw iRc; } } } catch( xbInt16 iRc ){ xbString sMsg; - sMsg.Sprintf( "xbdbf::DeleteNdxInfData() Exception Caught. Error Stop = [%d] iRc = [%d]", iErrorStop, iRc ); + sMsg.Sprintf( "xbdbf::DeleteInfData() Exception Caught. Error Stop = [%d] iRc = [%d]", iErrorStop, iRc ); xbase->WriteLogMessage( sMsg.Str() ); xbase->WriteLogMessage( GetErrorMessage( iRc )); } return iRc; } -#endif // XB_NDXINF_SUPPORT +#endif // XB_INF_SUPPORT /************************************************************************/ //! @brief Delete the current record. /*! This routine flags the current record for deletion if it's not already flagged. - - + \returns XB_NO_ERROR<br> XB_INVALID_RECORD */ @@ -1322,27 +1297,35 @@ xbInt16 xbDbf::DeleteTable(){ xbInt16 iRc = 0; xbInt16 iErrorStop = 0; + #ifdef XB_LOCKING_SUPPORT + xbBool bTableLocked = xbFalse; + #endif + try{ #ifdef XB_LOCKING_SUPPORT - if(( iRc = LockTable( XB_LOCK )) != XB_NO_ERROR ){ - iErrorStop = 10; - throw iRc; + if( iAutoLock && !bTableLocked ){ + if(( iRc = LockTable( XB_LOCK )) != XB_NO_ERROR ){ + iErrorStop = 100; + throw iRc; + } else { + bTableLocked = xbTrue; + } } #endif // XB_LOCKING_SUPPORT #ifdef XB_INDEX_SUPPORT if(( iRc = DeleteAllIndexFiles()) != XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 110; throw iRc; } - #ifdef XB_NDXINF_SUPPORT - if(( iRc = DeleteNdxInfData()) != XB_NO_ERROR ){ - iErrorStop = 30; + #ifdef XB_INF_SUPPORT + if(( iRc = DeleteInfData()) != XB_NO_ERROR ){ + iErrorStop = 120; throw iRc; } - #endif // XB_NDXINF_SUPPORT + #endif // XB_INF_SUPPORT #endif // XB_INDEX_SUPPORT #ifdef XB_MEMO_SUPPORT @@ -1354,12 +1337,12 @@ xbInt16 xbDbf::DeleteTable(){ #endif // XB_MEMO_SUPPORT if(( iRc = Close()) != XB_NO_ERROR ){ - iErrorStop = 40; + iErrorStop = 130; throw iRc; } if(( iRc = xbRemove()) != XB_NO_ERROR ){ - iErrorStop = 50; + iErrorStop = 140; throw iRc; } @@ -1367,7 +1350,7 @@ xbInt16 xbDbf::DeleteTable(){ if( iMemoFieldCnt > 0 ){ xbFile f( xbase ); if(( iRc = f.xbRemove( sMemoFileName )) != XB_NO_ERROR ){ - iErrorStop = 60; + iErrorStop = 150; throw iRc; } } @@ -1380,12 +1363,14 @@ xbInt16 xbDbf::DeleteTable(){ xbase->WriteLogMessage( GetErrorMessage( iRc )); } #ifdef XB_LOCKING_SUPPORT - LockTable( XB_UNLOCK ); + if( bTableLocked ) + LockTable( XB_UNLOCK ); #endif // XB_LOCKING_SUPPORT return iRc; } /************************************************************************/ +#ifdef XB_INDEX_SUPPORT //! @brief Delete an index tag. /*! @@ -1401,17 +1386,22 @@ xbInt16 xbDbf::DeleteTag( const xbString &sIxType, const xbString &sName ){ xbInt16 iRc = XB_NO_ERROR; xbIx *pIx = NULL; + #ifdef XB_LOCKING_SUPPORT + xbBool bTableLocked = xbFalse; + #endif + try{ #ifdef XB_LOCKING_SUPPORT - // xbInt16 iAutoLock = GetAutoLock(); if( iAutoLock && !GetTableLocked() ){ if(( iRc = LockTable( XB_LOCK )) != XB_NO_ERROR ){ iErrorStop = 100; throw iRc; + } else { + bTableLocked = xbTrue; } } - #endif + #endif // XB_LOCKING_SUPPORT if( sIxType == "" ){ iErrorStop = 110; @@ -1429,12 +1419,12 @@ xbInt16 xbDbf::DeleteTag( const xbString &sIxType, const xbString &sName ){ bDone = xbTrue; // remove from .INF if it's there - #ifdef XB_NDXINF_SUPPORT + #ifdef XB_INF_SUPPORT if(( iRc = AssociateIndex( "NDX", sName, 1 )) != XB_NO_ERROR ){ iErrorStop = 120; throw iRc; } - #endif // XB_NDXINF_SUPPORT + #endif // XB_INF_SUPPORT if(( iRc = ixl->ix->DeleteTag( ixl->ix->GetTag( 0 ))) != XB_NO_ERROR ){ iErrorStop = 130; @@ -1518,15 +1508,6 @@ xbInt16 xbDbf::DeleteTag( const xbString &sIxType, const xbString &sName ){ throw iRc; } - // unlock as necessary - #ifdef XB_LOCKING_SUPPORT - if( iAutoLock && GetTableLocked() ){ - if(( iRc = LockTable( XB_UNLOCK )) != XB_NO_ERROR ){ - iErrorStop = 200; - throw iRc; - } - } - #endif } catch (xbInt16 iRc ){ @@ -1540,14 +1521,20 @@ xbInt16 xbDbf::DeleteTag( const xbString &sIxType, const xbString &sName ){ if( iAutoLock && GetTableLocked() ){ LockTable( XB_UNLOCK ); } - #endif + #endif // XB_LOCKING_SUPPORT + } + #ifdef XB_LOCKING_SUPPORT + if( bTableLocked ){ + LockTable( XB_UNLOCK ); } + #endif // XB_LOCKING_SUPPORT + + return iRc; } - +#endif // XB_INDEX_SUPPORT /************************************************************************/ -#ifdef XB_DEBUG_SUPPORT //! @brief Dump dbf file header. /*! This routine dumps dbf header information to the console. @@ -1625,8 +1612,9 @@ xbInt16 xbDbf::DumpHeader( xbInt16 iOption ) const { std::cout << "Lang Driver = " << (int) cIndexFlag << " - "; xbase->BitDump( cIndexFlag ); std::cout << std::endl; - + #ifdef XB_INDEX_SUPPORT std::cout << "Open Index Files = " << GetPhysicalIxCnt() << std::endl; + #endif // XB_INDEX_SUPPORT } if( iOption != 1 ){ @@ -1657,7 +1645,6 @@ xbInt16 xbDbf::DumpHeader( xbInt16 iOption ) const { return XB_NO_ERROR; } - /************************************************************************/ //! Dump record /*! @@ -1690,7 +1677,7 @@ xbInt16 xbDbf::DumpRecord( xbUInt32 ulRecNo, xbInt16 iOutputDest, xbInt16 iOutpu if( iOutputFmt >= 1 ){ if( iOutputFmt == 2 ){ - sTemp = "RecNo"; + sTemp = "RecNo,DEL"; for( i = 0; i < iNoOfFields; i++ ){ s2 = SchemaPtr[i].cFieldName; s2.Trim(); @@ -1701,19 +1688,16 @@ xbInt16 xbDbf::DumpRecord( xbUInt32 ulRecNo, xbInt16 iOutputDest, xbInt16 iOutpu } if( RecordDeleted() ) - s2.Sprintf( "%ld Deleted", ulRecNo ); + s2.Sprintf( "%ld,DEL", ulRecNo ); + else + s2.Sprintf( "%ld,", ulRecNo ); - else{ - s2.Sprintf( "%ld ", ulRecNo ); - //xbString s3; - for( i = 0; i < iNoOfFields; i++ ){ - GetField( i, sTemp ); - sTemp.Trim(); - s2.Sprintf( "%s,'%s'", s2.Str(), sTemp.Str()); - } - xbase->WriteLogMessage( s2.Str(),iOutputDest ); + for( i = 0; i < iNoOfFields; i++ ){ + GetField( i, sTemp ); + sTemp.Trim(); + s2.Sprintf( "%s,'%s'", s2.Str(), sTemp.Str()); } - + xbase->WriteLogMessage( s2.Str(),iOutputDest ); return XB_NO_ERROR; } @@ -1768,6 +1752,9 @@ xbInt16 xbDbf::DumpRecord( xbUInt32 ulRecNo, xbInt16 iOutputDest, xbInt16 iOutpu /************************************************************************/ +#ifdef XB_DEBUG_SUPPORT + + #ifdef XB_LOCKING_SUPPORT //! @brief Dump the table lock status /*! @@ -1884,11 +1871,11 @@ xbInt16 xbDbf::GetAutoCommit( xbInt16 iOption ) const { /************************************************************************/ +#ifdef XB_LOCKING_SUPPORT //! @brief Get Auto Lock setting. /*! \returns Auto lock setting. */ -#ifdef XB_LOCKING_SUPPORT xbInt16 xbDbf::GetAutoLock() const{ return iAutoLock; } @@ -1903,7 +1890,7 @@ xbInt16 xbDbf::GetAutoLock() const{ xbUInt32 xbDbf::GetCreateMemoBlockSize() const { return ulCreateMemoBlockSize; } -#endif +#endif // XB_MEMO_SUPPORT /************************************************************************/ //! @brief Get a pointer to the current index object. @@ -2099,7 +2086,6 @@ xbInt32 xbDbf::GetFieldCnt() const { //! @brief Get the first first record lock. /*! Get the first record lock from a linked list of record locks. - \returns First record lock. */ xbLinkListNode<xbUInt32> * xbDbf::GetFirstRecLock() const { @@ -2152,7 +2138,7 @@ xbInt16 xbDbf::GetFirstRecord( xbInt16 iOption ) xbBool xbDbf::GetHeaderLocked() const { return this->bHeaderLocked; } -#endif +#endif // XB_LOCKING_SUPPORT #ifdef XB_INDEX_SUPPORT //! @brief Return pointer to list of index files for the table. @@ -2204,6 +2190,7 @@ xbInt16 xbDbf::GetLastRecord( xbInt16 iOption ) /************************************************************************/ +#ifdef XB_LOCKING_SUPPORT //! @brief Get lock flavor. /*! This routine is currently in place to provide structure for future locking @@ -2217,10 +2204,12 @@ xbInt16 xbDbf::GetLockFlavor() const{ else return iLockFlavor; } +#endif // XB_LOCKING_SUPPORT /************************************************************************/ #ifdef XB_MEMO_SUPPORT /************************************************************************/ +#ifdef XB_LOCKING_SUPPORT //! @brief Get the lock status of the memo file. /*! \returns Lock status of memo file. @@ -2231,6 +2220,8 @@ xbBool xbDbf::GetMemoLocked() const { else return xbFalse; } +#endif // XB_LOCKING_SUPPORT + /************************************************************************/ //! @brief Get pointer to Memo object. /*! @@ -2240,30 +2231,31 @@ xbBool xbDbf::GetMemoLocked() const { xbMemo * xbDbf::GetMemoPtr(){ return Memo; } -#endif + +#endif // XB_MEMO_SUPPORT /************************************************************************/ -#ifdef XB_NDXINF_SUPPORT +#ifdef XB_INF_SUPPORT //! @brief Return the .INF file name /*! If NDXIDX support is enabled in the library, and a non production (ndx) has been associated with the dbf file, the .INF file name can be retrieved with this routine. - \param sNdxInfFileName Output string containing .INF file name. + \param sInfFileName Output string containing .INF file name. \returns <a href="xbretcod_8h.html">Return Codes</a> */ -xbInt16 xbDbf::GetNdxInfFileName( xbString &sNdxInfFileName ){ +xbInt16 xbDbf::GetInfFileName( xbString &sInfFileName ){ - sNdxInfFileName = GetFqFileName(); - xbUInt32 lLen = sNdxInfFileName.Len(); + sInfFileName = GetFqFileName(); + xbUInt32 lLen = sInfFileName.Len(); if( lLen < 5 ) return XB_FILE_NOT_FOUND; - sNdxInfFileName.PutAt(lLen-2, 'I'); - sNdxInfFileName.PutAt(lLen-1, 'N'); - sNdxInfFileName.PutAt(lLen, 'F'); + sInfFileName.PutAt(lLen-2, 'I'); + sInfFileName.PutAt(lLen-1, 'N'); + sInfFileName.PutAt(lLen, 'F'); return XB_NO_ERROR; } @@ -2273,10 +2265,10 @@ xbInt16 xbDbf::GetNdxInfFileName( xbString &sNdxInfFileName ){ \returns List of .INF entries. */ -xbLinkListNode<xbString> * xbDbf::GetNdxInfList() const{ - return llNdxInfData.GetHeadNode(); +xbLinkListNode<xbString> * xbDbf::GetInfList() const{ + return llInfData.GetHeadNode(); } -#endif // XB_NDXINF_SUPPORT +#endif // XB_INF_SUPPORT /************************************************************************/ @@ -2362,7 +2354,7 @@ xbInt32 xbDbf::GetPhysicalIxCnt() const { #endif return lCnt; } -#endif +#endif // XB_INDEX_SUPPORT /************************************************************************/ @@ -2421,38 +2413,38 @@ xbInt16 xbDbf::GetRecord( xbUInt32 ulRecNo ){ try{ /* verify the file is open */ if( iDbfStatus == XB_CLOSED ){ - iErrorStop = 10; + iErrorStop = 100; iRc = XB_NOT_OPEN; throw iRc; } if( iDbfStatus == XB_UPDATED ){ if( GetAutoCommit() == 1 ){ if(( iRc = Commit()) != XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 110; throw iRc; } } else { if(( iRc = Abort()) != XB_NO_ERROR ){ - iErrorStop = 30; + iErrorStop = 120; throw iRc; } } } if( ulRecNo > ulNoOfRecs || ulRecNo == 0L ){ - iErrorStop = 40; + iErrorStop = 130; iRc = XB_INVALID_RECORD; throw iRc; } if(( xbFseek( (uiHeaderLen+(( (xbInt64) ulRecNo-1L ) * uiRecordLen )), SEEK_SET )) != XB_NO_ERROR ){ - iErrorStop = 50; + iErrorStop = 140; iRc = XB_SEEK_ERROR; throw iRc; } if( xbFread( RecBuf, uiRecordLen, 1 ) != XB_NO_ERROR ){ - iErrorStop = 60; + iErrorStop = 150; iRc = XB_READ_ERROR; throw iRc; } @@ -2483,6 +2475,24 @@ char * xbDbf::GetRecordBuf( xbInt16 iOpt ) const { return RecBuf; } + + + +/************************************************************************/ +//! @brief Get the current number of records in the dbf data file. +/*! + \returns Record count or <a href="xbretcod_8h.html">Return Codes</a> +*/ +xbUInt32 xbDbf::GetRecordCount(){ + + xbUInt32 ulCnt; + xbInt16 iRc = GetRecordCnt( ulCnt ); + if( iRc < 0 ) + return (xbUInt32) iRc; + else + return ulCnt; +} + /************************************************************************/ //! @brief Get the current number of records in the dbf data file. /*! @@ -2493,30 +2503,26 @@ xbInt16 xbDbf::GetRecordCnt( xbUInt32 & ulRecCnt ) { xbInt16 iRc = XB_NO_ERROR; xbInt16 iErrorStop = 0; - xbBool bIlocked = xbFalse; + + #ifdef XB_LOCKING_SUPPORT + xbBool bLocked = xbFalse; + #endif // XB_LOCKING_SUPPORT + try{ #ifdef XB_LOCKING_SUPPORT if( iAutoLock && !bTableLocked ){ if(( iRc = LockHeader( XB_LOCK )) != XB_NO_ERROR ){ - iErrorStop = 10; + iErrorStop = 100; throw iRc; } else - bIlocked = xbTrue; + bLocked = xbTrue; } + #endif // XB_LOCKING_SUPPORT if((iRc = ReadHeader(1,1)) != XB_NO_ERROR){ - LockHeader( XB_UNLOCK ); - iErrorStop = 20; + iErrorStop = 110; throw iRc; } - - if( iAutoLock && bIlocked ){ - if(( iRc = LockHeader( XB_UNLOCK )) != XB_NO_ERROR ){ - iErrorStop = 30; - throw iRc; - } - } - #endif } catch( xbInt16 iRc ){ if( iRc != XB_LOCK_FAILED ){ @@ -2526,6 +2532,13 @@ xbInt16 xbDbf::GetRecordCnt( xbUInt32 & ulRecCnt ) xbase->WriteLogMessage( GetErrorMessage( iRc )); } } + + #ifdef XB_LOCKING_SUPPORT + if( bLocked ){ + LockHeader( XB_UNLOCK ); + } + #endif + ulRecCnt = ulNoOfRecs; return iRc; } @@ -2538,15 +2551,17 @@ xbUInt16 xbDbf::GetRecordLen() const { return uiRecordLen; } /************************************************************************/ +#ifdef XB_LOCKING_SUPPORT //! @brief Get table locked status /*! \returns Table lock status. */ - xbBool xbDbf::GetTableLocked() const { return this->bTableLocked; } +#endif // XB_LOCKING_SUPPORT /************************************************************************/ +#ifdef XB_INDEX_SUPPORT //! @brief Get tag list for dbf file. /*! This routine returns a list of tags for the file.<br> @@ -2559,6 +2574,7 @@ xbBool xbDbf::GetTableLocked() const { xbLinkListNode<xbTag *> *xbDbf::GetTagList() const { return llTags.GetHeadNode(); } +#endif // XB_INDEX_SUPPORT /************************************************************************/ //! @brief Get the table alias. /*! @@ -2578,37 +2594,37 @@ xbXBase * xbDbf::GetXbasePtr() const { return xbase; } /************************************************************************/ -#ifdef XB_NDXINF_SUPPORT +#ifdef XB_INF_SUPPORT //! @brief Load .INF data file, /*! Protected method. This routine loads the ndx inf file. \returns <a href="xbretcod_8h.html">Return Codes</a> */ -xbInt16 xbDbf::LoadNdxInfData(){ +xbInt16 xbDbf::LoadInfData(){ xbInt16 iRc = 0; xbInt16 iErrorStop = 0; try{ // create file name - xbString sNdxInfFileName; - if(( iRc = GetNdxInfFileName( sNdxInfFileName )) != XB_NO_ERROR ){ - iErrorStop = 10; + xbString sInfFileName; + if(( iRc = GetInfFileName( sInfFileName )) != XB_NO_ERROR ){ + iErrorStop = 100; throw iRc; } // if file does not exist, return no error xbFile fMd( xbase ); - if( !fMd.FileExists( sNdxInfFileName )) + if( !fMd.FileExists( sInfFileName )) return XB_NO_ERROR; // open file file in read only mode - if(( iRc = fMd.xbFopen( "r", sNdxInfFileName, GetShareMode())) != XB_NO_ERROR ){ - iErrorStop = 20; + if(( iRc = fMd.xbFopen( "r", sInfFileName, GetShareMode())) != XB_NO_ERROR ){ + iErrorStop = 110; throw iRc; } // clear the linked list - llNdxInfData.Clear(); + llInfData.Clear(); // for each entry in the file, add a linked list item xbString sRec; @@ -2625,25 +2641,25 @@ xbInt16 xbDbf::LoadNdxInfData(){ sFn.ExtractElement(sRec.Str(), '=', 2 ); sFn.ZapChar( 0x0d ); sFn.ZapChar( 0x0a ); - llNdxInfData.InsertAtEnd( sFn ); + llInfData.InsertAtEnd( sFn ); } } } // close the file if(( iRc = fMd.xbFclose()) != XB_NO_ERROR ){ - iErrorStop = 40; + iErrorStop = 120; throw iRc; } } catch( xbInt16 iRc ){ xbString sMsg; - sMsg.Sprintf( "xbdbf::LoadNdxInfData() Exception Caught. Error Stop = [%d] iRc = [%d]", iErrorStop, iRc ); + sMsg.Sprintf( "xbdbf::LoadInfData() Exception Caught. Error Stop = [%d] iRc = [%d]", iErrorStop, iRc ); xbase->WriteLogMessage( sMsg.Str() ); xbase->WriteLogMessage( GetErrorMessage( iRc )); } return iRc; } -#endif // XB_NDXINF_SUPPORT +#endif // XB_INF_SUPPORT /************************************************************************/ #ifdef XB_LOCKING_SUPPORT @@ -2673,7 +2689,7 @@ xbInt16 xbDbf::LockAppend( xbInt16 iLockFunction ) if( iRc == XB_LOCK_FAILED ) return iRc; else{ - iErrorStop = 120; + iErrorStop = 110; throw iRc; } } @@ -2685,7 +2701,7 @@ xbInt16 xbDbf::LockAppend( xbInt16 iLockFunction ) if( iRc == XB_LOCK_FAILED ){ return iRc; } else { - iErrorStop = 130; + iErrorStop = 120; throw iRc; } } @@ -2695,13 +2711,12 @@ xbInt16 xbDbf::LockAppend( xbInt16 iLockFunction ) // } else { - other lock-table flavor options go here Clipper, Fox, etc - } } else { - iErrorStop = 190; + iErrorStop = 130; iRc = XB_INVALID_OPTION; throw iRc; } } else if( iLockFunction == XB_UNLOCK ){ - iErrorStop = 200; if( ulAppendLocked == 0 ) /* verify we have an active append lock */ @@ -2747,7 +2762,6 @@ xbInt16 xbDbf::LockAppend( xbInt16 iLockFunction ) return iRc; } - /************************************************************************/ //! @brief Lock Header /*! @@ -2781,7 +2795,7 @@ xbInt16 xbDbf::LockHeader( xbInt16 iLockFunction ) } } else { - iErrorStop = 190; + iErrorStop = 130; iRc = XB_INVALID_OPTION; throw iRc; } @@ -2802,7 +2816,7 @@ xbInt16 xbDbf::LockHeader( xbInt16 iLockFunction ) throw iRc; } } else { - iErrorStop = 290; + iErrorStop = 230; iRc = XB_INVALID_OPTION; throw iRc; } @@ -2825,7 +2839,7 @@ xbInt16 xbDbf::LockHeader( xbInt16 iLockFunction ) } /************************************************************************/ #ifdef XB_INDEX_SUPPORT -//! @brief Lock Index files. +//! @brief Lock Index files. /*! This routine locks all the index files. \param iLockFunction XB_LOCK<br>XB_UNLOCK @@ -2858,13 +2872,25 @@ xbInt16 xbDbf::LockIndices( xbInt16 iLockFunction ) } #endif + #ifdef XB_MDX_SUPPORT + if( *ixLI->sFmt == "MDX" ){ + if( !ixLI->ix->GetLocked()){ + if(( iRc = ixLI->ix->xbLock( XB_LOCK, LK4026531838, 1 )) != XB_NO_ERROR ){ + ixLI->ix->xbLock( XB_UNLOCK, LK4026531838, 1 ); + iErrorStop = 100; + throw iRc; + } + ixLI->ix->SetLocked( xbTrue ); + } + } + #endif + } else if( iLockFunction == XB_UNLOCK ){ #ifdef XB_NDX_SUPPORT if( *ixLI->sFmt == "NDX" ){ if( ixLI->ix->GetLocked()){ if(( iRc = ixLI->ix->xbLock( XB_UNLOCK, LK4026531838, 1 )) != XB_NO_ERROR ){ - ixLI->ix->xbLock( XB_UNLOCK, LK4026531838, 1 ); iErrorStop = 100; throw iRc; } @@ -2872,6 +2898,19 @@ xbInt16 xbDbf::LockIndices( xbInt16 iLockFunction ) } } #endif + + #ifdef XB_MDX_SUPPORT + if( *ixLI->sFmt == "MDX" ){ + if( ixLI->ix->GetLocked()){ + if(( iRc = ixLI->ix->xbLock( XB_UNLOCK, LK4026531838, 1 )) != XB_NO_ERROR ){ + iErrorStop = 100; + throw iRc; + } + ixLI->ix->SetLocked( xbFalse ); + } + } + #endif + } ixLI = ixLI->next; } @@ -2937,14 +2976,14 @@ xbInt16 xbDbf::LockRecord( xbInt16 iLockFunction, xbUInt32 ulRecNo ) if( iRc == XB_LOCK_FAILED ){ return iRc; } else { - iErrorStop = 130; + iErrorStop = 110; throw iRc; } } // other lock-table flavor options go here Clipper, Fox, etc } else { - iErrorStop = 190; + iErrorStop = 120; iRc = XB_INVALID_OPTION; throw iRc; } @@ -2953,7 +2992,7 @@ xbInt16 xbDbf::LockRecord( xbInt16 iLockFunction, xbUInt32 ulRecNo ) iRc = lloRecLocks.InsertKey( ulRecNo ); if( iRc != XB_NO_ERROR ){ xbLock( XB_UNLOCK, LK4026531838 - ulRecNo, 1 ); - iErrorStop = 140; + iErrorStop = 130; throw iRc; } @@ -2967,11 +3006,11 @@ xbInt16 xbDbf::LockRecord( xbInt16 iLockFunction, xbUInt32 ulRecNo ) if( GetLockFlavor() == LK_DBASE ){ iRc = xbLock( XB_UNLOCK, LK4026531838 - ulRecNo, 1 ); if( iRc != XB_NO_ERROR ){ - iErrorStop = 220; + iErrorStop = 210; throw iRc; } } else { - iErrorStop = 290; + iErrorStop = 220; iRc = XB_INVALID_OPTION; throw iRc; } @@ -2998,11 +3037,9 @@ xbInt16 xbDbf::LockRecord( xbInt16 iLockFunction, xbUInt32 ulRecNo ) xbase->WriteLogMessage( GetErrorMessage( iRc )); } } - return iRc; } - /************************************************************************/ //! @brief Lock table. /*! @@ -3113,6 +3150,7 @@ xbInt16 xbDbf::LockTable( xbInt16 iLockFunction ) return iRc; } +#endif // XB_LOCKING_SUPPORT /************************************************************************/ @@ -3121,6 +3159,8 @@ xbInt16 xbDbf::LockTable( xbInt16 iLockFunction ) \returns xbTrue - Memo fields exist.<br>xbFalse - Memo fields don't exist. */ xbBool xbDbf::MemoFieldsExist() const { + + #ifdef XB_MEMO_SUPPORT if( iMemoFieldCnt > 0 ) return xbTrue; @@ -3153,34 +3193,34 @@ xbInt16 xbDbf::Open( const xbString & sTableName, const xbString & sAlias ){ xbInt16 iRc = 0; xbInt16 iErrorStop = 0; - try{ - if(( iRc = Open( sTableName, sAlias, XB_READ_WRITE, XB_MULTI_USER )) != XB_NO_ERROR ){ - iErrorStop = 10; + iErrorStop = 100; throw iRc; } // do any .INF data things on the file, like open indices - #ifdef XB_NDXINF_SUPPORT - if(( iRc = LoadNdxInfData()) != XB_NO_ERROR ){ - iErrorStop = 20; + #ifdef XB_INF_SUPPORT + if(( iRc = LoadInfData()) != XB_NO_ERROR ){ + iErrorStop = 110; throw iRc; } - xbUInt32 llNodeCnt = llNdxInfData.GetNodeCnt(); + xbUInt32 llNodeCnt = llInfData.GetNodeCnt(); if( llNodeCnt > 0 ){ xbString s2; - xbLinkListNode<xbString> * llN = llNdxInfData.GetHeadNode(); + xbLinkListNode<xbString> * llN = llInfData.GetHeadNode(); for( xbUInt32 i = 0; i < llNodeCnt; i++ ){ s2 = llN->GetKey(); + #ifdef XB_NDX_SUPPORT if(( iRc = OpenIndex( "NDX", s2 )) != XB_NO_ERROR ){ - iErrorStop = 100; + iErrorStop = 120; throw iRc ; } + #endif // XB_NDX_SUPPORT llN = llN->GetNextNode(); } } - #endif // XB_NDXINF_SUPPORT + #endif // XB_INF_SUPPORT } catch (xbInt16 iRc ){ xbString sMsg; @@ -3190,7 +3230,6 @@ xbInt16 xbDbf::Open( const xbString & sTableName, const xbString & sAlias ){ } return iRc; } -#endif // XB_LOCKING_SUPPORT /************************************************************************/ #ifdef XB_INDEX_SUPPORT @@ -3216,7 +3255,7 @@ xbInt16 xbDbf::OpenIndex( const xbString &sIxType, const xbString &sFileName ){ sType.ToUpperCase(); if( sType == "" ){ - iErrorStop = 10; + iErrorStop = 100; iRc = XB_INVALID_OPTION; throw iRc; @@ -3224,7 +3263,7 @@ xbInt16 xbDbf::OpenIndex( const xbString &sIxType, const xbString &sFileName ){ } else if( sType == "NDX" ){ pIx = new xbIxNdx( this ); if(( iRc = pIx->Open( sFileName )) != XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 110; throw iRc; } #endif @@ -3234,24 +3273,24 @@ xbInt16 xbDbf::OpenIndex( const xbString &sIxType, const xbString &sFileName ){ pIx = new xbIxMdx( this ); if(( iRc = pIx->Open( sFileName )) != XB_NO_ERROR ){ - iErrorStop = 30; + iErrorStop = 120; throw iRc; } #endif } else { - iErrorStop = 40; + iErrorStop = 130; iRc = XB_INVALID_OPTION; throw iRc; } if(( iRc = AddIndex( pIx, sIxType )) != XB_NO_ERROR ){ - iErrorStop = 50; + iErrorStop = 140; throw iRc; } if(( iRc = UpdateTagList()) != XB_NO_ERROR ){ - iErrorStop = 60; + iErrorStop = 150; throw iRc; } pCurIx = pIx; @@ -3304,38 +3343,41 @@ xbInt16 xbDbf::Pack( xbUInt32 &ulDeletedRecCnt ) xbUInt32 ulRecCnt = 0; ulDeletedRecCnt = 0; + #ifdef XB_LOCKING_SUPPORT + xbBool bLocked = xbFalse; + #endif // XB_LOCKING_SUPPORT + try{ if( !FileIsOpen() ){ - iErrorStop = 10; + iErrorStop = 100; iRc = XB_DBF_FILE_NOT_OPEN; throw iRc; } #ifdef XB_LOCKING_SUPPORT - if( iAutoLock ){ + if( iAutoLock && !bTableLocked ){ if(( iRc = LockTable( XB_LOCK )) != XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 110; throw iRc; + } else { + bLocked = xbTrue; } } #endif if(( iRc = GetRecordCnt( ulRecCnt )) != XB_NO_ERROR ){ - iErrorStop = 30; + iErrorStop = 120; throw iRc; } xbBool bDone = xbFalse; for( xbUInt32 ulI = 1; ulI <= ulRecCnt && !bDone; ulI++ ){ - if(( iRc = GetRecord( ulI )) != XB_NO_ERROR ){ - iErrorStop = 40; + iErrorStop = 130; throw iRc; } - if( RecordDeleted()){ - ulDeletedRecCnt++; if( ulI > ulLastMovedRec ) ulStartPos = ulI; @@ -3352,24 +3394,24 @@ xbInt16 xbDbf::Pack( xbUInt32 &ulDeletedRecCnt ) bDone = xbTrue; } else{ - iErrorStop = 50; + iErrorStop = 140; throw iRc; } if( ulMoveRec > 0 ){ if(( iRc = DeleteRecord()) != XB_NO_ERROR ){ - iErrorStop = 60; + iErrorStop = 150; throw iRc; } if(( iRc = PutRecord( ulMoveRec )) != XB_NO_ERROR ){ - iErrorStop = 70; + iErrorStop = 160; throw iRc; } if(( iRc = UndeleteRecord()) != XB_NO_ERROR ){ - iErrorStop = 80; + iErrorStop = 170; throw iRc; } if(( iRc = PutRecord( ulI )) != XB_NO_ERROR ){ - iErrorStop = 90; + iErrorStop = 180; throw iRc; } ulLastPackedRec = ulI; @@ -3391,20 +3433,20 @@ xbInt16 xbDbf::Pack( xbUInt32 &ulDeletedRecCnt ) // rewrite the header record if(( iRc = WriteHeader( 1, 1 )) != XB_NO_ERROR ){ - iErrorStop = 200; + iErrorStop = 190; throw iRc; } // truncate the file to the new size if(( iRc = xbTruncate( uiHeaderLen + uiRecordLen * ulLastPackedRec )) != XB_NO_ERROR ){ - iErrorStop = 210; + iErrorStop = 200; throw iRc; } } if( ulNoOfRecs > 0 ){ if(( iRc = GetRecord( 1 )) != XB_NO_ERROR ){ - iErrorStop = 220; + iErrorStop = 210; throw iRc; } } else { @@ -3415,21 +3457,12 @@ xbInt16 xbDbf::Pack( xbUInt32 &ulDeletedRecCnt ) #ifdef XB_MEMO_SUPPORT if( iMemoFieldCnt > 0 ){ if(( iRc = Memo->PackMemo( 0 )) != XB_NO_ERROR ){ - iErrorStop = 230; + iErrorStop = 220; throw iRc; } } #endif // XB_MEMO_SUPPORT - #ifdef XB_LOCKING_SUPPORT - if( iAutoLock ){ - if(( iRc = LockTable( XB_UNLOCK )) != XB_NO_ERROR ){ - iErrorStop = 240; - throw iRc; - } - } - - #endif } catch (xbInt16 iRc ){ if( iRc != XB_LOCK_FAILED ){ @@ -3439,6 +3472,11 @@ xbInt16 xbDbf::Pack( xbUInt32 &ulDeletedRecCnt ) xbase->WriteLogMessage( GetErrorMessage( iRc )); } } + #ifdef XB_LOCKING_SUPPORT + if( bLocked ){ + LockTable( XB_UNLOCK ); + } + #endif return iRc; } @@ -3492,24 +3530,17 @@ xbInt16 xbDbf::PutRecord(xbUInt32 ulRecNo) } /* lock the database */ #ifdef XB_LOCKING_SUPPORT - // xbInt16 iAutoLock = GetAutoLock(); if( iAutoLock && !bTableLocked ){ if(( iRc = LockHeader( XB_LOCK )) != XB_NO_ERROR ){ - if( iRc == XB_LOCK_FAILED ) - return iRc; - else{ - iErrorStop = 140; throw iRc; - } } + } + #endif // XB_LOCKING_SUPPORT - if(( iRc = ReadHeader( 1, 1 )) != XB_NO_ERROR ){ - iErrorStop = 150; - LockHeader( XB_UNLOCK ); - throw iRc; - } + if(( iRc = ReadHeader( 1, 1 )) != XB_NO_ERROR ){ + iErrorStop = 150; + throw iRc; } - #endif // verify valid record number request if( ulRecNo > ulNoOfRecs || ulRecNo == 0L ){ @@ -3519,30 +3550,20 @@ xbInt16 xbDbf::PutRecord(xbUInt32 ulRecNo) } #ifdef XB_LOCKING_SUPPORT - if( iAutoLock ){ - if( !bTableLocked ){ - if(( iRc = LockRecord( XB_LOCK, ulRecNo )) != XB_NO_ERROR ){ - if( iRc == XB_LOCK_FAILED ) - return iRc; - else{ - iErrorStop = 170; - throw iRc; - } + if( iAutoLock && !bTableLocked ){ + if(( iRc = LockRecord( XB_LOCK, ulRecNo )) != XB_NO_ERROR ){ + iErrorStop = 170; + throw iRc; } - } #ifdef XB_INDEX_SUPPORT if(( iRc = LockIndices( XB_LOCK )) != XB_NO_ERROR ){ - if( iRc == XB_LOCK_FAILED ) - return iRc; - else{ - iErrorStop = 180; - throw iRc; - } + iErrorStop = 180; + throw iRc; } - #endif + #endif // XB_INDEX_SUPPORT } - #endif + #endif // XB_LOCKING_SUPPORT // build keys, check for duplicate keys, add keys #ifdef XB_INDEX_SUPPORT @@ -3559,7 +3580,7 @@ xbInt16 xbDbf::PutRecord(xbUInt32 ulRecNo) iErrorStop = 200; throw iRc; } - return XB_KEY_NOT_UNIQUE; + throw XB_KEY_NOT_UNIQUE; } ixList = ixList->next; } @@ -3576,9 +3597,6 @@ xbInt16 xbDbf::PutRecord(xbUInt32 ulRecNo) ixList = GetIxList(); while( ixList ){ - -// if(( iRc = ixList->ix->DeleteKeys( ulCurRec )) != XB_NO_ERROR ){ - if(( iRc = ixList->ix->DeleteKeys()) != XB_NO_ERROR ){ iErrorStop = 220; throw iRc; @@ -3600,19 +3618,6 @@ xbInt16 xbDbf::PutRecord(xbUInt32 ulRecNo) } } - #ifdef XB_LOCKING_SUPPORT - if( iAutoLock && !bTableLocked ){ - if(( iRc = LockHeader( XB_UNLOCK )) != XB_NO_ERROR ){ - if( iRc == XB_LOCK_FAILED ) - return iRc; - else{ - iErrorStop = 230; - throw iRc; - } - } - } - #endif - // update record iRc = xbFseek( (uiHeaderLen+(( (xbInt64) ulRecNo-1L ) * uiRecordLen )),0 ); if( iRc != XB_NO_ERROR ){ @@ -3635,47 +3640,30 @@ xbInt16 xbDbf::PutRecord(xbUInt32 ulRecNo) } #endif - // unlock record - #ifdef XB_LOCKING_SUPPORT - if( iAutoLock ){ - #ifdef XB_INDEX_SUPPORT - LockIndices( XB_UNLOCK ); - #endif // XB_INDEX_SUPPORT - if( !bTableLocked ){ - if(( iRc = LockRecord( XB_UNLOCK, ulRecNo )) != XB_NO_ERROR ){ - if( iRc == XB_LOCK_FAILED ) - return iRc; - else{ - iErrorStop = 270; - throw iRc; - } - } - } - } - - #endif ulCurRec = ulRecNo; iDbfStatus = XB_OPEN; } catch (xbInt16 iRc ){ - - #ifdef XB_LOCKING_SUPPORT - if( iAutoLock ){ - LockHeader( XB_UNLOCK ); - LockAppend( XB_UNLOCK ); - LockRecord( XB_UNLOCK, ulRecNo ); - LockIndices( XB_UNLOCK ); - } - #endif // XB_LOCKING_SUPPORT - - if( iRc != XB_LOCK_FAILED ){ + if( iRc != XB_LOCK_FAILED && iRc != XB_KEY_NOT_UNIQUE ){ xbString sMsg; sMsg.Sprintf( "xbdbf::PutRecord() Exception Caught. Error Stop = [%d] iRc = [%d] record = [%d]", iErrorStop, iRc, ulRecNo ); xbase->WriteLogMessage( sMsg.Str() ); xbase->WriteLogMessage( GetErrorMessage( iRc )); } } + + #ifdef XB_LOCKING_SUPPORT + if( iAutoLock ){ + LockHeader( XB_UNLOCK ); + LockAppend( XB_UNLOCK ); + LockRecord( XB_UNLOCK, ulRecNo ); + #ifdef XB_INDEX_SUPPORT + LockIndices( XB_UNLOCK ); + #endif // XB_INDEX_SUPPORT + } + #endif // XB_LOCKING_SUPPORT + return iRc; } @@ -3788,14 +3776,14 @@ void xbDbf::ResetNoOfRecords() { } /************************************************************************/ -#ifdef XB_NDXINF_SUPPORT +#ifdef XB_INF_SUPPORT // @brief Update .INF data file. /* Protected method. \returns <a href="xbretcod_8h.html">Return Codes</a> */ -xbInt16 xbDbf::SaveNdxInfData(){ +xbInt16 xbDbf::SaveInfData(){ xbInt16 iRc = 0; xbInt16 iErrorStop = 0; @@ -3803,17 +3791,17 @@ xbInt16 xbDbf::SaveNdxInfData(){ try{ - xbUInt32 llNodeCnt = llNdxInfData.GetNodeCnt(); + xbUInt32 llNodeCnt = llInfData.GetNodeCnt(); - xbString sNdxInfFileName; - if(( iRc = GetNdxInfFileName( sNdxInfFileName )) != XB_NO_ERROR ){ - iErrorStop = 10; + xbString sInfFileName; + if(( iRc = GetInfFileName( sInfFileName )) != XB_NO_ERROR ){ + iErrorStop = 100; throw iRc; } // open the file - if(( iRc = fMd.xbFopen( "w", sNdxInfFileName, GetShareMode())) != XB_NO_ERROR ){ - iErrorStop = 20; + if(( iRc = fMd.xbFopen( "w", sInfFileName, GetShareMode())) != XB_NO_ERROR ){ + iErrorStop = 110; throw iRc; } @@ -3821,13 +3809,12 @@ xbInt16 xbDbf::SaveNdxInfData(){ xbString s2; s2.Sprintf( "[dbase]%c%c", 0x0d, 0x0a ); if(( iRc = fMd.xbFputs( s2 )) != XB_NO_ERROR ){ - iErrorStop = 30; + iErrorStop = 120; throw iRc; } - // for each entry in the linked list, write a line - xbLinkListNode<xbString> * llN = llNdxInfData.GetHeadNode(); + xbLinkListNode<xbString> * llN = llInfData.GetHeadNode(); for( xbUInt32 i = 0; i < llNodeCnt; i++ ){ s2 = llN->GetKey(); if( i > 0 ) @@ -3836,7 +3823,7 @@ xbInt16 xbDbf::SaveNdxInfData(){ s1.Sprintf( "NDX=%s%c%c", s2.Str(), 0x0d, 0x0a ); if(( iRc = fMd.xbFputs( s1 )) != XB_NO_ERROR ){ - iErrorStop = 40; + iErrorStop = 130; throw iRc; } llN = llN->GetNextNode(); @@ -3844,7 +3831,7 @@ xbInt16 xbDbf::SaveNdxInfData(){ // close the file if(( iRc = fMd.xbFclose()) != XB_NO_ERROR ){ - iErrorStop = 50; + iErrorStop = 140; throw iRc; } @@ -3852,13 +3839,13 @@ xbInt16 xbDbf::SaveNdxInfData(){ if( fMd.FileIsOpen()) fMd.xbFclose(); xbString sMsg; - sMsg.Sprintf( "xbdbf::SaveNdxInfData() Exception Caught. Error Stop = [%d] iRc = [%d]", iErrorStop, iRc ); + sMsg.Sprintf( "xbdbf::SaveInfData() Exception Caught. Error Stop = [%d] iRc = [%d]", iErrorStop, iRc ); xbase->WriteLogMessage( sMsg.Str() ); xbase->WriteLogMessage( GetErrorMessage( iRc )); } return iRc; } -#endif // XB_NDXINF_SUPPORT +#endif // XB_INF_SUPPORT /************************************************************************/ //! @brief Set auto commit. /*! @@ -3884,14 +3871,14 @@ xbInt16 xbDbf::SetAutoCommit( xbBool iAutoCommit ) { -1 - (minus one) Use system default.<br> \returns <a href="xbretcod_8h.html">Return Codes</a> */ - +#ifdef XB_LOCKING_SUPPORT void xbDbf::SetAutoLock( xbInt16 iAutoLock ){ if( iAutoLock == -1 ) this->iAutoLock = xbase->GetDefaultAutoLock(); else this->iAutoLock = iAutoLock; } - +#endif /************************************************************************/ @@ -3946,9 +3933,11 @@ void xbDbf::SetCurTag( const xbString &sIxType, xbIx *pIx, void *vpTag ){ \param bHeaderLocked xbTrue - Locked<br>xbFalse - Not locked. \returns void */ +#ifdef XB_LOCKING_SUPPORT void xbDbf::SetHeaderLocked( xbBool bHeaderLocked ){ this->bHeaderLocked = bHeaderLocked; } +#endif /************************************************************************/ //! @brief Set lock flavor. @@ -3957,10 +3946,11 @@ void xbDbf::SetHeaderLocked( xbBool bHeaderLocked ){ \param iLockFlavor 1 - Use Dbase (tm) style locking. \returns void */ - +#ifdef XB_LOCKING_SUPPORT void xbDbf::SetLockFlavor( xbInt16 iLockFlavor ){ this->iLockFlavor = iLockFlavor; } +#endif /************************************************************************/ //! @brief Set table locked status. @@ -3968,10 +3958,11 @@ void xbDbf::SetLockFlavor( xbInt16 iLockFlavor ){ \param bTableLocked - xbTrue Table locked.<br>xbFalse Table unlocked. \returns void */ - +#ifdef XB_LOCKING_SUPPORT void xbDbf::SetTableLocked( xbBool bTableLocked ){ this->bTableLocked = bTableLocked; } +#endif /************************************************************************/ //! @brief Undelete all records. /*! @@ -4044,8 +4035,8 @@ void xbDbf::UpdateSchemaIxFlag( xbInt16 iFldNo, unsigned char cVal ){ SchemaPtr[iFldNo].cIxFlag = cVal; } -#endif // XB_INDEX_SUPPORT /************************************************************************/ + //! @brief Update tag list. /*! This routine updates the internal tag list of open index tags. @@ -4086,6 +4077,7 @@ xbInt16 xbDbf::UpdateTagList(){ } return iRc; } +#endif // XB_INDEX_SUPPORT /************************************************************************/ // @brief Write Header @@ -4094,8 +4086,8 @@ xbInt16 xbDbf::UpdateTagList(){ \param iPositionOption 0 - Don't fseek to beginning of file before read.<br> 1 - Go to beginning of file before read. - \param iWriteOption 0 - Write entire 32 byte header.<br> - 1 - Write first eight bytes needed for table updates - last update date and number of records. + \param iWriteOption 0 - Write entire 32 byte header.<br> + 1 - Write first eight bytes needed for table updates - last update date and number of records. \returns <a href="xbretcod_8h.html">Return Codes</a> */ xbInt16 xbDbf::WriteHeader( xbInt16 iPositionOption, xbInt16 iWriteOption ) @@ -4125,7 +4117,6 @@ xbInt16 xbDbf::WriteHeader( xbInt16 iPositionOption, xbInt16 iWriteOption ) return XB_NO_ERROR; } - /************************************************************************/ //! @brief Zap (remove) everything from the file, /*! @@ -4137,16 +4128,20 @@ xbInt16 xbDbf::Zap(){ xbInt16 iRc = 0; xbInt16 iErrorStop = 0; + #ifdef XB_LOCKING_SUPPORT + xbBool bLocked = xbFalse; + #endif // XB_LOCKING_SUPPORT + try{ if( iDbfStatus != XB_OPEN ){ - iErrorStop = 10; + iErrorStop = 100; iRc = XB_DBF_FILE_NOT_OPEN; throw iRc; } #ifdef XB_LOCKING_SUPPORT if( iAutoLock ){ if(( iRc = LockTable( XB_LOCK )) != XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 110; throw iRc; } } @@ -4160,13 +4155,13 @@ xbInt16 xbDbf::Zap(){ // rewrite the header record if(( iRc = WriteHeader( 1, 1 )) != XB_NO_ERROR ){ - iErrorStop = 30; + iErrorStop = 120; throw iRc; } // truncate the file to the new size if(( iRc = xbTruncate( uiHeaderLen )) != XB_NO_ERROR ){ - iErrorStop = 40; + iErrorStop = 130; throw iRc; } BlankRecord(); @@ -4175,7 +4170,7 @@ xbInt16 xbDbf::Zap(){ #ifdef XB_MEMO_SUPPORT if( iMemoFieldCnt ){ if(( iRc = Memo->Zap()) != XB_NO_ERROR ){ - iErrorStop = 50; + iErrorStop = 140; throw iRc; } } @@ -4197,14 +4192,6 @@ xbInt16 xbDbf::Zap(){ } #endif // XB_INDEX_SUPPORT - #ifdef XB_LOCKING_SUPPORT - if( iAutoLock ){ - if(( iRc = LockTable( XB_UNLOCK )) != XB_NO_ERROR ){ - iErrorStop = 70; - throw iRc; - } - } - #endif // XB_LOCKING_SUPPORT } catch (xbInt16 iRc ){ if( iRc != XB_LOCK_FAILED ){ @@ -4214,6 +4201,11 @@ xbInt16 xbDbf::Zap(){ xbase->WriteLogMessage( GetErrorMessage( iRc )); } } + #ifdef XB_LOCKING_SUPPORT + if( bLocked ){ + LockTable( XB_UNLOCK ); + } + #endif // XB_LOCKING_SUPPORT return iRc; } /************************************************************************/ diff --git a/src/core/xbdbf3.cpp b/src/core/xbdbf3.cpp index cbbff1f..504542f 100755 --- a/src/core/xbdbf3.cpp +++ b/src/core/xbdbf3.cpp @@ -47,7 +47,7 @@ xbDbf3::~xbDbf3() {}; \param iOverlay xbTrue - Overlay.<br> xbFalse - Don't overlay. \param iShareMode XB_SINGLE_USER<br>XB_MULTI_USER \returns <a href="xbretcod_8h.html">Return Codes</a> - + */ xbInt16 xbDbf3::CreateTable( const xbString & sTableName, const xbString & sAlias, xbSchema *pSchema, xbInt16 iOverlay, xbInt16 iShareMode ){ @@ -71,33 +71,46 @@ xbInt16 xbDbf3::CreateTable( const xbString & sTableName, const xbString & sAlia /* check if the file already exists */ if( FileExists( 0 )){ if( !iOverlay ){ - iErrorStop = 10; + iErrorStop = 100; rc = XB_FILE_EXISTS; throw rc; } - #ifdef XB_NDXINF_SUPPORT - // remove the metadata file if there is one + + // remove other files if they exist xbString sMname = sNfn; xbUInt32 iMnameLen = sMname.Len(); - sMname.PutAt( iMnameLen-2, 'X' ); - sMname.PutAt( iMnameLen-1, 'B' ); - sMname.PutAt( iMnameLen, 'M' ); + sMname.PutAt( iMnameLen-2, 'I' ); + sMname.PutAt( iMnameLen-1, 'N' ); + sMname.PutAt( iMnameLen, 'F' ); xbFile fTemp( xbase ); fTemp.SetFileName( sMname ); if( fTemp.FileExists() ) fTemp.xbRemove(); - #endif // XB_NDXINF_SUPPORT + + sMname.PutAt( iMnameLen-2, 'D' ); + sMname.PutAt( iMnameLen-1, 'B' ); + sMname.PutAt( iMnameLen, 'T' ); + fTemp.SetFileName( sMname ); + if( fTemp.FileExists() ) + fTemp.xbRemove(); + + sMname.PutAt( iMnameLen-2, 'M' ); + sMname.PutAt( iMnameLen-1, 'D' ); + sMname.PutAt( iMnameLen, 'X' ); + fTemp.SetFileName( sMname ); + if( fTemp.FileExists() ) + fTemp.xbRemove(); } /* check if we already have a file with this alias */ if(( rc = xbase->AddTblToTblList( this, GetFqFileName(), sAlias )) != XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 110; throw rc; } rc = ValidateSchema( pSchema ); if( rc < 0 ){ - iErrorStop = 30; + iErrorStop = 120; throw rc; } else iNoOfFields = rc; @@ -121,7 +134,7 @@ xbInt16 xbDbf3::CreateTable( const xbString & sTableName, const xbString & sAlia xbFile fTemp( xbase ); fTemp.SetFileName( sMfn ); if( fTemp.FileExists() && !iOverlay ){ - iErrorStop = 40; + iErrorStop = 130; rc = XB_FILE_EXISTS; throw rc; } @@ -129,7 +142,7 @@ xbInt16 xbDbf3::CreateTable( const xbString & sTableName, const xbString & sAlia Memo = new xbMemoDbt3( this, fTemp.GetFqFileName()); if(( rc = Memo->CreateMemoFile()) != XB_NO_ERROR ){ - iErrorStop = 50; + iErrorStop = 140; throw rc; } } @@ -145,18 +158,18 @@ xbInt16 xbDbf3::CreateTable( const xbString & sTableName, const xbString & sAlia #endif if(( rc = xbFopen( "w+b", iShareMode )) != XB_NO_ERROR ){ - iErrorStop = 60; + iErrorStop = 150; throw rc; } uiRecordLen++; /* add one byte for 0x0D */ if(( RecBuf = (char *) malloc( uiRecordLen )) == NULL ){ - iErrorStop = 70; + iErrorStop = 160; throw rc; } if(( RecBuf2 = (char *) malloc( uiRecordLen )) == NULL ){ - iErrorStop = 80; + iErrorStop = 170; rc = XB_NO_MEMORY; throw rc; } @@ -173,12 +186,12 @@ xbInt16 xbDbf3::CreateTable( const xbString & sTableName, const xbString & sAlia /* write the header prolog */ if(( rc = WriteHeader( 0, 0 )) != XB_NO_ERROR ){ - iErrorStop = 90; + iErrorStop = 180; rc = XB_WRITE_ERROR; throw rc; } if((SchemaPtr = (xbSchemaRec *) malloc( (size_t) iNoOfFields * sizeof( xbSchemaRec ))) == NULL){ - iErrorStop = 100; + iErrorStop = 190; rc = XB_NO_MEMORY; throw rc; } @@ -195,7 +208,7 @@ xbInt16 xbDbf3::CreateTable( const xbString & sTableName, const xbString & sAlia SchemaPtr[i].cNoOfDecs = (unsigned char) pSchema[i].iNoOfDecs; if( SchemaPtr[i].cNoOfDecs > SchemaPtr[i].cFieldLen ){ - iErrorStop = 110; + iErrorStop = 200; rc = XB_WRITE_ERROR; throw rc; } @@ -204,13 +217,13 @@ xbInt16 xbDbf3::CreateTable( const xbString & sTableName, const xbString & sAlia k += SchemaPtr[i].cFieldLen; if(( xbFwrite( &SchemaPtr[i].cFieldName, 1, 11 )) != XB_NO_ERROR ) { - iErrorStop = 110; + iErrorStop = 210; rc = XB_WRITE_ERROR; throw rc; } if(( xbFwrite( &SchemaPtr[i].cType, 1, 1 )) != XB_NO_ERROR ) { - iErrorStop = 120; + iErrorStop = 220; rc = XB_WRITE_ERROR; throw rc; } @@ -219,13 +232,13 @@ xbInt16 xbDbf3::CreateTable( const xbString & sTableName, const xbString & sAlia xbFputc( 0x00 ); if(( xbFwrite( &SchemaPtr[i].cFieldLen, 1, 1 )) != XB_NO_ERROR ) { - iErrorStop = 130; + iErrorStop = 230; rc = XB_WRITE_ERROR; throw rc; } if(( xbFwrite( &SchemaPtr[i].cNoOfDecs, 1, 1 )) != XB_NO_ERROR ) { - iErrorStop = 140; + iErrorStop = 240; rc = XB_WRITE_ERROR; throw rc; } @@ -240,7 +253,7 @@ xbInt16 xbDbf3::CreateTable( const xbString & sTableName, const xbString & sAlia /* write the header terminator */ if(( xbFputc( XB_CHARHDR )) != XB_NO_ERROR ){ - iErrorStop = 150; + iErrorStop = 250; rc = XB_WRITE_ERROR; throw rc; } @@ -321,7 +334,7 @@ xbInt16 xbDbf3::Open( const xbString & sTableName, const xbString & sAlias, /* verify the file is not already open */ if( iDbfStatus != XB_CLOSED ){ - iErrorStop = 10; + iErrorStop = 100; iRc = XB_ALREADY_OPEN; throw iRc; } @@ -330,32 +343,32 @@ xbInt16 xbDbf3::Open( const xbString & sTableName, const xbString & sAlias, this->sAlias = sAlias; if( !FileExists()){ - iErrorStop = 20; + iErrorStop = 110; iRc = XB_FILE_NOT_FOUND; throw iRc; } if(( iRc = xbase->AddTblToTblList( this, GetFqFileName(), sAlias )) != XB_NO_ERROR ){ - iErrorStop = 30; + iErrorStop = 120; throw iRc; } /* open the file */ if(( iRc = xbFopen( iOpenMode, iShareMode )) != XB_NO_ERROR ){ - iErrorStop = 40; + iErrorStop = 130; throw iRc; } /* copy the header into memory */ if(( iRc = ReadHeader( 1, 0 )) != XB_NO_ERROR ){ - iErrorStop = 50; + iErrorStop = 140; throw iRc; } /* check the version */ if(( cVersion & 0x07 ) != 3 ){ // if( xFileVersion != 3 && xFileVersion != 4 ){ - iErrorStop = 60; + iErrorStop = 150; iRc = XB_FILE_TYPE_NOT_SUPPORTED; throw iRc; } @@ -369,19 +382,19 @@ xbInt16 xbDbf3::Open( const xbString & sTableName, const xbString & sAlias, } if(( RecBuf = (char *) malloc( (size_t) uiRecordLen )) == NULL ){ - iErrorStop = 70; + iErrorStop = 160; iRc = XB_NO_MEMORY; throw iRc; } if(( RecBuf2 = (char *) malloc( uiRecordLen )) == NULL ) { - iErrorStop = 80; + iErrorStop = 170; iRc = XB_NO_MEMORY; throw iRc; } if((SchemaPtr=(xbSchemaRec *)malloc( (size_t) iNoOfFields * sizeof( xbSchemaRec ))) == NULL){ - iErrorStop = 90; + iErrorStop = 180; iRc = XB_NO_MEMORY; throw iRc; } @@ -410,7 +423,7 @@ xbInt16 xbDbf3::Open( const xbString & sTableName, const xbString & sAlias, ulCurRec = 0L; iDbfStatus = XB_OPEN; if(( iRc = BlankRecord()) != XB_NO_ERROR ){ - iErrorStop = 100; + iErrorStop = 190; throw iRc; } @@ -430,11 +443,11 @@ xbInt16 xbDbf3::Open( const xbString & sTableName, const xbString & sAlias, Memo = new xbMemoDbt3( this, fTemp.GetFqFileName()); if(( iRc = Memo->OpenMemoFile()) != XB_NO_ERROR ){ - iErrorStop = 110; + iErrorStop = 200; throw iRc; } } - #endif + #endif // XB_MEMO_SUPPORT } catch ( xbInt16 iRc ) @@ -458,13 +471,13 @@ xbInt16 xbDbf3::Open( const xbString & sTableName, const xbString & sAlias, } InitVars(); -#ifdef XB_MEMO_SUPPORT + #ifdef XB_MEMO_SUPPORT if( Memo ){ Memo->CloseMemoFile(); delete Memo; Memo = NULL; } -#endif + #endif // XB_MEMO_SUPPORT } if( iRc == XB_NO_ERROR ) @@ -472,6 +485,179 @@ xbInt16 xbDbf3::Open( const xbString & sTableName, const xbString & sAlias, return iRc; } +/************************************************************************/ +//! @brief Rename table. +/*! + This routine renames a give table, associated memo and inf files + \param sNewName - New file name. + \returns <a href="xbretcod_8h.html">Return Codes</a> +*/ +xbInt16 xbDbf3::Rename( const xbString sNewName ){ + + xbInt16 iRc = XB_NO_ERROR; + xbInt16 iErrorStop = 0; + + xbString sNewDbf; + + xbBool bDbfRenamed = xbFalse; + + #ifdef XB_INF_SUPPORT + xbString sNewInf; + xbString sThisInf; + xbBool bInfRenamed = xbFalse; + #endif + + #ifdef XB_MEMO_SUPPORT + xbString sNewDbt; + xbString sThisDbt; + xbBool bDbtRenamed = xbFalse; + #endif // XB_MEMO_SUPPORT + + #ifdef XB_LOCKING_SUPPORT + xbBool bLocked = xbFalse; + #endif + + try{ + + xbString sDir; + xbString sFile; + xbString sExt; + + xbString sNewNameWoExt; + sNewNameWoExt.Set( sNewName ); + if( sNewName.Pos( ".DBF" ) > 0 ) + sNewNameWoExt.Left( sNewName.Len() - 4 ); + + GetFileDirPart ( sDir ); + GetFileNamePart( sFile ); + GetFileExtPart ( sExt ); + + if( FileExists( sNewDbf )) return XB_FILE_EXISTS; + sNewDbf.Sprintf( "%s%s.DBF", sDir.Str(), sNewNameWoExt.Str()); + + #ifdef XB_MEMO_SUPPORT + sNewDbt.Sprintf( "%s%s.DBT", sDir.Str(), sNewNameWoExt.Str()); + if( FileExists( sNewDbt )) return XB_FILE_EXISTS; + sThisDbt.Sprintf( "%s%s.DBT", sDir.Str(), sFile.Str()); + #endif + + #ifdef XB_INF_SUPPORT + sNewInf.Sprintf( "%s%s.INF", sDir.Str(), sNewNameWoExt.Str()); + if( FileExists( sNewInf )) return XB_FILE_EXISTS; + sThisInf.Sprintf( "%s%s.INF", sDir.Str(), sFile.Str()); + #endif // XB_INF_SUPPORT + + #ifdef XB_LOCKING_SUPPORT + if( GetAutoLock() && GetTableLocked() ){ + if(( iRc = LockTable( XB_LOCK )) != XB_NO_ERROR ){ + iErrorStop = 100; + throw iRc; + } + bLocked = xbTrue; + } + #endif + + xbInt16 iOpenMode = GetOpenMode(); + xbInt16 iShareMode = GetShareMode(); + xbBool bWasOpen = xbFalse; + if( FileIsOpen() ){ + bWasOpen = xbTrue; + if(( iRc = xbFclose()) != XB_NO_ERROR ){ + iErrorStop = 110; + throw iRc; + } + } + + if(( iRc = xbRename( GetFqFileName().Str(), sNewDbf.Str())) != XB_NO_ERROR ){ + iErrorStop = 120; + throw iRc; + } else { + bDbfRenamed = xbTrue; + } + xbString sNameWext; + sNameWext.Sprintf( "%s.DBF", sNewNameWoExt.Str()); + SetFileName( sNameWext ); + + if( bWasOpen ){ + if(( iRc = xbFopen( iOpenMode, iShareMode )) != XB_NO_ERROR ){ + iErrorStop = 130; + throw iRc; + } + } + + #ifdef XB_MEMO_SUPPORT + if( FileExists( sThisDbt )){ + if( bWasOpen ){ + if(( iRc = Memo->xbFclose()) != XB_NO_ERROR ){ + iErrorStop = 140; + throw iRc; + } + } + if(( xbRename( sThisDbt.Str(), sNewDbt.Str())) != XB_NO_ERROR ){ + iErrorStop = 150; + throw iRc; + } + Memo->SetFileName( sNewDbt ); + if( bWasOpen ){ + if(( iRc = Memo->xbFopen( iOpenMode, iShareMode )) != XB_NO_ERROR ){ + iErrorStop = 160; + throw iRc; + } + } + bDbtRenamed = xbTrue; + } + #endif // XB_MEMO_SUPPORT + + #ifdef XB_INF_SUPPORT + if( FileExists( sThisInf )){ + if(( iRc = xbRename( sThisInf.Str(), sNewInf.Str())) != XB_NO_ERROR ){ + iErrorStop = 170; + throw iRc; + } else { + bInfRenamed = xbTrue; + } + } + #endif // XB_INF_SUPPORT + + // rname the table in the table list + xbTblList *tle = xbase->GetTblListEntry( this ); + if( tle ){ + // std::cout << "setting [" << GetFqFileName().Str() << "][" << sNewNameWoExt.Str() << "]\n"; + tle->psTblName->Set( GetFqFileName().Str()); + tle->psTblAlias->Set( sNewNameWoExt.Str()); + } + } + catch ( xbInt16 iRc ) + { + xbString sMsg; + sMsg.Sprintf( "xbdbf3::Rename() Exception Caught Error Stop = %d iRc = %d", iErrorStop, iRc ); + xbase->WriteLogMessage( sMsg ); + xbase->WriteLogMessage( GetErrorMessage( iRc )); + + // attempt to reverse things out if unsuccessful + if( bDbfRenamed ){ + #ifdef XB_MEMO_SUPPORT + if( bDbtRenamed ){ + xbRename( sNewDbt.Str(), sThisDbt.Str()); + } + #endif // XB_MEMO_SUPPORT + #ifdef XB_INF_SUPPORT + if( bInfRenamed ){ + xbRename( sNewInf.Str(), sNewInf.Str()); + } + #endif // XB_INF_SUPPORT + } + + #ifdef XB_LOCKING_SUPPORT + if( bLocked ){ + LockTable( XB_UNLOCK ); + } + #endif + + } + return iRc; +} + /************************************************************************/ #ifdef XB_MEMO_SUPPORT @@ -540,9 +726,9 @@ xbInt16 xbDbf3::ValidateSchema( xbSchema * s ){ if( s[i].cType != 'C' && s[i].cType != 'N' && s[i].cType != 'D' && -#ifdef XB_MEMO_SUPPORT + #ifdef XB_MEMO_SUPPORT s[i].cType != 'M' && -#endif /* XB_MEMO_SUPPORT */ + #endif // XB_MEMO_SUPPORT s[i].cType != 'L' ){ return XB_INVALID_FIELD_TYPE; } @@ -559,13 +745,17 @@ xbInt16 xbDbf3::ValidateSchema( xbSchema * s ){ else if( s[i].cType == 'N' && s[i].iFieldLen > 19 ){ return XB_INVALID_FIELD_LEN; } + // field len must be >= no of decimals + else if( s[i].cType == 'N' && s[i].iFieldLen < s[i].iNoOfDecs ){ + return XB_INVALID_FIELD_LEN; + } -#ifdef XB_MEMO_SUPPORT + #ifdef XB_MEMO_SUPPORT else if(s[i].cType == 'M'){ s[i].iFieldLen = 10; s[i].iNoOfDecs = 0; } -#endif /* XB_MEMO_SUPPORT */ + #endif // XB_MEMO_SUPPORT uiRecordLen += s[i].iFieldLen; i++; diff --git a/src/core/xbdbf4.cpp b/src/core/xbdbf4.cpp index c421add..2b49be9 100755 --- a/src/core/xbdbf4.cpp +++ b/src/core/xbdbf4.cpp @@ -71,33 +71,46 @@ xbInt16 xbDbf4::CreateTable( const xbString &sTableName, const xbString &sAlias, /* check if the file already exists */ if( FileExists( 0 )){ if( !iOverlay ){ - iErrorStop = 10; + iErrorStop = 100; rc = XB_FILE_EXISTS; throw rc; } - #ifdef XB_NDXINF_SUPPORT - // remove the metadata file if there is one + + // remove other files if they exist xbString sMname = sNfn; xbUInt32 iMnameLen = sMname.Len(); - sMname.PutAt( iMnameLen-2, 'X' ); - sMname.PutAt( iMnameLen-1, 'B' ); - sMname.PutAt( iMnameLen, 'M' ); + sMname.PutAt( iMnameLen-2, 'I' ); + sMname.PutAt( iMnameLen-1, 'N' ); + sMname.PutAt( iMnameLen, 'F' ); xbFile fTemp( xbase ); fTemp.SetFileName( sMname ); if( fTemp.FileExists() ) fTemp.xbRemove(); - #endif // XB_NDXINF_SUPPORT + + sMname.PutAt( iMnameLen-2, 'D' ); + sMname.PutAt( iMnameLen-1, 'B' ); + sMname.PutAt( iMnameLen, 'T' ); + fTemp.SetFileName( sMname ); + if( fTemp.FileExists() ) + fTemp.xbRemove(); + + sMname.PutAt( iMnameLen-2, 'M' ); + sMname.PutAt( iMnameLen-1, 'D' ); + sMname.PutAt( iMnameLen, 'X' ); + fTemp.SetFileName( sMname ); + if( fTemp.FileExists() ) + fTemp.xbRemove(); } /* check if we already have a file with this alias */ if(( rc = xbase->AddTblToTblList( this, GetFqFileName(), sAlias )) != XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 110; throw rc; } rc = ValidateSchema( pSchema ); if( rc < 0 ){ - iErrorStop = 30; + iErrorStop = 120; throw rc; } else iNoOfFields = rc; @@ -121,7 +134,7 @@ xbInt16 xbDbf4::CreateTable( const xbString &sTableName, const xbString &sAlias, xbFile fTemp( xbase ); fTemp.SetFileName( sMfn ); if( fTemp.FileExists() && !iOverlay ){ - iErrorStop = 40; + iErrorStop = 130; rc = XB_FILE_EXISTS; throw rc; } @@ -129,7 +142,7 @@ xbInt16 xbDbf4::CreateTable( const xbString &sTableName, const xbString &sAlias, Memo = new xbMemoDbt4( this, fTemp.GetFqFileName()); if(( rc = Memo->CreateMemoFile()) != XB_NO_ERROR ){ - iErrorStop = 50; + iErrorStop = 140; throw rc; } } @@ -145,18 +158,18 @@ xbInt16 xbDbf4::CreateTable( const xbString &sTableName, const xbString &sAlias, #endif if(( rc = xbFopen( "w+b", iShareMode )) != XB_NO_ERROR ){ - iErrorStop = 60; + iErrorStop = 150; throw rc; } uiRecordLen++; /* add one byte for 0x0D */ if(( RecBuf = (char *) malloc( uiRecordLen )) == NULL ){ - iErrorStop = 70; + iErrorStop = 160; throw rc; } if(( RecBuf2 = (char *) malloc( uiRecordLen )) == NULL ){ - iErrorStop = 80; + iErrorStop = 170; rc = XB_NO_MEMORY; throw rc; } @@ -176,12 +189,12 @@ xbInt16 xbDbf4::CreateTable( const xbString &sTableName, const xbString &sAlias, /* write the header prolog */ if(( rc = WriteHeader( 0, 0 )) != XB_NO_ERROR ){ - iErrorStop = 90; + iErrorStop = 180; rc = XB_WRITE_ERROR; throw rc; } if((SchemaPtr=(xbSchemaRec *)malloc( (size_t) iNoOfFields * sizeof( xbSchemaRec ))) == NULL){ - iErrorStop = 100; + iErrorStop = 190; rc = XB_NO_MEMORY; throw rc; } @@ -207,13 +220,13 @@ xbInt16 xbDbf4::CreateTable( const xbString &sTableName, const xbString &sAlias, k += SchemaPtr[i].cFieldLen; if(( xbFwrite( &SchemaPtr[i].cFieldName, 1, 11 )) != XB_NO_ERROR ) { - iErrorStop = 120; + iErrorStop = 200; rc = XB_WRITE_ERROR; throw rc; } if(( xbFwrite( &SchemaPtr[i].cType, 1, 1 )) != XB_NO_ERROR ) { - iErrorStop = 130; + iErrorStop = 210; rc = XB_WRITE_ERROR; throw rc; } @@ -222,13 +235,13 @@ xbInt16 xbDbf4::CreateTable( const xbString &sTableName, const xbString &sAlias, xbFputc( 0x00 ); if(( xbFwrite( &SchemaPtr[i].cFieldLen, 1, 1 )) != XB_NO_ERROR ) { - iErrorStop = 140; + iErrorStop = 220; rc = XB_WRITE_ERROR; throw rc; } if(( xbFwrite( &SchemaPtr[i].cNoOfDecs, 1, 1 )) != XB_NO_ERROR ) { - iErrorStop = 150; + iErrorStop = 230; rc = XB_WRITE_ERROR; throw rc; } @@ -243,7 +256,7 @@ xbInt16 xbDbf4::CreateTable( const xbString &sTableName, const xbString &sAlias, /* write the header terminator */ if(( xbFputc( XB_CHARHDR )) != XB_NO_ERROR ){ - iErrorStop = 160; + iErrorStop = 240; rc = XB_WRITE_ERROR; throw rc; } @@ -321,7 +334,7 @@ xbInt16 xbDbf4::Open( const xbString & sTableName, const xbString & sAlias, try{ /* verify the file is not already open */ if( iDbfStatus != XB_CLOSED ){ - iErrorStop = 10; + iErrorStop = 100; iRc = XB_ALREADY_OPEN; throw iRc; } @@ -330,32 +343,32 @@ xbInt16 xbDbf4::Open( const xbString & sTableName, const xbString & sAlias, this->sAlias = sAlias; if( !FileExists()){ - iErrorStop = 20; + iErrorStop = 110; iRc = XB_FILE_NOT_FOUND; throw iRc; } if(( iRc = xbase->AddTblToTblList( this, GetFqFileName(), sAlias )) != XB_NO_ERROR ){ - iErrorStop = 30; + iErrorStop = 120; throw iRc; } /* open the file */ if(( iRc = xbFopen( iOpenMode, iShareMode )) != XB_NO_ERROR ){ - iErrorStop = 40; + iErrorStop = 130; throw iRc; } /* copy the header into memory */ if(( iRc = ReadHeader( 1, 0 )) != XB_NO_ERROR ){ - iErrorStop = 50; + iErrorStop = 140; throw iRc; } /* check the version */ //if(( xFileVersion = DetermineXbaseTableVersion( cVersion )) != 4 ){ if(( cVersion & 0x07 ) != 3 ){ - iErrorStop = 60; + iErrorStop = 150; iRc = XB_FILE_TYPE_NOT_SUPPORTED; throw iRc; } @@ -369,19 +382,19 @@ xbInt16 xbDbf4::Open( const xbString & sTableName, const xbString & sAlias, } if(( RecBuf = (char *) malloc( uiRecordLen )) == NULL ){ - iErrorStop = 70; + iErrorStop = 160; iRc = XB_NO_MEMORY; throw iRc; } if(( RecBuf2 = (char *) malloc( uiRecordLen )) == NULL ) { - iErrorStop = 80; + iErrorStop = 170; iRc = XB_NO_MEMORY; throw iRc; } if((SchemaPtr=(xbSchemaRec *)malloc((size_t) iNoOfFields * sizeof( xbSchemaRec ))) == NULL){ - iErrorStop = 90; + iErrorStop = 180; iRc = XB_NO_MEMORY; throw iRc; } @@ -411,7 +424,7 @@ xbInt16 xbDbf4::Open( const xbString & sTableName, const xbString & sAlias, ulCurRec = 0L; iDbfStatus = XB_OPEN; if(( iRc = BlankRecord()) != XB_NO_ERROR ){ - iErrorStop = 100; + iErrorStop = 190; throw iRc; } @@ -432,7 +445,7 @@ xbInt16 xbDbf4::Open( const xbString & sTableName, const xbString & sAlias, Memo = new xbMemoDbt4( this, fTemp.GetFqFileName()); if(( iRc = Memo->OpenMemoFile()) != XB_NO_ERROR ){ - iErrorStop = 110; + iErrorStop = 200; throw iRc; } } @@ -448,7 +461,7 @@ xbInt16 xbDbf4::Open( const xbString & sTableName, const xbString & sAlias, sIxFileName.PutAt( lLen-1, 'D' ); sIxFileName.PutAt( lLen, 'X' ); if(( iRc = OpenIndex( "MDX", sIxFileName )) != XB_NO_ERROR ){ - iErrorStop = 120; + iErrorStop = 210; throw iRc; } } @@ -491,6 +504,279 @@ xbInt16 xbDbf4::Open( const xbString & sTableName, const xbString & sAlias, return iRc; } +/************************************************************************/ +//! @brief Rename table. +/*! + This routine renames a give table, associated memo and inf files + \param sNewName - New file name. + \returns <a href="xbretcod_8h.html">Return Codes</a> +*/ +xbInt16 xbDbf4::Rename( const xbString sNewName ){ + + xbInt16 iRc = XB_NO_ERROR; + xbInt16 iErrorStop = 0; + + xbString sNewDbf; + + #ifdef XB_MEMO_SUPPORT + xbString sNewDbt; + xbBool bDbtRenamed = xbFalse; + xbString sThisDbt; + #endif + + #ifdef XB_MDX_SUPPORT + xbString sNewMdx; + xbBool bMdxRenamed = xbFalse; + xbString sThisMdx; + #endif + + #ifdef XB_INF_SUPPORT + xbString sNewInf; + xbString sThisInf; + xbBool bInfRenamed = xbFalse; + #endif // XB_INF_SUPPORT + + xbBool bDbfRenamed = xbFalse; + + #ifdef XB_LOCKING_SUPPORT + xbBool bLocked = xbFalse; + #endif // XB_LOCKIN_SUPPORT + + + try{ + + xbString sDir; + xbString sFile; + xbString sExt; + xbString sNewNameWoExt; + sNewNameWoExt.Set( sNewName ); + if( sNewName.Pos( ".DBF" ) > 0 ) + sNewNameWoExt.Left( sNewName.Len() - 4 ); + +// std::cout << "NewName wo ext = [" << sNewNameWoExt.Str() << "]\n"; + + GetFileDirPart ( sDir ); + GetFileNamePart( sFile ); + GetFileExtPart ( sExt ); + + sNewDbf.Sprintf( "%s%s.DBF", sDir.Str(), sNewNameWoExt.Str()); + + #ifdef XB_MEMO_SUPPORT + sNewDbt.Sprintf( "%s%s.DBT", sDir.Str(), sNewNameWoExt.Str()); + if( FileExists( sNewDbt )) return XB_FILE_EXISTS; + sThisDbt.Sprintf( "%s%s.DBT", sDir.Str(), sFile.Str()); + #endif + + #ifdef XB_MDX_SUPPORT + sNewMdx.Sprintf( "%s%s.MDX", sDir.Str(), sNewNameWoExt.Str()); + if( FileExists( sNewMdx )) return XB_FILE_EXISTS; + sThisMdx.Sprintf( "%s%s.MDX", sDir.Str(), sFile.Str()); + #endif + + #ifdef XB_INF_SUPPORT + sNewInf.Sprintf( "%s%s.INF", sDir.Str(), sNewNameWoExt.Str()); + if( FileExists( sNewInf )) return XB_FILE_EXISTS; + sThisInf.Sprintf( "%s%s.INF", sDir.Str(), sFile.Str()); + #endif // XB_INF_SUPPORT + + +/* + std::cout << "xbDbf3::Rename dir = [" << sDir.Str() << "] file = [" << sFile.Str() << "] ext = [" << sExt.Str() << "]\n"; + std::cout << "xbDbf3::Rename new dbf = [" << sNewDbf.Str() << "]\n"; + std::cout << "xbDbf3::Rename new dbt = [" << sNewDbt.Str() << "]\n"; + std::cout << "xbDbf3::Rename new inf = [" << sNewInf.Str() << "]\n"; + std::cout << "xbDbf3::Rename new mdx = [" << sNewMdx.Str() << "]\n"; +*/ + + if( FileExists( sNewDbf )) return XB_FILE_EXISTS; + + #ifdef XB_LOCKING_SUPPORT + if( GetAutoLock() ){ + if(( iRc = LockTable( XB_LOCK )) != XB_NO_ERROR ){ + iErrorStop = 100; + throw iRc; + } + bLocked = xbTrue; + } + #endif + + xbInt16 iOpenMode = GetOpenMode(); + xbInt16 iShareMode = GetShareMode(); + xbBool bWasOpen = xbFalse; + if( FileIsOpen() ){ + bWasOpen = xbTrue; + if(( iRc = xbFclose()) != XB_NO_ERROR ){ + iErrorStop = 110; + throw iRc; + } + } + + if(( iRc = xbRename( GetFqFileName().Str(), sNewDbf.Str())) != XB_NO_ERROR ){ + iErrorStop = 120; + throw iRc; + } else { + bDbfRenamed = xbTrue; + } + xbString sNameWext; + sNameWext.Sprintf( "%s.DBF", sNewNameWoExt.Str()); + SetFileName( sNameWext ); + + + if( bWasOpen ){ + if(( iRc = xbFopen( iOpenMode, iShareMode )) != XB_NO_ERROR ){ + iErrorStop = 130; + throw iRc; + } + } + + #ifdef XB_MEMO_SUPPORT + if( FileExists( sThisDbt )){ + if(( iRc = Memo->xbFseek( 8, SEEK_SET )) != XB_NO_ERROR ){ + iErrorStop = 140; + throw iRc; + } + + sNewNameWoExt.PadRight( ' ', 8 ); + for( int i = 1; i < 9; i++ ) + Memo->xbFputc( sNewNameWoExt[i] ); + + if( bWasOpen ){ + if(( iRc = Memo->xbFclose()) != XB_NO_ERROR ){ + iErrorStop = 150; + throw iRc; + } + } + + Memo->SetFileName( sNewDbt ); + if(( xbRename( sThisDbt.Str(), sNewDbt.Str())) != XB_NO_ERROR ){ + iErrorStop = 160; + throw iRc; + } + + if( bWasOpen ){ + if(( iRc = Memo->xbFopen( iOpenMode, iShareMode )) != XB_NO_ERROR ){ + iErrorStop = 150; + throw iRc; + } + } + + bDbtRenamed = xbTrue; + } + #endif + + #ifdef XB_MDX_SUPPORT + if( FileExists( sThisMdx )){ + xbIxMdx *ixMdx; + xbString s; + xbBool bMdxFound = xbFalse; + xbIxList *ixList = GetIxList(); + while( ixList && !bMdxFound ){ + s = ixList->sFmt->Str(); + if( s == "MDX" ){ + ixMdx = (xbIxMdx *) ixList->ix; + bMdxFound = xbTrue; + } + } + + if( bMdxFound ){ + if(( iRc = ixMdx->xbFseek( 4, SEEK_SET )) != XB_NO_ERROR ){ + iErrorStop = 180; + throw iRc; + } + + sNewNameWoExt.PadRight( ' ', 8 ); + for( int i = 1; i < 9; i++ ) + ixMdx->xbFputc( sNewNameWoExt[i] ); + + if( bWasOpen ){ + if(( iRc = ixMdx->xbFclose()) != XB_NO_ERROR ){ + iErrorStop = 190; + throw iRc; + } + } + + ixMdx->SetFileName( sNewMdx ); + if(( xbRename( sThisMdx.Str(), sNewMdx.Str())) != XB_NO_ERROR ){ + iErrorStop = 200; + throw iRc; + } + + if( bWasOpen ){ + if(( iRc = ixMdx->xbFopen( iOpenMode, iShareMode )) != XB_NO_ERROR ){ + iErrorStop = 210; + throw iRc; + } + } + bMdxRenamed = xbTrue; + } + } + #endif // XB_MDX_SUPPORT + + #ifdef XB_INF_SUPPORT + if( FileExists( sThisInf )){ + if(( xbRename( sThisInf.Str(), sNewInf.Str())) != XB_NO_ERROR ){ + iErrorStop = 180; + throw iRc; + } else { + bInfRenamed = xbTrue; + } + } + #endif // XB_INF_SUPPORT + + // rename the table in the table list + xbTblList *tle = xbase->GetTblListEntry( this ); + if( tle ){ + tle->psTblName->Set( GetFqFileName().Str()); + tle->psTblAlias->Set( sNewNameWoExt.Str()); + } + + + } + catch ( xbInt16 iRc ) + { + xbString sMsg; + sMsg.Sprintf( "xbdbf4::Rename() Exception Caught Error Stop = %d iRc = %d", iErrorStop, iRc ); + xbase->WriteLogMessage( sMsg ); + xbase->WriteLogMessage( GetErrorMessage( iRc )); + + // attempt to reverse things out if unsuccessful + if( bDbfRenamed ){ + + #ifdef XB_MEMO_SUPPORT + if( bDbtRenamed ){ + xbRename( sNewDbt.Str(), sThisDbt.Str()); + } + #endif + + #ifdef XB_MDX_SUPPORT + if( bMdxRenamed ){ + xbRename( sNewMdx.Str(), sThisMdx.Str()); + } + #endif + + #ifdef XB_INF_SUPPORT + if( bInfRenamed ){ + xbRename( sNewInf.Str(), sNewInf.Str()); + } + #endif // XB_INF_SUPPORT + } + + #ifdef XB_LOCKING_SUPPORT + if( GetAutoLock() ){ + iRc = LockTable( XB_UNLOCK ); + } + #endif + + } + + #ifdef XB_LOCKING_SUPPORT + if( bLocked ){ + LockTable( XB_UNLOCK ); + } + #endif + + return iRc; +} /************************************************************************/ #ifdef XB_MEMO_SUPPORT @@ -573,6 +859,11 @@ xbInt16 xbDbf4::ValidateSchema( xbSchema * s ){ return XB_INVALID_FIELD_LEN; } + // field len must be greater then number of decimals + else if((s[i].cType == 'N' || s[i].cType == 'F') && s[i].iFieldLen < s[i].iNoOfDecs ){ + return XB_INVALID_FIELD_LEN; + } + #ifdef XB_MEMO_SUPPORT else if(s[i].cType == 'M'){ s[i].iFieldLen = 10; diff --git a/src/core/xbexp.cpp b/src/core/xbexp.cpp index d3e8ca8..23bc7c6 100755 --- a/src/core/xbexp.cpp +++ b/src/core/xbexp.cpp @@ -83,7 +83,7 @@ xbInt16 xbExp::CalcFunctionResultLen( xbExpNode * n ) const{ n->GetNodeText( sNodeText ); char cReturnType = 0; if(( iRc = xbase->GetFunctionInfo( sNodeText, cReturnType, iReturnLenCalc, lReturnLenVal )) != XB_NO_ERROR ){ - iErrorStop = 10; + iErrorStop = 100; throw iRc; } @@ -95,7 +95,7 @@ xbInt16 xbExp::CalcFunctionResultLen( xbExpNode * n ) const{ // use the length from the child node identified in lReturnLenVal xbExpNode *nChild = n->GetChild( (xbUInt32) lReturnLenVal - 1 ); if( !nChild ){ - iErrorStop = 20; + iErrorStop = 110; iRc = XB_PARSE_ERROR; throw iRc; } @@ -106,7 +106,7 @@ xbInt16 xbExp::CalcFunctionResultLen( xbExpNode * n ) const{ // use the length from the child node identified in lReturnLenVal xbExpNode *nChild = n->GetChild( (xbUInt32) lReturnLenVal - 1 ); if( !nChild ){ - iErrorStop = 30; + iErrorStop = 120; iRc = XB_PARSE_ERROR; throw iRc; } @@ -117,7 +117,7 @@ xbInt16 xbExp::CalcFunctionResultLen( xbExpNode * n ) const{ xbExpNode *nChild1 = n->GetChild( 0 ); xbExpNode *nChild2 = n->GetChild( 1 ); if( !nChild1 || !nChild2 ){ - iErrorStop = 40; + iErrorStop = 130; iRc = XB_PARSE_ERROR; throw iRc; } @@ -128,7 +128,7 @@ xbInt16 xbExp::CalcFunctionResultLen( xbExpNode * n ) const{ xbExpNode *nChild2 = n->GetChild( 1 ); xbExpNode *nChild3 = n->GetChild( 2 ); if( !nChild2 || !nChild3 ){ - iErrorStop = 50; + iErrorStop = 140; iRc = XB_PARSE_ERROR; throw iRc; } @@ -148,7 +148,7 @@ xbInt16 xbExp::CalcFunctionResultLen( xbExpNode * n ) const{ } } else { - iErrorStop = 100; + iErrorStop = 150; iRc = XB_PARSE_ERROR; throw iRc; } @@ -205,12 +205,12 @@ xbInt16 xbExp::CheckParensAndQuotes( const xbString &sExpression ){ s++; } if( iLparenCtr != iRparenCtr ){ - iErrorStop = 10; + iErrorStop = 100; iRc = XB_UNBALANCED_PARENS; throw iRc; } if( bInQuotes ){ - iErrorStop = 20; + iErrorStop = 110; iRc = XB_UNBALANCED_QUOTES; throw iRc; } @@ -369,21 +369,21 @@ xbInt16 xbExp::GetNextToken( xbExpToken &t ){ if((t.sExpression.Len() >= 10 && t.sExpression[1] == '{' && t.sExpression[4] == '/' && t.sExpression[7] == '/') && (t.sExpression[10] == '}' || (t.sExpression.Len() >= 12 && t.sExpression[12] == '}'))){ if(( iRc = GetTokenDateConstant( t )) != XB_NO_ERROR ){ - iErrorStop = 10; + iErrorStop = 100; throw iRc; } } // Check for parens else if( t.sExpression[1] == '(' || t.sExpression[1] == '{' ){ if(( iRc = GetTokenParen( t )) != XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 110; throw iRc; } } // Check for a char constant else if( t.sExpression[1] == '"' || t.sExpression[1] == '\'' ){ if(( iRc = GetTokenCharConstant( t )) != XB_NO_ERROR ){ - iErrorStop = 30; + iErrorStop = 120; iRc = XB_PARSE_ERROR; throw iRc; } @@ -391,7 +391,7 @@ xbInt16 xbExp::GetNextToken( xbExpToken &t ){ // Check for logical constant else if( IsLogicalConstant( t.sExpression )){ if(( iRc = GetTokenLogicalConstant( t )) != XB_NO_ERROR ){ - iErrorStop = 40; + iErrorStop = 130; iRc = XB_PARSE_ERROR; throw iRc; } @@ -399,7 +399,7 @@ xbInt16 xbExp::GetNextToken( xbExpToken &t ){ // check for numeric constant else if( IsNumericConstant( t.sExpression, t.cPrevNodeType )){ if(( iRc = GetTokenNumericConstant( t )) != XB_NO_ERROR ){ - iErrorStop = 50; + iErrorStop = 140; iRc = XB_PARSE_ERROR; throw iRc; } @@ -407,7 +407,7 @@ xbInt16 xbExp::GetNextToken( xbExpToken &t ){ // check for operator else if( IsOperator( t.sExpression )){ if(( iRc = GetTokenOperator( t )) != XB_NO_ERROR ){ - iErrorStop = 60; + iErrorStop = 150; iRc = XB_PARSE_ERROR; throw iRc; } @@ -415,13 +415,13 @@ xbInt16 xbExp::GetNextToken( xbExpToken &t ){ // check for function else if( IsFunction( t.sExpression, t.cReturnType )){ if(( iRc = GetTokenFunction( t )) != XB_NO_ERROR ){ - iErrorStop = 70; + iErrorStop = 160; iRc = XB_PARSE_ERROR; throw iRc; } } else if(( iRc = GetTokenDatabaseField( t )) != XB_NO_ERROR ){ - iErrorStop = 80; + iErrorStop = 170; iRc = XB_PARSE_ERROR; throw iRc; } @@ -429,16 +429,9 @@ xbInt16 xbExp::GetNextToken( xbExpToken &t ){ catch (xbInt16 iRc ){ xbString sMsg; - - //t.sExpression; - // std::cout << ">>>>>>>>>" << sMsg.Str() << "\n"; - // sMsg.Sprintf( "[%d][%s]", iErrorStop, t.sExpression.Str() ); - // sMsg.Sprintf( "xbexp::GetNextToken() Exception Caught. Error Stop = [%d] %s", iErrorStop, t.sExpression.Str()); - sMsg.Sprintf( "xbexp::GetNextToken() Exception Caught. Error Stop = [%d] iRc = [%d] Expression = [%s]", iErrorStop, iRc, t.sExpression.Str() );sMsg.Sprintf( "xbexp::GetNextToken() Exception Caught. Error Stop = [%d] iRc = [%d] Expression = [%s]", iErrorStop, iRc, t.sExpression.Str() );sMsg.Sprintf( "xbexp::GetNextToken() Exception Caught. Error Stop = [%d] iRc = [%d] Expression = [%s]", iErrorStop, iRc, t.sExpression.Str() );sMsg.Sprintf( "xbexp::GetNextToken() Exception Caught. Error Stop = [%d] iRc = [%d] Expression = [%s]", iErrorStop, iRc, t.sExpression.Str() ); xbase->WriteLogMessage( sMsg.Str() ); } - return iRc; } @@ -460,7 +453,6 @@ xbInt16 xbExp::GetNumericResult( xbDouble &dResult){ return XB_PARSE_ERROR; } } - /*************************************************************************/ //! Get result length. /*! @@ -573,7 +565,7 @@ xbInt16 xbExp::GetTokenCharConstant( xbExpToken &t ){ } else { iRc = XB_PARSE_ERROR; t.iSts = XB_UNBALANCED_QUOTES; - iErrorStop = 10; + iErrorStop = 100; throw iRc; } } @@ -612,7 +604,7 @@ xbInt16 xbExp::GetTokenDateConstant( xbExpToken &t ){ wBuf[i] = t.sExpression[i+2]; if(( iRc = dt.CTOD( wBuf )) != XB_NO_ERROR ){ - iErrorStop = 10; + iErrorStop = 100; throw iRc; } t.sToken.Set( dt.Str() ); @@ -634,7 +626,7 @@ xbInt16 xbExp::GetTokenDateConstant( xbExpToken &t ){ } else { iRc = XB_PARSE_ERROR; t.iSts = XB_INVALID_DATE; - iErrorStop = 20; + iErrorStop = 110; throw iRc; } } @@ -645,7 +637,6 @@ xbInt16 xbExp::GetTokenDateConstant( xbExpToken &t ){ } return iRc; } - /*************************************************************************/ //! GetTokenField /*! This method gets a database field token @@ -973,7 +964,7 @@ xbInt16 xbExp::GetTokenParen( xbExpToken &t ){ t.cReturnType = XB_EXP_UNKNOWN; t.iSts = XB_UNBALANCED_PARENS; iRc = XB_PARSE_ERROR; - iErrorStop = 10; + iErrorStop = 100; throw iRc; } } @@ -1215,7 +1206,7 @@ xbInt16 xbExp::ParseExpression( const xbString &sExpression, xbInt16 iWeight ){ delete nTree; if(( iRc = CheckParensAndQuotes( sExpression )) != XB_NO_ERROR ){ - iErrorStop = 10; + iErrorStop = 100; throw iRc; } @@ -1234,7 +1225,7 @@ xbInt16 xbExp::ParseExpression( const xbString &sExpression, xbInt16 iWeight ){ if( t.cNodeType == XB_EXP_NOTROOT ){ xbExp enr( xbase, dbf ); if(( iRc = enr.ParseExpression( t.sToken, iWeight + 10 )) != XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 110; throw iRc; } n = enr.GetTreeHandle(); @@ -1247,7 +1238,7 @@ xbInt16 xbExp::ParseExpression( const xbString &sExpression, xbInt16 iWeight ){ case XB_EXP_CONSTANT: n = new xbExpNode( t.sToken, t.cNodeType ); if(( iRc = ParseExpressionConstant( t, n )) != XB_NO_ERROR ){ - iErrorStop = 30; + iErrorStop = 120; throw iRc; } break; @@ -1255,7 +1246,7 @@ xbInt16 xbExp::ParseExpression( const xbString &sExpression, xbInt16 iWeight ){ case XB_EXP_FUNCTION: n = new xbExpNode( t.cNodeType ); if(( iRc = ParseExpressionFunction( t, n, iWeight )) != XB_NO_ERROR ){ - iErrorStop = 40; + iErrorStop = 130; throw iRc; } break; @@ -1263,7 +1254,7 @@ xbInt16 xbExp::ParseExpression( const xbString &sExpression, xbInt16 iWeight ){ case XB_EXP_FIELD: n = new xbExpNode( t.cNodeType ); if(( iRc = ParseExpressionField( t, n )) != XB_NO_ERROR ){ - iErrorStop = 50; + iErrorStop = 140; throw iRc; } break; @@ -1273,13 +1264,13 @@ xbInt16 xbExp::ParseExpression( const xbString &sExpression, xbInt16 iWeight ){ case XB_EXP_POST_OPERATOR: n = new xbExpNode( t.sToken, t.cNodeType ); if(( iRc = ParseExpressionOperator( t, n, iWeight )) != XB_NO_ERROR ){ - iErrorStop = 60; + iErrorStop = 150; throw iRc; } break; default: - iErrorStop = 70; + iErrorStop = 160; iRc = XB_PARSE_ERROR; throw iRc; // break; @@ -1337,7 +1328,7 @@ xbInt16 xbExp::ParseExpression( const xbString &sExpression, xbInt16 iWeight ){ } else{ // should not be stopping on anything but an operator node with one or two children - iErrorStop = 80; + iErrorStop = 170; iRc = XB_PARSE_ERROR; throw iRc; } @@ -1355,21 +1346,19 @@ xbInt16 xbExp::ParseExpression( const xbString &sExpression, xbInt16 iWeight ){ xbExpNode * nChild1; xbExpNode * nChild2; - while( nWork ){ - if( nWork->GetReturnType() == XB_EXP_UNKNOWN ){ nWork->GetNodeText( s ); // std::cout << "XB_EXP_UNKNOWN logic [" << s << "][" << nWork->GetChildCnt() << "]\n"; // if this is "-" and child 1 and child 2 are both dates, set this result type to numeric - if( s == "-" && nWork->GetChildCnt() == 2 && + if( s == "-" && nWork->GetChildCnt() == 2 && nWork->GetChild(0)->GetReturnType() == XB_EXP_DATE && nWork->GetChild(1)->GetReturnType() == XB_EXP_DATE ) nWork->SetReturnType( XB_EXP_NUMERIC ); else if( nWork->GetChildCnt() > 0 ) nWork->SetReturnType( nWork->GetChild(0)->GetReturnType()); else{ - iErrorStop = 90; + iErrorStop = 180; iRc = XB_PARSE_ERROR; throw iRc; } @@ -1384,12 +1373,12 @@ xbInt16 xbExp::ParseExpression( const xbString &sExpression, xbInt16 iWeight ){ case XB_EXP_CHAR: if( nWork->GetNodeType() != XB_EXP_OPERATOR ){ - iErrorStop = 100; + iErrorStop = 190; iRc = XB_PARSE_ERROR; throw iRc; } if( nWork->GetChildCnt() < 2 ){ - iErrorStop = 110; + iErrorStop = 200; iRc = XB_PARSE_ERROR; throw iRc; } @@ -1407,7 +1396,7 @@ xbInt16 xbExp::ParseExpression( const xbString &sExpression, xbInt16 iWeight ){ break; default: - iErrorStop = 120; + iErrorStop = 210; iRc = XB_PARSE_ERROR; throw iRc; // break; @@ -1415,12 +1404,12 @@ xbInt16 xbExp::ParseExpression( const xbString &sExpression, xbInt16 iWeight ){ } if( nWork->IsUnaryOperator() ){ if( nWork->GetChildCnt() != 1 ){ - iErrorStop = 130; + iErrorStop = 220; iRc = XB_PARSE_ERROR; throw iRc; } } else if( nWork->IsOperator() && nWork->GetChildCnt() != 2 ){ - iErrorStop = 140; + iErrorStop = 230; iRc = XB_PARSE_ERROR; throw iRc; } @@ -1513,19 +1502,19 @@ xbInt16 xbExp::ParseExpressionField( xbExpToken &t, xbExpNode *n ){ sFieldName = t.sToken; } if( !pDbf ){ - iErrorStop = 10; + iErrorStop = 100; iRc = XB_INVALID_FIELD; throw iRc; } xbInt16 iFieldNo = 0; if(( iRc = pDbf->GetFieldNo( sFieldName, iFieldNo )) != XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 110; throw iRc; } char cFieldType; if(( iRc = pDbf->GetFieldType( iFieldNo, cFieldType )) != XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 120; throw iRc; } n->SetDbfInfo( pDbf, iFieldNo ); @@ -1549,7 +1538,7 @@ xbInt16 xbExp::ParseExpressionField( xbExpToken &t, xbExpNode *n ){ case XB_MEMO_FLD: default: - iErrorStop = 30; + iErrorStop = 130; iRc = XB_PARSE_ERROR; throw iRc; // break; @@ -1557,7 +1546,7 @@ xbInt16 xbExp::ParseExpressionField( xbExpToken &t, xbExpNode *n ){ n->SetNodeText( sFieldName ); xbInt16 iResultLen = 0; if(( iRc = pDbf->GetFieldLen( iFieldNo, iResultLen )) != XB_NO_ERROR ){ - iErrorStop = 30; + iErrorStop = 140; throw iRc; } n->SetResultLen( (xbUInt32) iResultLen ); @@ -1587,7 +1576,7 @@ xbInt16 xbExp::ParseExpressionFunction( xbExpToken &t, xbExpNode *n, xbInt16 iWe // find the first "(" xbUInt32 lPos = t.sToken.Pos( '(' ); if( lPos == 0 ){ - iErrorStop = 10; + iErrorStop = 100; iRc = XB_INVALID_FUNCTION; throw iRc; } @@ -1600,7 +1589,7 @@ xbInt16 xbExp::ParseExpressionFunction( xbExpToken &t, xbExpNode *n, xbInt16 iWe xbInt16 i = 0; xbInt32 l = 0; if(( iRc = xbase->GetFunctionInfo( sFunc, cReturnType, i, l )) != XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 110; throw iRc; } n->SetNodeText( sFunc ); @@ -1611,7 +1600,7 @@ xbInt16 xbExp::ParseExpressionFunction( xbExpToken &t, xbExpNode *n, xbInt16 iWe sParms.Mid( lPos+1, t.sToken.Len() - lPos ); lPos = sParms.GetLastPos( ')' ); if( lPos == 0 ){ - iErrorStop = 30; + iErrorStop = 120; iRc = XB_INVALID_FUNCTION; throw iRc; } @@ -1626,7 +1615,7 @@ xbInt16 xbExp::ParseExpressionFunction( xbExpToken &t, xbExpNode *n, xbInt16 iWe // create a linked list of parms xbLinkList<xbString> llParms; if(( iRc = ParseExpressionFunctionParms( sParms, llParms )) != XB_NO_ERROR ){ - iErrorStop = 40; + iErrorStop = 130; throw iRc; } @@ -1636,7 +1625,7 @@ xbInt16 xbExp::ParseExpressionFunction( xbExpToken &t, xbExpNode *n, xbInt16 iWe while( llN ){ sParm = llN->GetKey(); if(( iRc = enr.ParseExpression( sParm, iWeight + 10 )) != XB_NO_ERROR ){ - iErrorStop = 40; + iErrorStop = 140; throw iRc; } n->AddChild( enr.GetTreeHandle()); @@ -1657,7 +1646,7 @@ xbInt16 xbExp::ParseExpressionFunction( xbExpToken &t, xbExpNode *n, xbInt16 iWe } if(( iRc = CalcFunctionResultLen( n )) != XB_NO_ERROR ){ - iErrorStop = 50; + iErrorStop = 150; throw iRc; } } @@ -1843,7 +1832,7 @@ xbInt16 xbExp::ProcessExpression( xbInt16 iRecBufSw ){ case XB_EXP_PRE_OPERATOR: // increment value before setting in head node if( nWork->GetChildCnt() != 1 ){ - iErrorStop = 10; + iErrorStop = 100; iRc = XB_PARSE_ERROR; throw iRc; } @@ -1868,7 +1857,7 @@ xbInt16 xbExp::ProcessExpression( xbInt16 iRecBufSw ){ case XB_EXP_POST_OPERATOR: // increment value after setting in head node if( nWork->GetChildCnt() != 1 ){ - iErrorStop = 20; + iErrorStop = 110; iRc = XB_PARSE_ERROR; throw iRc; } @@ -1895,14 +1884,14 @@ xbInt16 xbExp::ProcessExpression( xbInt16 iRecBufSw ){ case XB_EXP_FIELD: if(( dbf = nWork->GetDbf()) == NULL ){ - iErrorStop = 30; + iErrorStop = 120; iRc = XB_PARSE_ERROR; throw iRc; } switch( nWork->GetReturnType()){ case XB_EXP_CHAR: if(( iRc = dbf->GetField( nWork->GetFieldNo(), sWork1, iRecBufSw )) < XB_NO_ERROR ){ - iErrorStop = 40; + iErrorStop = 130; throw iRc; } nWork->SetResult( sWork1 ); @@ -1911,7 +1900,7 @@ xbInt16 xbExp::ProcessExpression( xbInt16 iRecBufSw ){ case XB_EXP_DATE: if(( iRc = dbf->GetField( nWork->GetFieldNo(), sWork1, iRecBufSw )) < XB_NO_ERROR ){ - iErrorStop = 50; + iErrorStop = 140; throw iRc; } if( sWork1 == " " ){ @@ -1924,7 +1913,7 @@ xbInt16 xbExp::ProcessExpression( xbInt16 iRecBufSw ){ case XB_EXP_LOGICAL: if(( iRc = dbf->GetLogicalField( nWork->GetFieldNo(), bWork, iRecBufSw )) != XB_NO_ERROR ){ - iErrorStop = 60; + iErrorStop = 150; throw iRc; } nWork->SetResult( bWork ); @@ -1932,14 +1921,14 @@ xbInt16 xbExp::ProcessExpression( xbInt16 iRecBufSw ){ case XB_EXP_NUMERIC: if(( iRc = dbf->GetDoubleField( nWork->GetFieldNo(), dWork, iRecBufSw )) != XB_NO_ERROR ){ - iErrorStop = 70; + iErrorStop = 160; throw iRc; } nWork->SetResult( dWork ); break; default: - iErrorStop = 80; + iErrorStop = 170; iRc = XB_PARSE_ERROR; throw iRc; // break; @@ -1949,7 +1938,7 @@ xbInt16 xbExp::ProcessExpression( xbInt16 iRecBufSw ){ case XB_EXP_OPERATOR: if(( iRc = ProcessExpressionOperator( nWork )) != XB_NO_ERROR ){ - iErrorStop = 300; + iErrorStop = 180; throw iRc; } @@ -1957,13 +1946,13 @@ xbInt16 xbExp::ProcessExpression( xbInt16 iRecBufSw ){ case XB_EXP_FUNCTION: if(( iRc = ProcessExpressionFunction( nWork, iRecBufSw )) != XB_NO_ERROR ){ - iErrorStop = 400; + iErrorStop = 190; throw iRc; } break; default: - iErrorStop = 500; + iErrorStop = 200; iRc = XB_PARSE_ERROR; throw iRc; // break; diff --git a/src/core/xbfields.cpp b/src/core/xbfields.cpp index 8cfb4e6..e683d9c 100755 --- a/src/core/xbfields.cpp +++ b/src/core/xbfields.cpp @@ -492,43 +492,50 @@ xbInt16 xbDbf::GetLogicalField( const xbString &sFieldName, xbBool &bFieldValue */ xbInt16 xbDbf::GetLongField( xbInt16 iFieldNo, xbInt32 & lFieldValue ) const { - xbInt16 rc = 0; - xbInt16 iErrorStop = 0; - char cFieldType; + xbInt16 iRc = 0; + xbInt16 iErrorStop = 0; + char cFieldType; + xbString sTemp; try{ - if(( rc = GetFieldType( iFieldNo, cFieldType )) != XB_NO_ERROR ){ - iErrorStop = 10; - throw rc; + if(( iRc = GetFieldType( iFieldNo, cFieldType )) != XB_NO_ERROR ){ + iErrorStop = 100; + throw iRc; } if( cFieldType != 'N' && cFieldType != 'F' && cFieldType != 'M' ){ - iErrorStop = 20; - rc = XB_INVALID_FIELD_TYPE; - throw rc; + iErrorStop = 110; + iRc = XB_INVALID_FIELD_TYPE; + throw iRc; } - xbString sTemp; - if(( rc = GetField( iFieldNo, sTemp, 0 )) < 0 ){ - iErrorStop = 30; - throw rc; + if(( iRc = GetField( iFieldNo, sTemp, 0 )) < 0 ){ + iErrorStop = 120; + throw iRc; } + sTemp.Trim(); - if( !sTemp.ValidNumericValue() || ((int) sTemp.Pos( '.' ) > 0)){ - iErrorStop = 40; - rc = XB_INVALID_DATA; - throw rc; + if( !sTemp.ValidNumericValue() ){ + iErrorStop = 130; + iRc = XB_INVALID_DATA; + throw iRc; + } + + if( sTemp.Pos( '.' ) > 0){ + iErrorStop = 140; + iRc = XB_INVALID_DATA; + throw iRc; } lFieldValue = atol( sTemp.Str()); } - catch (xbInt16 rc ){ + catch (xbInt16 iRc ){ xbString sMsg; - sMsg.Sprintf( "xbDbf::GetLongField() Exception Caught. Error Stop = [%d] rc = [%d]", iErrorStop, rc ); + sMsg.Sprintf( "xbDbf::GetLongField() Exception Caught. Error Stop = [%d] rc = [%d] [%s]", iErrorStop, iRc, sTemp.Str() ); xbase->WriteLogMessage( sMsg.Str() ); - xbase->WriteLogMessage( GetErrorMessage( rc )); + xbase->WriteLogMessage( GetErrorMessage( iRc )); } return XB_NO_ERROR; @@ -615,24 +622,24 @@ xbInt16 xbDbf::GetULongField( xbInt16 iFieldNo, xbUInt32 & ulFieldValue ) const try{ if(( rc = GetFieldType( iFieldNo, cFieldType )) != XB_NO_ERROR ){ - iErrorStop = 10; + iErrorStop = 100; throw rc; } if( cFieldType != 'N' && cFieldType != 'F' && cFieldType != 'M' ){ - iErrorStop = 20; + iErrorStop = 110; rc = XB_INVALID_FIELD_TYPE; throw rc; } xbString sTemp; if(( rc = GetField( iFieldNo, sTemp, 0 )) != XB_NO_ERROR ){ - iErrorStop = 30; + iErrorStop = 120; throw rc; } sTemp.Trim(); if( !sTemp.ValidNumericValue() || ((int) sTemp.Pos( '.' ) > 0)){ - iErrorStop = 40; + iErrorStop = 130; rc = XB_INVALID_DATA; throw rc; } @@ -1118,5 +1125,6 @@ xbBool xbDbf::MemoFieldExists( xbInt16 iFieldNo ) const{ } #endif + } /* namespace */ diff --git a/src/core/xbfile.cpp b/src/core/xbfile.cpp index a7d5257..937c16f 100755 --- a/src/core/xbfile.cpp +++ b/src/core/xbfile.cpp @@ -721,7 +721,7 @@ xbInt16 xbFile::GetFileSize( xbUInt64 &ullFileSize ){ try{ if(( iRc = xbFseek( 0, SEEK_END )) != XB_NO_ERROR ){ - iErrorStop = 10; + iErrorStop = 100; throw iRc; } ullFileSize = xbFtell(); @@ -777,12 +777,10 @@ xbInt16 xbFile::GetOpenMode() const { XB_MULTI_USER - (file buffering off)<br> */ - xbInt16 xbFile::GetShareMode() const { return iShareMode; } - /************************************************************************/ //! @brief Get the file type byte and version of the dbf file. /*! @@ -845,13 +843,13 @@ xbInt16 xbFile::GetXbaseFileTypeByte( const xbString &sFileName, unsigned char #ifdef HAVE__FSOPEN_F // 0x40 is SH_DENYNO or _SH_DENYNO if(( tfp = _fsopen( sFileName.Str(), "r", 0x40 )) == NULL ){ - iErrorStop = 20; + iErrorStop = 100; iRc = XB_OPEN_ERROR; throw iRc; } #else if(( tfp = fopen( sFileName.Str(), "r" )) == NULL ){ - iErrorStop = 20; + iErrorStop = 110; iRc = XB_OPEN_ERROR; throw iRc; } @@ -864,13 +862,13 @@ xbInt16 xbFile::GetXbaseFileTypeByte( const xbString &sFileName, unsigned char #endif if( iRc != 0 ){ - iErrorStop = 30; + iErrorStop = 120; iRc = XB_SEEK_ERROR; throw iRc; } stRc = fread( &cFileTypeByte, (size_t) 1, (size_t) 1, tfp ); if( stRc != (size_t) 1 ){ - iErrorStop = 40; + iErrorStop = 130; iRc = XB_READ_ERROR; throw iRc; } @@ -960,7 +958,6 @@ xbInt16 xbFile::ReadBlock( xbUInt32 ulBlockNo, size_t lReadSize, void * buf ){ return ReadBlock( ulBlockNo, ulBlockSize, lReadSize, buf ); } - /***********************************************************************/ //! @brief Read a block of data from file. /*! @@ -980,13 +977,13 @@ xbInt16 xbFile::ReadBlock( xbUInt32 ulBlockNo, xbUInt32 ulBlockSize, size_t lRea try{ if( ulBlockSize <= 0 ){ - iErrorStop = 10; + iErrorStop = 100; iRc = XB_INVALID_BLOCK_SIZE; throw iRc; } if(( iRc = xbFseek(((xbInt64) ulBlockNo*ulBlockSize ), SEEK_SET )) != XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 110; iRc = XB_SEEK_ERROR; throw iRc; } @@ -995,7 +992,7 @@ xbInt16 xbFile::ReadBlock( xbUInt32 ulBlockNo, xbUInt32 ulBlockSize, size_t lRea lReadSize = ulBlockSize; if(( iRc = xbFread( buf, lReadSize, 1 )) != XB_NO_ERROR ){ - iErrorStop = 30; + iErrorStop = 120; iRc = XB_READ_ERROR; throw iRc; } @@ -1149,18 +1146,18 @@ xbInt16 xbFile::WriteBlock( xbUInt32 ulBlockNo, size_t lWriteSize, void * buf ){ try{ if( ulBlockSize == 0 ){ - iErrorStop = 10; + iErrorStop = 100; iRc = XB_INVALID_BLOCK_SIZE; throw iRc; } if( lWriteSize <= 0 ) lWriteSize = ulBlockSize; if(( iRc = xbFseek(( (xbInt64) ulBlockNo*ulBlockSize), SEEK_SET )) != XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 110; throw iRc; } if(( iRc = xbFwrite( buf, lWriteSize, 1 )) != XB_NO_ERROR ){ - iErrorStop = 30; + iErrorStop = 120; throw iRc; } } @@ -1488,7 +1485,7 @@ xbInt16 xbFile::xbFseek( xbInt64 lOffset, xbInt32 iWhence ) { #elif defined(HAVE__FSEEKI64_F) iRc = _fseeki64( fp, lOffset, iWhence ); if( iRc != 0 ){ - iErrorStop = 200; + iErrorStop = 110; throw iRc; } #else @@ -1498,7 +1495,7 @@ xbInt16 xbFile::xbFseek( xbInt64 lOffset, xbInt32 iWhence ) { if( lOffset > 2147483647 && iWhence == SEEK_SET ){ /* move forward max amt - 2G */ if(( iRc = fseek( fp, 2147483647, SEEK_SET )) != 0 ){ - iErrorStop = 300; + iErrorStop = 120; throw iRc; } lOffset -= 2147483647; @@ -1582,13 +1579,13 @@ xbInt16 xbFile::xbReadUntil( const char cDelim, xbString &sOut ){ try{ sOut = ""; if(( iRc = xbFgetc( c )) != XB_NO_ERROR ){ - iErrorStop = 10; + iErrorStop = 100; throw iRc; } sOut = c; while( iRc == XB_NO_ERROR && c != cDelim ){ if(( iRc = xbFgetc( c )) != XB_NO_ERROR ){ - iErrorStop = 10; + iErrorStop = 110; throw iRc; } sOut += c; @@ -1662,44 +1659,12 @@ xbInt16 xbFile::xbRemove( const xbString & sFileNameIn, xbInt16 iOption ) { */ xbInt16 xbFile::xbRename( const xbString & sOldName, const xbString & sNewName ){ - return xbRename( sOldName, sNewName, 0 ); -} - -/************************************************************************/ -//! @brief Rename file. -/*! - \param sOldName Original file name - \param sNewName New file name - \param iOption If Set to 1, assume this is a rename request for a dbf file, and should rename the dbt file also - \returns <a href="xbretcod_8h.html">Return Codes</a> -*/ -xbInt16 xbFile::xbRename( const xbString & sOldName, const xbString & sNewName, xbInt16 iOption ){ - - - if( rename( sOldName.Str(), sNewName.Str())){ + if( rename( sOldName.Str(), sNewName.Str())) return XB_RENAME_ERROR; - } - if( iOption == 1 ){ - xbString sOldName2 = sOldName; - xbString sNewName2 = sNewName; - - if( sOldName2[sOldName2.Len()] == 'F' ) - sOldName2.PutAt( sOldName2.Len(), 'T' ); - else - sOldName2.PutAt( sOldName2.Len(), 't' ); - - if( sNewName2[sNewName2.Len()] == 'F' ) - sNewName2.PutAt( sNewName2.Len(), 'T' ); - else - sNewName2.PutAt( sNewName2.Len(), 't' ); - - if( rename( sOldName2.Str(), sNewName2.Str())) - return XB_RENAME_ERROR; - } - return XB_NO_ERROR; + else + return XB_NO_ERROR; } - /************************************************************************/ //! @brief Xbase wrapper for rewind. /*! @@ -1724,17 +1689,17 @@ xbInt16 xbFile::xbTruncate( xbInt64 llSize ) { try{ #ifdef HAVE_FTRUNCATE_F if(( iRc = ftruncate( iFileNo, llSize )) != 0 ){ - iErrorStop = 10; + iErrorStop = 100; iRc = XB_WRITE_ERROR; throw iRc; } #elif defined(HAVE_SETENDOFFILE_F) if(( iRc = xbFseek( llSize, SEEK_SET )) != XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 110; throw iRc; } if(( iRc = SetEndOfFile( fHandle )) == 0 ){ - iErrorStop = 30; + iErrorStop = 120; iRc = XB_WRITE_ERROR; throw iRc; } else { @@ -1781,7 +1746,7 @@ xbInt16 xbFile::xbLock( xbInt16 iFunction, xbInt64 lOffset, size_t stLen ){ /* Unix lock function */ if(( iRc = xbFseek( lOffset, SEEK_SET )) != XB_NO_ERROR ){ - iErrorStop = 10; + iErrorStop = 100; throw iRc; } @@ -1794,7 +1759,7 @@ xbInt16 xbFile::xbLock( xbInt16 iFunction, xbInt64 lOffset, size_t stLen ){ fl.l_type = F_UNLCK; break; default: - iErrorStop = 20; + iErrorStop = 110; iRc = XB_INVALID_LOCK_OPTION; throw iRc; break; @@ -1808,7 +1773,7 @@ xbInt16 xbFile::xbLock( xbInt16 iFunction, xbInt64 lOffset, size_t stLen ){ iTries++; xbase->xbSleep( GetDefaultLockWait() ); } else if( iRc ){ - iErrorStop = 30; + iErrorStop = 120; iRc = XB_LOCK_FAILED; throw iRc; } @@ -1844,7 +1809,7 @@ xbInt16 xbFile::xbLock( xbInt16 iFunction, xbInt64 lOffset, size_t stLen ){ } else { - iErrorStop = 30; + iErrorStop = 130; iRc = XB_INVALID_LOCK_OPTION; throw iRc; } @@ -1863,13 +1828,13 @@ xbInt16 xbFile::xbLock( xbInt16 iFunction, xbInt64 lOffset, size_t stLen ){ } else if( iFunction == XB_UNLOCK ){ iLockType = 0; } else { - iErrorStop = 50; + iErrorStop = 140; iRc = XB_INVALID_LOCK_OPTION; throw iRc; } if(( iRc = xbFseek( lOffset, SEEK_SET )) != XB_NO_ERROR ){ - iErrorStop = 60; + iErrorStop = 150; iRc = XB_SEEK_ERROR; throw iRc; } @@ -1961,13 +1926,13 @@ xbInt16 xbFile::DumpBlockToDisk( xbUInt32 ulBlockNo, size_t lBlkSize ){ char *buf = NULL; FILE *fpd = NULL; try{ - iErrorStop = 10; + iErrorStop = 100; if( ulBlockNo == 0 ){ ulStartBlock = 0; xbUInt64 ullFileSizeulBlockNo; if(( iRc = GetFileSize( ullFileSizeulBlockNo )) != XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 110; throw iRc; } ulEndBlock = (xbUInt32) (ullFileSizeulBlockNo / lBlkSize); @@ -1977,7 +1942,7 @@ xbInt16 xbFile::DumpBlockToDisk( xbUInt32 ulBlockNo, size_t lBlkSize ){ } if(( buf = (char *) malloc( lBlkSize )) == NULL ){ - iErrorStop = 30; + iErrorStop = 120; iRc = XB_NO_MEMORY; throw iRc; } @@ -1988,7 +1953,7 @@ xbInt16 xbFile::DumpBlockToDisk( xbUInt32 ulBlockNo, size_t lBlkSize ){ for( xbUInt32 l = ulStartBlock; l < ulEndBlock; l++ ){ if(( iRc = ReadBlock( l, lBlkSize, buf )) != XB_NO_ERROR ){ - iErrorStop = 40; + iErrorStop = 130; throw iRc; } @@ -2004,7 +1969,7 @@ xbInt16 xbFile::DumpBlockToDisk( xbUInt32 ulBlockNo, size_t lBlkSize ){ #else if(( fpd = fopen( sFn.Str(), "w+b")) == NULL ){ #endif - iErrorStop = 50; + iErrorStop = 140; iRc = XB_OPEN_ERROR; throw iRc; } @@ -2014,7 +1979,7 @@ xbInt16 xbFile::DumpBlockToDisk( xbUInt32 ulBlockNo, size_t lBlkSize ){ for( size_t l = 0; l < lBlkSize; l++ ){ //if( fputc( *p, fpd ) != *p ){ if( fputc( *p, fpd ) == EOF ){ - iErrorStop = 60; + iErrorStop = 150; iRc = XB_WRITE_ERROR; throw iRc; } @@ -2030,7 +1995,7 @@ xbInt16 xbFile::DumpBlockToDisk( xbUInt32 ulBlockNo, size_t lBlkSize ){ } catch (xbInt16 iRc ){ xbString sMsg; - if( iErrorStop == 60 ) + if( iErrorStop == 160 ) sMsg.Sprintf( "xbFile::DumpBlockToDisk() Exception Caught. Error Stop = [%d] iRc = [%d] c=[%c][%x]", iErrorStop, iRc, *p, *p ); else sMsg.Sprintf( "xbFile::DumpBlockToDisk() Exception Caught. Error Stop = [%d] iRc = [%d]", iErrorStop, iRc ); diff --git a/src/core/xbfilter.cpp b/src/core/xbfilter.cpp index e75f583..507a9e7 100755 --- a/src/core/xbfilter.cpp +++ b/src/core/xbfilter.cpp @@ -14,7 +14,6 @@ Email Contact: This module handles uda (user data area) methods - */ #include "xbase.h" @@ -75,11 +74,11 @@ xbInt16 xbFilter::Set( xbString &sFilter ) { exp = new xbExp( xbase, dbf ); if(( iRc = exp->ParseExpression( sFilter.Str() )) != XB_NO_ERROR ){ - iErrorStop = 10; + iErrorStop = 100; throw iRc; } if( exp->GetReturnType() != XB_EXP_LOGICAL ){ - iErrorStop = 20; + iErrorStop = 110; iRc = XB_INVALID_EXPRESSION; delete exp; exp = NULL; @@ -102,21 +101,16 @@ xbInt16 xbFilter::GetFirstRecord( xbInt16 iOption ) { try{ if( !exp ){ - iErrorStop = 10; + iErrorStop = 100; throw iRc; } - #ifdef XB_INDEX_SUPPORT - if( dbf->GetCurIx() && dbf->GetCurTag() ) - return GetFirstRecordIx( iOption ); - #endif - lCurQryCnt = 0; if(( iRc = dbf->GetFirstRecord( iOption )) != XB_NO_ERROR ){ if( iRc == XB_EMPTY || iRc == XB_EOF ) return iRc; else{ - iErrorStop = 20; + iErrorStop = 110; throw iRc; } } @@ -124,11 +118,11 @@ xbInt16 xbFilter::GetFirstRecord( xbInt16 iOption ) { xbBool bFound = xbFalse; while( !bFound && iRc == XB_NO_ERROR ){ if(( iRc = exp->ProcessExpression()) != XB_NO_ERROR ){ - iErrorStop = 30; + iErrorStop = 120; throw iRc; } if(( iRc = exp->GetBoolResult( bFound )) != XB_NO_ERROR ){ - iErrorStop = 40; + iErrorStop = 130; throw iRc; } if( !bFound ){ @@ -136,7 +130,7 @@ xbInt16 xbFilter::GetFirstRecord( xbInt16 iOption ) { if( iRc == XB_EOF ){ return iRc; } else { - iErrorStop = 50; + iErrorStop = 140; throw iRc; } } @@ -160,15 +154,10 @@ xbInt16 xbFilter::GetNextRecord( xbInt16 iOption ){ try{ if( !exp ){ - iErrorStop = 10; + iErrorStop = 100; throw iRc; } - #ifdef XB_INDEX_SUPPORT - if( dbf->GetCurIx() && dbf->GetCurTag()) - return GetNextRecordIx( iOption ); - #endif - if( lLimit != 0 && abs( lCurQryCnt ) >= lLimit ) return XB_LIMIT_REACHED; @@ -176,7 +165,7 @@ xbInt16 xbFilter::GetNextRecord( xbInt16 iOption ){ if( iRc == XB_EOF ) return iRc; else{ - iErrorStop = 20; + iErrorStop = 110; throw iRc; } } @@ -184,11 +173,11 @@ xbInt16 xbFilter::GetNextRecord( xbInt16 iOption ){ xbBool bFound = xbFalse; while( !bFound && iRc == XB_NO_ERROR ){ if(( iRc = exp->ProcessExpression()) != XB_NO_ERROR ){ - iErrorStop = 30; + iErrorStop = 120; throw iRc; } if(( iRc = exp->GetBoolResult( bFound )) != XB_NO_ERROR ){ - iErrorStop = 40; + iErrorStop = 130; throw iRc; } if( !bFound ){ @@ -196,7 +185,7 @@ xbInt16 xbFilter::GetNextRecord( xbInt16 iOption ){ if( iRc == XB_EOF ){ return iRc; } else { - iErrorStop = 50; + iErrorStop = 140; throw iRc; } } @@ -220,16 +209,10 @@ xbInt16 xbFilter::GetPrevRecord( xbInt16 iOption ){ try{ if( !exp ){ - iErrorStop = 10; + iErrorStop = 100; throw iRc; } - #ifdef XB_INDEX_SUPPORT - //if( pIx && vpTag ) - if( dbf->GetCurIx() && dbf->GetCurTag()) - return GetPrevRecordIx( iOption ); - #endif - if( lLimit != 0 && abs( lCurQryCnt ) >= lLimit ) return XB_LIMIT_REACHED; @@ -237,7 +220,7 @@ xbInt16 xbFilter::GetPrevRecord( xbInt16 iOption ){ if( iRc == XB_BOF ) return iRc; else{ - iErrorStop = 20; + iErrorStop = 110; throw iRc; } } @@ -245,11 +228,11 @@ xbInt16 xbFilter::GetPrevRecord( xbInt16 iOption ){ xbBool bFound = xbFalse; while( !bFound && iRc == XB_NO_ERROR ){ if(( iRc = exp->ProcessExpression()) != XB_NO_ERROR ){ - iErrorStop = 30; + iErrorStop = 120; throw iRc; } if(( iRc = exp->GetBoolResult( bFound )) != XB_NO_ERROR ){ - iErrorStop = 40; + iErrorStop = 130; throw iRc; } if( !bFound ){ @@ -257,7 +240,7 @@ xbInt16 xbFilter::GetPrevRecord( xbInt16 iOption ){ if( iRc == XB_BOF ){ return iRc; } else { - iErrorStop = 50; + iErrorStop = 140; throw iRc; } } @@ -281,21 +264,16 @@ xbInt16 xbFilter::GetLastRecord( xbInt16 iOption ){ try{ if( !exp ){ - iErrorStop = 10; + iErrorStop = 100; throw iRc; } - #ifdef XB_INDEX_SUPPORT - if( dbf->GetCurIx() && dbf->GetCurTag()) - return GetLastRecordIx( iOption ); - #endif - lCurQryCnt = 0; if(( iRc = dbf->GetLastRecord( iOption )) != XB_NO_ERROR ){ if( iRc == XB_EOF ) return iRc; else{ - iErrorStop = 20; + iErrorStop = 110; throw iRc; } } @@ -303,11 +281,11 @@ xbInt16 xbFilter::GetLastRecord( xbInt16 iOption ){ xbBool bFound = xbFalse; while( !bFound && iRc == XB_NO_ERROR ){ if(( iRc = exp->ProcessExpression()) != XB_NO_ERROR ){ - iErrorStop = 30; + iErrorStop = 120; throw iRc; } if(( iRc = exp->GetBoolResult( bFound )) != XB_NO_ERROR ){ - iErrorStop = 40; + iErrorStop = 130; throw iRc; } if( !bFound ){ @@ -315,7 +293,7 @@ xbInt16 xbFilter::GetLastRecord( xbInt16 iOption ){ if( iRc == XB_BOF ){ return iRc; } else { - iErrorStop = 50; + iErrorStop = 140; throw iRc; } } @@ -336,11 +314,6 @@ xbInt16 xbFilter::GetLastRecord( xbInt16 iOption ){ #ifdef XB_INDEX_SUPPORT -//void xbFilter::Set( xbIx *pIx, void *vpTag ) { -// this->pIx = pIx; -// this->vpTag = vpTag; -//} - /************************************************************************/ xbInt16 xbFilter::GetFirstRecordIx( xbInt16 iOption ) { @@ -349,7 +322,7 @@ xbInt16 xbFilter::GetFirstRecordIx( xbInt16 iOption ) { try{ if( !exp ){ - iErrorStop = 10; + iErrorStop = 100; throw iRc; } @@ -358,7 +331,7 @@ xbInt16 xbFilter::GetFirstRecordIx( xbInt16 iOption ) { if( iRc == XB_EMPTY || iRc == XB_EOF ) return iRc; else{ - iErrorStop = 20; + iErrorStop = 110; throw iRc; } } @@ -366,11 +339,11 @@ xbInt16 xbFilter::GetFirstRecordIx( xbInt16 iOption ) { xbBool bFound = xbFalse; while( !bFound && iRc == XB_NO_ERROR ){ if(( iRc = exp->ProcessExpression()) != XB_NO_ERROR ){ - iErrorStop = 30; + iErrorStop = 120; throw iRc; } if(( iRc = exp->GetBoolResult( bFound )) != XB_NO_ERROR ){ - iErrorStop = 40; + iErrorStop = 130; throw iRc; } if( !bFound ){ @@ -379,7 +352,7 @@ xbInt16 xbFilter::GetFirstRecordIx( xbInt16 iOption ) { if( iRc == XB_EOF ){ return iRc; } else { - iErrorStop = 50; + iErrorStop = 140; throw iRc; } } @@ -403,7 +376,7 @@ xbInt16 xbFilter::GetNextRecordIx( xbInt16 iOption ){ try{ if( !exp ){ - iErrorStop = 10; + iErrorStop = 100; throw iRc; } @@ -414,7 +387,7 @@ xbInt16 xbFilter::GetNextRecordIx( xbInt16 iOption ){ if( iRc == XB_EOF ) return iRc; else{ - iErrorStop = 20; + iErrorStop = 110; throw iRc; } } @@ -422,11 +395,11 @@ xbInt16 xbFilter::GetNextRecordIx( xbInt16 iOption ){ xbBool bFound = xbFalse; while( !bFound && iRc == XB_NO_ERROR ){ if(( iRc = exp->ProcessExpression()) != XB_NO_ERROR ){ - iErrorStop = 30; + iErrorStop = 120; throw iRc; } if(( iRc = exp->GetBoolResult( bFound )) != XB_NO_ERROR ){ - iErrorStop = 40; + iErrorStop = 130; throw iRc; } if( !bFound ){ @@ -435,7 +408,7 @@ xbInt16 xbFilter::GetNextRecordIx( xbInt16 iOption ){ if( iRc == XB_EOF ){ return iRc; } else { - iErrorStop = 50; + iErrorStop = 140; throw iRc; } } @@ -459,7 +432,7 @@ xbInt16 xbFilter::GetPrevRecordIx( xbInt16 iOption ){ try{ if( !exp ){ - iErrorStop = 10; + iErrorStop = 100; throw iRc; } @@ -470,7 +443,7 @@ xbInt16 xbFilter::GetPrevRecordIx( xbInt16 iOption ){ if( iRc == XB_BOF ) return iRc; else{ - iErrorStop = 20; + iErrorStop = 110; throw iRc; } } @@ -478,11 +451,11 @@ xbInt16 xbFilter::GetPrevRecordIx( xbInt16 iOption ){ xbBool bFound = xbFalse; while( !bFound && iRc == XB_NO_ERROR ){ if(( iRc = exp->ProcessExpression()) != XB_NO_ERROR ){ - iErrorStop = 30; + iErrorStop = 120; throw iRc; } if(( iRc = exp->GetBoolResult( bFound )) != XB_NO_ERROR ){ - iErrorStop = 40; + iErrorStop = 130; throw iRc; } if( !bFound ){ @@ -491,7 +464,7 @@ xbInt16 xbFilter::GetPrevRecordIx( xbInt16 iOption ){ if( iRc == XB_BOF ){ return iRc; } else { - iErrorStop = 50; + iErrorStop = 140; throw iRc; } } @@ -515,7 +488,7 @@ xbInt16 xbFilter::GetLastRecordIx( xbInt16 iOption ){ try{ if( !exp ){ - iErrorStop = 10; + iErrorStop = 100; throw iRc; } @@ -524,7 +497,7 @@ xbInt16 xbFilter::GetLastRecordIx( xbInt16 iOption ){ if( iRc == XB_EOF ) return iRc; else{ - iErrorStop = 20; + iErrorStop = 110; throw iRc; } } @@ -532,11 +505,11 @@ xbInt16 xbFilter::GetLastRecordIx( xbInt16 iOption ){ xbBool bFound = xbFalse; while( !bFound && iRc == XB_NO_ERROR ){ if(( iRc = exp->ProcessExpression()) != XB_NO_ERROR ){ - iErrorStop = 30; + iErrorStop = 120; throw iRc; } if(( iRc = exp->GetBoolResult( bFound )) != XB_NO_ERROR ){ - iErrorStop = 40; + iErrorStop = 130; throw iRc; } if( !bFound ){ @@ -544,7 +517,7 @@ xbInt16 xbFilter::GetLastRecordIx( xbInt16 iOption ){ if( iRc == XB_BOF ){ return iRc; } else { - iErrorStop = 50; + iErrorStop = 140; throw iRc; } } diff --git a/src/core/xbixbase.cpp b/src/core/xbixbase.cpp index 40c1563..8b64fd6 100755 --- a/src/core/xbixbase.cpp +++ b/src/core/xbixbase.cpp @@ -52,7 +52,6 @@ xbInt16 xbIx::AddKeys( xbUInt32 ulRecNo ){ xbInt16 iErrorStop = 0; xbInt16 i = 0; xbInt16 iKeySts; -// std::cout << "xbIx::AddKeys\n"; try{ void * vpTag; @@ -60,9 +59,7 @@ xbInt16 xbIx::AddKeys( xbUInt32 ulRecNo ){ for( i = 0; i < iTagCount; i++ ){ vpTag = GetTag( i ); - iKeySts = GetKeySts( vpTag ); -// std::cout << "AddKeys() KeySts = " << iKeySts << "\n"; if( iKeySts == 1 || iKeySts == 2 ){ if(( iRc = UpdateTagKey( 'A', vpTag, ulRecNo )) != XB_NO_ERROR ){ @@ -241,7 +238,7 @@ xbInt16 xbIx::CheckForDupKeys(){ for( i = 0; i < iTagCount; i++ ){ vpTag = GetTag( i ); if(( iRc = CheckForDupKey( vpTag )) < XB_NO_ERROR ){ - iErrorStop = 10; + iErrorStop = 100; throw iRc; } } @@ -269,7 +266,7 @@ xbInt16 xbIx::Close(){ try{ if(( iRc = xbFclose()) != XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 100; throw iRc; } } @@ -335,7 +332,7 @@ xbInt16 xbIx::CreateKeys( xbInt16 iOpt ) { for( i = 0; i < iTagCount; i++ ){ vpTag = GetTag( i ); if(( iRc = CreateKey( vpTag, iOpt )) < XB_NO_ERROR ){ - iErrorStop = 10; + iErrorStop = 100; throw iRc; } } @@ -372,7 +369,7 @@ xbInt16 xbIx::DeleteKeys(){ vpTag = GetTag( i ); if( GetKeySts( vpTag ) > 1 ){ // 0 = no update 1 = add 2 = update, 3 = delete if(( iRc = UpdateTagKey( 'D', vpTag )) != XB_NO_ERROR ){ - iErrorStop = 10; + iErrorStop = 100; throw iRc; } } @@ -736,17 +733,17 @@ xbInt16 xbIx::Open( const xbString & sFileName ){ this->SetFileName( sFileName ); if( !FileExists()){ - iErrorStop = 10; + iErrorStop = 100; iRc = XB_FILE_NOT_FOUND; throw iRc; } /* open the file */ if(( iRc = xbFopen( dbf->GetOpenMode(), dbf->GetShareMode())) != XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 110; throw iRc; } if(( iRc = ReadHeadBlock()) != XB_NO_ERROR ){ - iErrorStop = 40; + iErrorStop = 120; throw iRc; } SetCurTag( (xbInt16) 0 ); // default the first tag as the current tag diff --git a/src/core/xbixmdx.cpp b/src/core/xbixmdx.cpp index 53d7053..95f342c 100755 --- a/src/core/xbixmdx.cpp +++ b/src/core/xbixmdx.cpp @@ -582,28 +582,29 @@ xbInt16 xbIxMdx::CheckTagIntegrity( void *vpTag, xbInt16 iOpt ){ char cKeyType; char *pPrevKeyBuf = NULL; xbMdxTag *npTag = (xbMdxTag *) vpTag; - xbInt16 iAutoLock; xbBool bDescending = npTag->cKeyFmt2 & 0x08; + #ifdef XB_LOCKING_SUPPORT + xbBool bLocked = xbFalse; + #endif + + try{ // xbase->WriteLogMessage( "xbIxMdx::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 = 100; throw iRc; } + bLocked = xbTrue; } #endif memset( npTag->cpKeyBuf2, 0x00, (size_t) npTag->iKeyLen ); cKeyType = GetKeyType( vpTag ); - // sMsg.Sprintf( "Checking index type [%c]", cKeyType ); - // xbase->WriteLogMessage( sMsg, iOpt ); - pPrevKeyBuf = (char *) calloc( 1, (size_t) npTag->iKeyLen ); iRc = GetFirstKey( vpTag, 0 ); memcpy( pPrevKeyBuf, GetKeyData( npTag->npCurNode, npTag->npCurNode->iCurKeyNo, npTag->iKeyItemLen ), (size_t) npTag->iKeyLen ); @@ -704,14 +705,6 @@ xbInt16 xbIxMdx::CheckTagIntegrity( void *vpTag, xbInt16 iOpt ){ 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 ); @@ -730,6 +723,13 @@ xbInt16 xbIxMdx::CheckTagIntegrity( void *vpTag, xbInt16 iOpt ){ xbase->WriteLogMessage( sMsg, iOpt ); } } + + #ifdef XB_LOCKING_SUPPORT + if( bLocked ){ + dbf->LockTable( XB_UNLOCK ); + } + #endif + return iRc; } @@ -1765,7 +1765,6 @@ xbInt16 xbIxMdx::DeleteTag( void *vpTag ){ /***********************************************************************/ #ifdef XB_DEBUG_SUPPORT - //! @brief Dump a given block for a tag /*! \param iOpt Output message destination<br> @@ -1958,7 +1957,6 @@ xbInt16 xbIxMdx::DumpFreeBlocks( xbInt16 iOpt ){ } /**************************************************************************************************************/ - //! @brief Dump interior and leaf blocks for a given tag. /*! Dump blocks for given tag for index debugging purposes. @@ -4325,12 +4323,12 @@ xbInt16 xbIxMdx::ReadHeadBlock( xbInt16 iOpt ) free( cNodeBuf ); if(( cNodeBuf = (char *) malloc( (size_t) GetBlockSize())) == NULL ){ - iErrorStop = 40; + iErrorStop = 150; throw XB_NO_MEMORY; } if(( iRc = xbIxMdx::LoadTagTable()) != XB_NO_ERROR ){ - iErrorStop = 50; + iErrorStop = 160; throw iRc; } @@ -4379,7 +4377,7 @@ xbInt16 xbIxMdx::Reindex( void **vpTag ){ xbInt16 iErrorStop = 0; xbMdxTag * mpTag; #ifdef XB_LOCKING_SUPPORT - xbInt16 iAutoLock = 0; + xbBool bLocked = xbFalse; #endif if( vpTag ) @@ -4400,12 +4398,12 @@ xbInt16 xbIxMdx::Reindex( void **vpTag ){ try{ #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 = 100; throw iRc; } + bLocked = xbTrue; } #endif @@ -4524,34 +4522,20 @@ xbInt16 xbIxMdx::Reindex( void **vpTag ){ mpTag = (xbMdxTag *) GetTag( iCurTag++ ); } } - - // unlock as necessary - #ifdef XB_LOCKING_SUPPORT - if( iAutoLock && dbf->GetTableLocked() ){ - if(( iRc = dbf->LockTable( XB_UNLOCK )) != XB_NO_ERROR ){ - iErrorStop = 190; - throw iRc; - } - } - #endif - - } catch (xbInt16 iRc ){ xbString sMsg; sMsg.Sprintf( "xbIxMdx::ReIndex() Exception Caught. Error Stop = [%d] iRc = [%d]", iErrorStop, iRc ); xbase->WriteLogMessage( sMsg.Str() ); xbase->WriteLogMessage( GetErrorMessage( iRc )); + } - // unlock as necessary - #ifdef XB_LOCKING_SUPPORT - if( iAutoLock && dbf->GetTableLocked() ){ - dbf->LockTable( XB_UNLOCK ); - } - #endif + #ifdef XB_LOCKING_SUPPORT + if( bLocked ){ + dbf->LockTable( XB_UNLOCK ); } + #endif return iRc; - } /***********************************************************************/ 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<br> 1 = Syslog<br> 2 = Both<br> - \returns XB_NVALID_OBJECT<br>XB_NO_ERROR + \returns XB_INVALID_OBJECT<br>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 { diff --git a/src/core/xbmemo.cpp b/src/core/xbmemo.cpp index 02bdbbf..2bde853 100755 --- a/src/core/xbmemo.cpp +++ b/src/core/xbmemo.cpp @@ -94,7 +94,7 @@ xbInt16 xbMemo::GetHdrNextBlock( xbUInt32 & ulBlockNo ){ xbInt16 iErrorStop = 0; try{ if(( iRc = ReadDbtHeader( 0 )) != XB_NO_ERROR ){ - iErrorStop = 10; + iErrorStop = 100; throw iRc; } ulBlockNo = ulHdrNextBlock; @@ -133,7 +133,7 @@ xbInt16 xbMemo::LockMemo( xbInt16 iLockFunction ){ if( iRc == XB_LOCK_FAILED ) return iRc; else { - iErrorStop = 120; + iErrorStop = 100; throw iRc; } } else { @@ -151,7 +151,7 @@ xbInt16 xbMemo::LockMemo( xbInt16 iLockFunction ){ if( iRc == XB_LOCK_FAILED ) return iRc; else { - iErrorStop = 140; + iErrorStop = 110; throw iRc; } } else { @@ -159,7 +159,7 @@ xbInt16 xbMemo::LockMemo( xbInt16 iLockFunction ){ } } } else { - iErrorStop = 300; + iErrorStop = 120; iRc = XB_INVALID_OPTION; throw iRc; } @@ -197,11 +197,11 @@ xbInt16 xbMemo::UpdateHeadNextNode(){ char buf[4]; ePutUInt32( buf, ulHdrNextBlock ); if(( iRc = xbFseek( 0, SEEK_SET )) != XB_NO_ERROR ){ - iErrorStop = 10; + iErrorStop = 100; throw iRc; } if(( iRc = xbFwrite( &buf, 4, 1 )) != XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 110; throw iRc; } } diff --git a/src/core/xbmemo3.cpp b/src/core/xbmemo3.cpp index b5494fb..60c1d53 100755 --- a/src/core/xbmemo3.cpp +++ b/src/core/xbmemo3.cpp @@ -92,6 +92,7 @@ xbInt16 xbMemoDbt3::DumpMemoFreeChain() { std::cout << "Xbase version 3 file - no free block chain" << std::endl; return XB_NO_ERROR; } +#endif // XB_DEBUG_SUPPORT //! @brief Dump memo file header. /*! @@ -114,7 +115,6 @@ xbInt16 xbMemoDbt3::DumpMemoHeader(){ std::cout << "Block Count = " << stFileSize / GetBlockSize() << std::endl; return XB_NO_ERROR; } -#endif // XB_DEBUG_SUPPORT /***********************************************************************/ //! @brief Get a memo field for a given field number. /*! @@ -134,7 +134,7 @@ xbInt16 xbMemoDbt3::GetMemoField( xbInt16 iFieldNo, xbString & sMemoData ){ sMemoData = ""; try{ if(( rc = dbf->GetULongField( iFieldNo, ulBlockNo )) < XB_NO_ERROR ){ - iErrorStop = 10; + iErrorStop = 100; throw rc; } if( ulBlockNo == 0L ){ @@ -144,7 +144,7 @@ xbInt16 xbMemoDbt3::GetMemoField( xbInt16 iFieldNo, xbString & sMemoData ){ spp = NULL; while( !bDone ){ if(( rc = ReadBlock( ulBlockNo++, GetBlockSize(), mbb )) != XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 120; throw rc; } ulScnt = 0; @@ -185,7 +185,7 @@ xbInt16 xbMemoDbt3::GetMemoFieldLen( xbInt16 iFieldNo, xbUInt32 & ulFieldLen ){ xbInt16 iNotDone; try{ if(( rc = dbf->GetULongField( iFieldNo, ulBlockNo )) < XB_NO_ERROR ){ - iErrorStop = 10; + iErrorStop = 100; throw rc; } if( ulBlockNo == 0 ){ @@ -197,7 +197,7 @@ xbInt16 xbMemoDbt3::GetMemoFieldLen( xbInt16 iFieldNo, xbUInt32 & ulFieldLen ){ iNotDone = 1; while( iNotDone ){ if(( rc = ReadBlock( ulBlockNo++, GetBlockSize(), mbb )) != XB_NO_ERROR ){ - iErrorStop = 1; + iErrorStop = 110; throw rc; } iScnt = 0; @@ -251,22 +251,21 @@ xbInt16 xbMemoDbt3::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; @@ -277,20 +276,20 @@ xbInt16 xbMemoDbt3::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; } xbMemoDbt3 *pMemo = new xbMemoDbt3( 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(); @@ -299,7 +298,7 @@ xbInt16 xbMemoDbt3::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; } if( (void *) memoStatusFunc ) @@ -308,18 +307,18 @@ xbInt16 xbMemoDbt3::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; } } @@ -330,25 +329,25 @@ xbInt16 xbMemoDbt3::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( (size_t) ulBlkSize )) == NULL ){ - iErrorStop = 110; + iErrorStop = 220; throw iRc; } @@ -356,54 +355,40 @@ xbInt16 xbMemoDbt3::PackMemo( void (*memoStatusFunc ) ( xbUInt32 ulItemNum, xbUI // copy work table back to source table 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; } } //close and delete target if(( iRc = pMemo->xbFclose()) != XB_NO_ERROR ){ - iErrorStop = 140; + iErrorStop = 250; throw iRc; } if(( iRc = pMemo->xbRemove()) != XB_NO_ERROR ){ - iErrorStop = 150; + iErrorStop = 260; 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( "xbMemoDbt3::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; } @@ -424,7 +409,7 @@ xbInt16 xbMemoDbt3::ReadDbtHeader( xbInt16 iOption ){ try{ if( !FileIsOpen() ){ - iErrorStop = 10; + iErrorStop = 100; rc = XB_NOT_OPEN; throw rc; } @@ -433,26 +418,26 @@ xbInt16 xbMemoDbt3::ReadDbtHeader( xbInt16 iOption ){ else{ xbUInt64 stFileSize = 0; if(( rc = GetFileSize( stFileSize )) != XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 110; throw rc; } if( stFileSize < 4 ){ - iErrorStop = 30; + iErrorStop = 120; rc = XB_INVALID_BLOCK_NO; throw rc; } else if( stFileSize > 20 ) - ulReadSize = 40; + ulReadSize = 130; else ulReadSize = 4; } if( xbFseek( 0, SEEK_SET )){ - iErrorStop = 50; + iErrorStop = 140; rc = XB_SEEK_ERROR; throw rc; } if(( xbFread( &MemoBlock, ulReadSize, 1 )) != XB_NO_ERROR ){ - iErrorStop = 60; + iErrorStop = 150; rc = XB_READ_ERROR; throw rc; } @@ -498,7 +483,7 @@ xbInt16 xbMemoDbt3::UpdateMemoField( xbInt16 iFieldNo, const xbString & sMemoDat try{ if( sMemoData == "" ){ if(( rc = dbf->PutField( iFieldNo, "" )) != XB_NO_ERROR ){ - iErrorStop = 10; + iErrorStop = 100; throw rc; } } else { @@ -506,32 +491,32 @@ xbInt16 xbMemoDbt3::UpdateMemoField( xbInt16 iFieldNo, const xbString & sMemoDat xbUInt32 ulBlocksNeeded = (ulDataLen / 512) + 1; xbUInt32 ulLastDataBlock; if(( rc = CalcLastDataBlock( ulLastDataBlock )) != XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 110; throw rc; } if(( rc = xbFseek( ((xbInt64) ulLastDataBlock * 512), SEEK_SET )) != XB_NO_ERROR ){ - iErrorStop = 30; + iErrorStop = 120; throw rc; } if(( rc = xbFwrite( sMemoData.Str(), sMemoData.Len(), 1 )) != XB_NO_ERROR ){ - iErrorStop = 40; + iErrorStop = 130; throw rc; } if(( rc = xbFputc( 0x1a, 2 )) != XB_NO_ERROR ){ - iErrorStop = 50; + iErrorStop = 140; throw rc; } if(( rc = xbFputc( 0x00, (xbInt32) ( ulBlocksNeeded * 512 ) - (xbInt32) ulDataLen )) != XB_NO_ERROR ){ - iErrorStop = 60; + iErrorStop = 150; throw rc; } if(( rc = dbf->PutULongField( iFieldNo, ulLastDataBlock )) != XB_NO_ERROR ){ - iErrorStop = 70; + iErrorStop = 160; throw rc; } ulHdrNextBlock = ulLastDataBlock + ulBlocksNeeded; if(( rc = UpdateHeadNextNode()) != XB_NO_ERROR ){ - iErrorStop = 80; + iErrorStop = 170; throw rc; } } @@ -563,15 +548,15 @@ xbInt16 xbMemoDbt3::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( 512 )) != XB_NO_ERROR ){ - iErrorStop = 30; + iErrorStop = 120; throw iRc; } } 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; } } diff --git a/src/core/xbssv.cpp b/src/core/xbssv.cpp index c595f6b..252daab 100755 --- a/src/core/xbssv.cpp +++ b/src/core/xbssv.cpp @@ -121,7 +121,6 @@ xbInt16 xbSsv::iCreateMdxBlockSize = 1024; // 1024 is DBase 7 default siz //! @brief Class Constructor. xbSsv::xbSsv(){} /*************************************************************************/ -#ifdef XB_DEBUG_SUPPORT void xbSsv::BitDump( unsigned char c ) const { for( int i = 7; i >= 0; i-- ) std::cout << (BitSet( c, i ) ? 1 : 0); @@ -129,7 +128,6 @@ void xbSsv::BitDump( unsigned char c ) const { void xbSsv::BitDump( char c ) const { BitDump( (unsigned char) c ); } -#endif /*************************************************************************/ //! @brief Check a bit in a one byte field and see if it is set. /*! diff --git a/src/core/xbstring.cpp b/src/core/xbstring.cpp index 872062f..81e67b8 100755 --- a/src/core/xbstring.cpp +++ b/src/core/xbstring.cpp @@ -1358,6 +1358,61 @@ xbString &xbString::Remove(xbUInt32 ulStartPos, xbUInt32 ulDelSize ) { } + + + +/************************************************************************/ +//! @brief Replace a value within a string with another value +/*! + \param sReplace - Character string to replace. + \param sReplaceWith - Character string to replace with + \param iOption - 0 = All occurrences, 1 = first occurrence + \returns Reference to this string. +*/ + +//the new size includes the null termination byte +xbString &xbString::Replace( const char *sReplace, const char *sReplaceWith, xbInt16 iOption ){ + + xbBool bDone = xbFalse; + xbUInt32 ulPos; + xbUInt32 ulNewSize; + xbUInt32 ulSp2; + char *sBuf2; + + while( !bDone ){ + ulPos = Pos( sReplace ); + if( ulPos == 0 ){ + bDone = xbTrue; + } else { + + ulNewSize = this->size + sizeof( sReplaceWith ) - sizeof( sReplace ); + sBuf2 = (char *) calloc( 1, ulNewSize ); + + // copy part1 + for( xbUInt32 ul = 0; ul < ulPos-1; ul++ ) + sBuf2[ul] = data[ul]; + + // copy part2 + strcat( sBuf2, sReplaceWith ); + + // copy part3 + ulSp2 = ulPos + strlen( sReplace ); + char *p = data; + p+= (ulSp2 - 1); + strcat( sBuf2, p ); + + if( iOption ) + bDone = xbTrue; + + free(data); + data = sBuf2; + + } + } + + return *this; +} + /************************************************************************/ //! @brief Resize a string /*! diff --git a/src/core/xbtblmgr.cpp b/src/core/xbtblmgr.cpp index e1bf496..f154dc6 100755 --- a/src/core/xbtblmgr.cpp +++ b/src/core/xbtblmgr.cpp @@ -61,7 +61,7 @@ xbInt16 xbTblMgr::AddTblToTblList( xbDbf *d, const xbString & sTblName, const xb try{ if( sTblName.Len() == 0 ){ - iErrorStop = 10; + iErrorStop = 100; iRc = XB_INVALID_TABLE_NAME; throw iRc; } @@ -77,7 +77,7 @@ xbInt16 xbTblMgr::AddTblToTblList( xbDbf *d, const xbString & sTblName, const xb } if((i = (xbTblList *) calloc(1, sizeof(xbTblList))) == NULL){ - iErrorStop = 20; + iErrorStop = 110; iRc = XB_NO_MEMORY; throw iRc; } @@ -96,7 +96,7 @@ xbInt16 xbTblMgr::AddTblToTblList( xbDbf *d, const xbString & sTblName, const xb } if( t && (strcmp( t->psTblAlias->Str(), sAlias.Str()) == 0 )){ - iErrorStop = 30; + iErrorStop = 120; delete i->psTblName; delete i->psTblAlias; free( i ); @@ -110,7 +110,7 @@ xbInt16 xbTblMgr::AddTblToTblList( xbDbf *d, const xbString & sTblName, const xb s->pNext = i; } catch (xbInt16 iRc ){ - if( iErrorStop != 30 ){ + if( iErrorStop != 120 ){ xbString sMsg; sMsg.Sprintf( "xbTblMgr::AddTblToTblList() Exception Caught. Error Stop = [%d] iRc = [%d] Tbl Name = [%s] Alias = [%s]", iErrorStop, iRc, sTblName.Str(), sTblAlias.Str() ); std::cout << sMsg << std::endl; @@ -137,7 +137,6 @@ xbInt16 xbTblMgr::DisplayTableList() const { } return iTblCnt; } - /*************************************************************************/ /* Get pointer to named dbf. Looks up an open DBF file by Name. @@ -152,8 +151,15 @@ xbDbf *xbTblMgr::GetDbfPtr(const xbString& sTblAlias) const { xbTblList *t; t = TblList; + xbString s; + xbUInt32 ui = sTblAlias.Pos( ".DBF" ); + if( ui > 0 ) + s.Assign( sTblAlias.Str(), 1, ui - 1 ); + else + s.Set( sTblAlias ); + while( t ){ - if( sTblAlias == t->psTblAlias->Str()) + if( s == t->psTblAlias->Str()) return t->pDbf; t = t->pNext; } @@ -166,7 +172,6 @@ xbDbf *xbTblMgr::GetDbfPtr(const xbString& sTblAlias) const { } return NULL; } - /*************************************************************************/ /* Get pointer to named dbf. Looks up an open DBF file by Name. @@ -192,12 +197,21 @@ xbDbf *xbTblMgr::GetDbfPtr(xbInt16 iItemNo ) const { else return NULL; } - /*************************************************************************/ xbInt16 xbTblMgr::GetOpenTableCount() const { return iOpenTableCount; } +/*************************************************************************/ +xbTblList * xbTblMgr::GetTblListEntry( xbDbf *pTbl ){ + xbTblList * i = TblList; + while( i ){ + if( i->pDbf == pTbl ) + return i; + i = i->pNext; + } + return NULL; +} /*************************************************************************/ xbInt16 xbTblMgr::RemoveTblFromTblList( const xbString & sTblAlias ) { xbTblList *i, *s; @@ -252,6 +266,5 @@ xbInt16 xbTblMgr::RemoveTblFromTblList( xbDbf *pTbl ) { } return XB_NOT_FOUND; } - /*************************************************************************/ } /* namespace */ diff --git a/src/core/xbxbase.cpp b/src/core/xbxbase.cpp index 7dd3ac7..7443b26 100755 --- a/src/core/xbxbase.cpp +++ b/src/core/xbxbase.cpp @@ -51,12 +51,12 @@ xbInt16 xbXBase::CloseAllTables(){ d = (xbDbf *) GetDbfPtr( 1 ); if( d ){ if(( iRc = d->Close()) != XB_NO_ERROR ){ - iErrorStop = 10; + iErrorStop = 100; throw iRc; } } else { iRc = XB_INVALID_OBJECT; - iErrorStop = 20; + iErrorStop = 110; throw iRc; } } @@ -130,7 +130,6 @@ void xbXBase::SetLogSize( size_t lSize ) { xLog->LogSetLogSize( lSize ); } - //! @brief Write message to logfile. /*! \param sLogMessage - Message to write. @@ -189,7 +188,7 @@ void xbXBase::SetLogDirectory( const xbString & sLogDirectory ){ xbBool xbXBase::GetLogStatus() const { return xbFalse; } -xbInt16 xbXBase::WriteLogMessage( const xbString & sLogMessage ){ +xbInt16 xbXBase::WriteLogMessage( const xbString & sLogMessage, xbInt16 ){ return XB_NO_ERROR; } xbInt16 xbXBase::WriteLogBytes( xbUInt32 lCnt, const char *p ){ @@ -202,7 +201,7 @@ void xbXBase::DisableMsgLogging() { return; } xbInt16 xbXBase::FlushLog() { - return; + return XB_NO_ERROR; } void xbXBase::SetLogSize( size_t lSize ) { return; @@ -569,23 +568,22 @@ xbDbf* xbXBase::Open( const xbString &sTableName, const xbString &sAlias, xbInt1 try{ if( sTableName.Len() == 0 ){ - iErrorStop = 10; + iErrorStop = 100; iRc = XB_FILE_NOT_FOUND; throw iRc; } xbFile *f = new xbFile(this); f->SetFileName( sTableName ); if(( iRc = f->FileExists( f->GetFqFileName())) != xbTrue ){ - iErrorStop = 20; + iErrorStop = 110; iRc = XB_FILE_NOT_FOUND; throw iRc; } unsigned char cFileTypeByte; if(( iRc = f->GetXbaseFileTypeByte( f->GetFqFileName(), cFileTypeByte )) != XB_NO_ERROR ){ - iErrorStop = 30; + iErrorStop = 120; throw iRc; } - xbInt16 iTblVsn = f->DetermineXbaseTableVersion( cFileTypeByte ); f->xbFclose(); sFqFileName.Set( f->GetFqFileName() ); @@ -597,7 +595,7 @@ xbDbf* xbXBase::Open( const xbString &sTableName, const xbString &sAlias, xbInt1 iRc = pDbf->Open( sFqFileName, sAlias, iOpenMode, iShareMode ); #else // std::cout << "Dbase IV file support not build into library. See XB_DBF4_SUPPORT" << std::endl; - iErrorStop = 40; + iErrorStop = 130; iRc = XB_FILE_TYPE_NOT_SUPPORTED; throw iRc; #endif @@ -609,72 +607,64 @@ xbDbf* xbXBase::Open( const xbString &sTableName, const xbString &sAlias, xbInt1 iRc = pDbf->Open( sFqFileName, sAlias, iOpenMode, iShareMode ); #else //std::cout << "Dbase III file support not build into library. See XB_DBF3_SUPPORT" << std::endl; - iErrorStop = 50; + iErrorStop = 140; iRc = XB_FILE_TYPE_NOT_SUPPORTED; throw iRc; #endif } else { - iErrorStop = 60; + iErrorStop = 150; iRc = XB_FILE_TYPE_NOT_SUPPORTED; throw iRc; } if( iRc != XB_NO_ERROR ){ - iErrorStop = 70; + iErrorStop = 160; throw iRc; } } catch (xbInt16 iRc ){ - - std::cout << "Openerror\n"; - xbString sMsg; sMsg.Sprintf( "xbxbase::Open() Exception Caught. Error Stop = [%d] rc = [%d]", iErrorStop, iRc ); WriteLogMessage( sMsg.Str() ); WriteLogMessage( GetErrorMessage( iRc )); - } return pDbf; - } xbInt16 xbXBase::OpenHighestVersion( const xbString &sTableName, const xbString &sAlias, xbDbf **dbf ) { - xbInt16 iRc = 0; xbInt16 iErrorStop = 0; - - xbDbf * pwDbf; - + try{ xbFile f(this); if( sTableName.Len() == 0 ){ - iErrorStop = 10; + iErrorStop = 100; iRc = XB_FILE_NOT_FOUND; throw iRc; } f.SetFileName( sTableName ); if(( iRc = f.FileExists( f.GetFqFileName() )) != xbTrue ){ - iErrorStop = 20; + iErrorStop = 110; iRc = XB_FILE_NOT_FOUND; throw iRc; } unsigned char cFileTypeByte; if(( iRc = f.GetXbaseFileTypeByte( f.GetFqFileName(), cFileTypeByte )) != XB_NO_ERROR ){ - iErrorStop = 30; + iErrorStop = 120; return iRc; } if( f.DetermineXbaseTableVersion( cFileTypeByte ) == 4 ){ #ifdef XB_DBF4_SUPPORT - pwDbf = new xbDbf4( this ); + xbDbf *pwDbf = new xbDbf4( this ); pwDbf->Open( f.GetFqFileName(), sAlias ); *dbf = pwDbf; pwDbf = 0; #else // std::cout << "Dbase IV file support not build into library. See XB_DBF4_SUPPORT" << std::endl; - iErrorStop = 40; + iErrorStop = 130; iRc = XB_FILE_TYPE_NOT_SUPPORTED; throw iRc; #endif @@ -684,27 +674,22 @@ xbInt16 xbXBase::OpenHighestVersion( const xbString &sTableName, const xbString *dbf = new xbDbf3( this ); #else //std::cout << "Dbase III file support not build into library. See XB_DBF3_SUPPORT" << std::endl; - iErrorStop = 50; + iErrorStop = 140; iRc = XB_FILE_TYPE_NOT_SUPPORTED; throw iRc; #endif } else { - iErrorStop = 60; + iErrorStop = 150; iRc = XB_FILE_TYPE_NOT_SUPPORTED; throw iRc; } - } catch (xbInt16 iRc ){ - - std::cout << "OpenHighestVersion error\n"; - xbString sMsg; sMsg.Sprintf( "xbxbase::OpenHighestVersion() Exception Caught. Error Stop = [%d] rc = [%d]", iErrorStop, iRc ); WriteLogMessage( sMsg.Str() ); WriteLogMessage( GetErrorMessage( iRc )); - } return iRc; } |