diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2023-01-29 15:45:54 +0100 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2023-01-29 15:45:54 +0100 |
commit | ea61b72fd4e7485b1487a4c94d908a9051ce2c9d (patch) | |
tree | 453ec4076d8a2374b2261dd42de59604095dc044 /src | |
parent | 37e148ea3642ac18f703bfe68083e185d29eea95 (diff) | |
parent | 517ad9d4b6eae320b708d03a9340a22893b0cab7 (diff) |
Update upstream source from tag 'upstream/4.0.3'
Update to upstream version '4.0.3'
with Debian dir 538ed2ce92d0b7f84f42a595fb73b1fa053aa759
Diffstat (limited to 'src')
63 files changed, 2915 insertions, 2081 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; } diff --git a/src/examples/xb_ex_expression.cpp b/src/examples/xb_ex_expression.cpp new file mode 100755 index 0000000..dc6d7e6 --- /dev/null +++ b/src/examples/xb_ex_expression.cpp @@ -0,0 +1,230 @@ +/* xb_ex_expression.cpp + +XBase64 Software Library + +Copyright (c) 1997,2003,2014,2022 Gary A Kunkel + +The xb64 software library is covered under +the terms of the GPL Version 3, 2007 license. + +Email Contact: + + xb64-devel@lists.sourceforge.net + xb64-users@lists.sourceforge.net + + + This example program demonstrates expression usage + +*/ + + +#include <xbase.h> + +using namespace xb; + + + + xbSchema MyV4Record[] = + { + { "CFLD1", XB_CHAR_FLD, 20, 0 }, + { "CFLD2", XB_CHAR_FLD, 10, 0 }, + { "NFLD1", XB_NUMERIC_FLD, 5, 0 }, + { "DATE1", XB_DATE_FLD, 8, 0 }, + { "",0,0,0 } + }; + +//********************************************************************************************************************************* +void PrintResult( xbString *sExpression, xbExp *exp ); +void PrintResult( xbString *sExpression, xbExp *exp ){ + + // Determine the expression return type + char cExpType = exp->GetReturnType(); + + // Process the expression results, dependent on return type + if( cExpType == XB_EXP_NUMERIC ){ + xbDouble dResult; + exp->GetNumericResult( dResult ); + std::cout << "Numeric result from expression [" << sExpression->Str() << "] is [" << dResult << "]" << std::endl; + + } else if( cExpType == XB_EXP_DATE ){ + xbDate dt; + exp->GetDateResult( dt ); + std::cout << "Date result from expression [" << sExpression->Str() << "] is [" << dt.Str() << "]" << std::endl; + + } else if( cExpType == XB_EXP_LOGICAL ){ + xbBool bResult; + exp->GetBoolResult( bResult ); + std::cout << "Bool result from expression [" << sExpression->Str() << "] is [" << (bResult ? " True" : "False") << "]" << std::endl; + + } else if( cExpType == XB_EXP_CHAR ){ + xbString sResult; + exp->GetStringResult( sResult ); + std::cout << "Char result from expression [" << sExpression->Str() << "] is [" << sResult.Str() << "]" << std::endl; + } + +} + +//********************************************************************************************************************************* +int main( int ac, char ** av ){ + + xbInt16 iRc = 0; + xbInt16 iErrorStop = 0; + xbIx *pIx = NULL; + void *pTag = NULL; + + xbXBase x; + xbDbf *MyFile = new xbDbf4( &x ); + + try{ + + if(( iRc = MyFile->CreateTable( "EXPEXAMPL.DBF", "TestMdxX2", MyV4Record, XB_OVERLAY, XB_MULTI_USER )) != XB_NO_ERROR ){ + iErrorStop = 100; + throw iRc; + } + /* + CreateTag( const xbString &sIxType, const xbString &sName, const xbString &sKey, const xbString &sFilter, + xbInt16 iDescending, xbInt16 iUnique, xbInt16 iOverLay, xbIx **xbIxOut, void **vpTagOut ); + */ + + // the following index definition has two expressions + // 1) CFLD1+CFLD2 -- concat two char fields into an index key + // 2) .NOT. DELETED() -- don't include any deleted records in the index + if(( iRc = MyFile->CreateTag( "MDX", "TAG1", "CFLD1+CFLD2", ".NOT. DELETED()", 0, 0, XB_OVERLAY, &pIx, &pTag )) != XB_NO_ERROR ){ + iErrorStop = 110; + throw iRc; + } + + // add a record to the table + if(( iRc = MyFile->BlankRecord()) != XB_NO_ERROR ){ + iErrorStop = 120; + throw iRc; + } + + if(( iRc = MyFile->PutField( "CFLD1", "Some text" )) != XB_NO_ERROR ){ + iErrorStop = 130; + throw iRc; + } + + if(( iRc = MyFile->PutField( "CFLD2", "Other text" )) != XB_NO_ERROR ){ + iErrorStop = 140; + throw iRc; + } + + if(( iRc = MyFile->PutLongField( "NFLD1", 1000 )) != XB_NO_ERROR ){ + iErrorStop = 150; + throw iRc; + } + + xbDate dt; + dt.Set( "19890209" ); + if(( iRc = MyFile->PutDateField( "DATE1", dt )) != XB_NO_ERROR ){ + iErrorStop = 160; + throw iRc; + } + + if(( iRc = MyFile->AppendRecord()) != XB_NO_ERROR ){ + iErrorStop = 170; + throw iRc; + } + + if(( iRc = MyFile->Commit()) != XB_NO_ERROR ){ + iErrorStop = 180; + throw iRc; + } + + + // To use the XBase64 expression processing logic + // 1) Parse an expression with the xbExp::ParseExpression() method + // 2) Process the parsed expression with the xbExp::ProcessExpression() method + // 3) If needed, determine the expression return type with the xbExp::GetReturnType() method + // 4) Use the appriate methid to retrieve the expression value: + // xbExp::GetNumericResult() + // xbExp::GetDateResult() + // xbExp::GetLogicalResult() + // xbExp::GetStringResult() + + + // The expression only needs to be parsed once. The ProcessExpression() method can be used + // zero, one or many times after it is initially parsed. + + // see docs/html/xbc5.html for expression documentation + // see example below + + + // Numeric expression example + xbString sExpression = "NFLD1 * (2 + RECNO())"; + xbExp exp( &x ); + // Parse the expression + if(( iRc = exp.ParseExpression( MyFile, sExpression )) != XB_NO_ERROR ){ + iErrorStop = 190; + throw iRc; + } + // Process the parsed expression + if(( iRc = exp.ProcessExpression()) != XB_NO_ERROR ){ + iErrorStop = 200; + return -1; + } + PrintResult( &sExpression, &exp ); + + + // String expression example + sExpression = "CFLD1+CFLD2+'{'+DTOS(DATE1)+'}'"; + xbExp exp2( &x ); + if(( iRc = exp2.ParseExpression( MyFile, sExpression )) != XB_NO_ERROR ){ + iErrorStop = 210; + throw iRc; + } + // Process the parsed expression + if(( iRc = exp2.ProcessExpression()) != XB_NO_ERROR ){ + iErrorStop = 220; + return -1; + } + PrintResult( &sExpression, &exp2 ); + + // Date example + sExpression = "DATE() + 6"; + xbExp exp3( &x ); + if(( iRc = exp3.ParseExpression( MyFile, sExpression )) != XB_NO_ERROR ){ + iErrorStop = 230; + throw iRc; + } + // Process the parsed expression + if(( iRc = exp3.ProcessExpression()) != XB_NO_ERROR ){ + iErrorStop = 240; + return -1; + } + PrintResult( &sExpression, &exp3 ); + + // Logic example + sExpression = "NFLD1 = 5"; + xbExp exp4( &x ); + if(( iRc = exp4.ParseExpression( MyFile, sExpression )) != XB_NO_ERROR ){ + iErrorStop = 250; + throw iRc; + } + // Process the parsed expression + if(( iRc = exp4.ProcessExpression()) != XB_NO_ERROR ){ + iErrorStop = 260; + return -1; + } + PrintResult( &sExpression, &exp4 ); + + + + // Cleanup + MyFile->DeleteTable(); + delete MyFile; + + + } catch (xbInt16 iRc ){ + + std::cout << "Error in program xb_ex_expression at location " << iErrorStop << std::endl; + std::cout << x.GetErrorMessage( iRc ) << std::endl; + + } + + + + + return iRc; +} diff --git a/src/examples/xb_ex_string.cpp b/src/examples/xb_ex_string.cpp index 3d582a1..30fd74e 100755 --- a/src/examples/xb_ex_string.cpp +++ b/src/examples/xb_ex_string.cpp @@ -65,15 +65,18 @@ int main() // trim methods s3 = " abc "; s3.Ltrim(); + #ifdef XB_DEBUG_SUPPORT s3.Dump( "LTrim test" ); - + #else + std::cout << s3.Str() << std::endl; + #endif s3 = " abc "; s3.Rtrim(); - s3.Dump( "RTrim test" ); + std::cout << "RTrim test - " << s3.Str() << std::endl; s3.Trim(); - s3.Dump( "Trim test" ); + std::cout << "Trim test - " << s3.Str() << std::endl; printf( "s3 Len = [%d]\n", s3.Len() ); // Concatenation tests - I @@ -88,29 +91,24 @@ int main() s1 -= "Concatenation test1 part 2 "; s1 -= 'X'; s1 -= s2; - s1.Dump( "Concatenation test 2 " ); - + std::cout << "Concatenation test 2 - " << s1.Str() << std::endl; // Concatenation tests - III s1 = "s1data "; s2 = "s2data "; s3 = s1 - s2; - s3.Dump( "Concatenation test 3a" ); + std::cout << "Concatenation test 3a - " << s3.Str() << std::endl; s3 = s1 + s2; - s3.Dump( "Concatenation test 3b" ); + std::cout << "Concatenation test 3b - " << s3.Str() << std::endl; s3 = s1 + " char * data "; - s3.Dump( "Concatenation test 3c" ); - - // s3 = " char * data " + s2; - // s3.Dump( "Concatenation test 3d" ); + std::cout << "Concatenation test 3c - " << s3.Str() << std::endl; s3 = s1 + 'Z'; - s3.Dump( "Concatenation test 3e" ); + std::cout << "Concatenation test 3d - " << s3.Str() << std::endl; -// s3 = 'A' + s1; s3 = 'A'; std::cout << s3.Str() << std::endl; @@ -118,14 +116,8 @@ int main() std::cout << s3.Str() << std::endl; - - s3 = 'A' + s1; - - - return 0; - - // s3.Dump( "Concatenation test 3f" ); - + s3 = 'A' + s1; + std::cout << std::endl << "== operator tests" << std::endl; if( s1 == s2 ) std::cout << s1.Str() << " == " << s2.Str() << std::endl; @@ -145,8 +137,9 @@ int main() std::cout << std::endl << "!= operator tests" << std::endl; s2 = "abc123"; - s1.Dump( "s1" ); - s2.Dump( "s2" ); + std::cout << "s1 - " << s1.Str() << std::endl; + std::cout << "s2 - " << s2.Str() << std::endl; + if( s1 != s2 ) std::cout << s1.Str() << " != " << s2.Str() << std::endl; else @@ -284,7 +277,7 @@ int main() std::cout << "s2 = " << s2.Str() << std::endl; s1 = s2.Copy(); - s1.Dump( "s1.Copy() results" ); + std::cout << "s1.Copy() results" << s1.Str() << std::endl; s1 = "0x35"; char hexChar; @@ -299,7 +292,7 @@ int main() std::cout << "CvtHexString [" << s1.Str() << "] converts to [" << s2.Str() << "]" << std::endl; s1.ExtractElement( "aaaa|bbbb|cccc|dddd", '|', 2, 0 ); - s1.Dump( "ExtractElement() " ); + std::cout << "ExtractElement() " << s1.Str() << std::endl; s1 = "123"; s2 = "ABC"; @@ -317,50 +310,52 @@ int main() std::cout << s1.Str() << " s1.Pos('G') = " << s1.Pos( 'G' ) << std::endl; std::cout << s1.Str() << " s1.Pos(\"JKL\") = " << s1.Pos( "JKL" ) << std::endl; - s1.Dump( "Remove( 3, 5 ) before " ); + std::cout << "Remove( 3, 5 ) before " << s1.Str() << std::endl; std::cout << s1.Str() << " s1.Remove( 3, 5 ) = [" << s1.Remove( 3, 5 ).Str() << "]" << std::endl; - s1.Dump( "Remove( 3, 5 ) after " ); + std::cout << "Remove( 3, 5 ) after " << s1.Str() << std::endl; s1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; std::cout << "s1.Remove( 20, 10 ) = [" << s1.Remove( 20, 10 ).Str() << "]" << std::endl; - s1.Dump( "Remove( 20, 10 ) " ); + + std::cout << "Remove( 20, 10 ) - " << s1.Str() << std::endl; + s1.Sprintf( "%d", 12345 ); - s1.Dump( "Sprintf( %d, 12345 ) " ); + std::cout << "Sprintf( %d, 12345 ) " << s1.Str() << std::endl; s1.SetNum( (long) 123456 ); std::cout << "s1.SetNum( 123456 ) = " << s1.Str() << std::endl; s1.Set( "Yet another way to set a string value" ); - s1.Dump( "Set" ); + std::cout << "Set - " << s1.Str() << std::endl; s1 = "ABCABCABZ"; - s1.Dump( "SwapChars( 'A', '9' ) before" ); + std::cout << "SwapChars( 'A', '9' ) before - " << s1.Str() << std::endl; s1.SwapChars( 'A', '9' ); - s1.Dump( "SwapChars( 'A', '9' ) after"); + std::cout << "SwapChars( 'A', '9' ) after - " << s1.Str() << std::endl; s1.ToLowerCase(); - s1.Dump( "ToLowerCase" ); + std::cout << "ToLowerCase - " << s1.Str() << std::endl; s1.ToUpperCase(); - s1.Dump( "ToUpperCase" ); + std::cout << "ToUpperCase - " << s1.Str() << std::endl; s1.ZapChar( '9' ); - s1.Dump( "ZapChar( '9' )" ); + std::cout << "ZapChar( '9' )" << s1.Str() << std::endl; s1.ZapLeadingChar( 'B' ); - s1.Dump( "ZapLeadingChar( 'B' )" ); + std::cout << "ZapLeadingChar( 'B' )" << s1.Str() << std::endl; s1.ZapTrailingChar( 'Z' ); - s1.Dump( "ZapLeadingChar( 'Z' )" ); + std::cout << "ZapLeadingChar( 'Z' ) - " << s1.Str() << std::endl; s1 = "123"; s1.PadLeft( '0', 9 ); - s1.Dump( "s1.PadLeft('0', 9 ) "); + std::cout << "s1.PadLeft('0', 9 ) - " << s1.Str() << std::endl; s1 = "abc"; s1.PadRight( 'Z', 9 ); - s1.Dump( "s1.PadRight('Z', 9 ) "); + std::cout << "s1.PadRight('Z', 9 ) " << s1.Str() << std::endl; xbString sNullString; if( sNullString.IsNull()) diff --git a/src/examples/xb_ex_v4_create_dbf.cpp b/src/examples/xb_ex_v4_create_dbf.cpp index a2aff74..6169213 100755 --- a/src/examples/xb_ex_v4_create_dbf.cpp +++ b/src/examples/xb_ex_v4_create_dbf.cpp @@ -13,6 +13,11 @@ Email Contact: This example demonstrates the creation of a Version IV file and and indices + Creates three files in folder "PROJECT_DATA_DIR" + Address.DBF - Table with all the data + Address.DBT - Memo (variable lenght char field) data + Address.MDX - File with index data + */ #include <xbase.h> @@ -24,18 +29,27 @@ int main() #ifdef XB_DBF4_SUPPORT - xbSchema MyRecord[] = + xbSchema MyAddressBookRecord[] = { - { "FIRSTNAME", XB_CHAR_FLD, 15, 0 }, { "LASTNAME", XB_CHAR_FLD, 20, 0 }, + { "FIRSTNAME", XB_CHAR_FLD, 15, 0 }, + { "COMPANY", XB_CHAR_FLD, 20, 0 }, + { "ADDRESS", XB_CHAR_FLD, 35, 0 }, + { "CITY", XB_CHAR_FLD, 30, 0 }, + { "STATECD", XB_CHAR_FLD, 2, 0 }, + { "ZIPCD", XB_CHAR_FLD, 10, 0 }, + { "BIRTHDATE", XB_DATE_FLD, 8, 0 }, - { "AMOUNT", XB_NUMERIC_FLD, 9, 2 }, - { "RETIRED?", XB_LOGICAL_FLD, 1, 0 }, - { "ZIPCODE", XB_NUMERIC_FLD, 5, 0 }, - { "NUMFLD1", XB_FLOAT_FLD, 12, 2 }, - { "NUMFLD2", XB_FLOAT_FLD, 14, 2 }, + + { "AMOUNT1", XB_NUMERIC_FLD, 9, 2 }, + { "AMOUNT2", XB_FLOAT_FLD, 12, 2 }, + + { "FRIEND?", XB_LOGICAL_FLD, 1, 0 }, + { "FAMILY?", XB_LOGICAL_FLD, 1, 0 }, + { "BUSASSOC?", XB_LOGICAL_FLD, 1, 0 }, + #ifdef XB_MEMO_SUPPORT - { "MEMO1", XB_MEMO_FLD, 10, 0 }, + { "NOTES", XB_MEMO_FLD, 10, 0 }, #endif { "",0,0,0 } }; @@ -46,11 +60,15 @@ int main() xbInt16 iRc; xbDbf * MyDbfFile; + + #ifdef XB_MDX_SUPPORT xbIx *pIx; void *pTag; + #endif // XB_MDX_SUPPORT + MyDbfFile = new xbDbf4( &x ); - if(( iRc = MyDbfFile->CreateTable( "MyV4Table1", "MyV4TableAlias", MyRecord, XB_OVERLAY, XB_MULTI_USER )) != XB_NO_ERROR ) + if(( iRc = MyDbfFile->CreateTable( "Address.DBF", "Address", MyAddressBookRecord, XB_OVERLAY, XB_MULTI_USER )) != XB_NO_ERROR ) x.DisplayError( iRc ); else { @@ -64,11 +82,11 @@ int main() */ // std::cout << "Creating three index tags\n"; - if(( iRc = MyDbfFile->CreateTag( "MDX", "NAME_TAG", "LASTNAME+FIRSTNAME", ".NOT. DELETED()", 0, 0, XB_OVERLAY, &pIx, &pTag )) != XB_NO_ERROR ) + if(( iRc = MyDbfFile->CreateTag( "MDX", "NAME", "LASTNAME+FIRSTNAME", ".NOT. DELETED()", 0, 0, XB_OVERLAY, &pIx, &pTag )) != XB_NO_ERROR ) x.DisplayError( iRc ); - if(( iRc = MyDbfFile->CreateTag( "MDX", "BDDATE_TAG", "BIRTHDATE", "", 0, 0, XB_OVERLAY, &pIx, &pTag )) != XB_NO_ERROR ) + if(( iRc = MyDbfFile->CreateTag( "MDX", "BDDATE", "BIRTHDATE", ".NOT. DELETED()", 0, 0, XB_OVERLAY, &pIx, &pTag )) != XB_NO_ERROR ) x.DisplayError( iRc ); - if(( iRc = MyDbfFile->CreateTag( "MDX", "ZIP_TAG", "ZIPCODE", "", 0, 0, XB_OVERLAY, &pIx, &pTag )) != XB_NO_ERROR ) + if(( iRc = MyDbfFile->CreateTag( "MDX", "COMPANY", "COMPANY+LASTNAME+FIRSTNAME", ".NOT. DELETED()", 0, 0, XB_OVERLAY, &pIx, &pTag )) != XB_NO_ERROR ) x.DisplayError( iRc ); #endif // XB_MDX_SUPPORT diff --git a/src/examples/xb_ex_v4_upd_dbf.cpp b/src/examples/xb_ex_v4_upd_dbf.cpp index 6f68c73..96b6bdf 100755 --- a/src/examples/xb_ex_v4_upd_dbf.cpp +++ b/src/examples/xb_ex_v4_upd_dbf.cpp @@ -11,7 +11,7 @@ Email Contact: XDB-devel@lists.sourceforge.net XDB-users@lists.sourceforge.net - This example demonstrates how to open the DBase III table created by xb_ex_v4_create_dbf + This example demonstrates how to open the DBase IV table created by xb_ex_v4_create_dbf and apply various updates to the table. */ @@ -20,27 +20,11 @@ Email Contact: using namespace xb; -#undef XB_MEMO_FIELDS - int main() { #ifdef XB_DBF4_SUPPORT - xbInt16 fld_FIRSTNAME; - xbInt16 fld_LASTNAME; - xbInt16 fld_BIRTHDATE; - xbInt16 fld_AMOUNT; - xbInt16 fld_RETIRED; - xbInt16 fld_ZIPCODE; - xbInt16 fld_NUMFLD1; - xbInt16 fld_NUMFLD2; - - - #ifdef XB_MEMO_FIELDS - xbInt16 fld_MEMO1; - #endif - /* define the classes */ xbXBase x; /* initialize xbase */ @@ -48,37 +32,30 @@ int main() x.EnableMsgLogging(); x.WriteLogMessage( "Program [xb_ex_v4_upd_dbf] initializing..." ); - - xbDbf *MyTable = new xbDbf4( &x ); /* class for table */ - -#ifdef XB_INDEX_NDX - xbNdx MyIndex1( &MyTable ); /* class for index 1 */ -#endif + xbDbf *MyTable = new xbDbf4( &x ); /* class for DBase V4 table */ xbInt16 iRc = 0; xbInt16 iErrorStop = 0; try{ - if(( iRc = MyTable->Open( "MyV4Table1.DBF" )) != XB_NO_ERROR ){ - iErrorStop = 1; + if(( iRc = MyTable->Open( "Address.DBF" )) != XB_NO_ERROR ){ + iErrorStop = 100; throw iRc; } /* get the field numbers for all the fields in the table */ - - fld_FIRSTNAME = MyTable->GetFieldNo( "FIRSTNAME" ); - fld_LASTNAME = MyTable->GetFieldNo( "LASTNAME" ); - fld_BIRTHDATE = MyTable->GetFieldNo( "BIRTHDATE" ); - fld_AMOUNT = MyTable->GetFieldNo( "AMOUNT" ); - fld_RETIRED = MyTable->GetFieldNo( "RETIRED?" ); - fld_ZIPCODE = MyTable->GetFieldNo( "ZIPCODE" ); - fld_NUMFLD1 = MyTable->GetFieldNo( "NUMFLD1" ); - fld_NUMFLD2 = MyTable->GetFieldNo( "NUMFLD2" ); + xbInt16 iFld_FIRSTNAME = MyTable->GetFieldNo( "FIRSTNAME" ); + xbInt16 iFld_LASTNAME = MyTable->GetFieldNo( "LASTNAME" ); + xbInt16 iFld_BIRTHDATE = MyTable->GetFieldNo( "BIRTHDATE" ); + xbInt16 iFld_AMOUNT1 = MyTable->GetFieldNo( "AMOUNT1" ); + xbInt16 iFld_FRIEND = MyTable->GetFieldNo( "FRIEND?" ); + xbInt16 iFld_ZIPCD = MyTable->GetFieldNo( "ZIPCD" ); + xbInt16 iFld_AMOUNT2 = MyTable->GetFieldNo( "AMOUNT2" ); #ifdef XB_MEMO_FIELDS - fld_MEMO1 = MyTable->GetFieldNo( "MEMO1" ); + zbInt16 iFld_MEMO1 = MyTable->GetFieldNo( "MEMO1" ); #endif @@ -88,187 +65,213 @@ int main() // Blank the record buffer if(( iRc = MyTable->BlankRecord()) != XB_NO_ERROR ){ - iErrorStop = 7; + iErrorStop = 110; throw iRc; } // put field examples - using field numbers - if(( iRc = MyTable->PutField( fld_LASTNAME, "JONES" )) != XB_NO_ERROR ){ - iErrorStop = 8; + if(( iRc = MyTable->PutField( iFld_LASTNAME, "JONES" )) != XB_NO_ERROR ){ + iErrorStop = 120; throw iRc; } + // could also reference by field name (see below) but referencing by number + // is a little bit faster because it doesn't need to look up the number for the field name + // Alternative--> if(( iRc = MyTable->PutField( "LASTNAME", "JONES" )) != XB_NO_ERROR ){ - if(( iRc = MyTable->PutField( fld_FIRSTNAME, "JERRY" )) != XB_NO_ERROR ){ - iErrorStop = 9; + if(( iRc = MyTable->PutField( iFld_FIRSTNAME, "JERRY" )) != XB_NO_ERROR ){ + iErrorStop = 130; throw iRc; } - if(( iRc = MyTable->PutField( fld_AMOUNT, "12.35" )) != XB_NO_ERROR ){ - iErrorStop = 10; + if(( iRc = MyTable->PutField( iFld_AMOUNT1, "12.35" )) != XB_NO_ERROR ){ + iErrorStop = 140; throw iRc; } - if(( iRc = MyTable->PutLogicalField( fld_RETIRED, "Y" )) != XB_NO_ERROR ){ - iErrorStop = 11; + if(( iRc = MyTable->PutLogicalField( iFld_FRIEND, "Y" )) != XB_NO_ERROR ){ + iErrorStop = 150; throw iRc; } - if(( iRc = MyTable->PutField( fld_BIRTHDATE, "19880209" )) != XB_NO_ERROR ){ - iErrorStop = 12; + if(( iRc = MyTable->PutField( iFld_BIRTHDATE, "19880209" )) != XB_NO_ERROR ){ + iErrorStop = 160; throw iRc; } - if(( iRc = MyTable->PutLongField( fld_ZIPCODE, 12345 )) != XB_NO_ERROR ){ - iErrorStop = 13; + if(( iRc = MyTable->PutLongField( iFld_ZIPCD, 12345 )) != XB_NO_ERROR ){ + iErrorStop = 170; throw iRc; } // Append the first record if(( iRc = MyTable->AppendRecord()) != XB_NO_ERROR ){ - iErrorStop = 15; + iErrorStop = 180; + throw iRc; + } + + // Commit the updates + if(( iRc = MyTable->Commit()) != XB_NO_ERROR ){ + iErrorStop = 190; throw iRc; } // Blank the record buffer if(( iRc = MyTable->BlankRecord()) != XB_NO_ERROR ){ - iErrorStop = 16; + iErrorStop = 200; throw iRc; } // put field to the record buffer using field name (slightly less efficient than using field numbers) if(( iRc = MyTable->PutField( "LASTNAME", "FUCKPUTIN" )) != XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 210; throw iRc; } if(( iRc = MyTable->PutField( "FIRSTNAME", "ALBERT" )) != XB_NO_ERROR ){ - iErrorStop = 21; + iErrorStop = 220; throw iRc; } - if(( iRc = MyTable->PutField( "AMOUNT", "987.55" )) != XB_NO_ERROR ){ - iErrorStop = 22; + if(( iRc = MyTable->PutDoubleField( "AMOUNT1", (xbDouble) 987.55 )) != XB_NO_ERROR ){ + iErrorStop = 230; throw iRc; } - if(( iRc = MyTable->PutLogicalField( "RETIRED?", "N" )) != XB_NO_ERROR ){ - iErrorStop = 23; + if(( iRc = MyTable->PutLogicalField( "FRIEND?", "N" )) != XB_NO_ERROR ){ + iErrorStop = 240; throw iRc; } - if(( iRc = MyTable->PutLongField( "ZIPCODE", 44256 )) != XB_NO_ERROR ){ - iErrorStop = 24; + if(( iRc = MyTable->PutLongField( "ZIPCD", 44256 )) != XB_NO_ERROR ){ + iErrorStop = 250; throw iRc; } xbFloat f = (xbFloat) 12345.67; std::cout << f << std::endl; - if(( iRc = MyTable->PutFloatField( fld_NUMFLD1, f )) != XB_NO_ERROR ){ - iErrorStop = 13; + if(( iRc = MyTable->PutFloatField( iFld_AMOUNT2, f )) != XB_NO_ERROR ){ + iErrorStop = 260; throw iRc; } xbDouble d = 76543.21; - if(( iRc = MyTable->PutDoubleField( fld_NUMFLD2, d )) != XB_NO_ERROR ){ - iErrorStop = 14; + if(( iRc = MyTable->PutDoubleField( iFld_AMOUNT1, d )) != XB_NO_ERROR ){ + iErrorStop = 270; throw iRc; } // Append the second record if(( iRc = MyTable->AppendRecord()) != XB_NO_ERROR ){ - iErrorStop = 25; + iErrorStop = 280; + throw iRc; + } + + // Commit the updates + if(( iRc = MyTable->Commit()) != XB_NO_ERROR ){ + iErrorStop = 290; throw iRc; } + // get a field with a field number xbString FirstName; - if(( iRc = MyTable->GetField( fld_FIRSTNAME, FirstName )) < 0 ){ - iErrorStop = 30; + if(( iRc = MyTable->GetField( iFld_FIRSTNAME, FirstName )) < 0 ){ + iErrorStop = 300; throw iRc; } std::cout << "First Name is [" << FirstName.Str() << "]" << std::endl; xbString LastName; if(( iRc = MyTable->GetField( "LASTNAME", LastName )) < 0 ){ - iErrorStop = 31; + iErrorStop = 310; throw iRc; } std::cout << "Last Name is [" << LastName.Str() << "]" << std::endl; xbInt16 iNoOfDecimals; - if(( iRc = MyTable->GetFieldDecimal( "AMOUNT", iNoOfDecimals )) != XB_NO_ERROR ){ - iErrorStop = 32; + if(( iRc = MyTable->GetFieldDecimal( "AMOUNT2", iNoOfDecimals )) != XB_NO_ERROR ){ + iErrorStop = 320; throw iRc; } std::cout << "There are " << iNoOfDecimals << " decimals in the AMOUNT field" << std::endl; xbString FieldName; if(( iRc = MyTable->GetFieldName( 4, FieldName )) != XB_NO_ERROR ){ - iErrorStop = 36; + iErrorStop = 330; throw iRc; } std::cout << "Field #4 name is " << FieldName.Str() << std::endl; - xbString sRetired; - if(( iRc = MyTable->GetLogicalField( "RETIRED?", sRetired )) < 0 ){ - iErrorStop = 38; + xbString sFriend; + if(( iRc = MyTable->GetLogicalField( "FRIEND?", sFriend )) < 0 ){ + iErrorStop = 340; throw iRc; } - std::cout << "Switch value = [" << sRetired.Str() << "]" << std::endl; + std::cout << "Switch value = [" << sFriend.Str() << "]" << std::endl; xbInt32 lZip; if(( iRc = MyTable->GetLongField( "ZIPCODE", lZip )) < 0 ){ - iErrorStop = 39; + iErrorStop = 350; throw iRc; } std::cout << "Long value = [" << lZip << "]" << std::endl; - if(( iRc = MyTable->GetFloatField( fld_NUMFLD1, f )) < 0 ){ - iErrorStop = 41; + if(( iRc = MyTable->GetFloatField( iFld_AMOUNT2, f )) < 0 ){ + iErrorStop = 360; throw iRc; } printf( "Field NUMFLD1 %8.2f\n", f ); - if(( iRc = MyTable->GetDoubleField( fld_NUMFLD2, d )) < 0 ){ - iErrorStop = 42; + if(( iRc = MyTable->GetDoubleField( iFld_AMOUNT1, d )) < 0 ){ + iErrorStop = 370; throw iRc; } printf( "Field NUMFLD2 %8.2f\n", d ); - // Initialize the record buffer in preparation for another record if(( iRc = MyTable->BlankRecord()) != XB_NO_ERROR ){ - iErrorStop = 44; + iErrorStop = 380; throw iRc; } // Append another record (it will be blank) if(( iRc = MyTable->AppendRecord()) != XB_NO_ERROR ){ - iErrorStop = 45; + iErrorStop = 390; throw iRc; }; // mark current record for deletion if(( iRc = MyTable->DeleteRecord()) != XB_NO_ERROR ){ - iErrorStop = 50; + iErrorStop = 400; throw iRc; }; // save current record if(( iRc = MyTable->PutRecord()) != XB_NO_ERROR ){ - iErrorStop = 51; + iErrorStop = 410; throw iRc; } if(( iRc = MyTable->Commit()) != XB_NO_ERROR ){ - iErrorStop = 52; + iErrorStop = 420; throw iRc; } + + // example code to loop through the table + for( xbUInt32 ulTuple = 1; ulTuple <= MyTable->GetRecordCount(); ulTuple++ ){ + if(( iRc = MyTable->GetRecord( ulTuple ) != XB_NO_ERROR )){ + iErrorStop = 430; + throw iRc; + } + // do something with the record here + std::cout << "Tuple = " << MyTable->GetCurRecNo() << std::endl; + } + /* Close database and associated indexes */ if(( iRc = MyTable->Close()) != XB_NO_ERROR ){ - iErrorStop = 53; + iErrorStop = 440; throw iRc; } diff --git a/src/include/xbase.h b/src/include/xbase.h index 33d2dc9..480d716 100755 --- a/src/include/xbase.h +++ b/src/include/xbase.h @@ -58,8 +58,10 @@ Email Contact: #endif #ifdef HAVE_VARARGS_H +#ifndef HAVE_STDARG_H #include <varargs.h> #endif +#endif #ifdef HAVE_WINDOWS_H #include <windows.h> diff --git a/src/include/xbbcd.h b/src/include/xbbcd.h index f94ed01..8c931d3 100755 --- a/src/include/xbbcd.h +++ b/src/include/xbbcd.h @@ -65,8 +65,6 @@ class XBDLLEXPORT xbBcd { // const unsigned char * GetBcd() const; void StringToBcd( const xbString &sStringIn ); -// void StringToBcdOld( const xbString &sStringIn ); - xbInt16 Compare( const xbBcd &bcdIn ); xbInt16 Compare( xbDouble d ); diff --git a/src/include/xbconfig.h.in b/src/include/xbconfig.h.in index b749ff2..969b761 100755 --- a/src/include/xbconfig.h.in +++ b/src/include/xbconfig.h.in @@ -98,7 +98,7 @@ #cmakedefine XB_NDX_SUPPORT #cmakedefine XB_MDX_SUPPORT #cmakedefine XB_SQL_SUPPORT -#cmakedefine XB_NDXINF_SUPPORT +#cmakedefine XB_INF_SUPPORT #cmakedefine XB_FILTER_SUPPORT #cmakedefine XB_UTILS_SUPPORT diff --git a/src/include/xbdbf.h b/src/include/xbdbf.h index 710dd14..c0842cb 100755 --- a/src/include/xbdbf.h +++ b/src/include/xbdbf.h @@ -179,17 +179,20 @@ class XBDLLEXPORT xbDbf : public xbFile { virtual xbInt16 GetNextRecord (); virtual xbInt16 GetNextRecord ( xbInt16 iOption ); virtual xbInt16 GetNextRecord ( xbInt16 iOption, xbUInt32 ulStartRec ); - virtual xbInt32 GetPhysicalIxCnt () const; virtual xbInt16 GetPrevRecord (); virtual xbInt16 GetPrevRecord ( xbInt16 iOption ); virtual xbInt16 GetRecord ( xbUInt32 ulRecNo ); + + virtual xbUInt32 GetRecordCount (); virtual xbInt16 GetRecordCnt ( xbUInt32 & ulRecCnt ); + virtual char * GetRecordBuf ( xbInt16 iOpt = 0 ) const; virtual xbUInt16 GetRecordLen () const; virtual const xbString &GetTblAlias() const; virtual xbInt16 GetVersion () const = 0; virtual xbXBase *GetXbasePtr () const; // return xbase pointer + virtual xbBool MemoFieldsExist () const; virtual xbInt16 Open ( const xbString &sTableName ); @@ -203,6 +206,7 @@ class XBDLLEXPORT xbDbf : public xbFile { virtual xbInt16 PutRecord ( xbUInt32 ulRecNo ); virtual xbInt16 ReadHeader ( xbInt16 iFilePositionOption, xbInt16 iReadOption ); virtual xbInt16 RecordDeleted ( xbInt16 iOpt = 0 ) const; + virtual xbInt16 Rename ( const xbString sNewName ) = 0; virtual xbInt16 SetAutoCommit ( xbInt16 iAutoCommit ); @@ -316,6 +320,7 @@ class XBDLLEXPORT xbDbf : public xbFile { #ifdef XB_INDEX_SUPPORT + virtual xbInt16 CheckTagIntegrity( xbInt16 iTagOpt, xbInt16 iOutputOpt ); virtual xbInt16 CloseIndexFile( xbIx *pIx ); virtual xbInt16 CreateTag( const xbString &sIxType, const xbString &sName, const xbString &sKey, const xbString &sFilter, xbInt16 iDescending, xbInt16 iUnique, xbInt16 iOverLay, xbIx **xbIxOut, void **vpTagOut ); @@ -326,30 +331,29 @@ class XBDLLEXPORT xbDbf : public xbFile { virtual xbInt16 Find( xbDouble &dKey ); virtual xbIx *GetCurIx() const; virtual void *GetCurTag() const; - + virtual xbInt16 GetFirstKey(); virtual xbInt16 GetNextKey(); virtual xbInt16 GetPrevKey(); virtual xbInt16 GetLastKey(); - + virtual const xbString &GetCurIxType() const; virtual const xbString &GetCurTagName() const; virtual xbIxList *GetIxList() const; + virtual xbInt32 GetPhysicalIxCnt () const; xbLinkListNode<xbTag *> *GetTagList () const; + virtual xbInt16 OpenIndex( const xbString &sIxType, const xbString &sIndexName ); + virtual xbInt16 Reindex( xbInt16 iTagOpt ); virtual xbInt16 SetCurTag( const xbString &sTagName ); virtual void SetCurTag( const xbString &sIxType, xbIx *pIx, void *vpTag ); - #ifdef XB_DEBUG_SUPPORT - virtual xbInt16 CheckTagIntegrity( xbInt16 iTagOpt, xbInt16 iOutputOpt ); - virtual xbInt16 Reindex( xbInt16 iTagOpt ); - #endif // XB_DEBUG_SUPPORT #endif // XB_INDEX_SUPPORT - #ifdef XB_NDXINF_SUPPORT + #ifdef XB_INF_SUPPORT virtual xbInt16 AssociateIndex( const xbString &sType, const xbString &sName, xbInt16 iOption ); - xbLinkListNode<xbString> *GetNdxInfList() const; - #endif // XB_NDXINF_SUPPORT + xbLinkListNode<xbString> *GetInfList() const; + #endif // XB_INF_SUPPORT //#ifdef XB_MDX_SUPPORT //virtual xbInt16 GetCreateMdxBlockSize() const; @@ -365,12 +369,14 @@ class XBDLLEXPORT xbDbf : public xbFile { xbInt16 AddIndex( xbIx *ix, const xbString &sFmt ); void ClearTagList(); - virtual xbInt16 GetNdxInfFileName( xbString &sNdxIdxFileName ); xbInt16 RemoveIndex( xbIx * ix ); void UpdateSchemaIxFlag( xbInt16 iFldNo, unsigned char cVal ); virtual xbInt16 UpdateTagList (); - #endif + #endif // XB_INDEX_SUPPORT + #ifdef XB_INF_SUPPORT + virtual xbInt16 GetInfFileName( xbString &sNdxIdxFileName ); + #endif // XB_INF_SUPPORT #ifdef XB_LOCKING_SUPPORT @@ -384,11 +390,11 @@ class XBDLLEXPORT xbDbf : public xbFile { xbUInt32 ulCreateMemoBlockSize; // blocksize to use when creating dbt file #endif - #ifdef XB_NDXINF_SUPPORT - virtual xbInt16 DeleteNdxInfData(); - virtual xbInt16 LoadNdxInfData(); - virtual xbInt16 SaveNdxInfData(); - #endif // XB_NDXINF_SUPPORT + #ifdef XB_INF_SUPPORT + virtual xbInt16 DeleteInfData(); + virtual xbInt16 LoadInfData(); + virtual xbInt16 SaveInfData(); + #endif // XB_INF_SUPPORT /* #ifdef XB_MDX_SUPPORT @@ -454,9 +460,6 @@ class XBDLLEXPORT xbDbf : public xbFile { #ifdef XB_INDEX_SUPPORT xbIxList *ixList; // pointer to a list of indices associated with the table -// #ifdef XB_MDX_SUPPORT -// xbIx *ixMdx; // pointer to production multi-tag index file -// #endif xbIx *pCurIx; // Pointer to current index class void *vpCurIxTag; // Pointer to current tag xbString sCurIxType; // Current index type @@ -464,9 +467,9 @@ class XBDLLEXPORT xbDbf : public xbFile { #endif // XB_INDEX_SUPPORT -#ifdef XB_NDXINF_SUPPORT - xbLinkList<xbString> llNdxInfData; // linked list of strings containing ndx file entries -#endif // XB_NDXINF_SUPPORT +#ifdef XB_INF_SUPPORT + xbLinkList<xbString> llInfData; // linked list of strings containing ndx file entries +#endif // XB_INF_SUPPORT }; @@ -487,6 +490,7 @@ class XBDLLEXPORT xbDbf3 : public xbDbf { virtual xbInt16 CreateTable ( const xbString &sTableName, const xbString &sAlias, xbSchema *, xbInt16 iOverlay, xbInt16 iShareMode ); virtual xbInt16 GetVersion () const; virtual xbInt16 Open ( const xbString &sTableName, const xbString &sAlias, xbInt16 iOpenMode, xbInt16 iShareMode ); + virtual xbInt16 Rename ( const xbString sNewName ); #ifdef XB_MEMO_SUPPORT virtual xbInt16 SetCreateMemoBlockSize( xbUInt32 iBlockSize ); @@ -518,6 +522,7 @@ class XBDLLEXPORT xbDbf4 : public xbDbf { virtual xbInt16 CreateTable ( const xbString &sTableName, const xbString &sAlias, xbSchema *, xbInt16 iOverlay, xbInt16 iShareMode ); virtual xbInt16 GetVersion () const; virtual xbInt16 Open ( const xbString &sTableName, const xbString &sAlias, xbInt16 iOpenMode, xbInt16 iShareMode ); + virtual xbInt16 Rename ( const xbString sNewName ); #ifdef XB_MEMO_SUPPORT virtual xbInt16 SetCreateMemoBlockSize( xbUInt32 iBlockSize ); diff --git a/src/include/xbfile.h b/src/include/xbfile.h index a636632..ffbda06 100755 --- a/src/include/xbfile.h +++ b/src/include/xbfile.h @@ -151,7 +151,6 @@ class XBDLLEXPORT xbFile : public xbSsv { xbInt16 xbRemove (); xbInt16 xbRename ( const xbString &sOldName, const xbString &sNewName ); - xbInt16 xbRename ( const xbString &sOldName, const xbString &sNewName, xbInt16 iOption ); void xbRewind (); xbInt16 xbTruncate ( xbInt64 llSize ); diff --git a/src/include/xbmemo.h b/src/include/xbmemo.h index e86a65c..ad9aac2 100755 --- a/src/include/xbmemo.h +++ b/src/include/xbmemo.h @@ -59,30 +59,32 @@ class XBDLLEXPORT xbMemo : public xbFile { /* virtual methods */ virtual ~xbMemo(); - virtual xbInt16 Abort () = 0; - virtual xbInt16 CloseMemoFile (); - virtual xbInt16 Commit () = 0; + virtual xbInt16 Abort () = 0; + virtual xbInt16 CloseMemoFile (); + virtual xbInt16 Commit () = 0; + virtual xbInt16 CreateMemoFile () = 0; + + virtual xbInt16 DumpMemoHeader () = 0; - #ifdef XB_LOCKING_SUPPORT - virtual xbInt16 LockMemo ( xbInt16 iLockFunction ); - virtual xbBool GetMemoLocked () const; - #endif - /* pure virtual methods */ - virtual xbInt16 CreateMemoFile () = 0; - - virtual xbInt16 GetMemoField ( xbInt16 iFieldNo, xbString &sMemoData ) = 0; - virtual xbInt16 GetMemoFieldLen( xbInt16 iFieldNo, xbUInt32 &ulMemoFieldLen ) = 0; - virtual xbInt16 OpenMemoFile () = 0; - virtual xbInt16 GetMemoFileType(); - virtual xbInt16 PackMemo ( void (*memoStatusFunc)(xbUInt32 ulItemNum, xbUInt32 ulNumItems)) = 0; - virtual xbInt16 UpdateMemoField( xbInt16 iFieldNo, const xbString &sMemoData ) = 0; + virtual xbInt16 GetMemoField ( xbInt16 iFieldNo, xbString &sMemoData ) = 0; + virtual xbInt16 GetMemoFieldLen ( xbInt16 iFieldNo, xbUInt32 &ulMemoFieldLen ) = 0; + virtual xbInt16 OpenMemoFile () = 0; + virtual xbInt16 GetMemoFileType (); + virtual xbInt16 PackMemo ( void (*memoStatusFunc)(xbUInt32 ulItemNum, xbUInt32 ulNumItems)) = 0; + virtual xbInt16 UpdateMemoField ( xbInt16 iFieldNo, const xbString &sMemoData ) = 0; #ifdef XB_DEBUG_SUPPORT virtual xbInt16 DumpMemoFreeChain() = 0; - virtual xbInt16 DumpMemoHeader () = 0; #endif + #ifdef XB_LOCKING_SUPPORT + virtual xbInt16 LockMemo ( xbInt16 iLockFunction ); + virtual xbBool GetMemoLocked () const; + #endif + + + // *********** FIXME ************* // next two methods should be protected but are called in the xb_test_xxxx programs testing routines // so for now, they are kept as public @@ -135,6 +137,7 @@ class XBDLLEXPORT xbMemoDbt3 : public xbMemo { virtual xbInt16 Abort (); virtual xbInt16 Commit (); virtual xbInt16 CreateMemoFile (); + virtual xbInt16 DumpMemoHeader (); virtual xbInt16 GetMemoField ( xbInt16 iFieldNo, xbString &sMemoData ); virtual xbInt16 GetMemoFieldLen( xbInt16 iFieldNo, xbUInt32 &ulMemoFieldLen ); virtual xbInt16 OpenMemoFile (); @@ -143,7 +146,6 @@ class XBDLLEXPORT xbMemoDbt3 : public xbMemo { #ifdef XB_DEBUG_SUPPORT virtual xbInt16 DumpMemoFreeChain(); - virtual xbInt16 DumpMemoHeader (); #endif protected: @@ -176,7 +178,7 @@ class XBDLLEXPORT xbMemoDbt4 : public xbMemo { virtual xbInt16 Abort (); virtual xbInt16 Commit (); virtual xbInt16 CreateMemoFile (); - + virtual xbInt16 DumpMemoHeader (); virtual xbInt16 GetMemoField ( xbInt16 iFieldNo, xbString &sMemoData ); virtual xbInt16 GetMemoFieldLen ( xbInt16 iFieldNo, xbUInt32 &ulMemoFieldLen ); virtual xbInt16 GetMemoFieldLen ( xbInt16 iFieldNo, xbUInt32 &ulMemoFieldLen, xbUInt32 &lBlockNo ); @@ -186,7 +188,6 @@ class XBDLLEXPORT xbMemoDbt4 : public xbMemo { #ifdef XB_DEBUG_SUPPORT virtual xbInt16 DumpMemoFreeChain (); - virtual xbInt16 DumpMemoHeader (); virtual xbInt16 DumpMemoInternals (); virtual xbInt16 ReadFreeBlockHeader( xbUInt32 ulBlockNo, xbUInt32 &ulNextBlock, xbUInt32 &ulFreeBlockCnt ); #endif diff --git a/src/include/xbsql.h b/src/include/xbsql.h index 3869995..653096c 100755 --- a/src/include/xbsql.h +++ b/src/include/xbsql.h @@ -29,6 +29,19 @@ This class manages a list of open tables, open indices are connected to the open namespace xb{ +struct XBDLLEXPORT xbSqlFld{ + char cType; // F - Database field + // L - Literal + // E - Expression + xbInt16 iFldNo; // Field number if db field + xbExp * pExp; // If cType=E, pointer to parsed expression + xbString sFldAlias; // Alias name for query display + xbSqlFld * Next; // Next field in list +}; + + + + class XBDLLEXPORT xbSql : public xbSsv { public: // xbSql(); @@ -42,18 +55,21 @@ class XBDLLEXPORT xbSql : public xbSsv { private: + xbInt16 SqlAlterTable( const xbString &sCmdLine ); xbInt16 SqlCreateTable( const xbString &sCmdLine ); - xbInt16 SqlCreateIndex( const xbString &sCmdLine ); - - xbInt16 SqlDropIndex( const xbString &sCmdLine ); + xbInt16 SqlDelete( const xbString &sCmdLine ); xbInt16 SqlDropTable( const xbString &sCmdLine ); + #ifdef XB_INDEX_SUPPORT + xbInt16 SqlCreateIndex( const xbString &sCmdLine ); + xbInt16 SqlDropIndex( const xbString &sCmdLine ); + #endif // XB_INDEX_SUPPORT // xbInt16 SqlCreateView( const xbString &sCmdLine ); // xbInt16 SqlDropView( const xbString &sCmdLine ); // xbInt16 SqlUpdate( const xbString &sCmdLine ); -// xbInt16 SqlSelect( const xbString &sCmdLine ); - + xbInt16 SqlSelect( const xbString &sCmdLine ); + void SqlHelp() const; xbInt16 SqlInsert( const xbString &sCmLine ); xbInt16 SqlSet( const xbString &sCmdLine ); diff --git a/src/include/xbssv.h b/src/include/xbssv.h index 80da2d0..b9345fd 100755 --- a/src/include/xbssv.h +++ b/src/include/xbssv.h @@ -70,12 +70,9 @@ class XBDLLEXPORT xbSsv{ void SetDataDirectory ( const xbString &sDataDirectory ); void SetDefaultDateFormat ( const xbString &sDefaultDateFormat ); - xbBool BitSet ( unsigned char c, xbInt16 iBitNo ) const; - #ifdef XB_DEBUG_SUPPORT void BitDump ( unsigned char c ) const; void BitDump ( char c ) const; - #endif xbBool GetDefaultAutoCommit () const; void SetDefaultAutoCommit ( xbBool bDefaultAutoCommit ); diff --git a/src/include/xbstring.h b/src/include/xbstring.h index c2f15cd..f5a22da 100755 --- a/src/include/xbstring.h +++ b/src/include/xbstring.h @@ -95,8 +95,8 @@ class XBDLLEXPORT xbString { xbString &Append(char c); xbString &Assign(const char *srcStr, xbUInt32 lStartPos, xbUInt32 lCopyLen ); xbString &Assign(const char *srcStr, xbUInt32 lStartPos ); - xbString &Assign(const xbString &s, xbUInt32 pos, xbUInt32 n ); - xbString &Assign(const xbString &s, xbUInt32 n ); + xbString &Assign(const xbString &s, xbUInt32 pos, xbUInt32 lCopyLen ); + xbString &Assign(const xbString &s, xbUInt32 lCopyLen ); xbString Copy() const; xbUInt32 CountChar( char c ) const; @@ -136,6 +136,7 @@ class XBDLLEXPORT xbString { xbString &PutAt(xbUInt32 ulPos, char c); xbString &Remove( xbUInt32 ulPos, xbUInt32 ulN ); + xbString &Replace( const char *sReplace, const char *sReplaceWith, xbInt16 iOpt = 0 ); xbString &Resize( xbUInt32 lSize ); xbString &Rtrim(); diff --git a/src/include/xbtblmgr.h b/src/include/xbtblmgr.h index d551002..150026b 100755 --- a/src/include/xbtblmgr.h +++ b/src/include/xbtblmgr.h @@ -39,14 +39,15 @@ class XBDLLEXPORT xbTblMgr : public xbSsv { public: xbTblMgr(); ~xbTblMgr(); - xbInt16 AddTblToTblList ( xbDbf *d, const xbString &sTblName ); - xbInt16 AddTblToTblList ( xbDbf *d, const xbString &sTblName, const xbString &sTblAlias ); - xbInt16 DisplayTableList () const; - xbDbf * GetDbfPtr ( const xbString &sTblAlias ) const; - xbDbf * GetDbfPtr ( xbInt16 sItemNo ) const; - xbInt16 GetOpenTableCount () const; - xbInt16 RemoveTblFromTblList ( const xbString &sTblAlias ); - xbInt16 RemoveTblFromTblList ( xbDbf *d ); + xbInt16 AddTblToTblList ( xbDbf *d, const xbString &sTblName ); + xbInt16 AddTblToTblList ( xbDbf *d, const xbString &sTblName, const xbString &sTblAlias ); + xbInt16 DisplayTableList () const; + xbDbf * GetDbfPtr ( const xbString &sTblAlias ) const; + xbDbf * GetDbfPtr ( xbInt16 sItemNo ) const; + xbTblList * GetTblListEntry ( xbDbf *d ); + xbInt16 GetOpenTableCount () const; + xbInt16 RemoveTblFromTblList ( const xbString &sTblAlias ); + xbInt16 RemoveTblFromTblList ( xbDbf *d ); protected: diff --git a/src/sql/xbalttbl.cpp b/src/sql/xbalttbl.cpp new file mode 100755 index 0000000..576eab7 --- /dev/null +++ b/src/sql/xbalttbl.cpp @@ -0,0 +1,125 @@ +/* xbslttbl.cpp + +XBase64 Software Library + +Copyright (c) 1997,2003,2014,2022 Gary A Kunkel + +The xb64 software library is covered under the terms of the GPL Version 3, 2007 license. + +Email Contact: + + XDB-devel@lists.sourceforge.net + XDB-users@lists.sourceforge.net + +*/ + +#include "xbase.h" + +#ifdef XB_SQL_SUPPORT + +namespace xb{ + + +/***********************************************************************/ +xbInt16 xbSql::SqlAlterTable( const xbString &sCmdLine ){ + + // expected format: + // ALTER TABLE tablename.DBF RENAME TO newtablename.DBF + + + xbInt16 iRc = 0; + xbInt16 iErrorStop = 0; + xbString sTableName = ""; + xbUInt32 ulPos = 0; + xbString sCmd = sCmdLine; + xbString sNode = ""; + + xbString sSrcTbl; + xbString sTrgTbl; + xbDbf * dbf = NULL; + + try{ + +// std::cout << "xbSql::SqlAlterTable( " << sCmdLine.Str() << " )\n"; + + // drop off the first node "DROP" + ulPos = sCmd.Pos( ' ' ); + sCmd.Ltrunc( ulPos ); + sCmd.Ltrim(); + + // drop off the second node "TABLE" + ulPos = sCmd.Pos( ' ' ); + sCmd.Ltrunc( ulPos ); + sCmd.Ltrim(); + + // pull off the source table + sSrcTbl.ExtractElement( sCmd, ' ', 1, 0 ); + sSrcTbl.Trim(); + + // pull off the action + sNode.ExtractElement( sCmd, ' ', 2, 0 ); + sNode.Trim(); + sNode.ToUpperCase(); + if( sNode != "RENAME" ){ + iErrorStop = 100; + iRc = XB_SYNTAX_ERROR; + throw iRc; + } + + // pull off "TO" + sNode.ExtractElement( sCmd, ' ', 3, 0 ); + sNode.Trim(); + sNode.ToUpperCase(); + if( sNode != "TO" ){ + iErrorStop = 110; + iRc = XB_SYNTAX_ERROR; + throw iRc; + } + + sTrgTbl.ExtractElement( sCmd, ' ', 4, 0 ); + sTrgTbl.Trim(); + + std::cout << "source table name = " << sSrcTbl.Str() << "\n"; +// std::cout << "target table name = " << sTrgTbl.Str() << "\n"; + + // if not open, attempt to open it + dbf = xbase->GetDbfPtr( sSrcTbl ); + + if( dbf ) + std::cout << "dbf valued\n"; + else + std::cout << "dbf not valued\n"; + + if( !dbf ){ + if(( iRc = xbase->OpenHighestVersion( sSrcTbl, "", &dbf )) != XB_NO_ERROR ){ + iErrorStop = 120; + throw iRc; + } + } + if( !dbf ){ + iErrorStop = 130; + iRc = XB_DBF_FILE_NOT_OPEN; + throw iRc; + } + + if(( iRc = dbf->Rename( sTrgTbl )) != XB_NO_ERROR ){ + iErrorStop = 140; + throw iRc; + } + + } + + catch (xbInt16 iRc ){ + xbString sMsg; + sMsg.Sprintf( "xbSql::SqlAlterTable() Exception Caught. Error Stop = [%d] rc = [%d] table = [%s]", iErrorStop, iRc, sTableName.Str() ); + xbase->WriteLogMessage( sMsg.Str() ); + xbase->WriteLogMessage( GetErrorMessage( iRc )); + } + + return iRc; +} + +/***********************************************************************/ +} /* namespace */ +#endif /* XB_SQL_SUPPORT */ + diff --git a/src/sql/xbcrix.cpp b/src/sql/xbcrix.cpp index b24782e..8dc6f62 100755 --- a/src/sql/xbcrix.cpp +++ b/src/sql/xbcrix.cpp @@ -21,6 +21,7 @@ namespace xb{ /***********************************************************************/ +#ifdef XB_INDEX_SUPPORT xbInt16 xbSql::SqlCreateIndex( const xbString &sCmdLine ){ // std::cout << "CREATE INDEX " << sCmdLine << std::endl; @@ -68,8 +69,6 @@ xbInt16 xbSql::SqlCreateIndex( const xbString &sCmdLine ){ try{ - // std::cout << "xbSql::CreateIx()\n" ; - // drop off the first node ulPos = sCmd.Pos( ' ' ); sCmd.Ltrunc( ulPos ); @@ -104,7 +103,7 @@ xbInt16 xbSql::SqlCreateIndex( const xbString &sCmdLine ){ if( sIxType == "" ){ if(( iRc = uda.GetTokenForKey( "IXTYPE", sIxType )) != XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 100; throw iRc; } } @@ -114,7 +113,7 @@ xbInt16 xbSql::SqlCreateIndex( const xbString &sCmdLine ){ xbFile f( xbase ); f.SetFileName( sIxName ); if( f.FileExists()){ - iErrorStop = 30; + iErrorStop = 110; iRc = XB_FILE_EXISTS; throw iRc; } @@ -143,7 +142,7 @@ xbInt16 xbSql::SqlCreateIndex( const xbString &sCmdLine ){ dbf = xbase->GetDbfPtr( fDbf.GetFqFileName()); if( !dbf ){ if(( iRc = xbase->OpenHighestVersion( sTableName, "", &dbf )) != XB_NO_ERROR ){ - iErrorStop = 40; + iErrorStop = 120; throw iRc; } } @@ -154,13 +153,14 @@ xbInt16 xbSql::SqlCreateIndex( const xbString &sCmdLine ){ } sCmd.Ltrunc( ulPos ); - // std::cout << "cp1 ulPos = " << ulPos << " scmd = " << sCmd << "\n"; + std::cout << "cp1 ulPos = " << ulPos << " sCmd = [" << sCmd << "]\n"; //ulPos = sCmd.GetLastPos( ')' ); xbString sKeyExpression; xbBool bDone = xbFalse; xbUInt32 lPos = 1; xbInt16 iParenCtr = 0; + while( !bDone && lPos < sCmd.Len()){ if( sCmd[lPos] == '(' ){ iParenCtr++; @@ -172,19 +172,21 @@ xbInt16 xbSql::SqlCreateIndex( const xbString &sCmdLine ){ } else { bDone = xbTrue; } - } else if( sCmd[lPos] == ',' ){ + } else if( sCmd[lPos] == ',' && iParenCtr == 0 ){ sKeyExpression.Append( '+' ); } else if( sCmd[lPos] != ' ' ){ sKeyExpression.Append( sCmd[lPos] ); } lPos++; } -// std::cout << "Key Expression =[" << sKeyExpression << "]\n"; + + std::cout << "Key Expression =[" << sKeyExpression << "]\n"; + sCmd.Ltrunc( lPos ); sCmd.Trim(); xbBool bDesc = xbFalse; -// std::cout << "sCmd - looking for DESC [" << sCmd << "]\n"; + // std::cout << "sCmd - looking for DESC [" << sCmd << "]\n"; if( sCmd.Len() > 4 ){ sNode = sCmd; sNode.ToUpperCase(); @@ -193,11 +195,12 @@ xbInt16 xbSql::SqlCreateIndex( const xbString &sCmdLine ){ bDesc = xbTrue; sCmd.Ltrunc( 4 ); sCmd.Trim(); - // std::cout << "Descending\n"; + std::cout << "Descending\n"; } } -// std::cout << "sCmd - looking for FILTER stuff [" << sCmd << "]\n"; + + // std::cout << "sCmd - looking for FILTER stuff [" << sCmd << "]\n"; xbString sFilter; if( sCmd.Len() > 6 ){ sNode = sCmd; @@ -205,29 +208,29 @@ xbInt16 xbSql::SqlCreateIndex( const xbString &sCmdLine ){ ulPos = sNode.Pos( "FILTER" ); if( ulPos > 0 ){ sFilter = sCmd; - sFilter.Ltrunc( ulPos + 7 ); + sFilter.Ltrunc( ulPos + 6 ); sFilter.Trim(); } } -// std::cout << "sCmd - FILTER = [" << sFilter << "]\n"; + // std::cout << "sCmd - FILTER = [" << sFilter << "]\n"; #ifdef XB_LOCKING_SUPPORT if(( iRc = dbf->LockTable( XB_LOCK )) != XB_NO_ERROR ){ - iErrorStop = 60; + iErrorStop = 130; throw iRc; } #endif // XB_LOCKING_SUPPORT -// std::cout << "SqlCreateIndex() - ixtype = " << sIxType << "\n"; + // std::cout << "SqlCreateIndex() - ixtype = " << sIxType << "\n"; xbIx *pIx; void *vpTag; if(( iRc = dbf->CreateTag( sIxType, sIxName, sKeyExpression, sFilter, bDesc, bUnique, xbFalse, &pIx, &vpTag )) != XB_NO_ERROR ){ - iErrorStop = 70; + iErrorStop = 140; throw iRc; } -// std::cout << "SqlCreateIndex() - back from tag create\n"; + // std::cout << "SqlCreateIndex() - back from tag create\n"; #ifdef XB_NDX_SUPPORT if( sIxType == "NDX"){ sCmd.Ltrunc( ulPos ); @@ -236,20 +239,27 @@ xbInt16 xbSql::SqlCreateIndex( const xbString &sCmdLine ){ sCmd.ToUpperCase(); if( sCmd.Pos( "ASSOCIATE" )){ if(( iRc = dbf->AssociateIndex( "NDX", sIxName, 0 )) != XB_NO_ERROR ){ - iErrorStop = 80; + iErrorStop = 150; throw iRc; } } } } - if( sIxType == "NDX"){ - if(( iRc = pIx->Reindex( &vpTag )) != XB_NO_ERROR ){ - iErrorStop = 100; - throw iRc; - } - } +// if( sIxType == "NDX"){ +// if(( iRc = pIx->Reindex( &vpTag )) != XB_NO_ERROR ){ +// iErrorStop = 160; +// throw iRc; +// } +// } #endif // XB_NDX_SUPPORT + + if(( iRc = pIx->Reindex( &vpTag )) != XB_NO_ERROR ){ + iErrorStop = 160; + throw iRc; + } + + #ifdef XB_LOCKING_SUPPORT if(( iRc = dbf->LockTable( XB_UNLOCK )) != XB_NO_ERROR ){ iErrorStop = 140; @@ -272,7 +282,7 @@ xbInt16 xbSql::SqlCreateIndex( const xbString &sCmdLine ){ return iRc; } - +#endif // XB_INDEX_SUPPORT /***********************************************************************/ } /* namespace */ #endif /* XB_SQL_SUPPORT */ diff --git a/src/sql/xbcrtbl.cpp b/src/sql/xbcrtbl.cpp index 4193d01..7f6b8fa 100755 --- a/src/sql/xbcrtbl.cpp +++ b/src/sql/xbcrtbl.cpp @@ -225,7 +225,7 @@ xbInt16 xbSql::SqlCreateTable( const xbString &sCmdLine ){ xbDbf * dbf = NULL; #ifdef XB_DBF4_SUPPORT dbf = new xbDbf4( xbase ); - #elif XB_DBF3_SUPPORT + #elif defined (XB_DBF3_SUPPORT) dbf = new xbDbf3( xbase ); #endif if(( iRc = dbf->CreateTable( sTableName, "", schema, 0, XB_MULTI_USER )) != XB_NO_ERROR ){ diff --git a/src/sql/xbdelete.cpp b/src/sql/xbdelete.cpp new file mode 100755 index 0000000..157b281 --- /dev/null +++ b/src/sql/xbdelete.cpp @@ -0,0 +1,148 @@ +/* xbdelete.cpp + +XBase64 Software Library + +Copyright (c) 1997,2003,2014,2022 Gary A Kunkel + +The xb64 software library is covered under the terms of the GPL Version 3, 2007 license. + +Email Contact: + + XDB-devel@lists.sourceforge.net + XDB-users@lists.sourceforge.net + +*/ + +#include "xbase.h" + +#ifdef XB_SQL_SUPPORT + +namespace xb{ + + +/***********************************************************************/ +xbInt16 xbSql::SqlDelete( const xbString &sCmdLine ){ + + // expected format: + // DELETE FROM tablename.DBF [WHERE expression] + + + xbInt16 iRc = 0; + xbInt16 iRc2 = 0; + xbInt16 iErrorStop = 0; + xbString sTableName = ""; + xbUInt32 ulPos = 0; + xbString sCmd = sCmdLine; + xbString sNode = ""; + xbString sFilter; + xbInt16 iDelOpt = 0; + + xbString sTable; + xbDbf * dbf = NULL; + + try{ + +// std::cout << "xbSql::SqlDelete( " << sCmdLine.Str() << " )\n"; + + sNode.ExtractElement( sCmd, ' ', 1, 0 ); + sNode.Trim(); + sNode.ToUpperCase(); + if( sNode == "UNDELETE" ) + iDelOpt = 1; + + // pull off the action + sNode.ExtractElement( sCmd, ' ', 2, 0 ); + sNode.Trim(); + sNode.ToUpperCase(); + if( sNode != "FROM" ){ + iErrorStop = 100; + iRc = XB_SYNTAX_ERROR; + throw iRc; + } + + // pull off the table name + sTable.ExtractElement( sCmd, ' ', 3, 0 ); + sTable.Trim(); + + // pull off the "WHERE" statement if it exists + sNode.ExtractElement( sCmd, ' ', 4, 0 ); + sNode.Trim(); + sNode.ToUpperCase(); + if( sNode == "WHERE" ){ + ulPos = sCmd.Pos( "WHERE" ); + sFilter = sCmd; + sFilter.Ltrunc( ulPos + 5 ); + } + + // if not open, attempt to open it + dbf = xbase->GetDbfPtr( sTable ); + if( !dbf ){ + if(( iRc = xbase->OpenHighestVersion( sTable, "", &dbf )) != XB_NO_ERROR ){ + iErrorStop = 110; + throw iRc; + } + } + if( !dbf ){ + iErrorStop = 120; + iRc = XB_DBF_FILE_NOT_OPEN; + throw iRc; + } + + if( sFilter == "" ){ + if(( iRc = dbf->DeleteAll( iDelOpt )) != XB_NO_ERROR ){ + iErrorStop = 130; + throw iRc; + } + } else { + + xbFilter f( dbf->GetXbasePtr(), dbf ); + if(( iRc = f.Set( sFilter )) != XB_NO_ERROR ){ + iErrorStop = 150; + throw iRc; + } + + iRc2 = f.GetFirstRecord( XB_ALL_RECS ); + while( iRc2 == XB_NO_ERROR ){ + if( iDelOpt == 0 ){ + if( !dbf->RecordDeleted()){ + if(( iRc = dbf->DeleteRecord()) != XB_NO_ERROR ){ + iErrorStop = 160; + throw iRc; + } + if(( iRc = dbf->Commit()) != XB_NO_ERROR ){ + iErrorStop = 170; + throw iRc; + } + } + + } else { // undelete + if( dbf->RecordDeleted()){ + if(( iRc = dbf->UndeleteRecord()) != XB_NO_ERROR ){ + iErrorStop = 180; + throw iRc; + } + if(( iRc = dbf->Commit()) != XB_NO_ERROR ){ + iErrorStop = 190; + throw iRc; + } + } + } + iRc2 = f.GetNextRecord(); + } + } + } + + catch (xbInt16 iRc ){ + xbString sMsg; + sMsg.Sprintf( "xbSql::SqlDropTable() Exception Caught. Error Stop = [%d] rc = [%d] table = [%s]", iErrorStop, iRc, sTableName.Str() ); + xbase->WriteLogMessage( sMsg.Str() ); + xbase->WriteLogMessage( GetErrorMessage( iRc )); + } + + return iRc; +} + +/***********************************************************************/ +} /* namespace */ +#endif /* XB_SQL_SUPPORT */ + diff --git a/src/sql/xbdrpix.cpp b/src/sql/xbdrpix.cpp index 9e3bc3b..2815264 100755 --- a/src/sql/xbdrpix.cpp +++ b/src/sql/xbdrpix.cpp @@ -19,7 +19,7 @@ Email Contact: namespace xb{ - +#ifdef XB_INDEX_SUPPORT /***********************************************************************/ xbInt16 xbSql::SqlDropIndex( const xbString &sCmdLine ){ @@ -63,7 +63,7 @@ xbInt16 xbSql::SqlDropIndex( const xbString &sCmdLine ){ sNode.Trim(); sNode.ToUpperCase(); if( sNode != "EXISTS" ){ - iErrorStop = 10; + iErrorStop = 100; iRc = XB_SYNTAX_ERROR; throw iRc; } else { @@ -97,30 +97,42 @@ xbInt16 xbSql::SqlDropIndex( const xbString &sCmdLine ){ dbf = xbase->GetDbfPtr( fDbf.GetFqFileName()); if( !dbf ){ if(( iRc = xbase->OpenHighestVersion( sTableName, "", &dbf )) != XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 110; throw iRc; } } if( dbf == NULL ){ - iErrorStop = 40; + iErrorStop = 120; iRc = XB_FILE_NOT_FOUND; throw iRc; } #ifdef XB_LOCKING_SUPPORT if(( iRc = dbf->LockTable( XB_LOCK )) != XB_NO_ERROR ){ - iErrorStop = 50; + iErrorStop = 130; throw iRc; } #endif // XB_LOCKING_SUPPORT - iRc = dbf->DeleteTag( "NDX", sIxName ); - if( iRc == XB_FILE_NOT_FOUND && !bIfExists ){ - iErrorStop = 60; - throw( iRc ); - } else if( iRc != XB_NO_ERROR ){ - iErrorStop = 70; - throw iRc; + ulPos = sIxName.Pos( ".NDX" ); + if( ulPos > 0 ){ + iRc = dbf->DeleteTag( "NDX", sIxName ); + if( iRc == XB_FILE_NOT_FOUND && !bIfExists ){ + iErrorStop = 140; + throw( iRc ); + } else if( iRc != XB_NO_ERROR ){ + iErrorStop = 150; + throw iRc; + } + } else { // assuming MDX tag + iRc = dbf->DeleteTag( "MDX", sIxName ); + if( iRc == XB_FILE_NOT_FOUND && !bIfExists ){ + iErrorStop = 160; + throw( iRc ); + } else if( iRc != XB_NO_ERROR ){ + iErrorStop = 170; + throw iRc; + } } } catch (xbInt16 iRc ){ @@ -136,7 +148,7 @@ xbInt16 xbSql::SqlDropIndex( const xbString &sCmdLine ){ return iRc; } - +#endif // XB_INDEX_SUPPORT /***********************************************************************/ } /* namespace */ #endif /* XB_SQL_SUPPORT */ diff --git a/src/sql/xbinsert.cpp b/src/sql/xbinsert.cpp index 1095202..835f9e6 100755 --- a/src/sql/xbinsert.cpp +++ b/src/sql/xbinsert.cpp @@ -52,13 +52,13 @@ xbInt16 xbSql::SqlInsert( const xbString &sCmdLine ){ if( !dbf ){ if(( iRc = xbase->OpenHighestVersion( sTableName, "", &dbf )) != XB_NO_ERROR ){ - iErrorStop = 10; + iErrorStop = 100; throw iRc; } } - + if( !dbf ){ - iErrorStop = 20; + iErrorStop = 110; iRc = XB_FILE_NOT_FOUND; throw iRc; } @@ -78,7 +78,7 @@ xbInt16 xbSql::SqlInsert( const xbString &sCmdLine ){ // verify there are the same count in the field list and values list if( iFldCnt != iDataCnt ){ - iErrorStop = 30; + iErrorStop = 120; iRc = XB_SYNTAX_ERROR; throw iRc; } @@ -90,11 +90,11 @@ xbInt16 xbSql::SqlInsert( const xbString &sCmdLine ){ sFieldName.ExtractElement( sFieldList, ',', i, 0 ); sFieldName.Trim(); if(( iRc = dbf->GetFieldNo( sFieldName, iFldNo )) != XB_NO_ERROR ){ - iErrorStop = 40; + iErrorStop = 130; throw iRc; } if(( iRc = dbf->GetFieldType( iFldNo, cFldType )) != XB_NO_ERROR ){ - iErrorStop = 50; + iErrorStop = 140; throw iRc; } @@ -113,7 +113,7 @@ xbInt16 xbSql::SqlInsert( const xbString &sCmdLine ){ case 'N': case 'L': if(( iRc = dbf->PutField( iFldNo, sFieldData )) != XB_NO_ERROR ){ - iErrorStop = 100; + iErrorStop = 150; throw iRc; } break; @@ -121,7 +121,7 @@ xbInt16 xbSql::SqlInsert( const xbString &sCmdLine ){ case 'D': // assumes input date format of yyyy-mm-dd if( sFieldData.Len() != 10 || sFieldData[5] != '-' || sFieldData[8] != '-' ){ - iErrorStop = 110; + iErrorStop = 160; iRc = XB_INVALID_DATA; throw iRc; } @@ -129,7 +129,7 @@ xbInt16 xbSql::SqlInsert( const xbString &sCmdLine ){ sWork1.Remove( 8, 1 ); sWork1.Remove( 5, 1 ); if(( iRc = dbf->PutField( iFldNo, sWork1 )) != XB_NO_ERROR ){ - iErrorStop = 120; + iErrorStop = 170; throw iRc; } break; @@ -140,14 +140,14 @@ xbInt16 xbSql::SqlInsert( const xbString &sCmdLine ){ break; default: - iErrorStop= 150; + iErrorStop= 180; iRc = XB_INVALID_FIELD_TYPE; throw iRc; } } if(( iRc = dbf->AppendRecord()) != XB_NO_ERROR ){ - iErrorStop = 300; + iErrorStop = 190; throw iRc; } @@ -159,17 +159,17 @@ xbInt16 xbSql::SqlInsert( const xbString &sCmdLine ){ iFldNo = llN->GetKey(); sFieldData = llD->GetKey(); if(( iRc = dbf->UpdateMemoField( iFldNo, sFieldData )) != XB_NO_ERROR ){ - iErrorStop = 400; + iErrorStop = 200; throw iRc; } llN = llN->GetNextNode(); llD = llD->GetNextNode(); } - if(( iRc == dbf->Commit()) != XB_NO_ERROR ){ - iErrorStop = 500; - throw iRc; - } + if(( iRc = dbf->Commit()) != XB_NO_ERROR ){ + iErrorStop = 210; + throw iRc; + } } catch (xbInt16 iRc ){ xbString sMsg; diff --git a/src/sql/xbselect.cpp b/src/sql/xbselect.cpp new file mode 100755 index 0000000..91c0485 --- /dev/null +++ b/src/sql/xbselect.cpp @@ -0,0 +1,92 @@ +/* xbset.cpp + +XBase64 Software Library + +Copyright (c) 1997,2003,2014,2022 Gary A Kunkel + +The xb64 software library is covered under the terms of the GPL Version 3, 2007 license. + +Email Contact: + + XDB-devel@lists.sourceforge.net + XDB-users@lists.sourceforge.net + +*/ + +#include "xbase.h" + +#ifdef XB_SQL_SUPPORT + +namespace xb{ + + +/***********************************************************************/ +xbInt16 xbSql::SqlSelect( const xbString &sCmdLine ){ + + std::cout << "SELECT [" << sCmdLine << "]\n"; + // expected format: + // SELECT + + xbInt16 iRc = 0; + xbInt16 iErrorStop = 0; + xbUInt32 ulPos; + + try{ + +/* + xbString sCmd = sCmdLine; + sCmd.Trim(); + sCmd.ZapTrailingChar( ';' ); + sCmd.Trim(); + + // drop off the first node "SET" + ulPos = sCmd.Pos( ' ' ); + sCmd.Ltrunc( ulPos ); + sCmd.Ltrim(); + + xbString sNode1 = sCmd; + sNode1.ToUpperCase(); + + if( sNode1 == "SET" ) { + uda.DumpUda(); + + } else { + + xbString sKey; + sKey.ExtractElement( sCmd, '=', 1, 0 ); + sKey.Trim(); + + xbString sToken; + sToken.ExtractElement( sCmd, '=', 2, 0 ); + sToken.Trim(); + + + if( sToken == '^' ){ + if(( iRc = uda.DelTokenForKey( sKey )) != XB_NO_ERROR ){ + iErrorStop = 10; + throw iRc; + } + } else { + if(( iRc = uda.UpdTokenForKey( sKey, sToken )) != XB_NO_ERROR ){ + iErrorStop = 10; + throw iRc; + } + } + } +*/ + + } + catch (xbInt16 iRc ){ + xbString sMsg; + sMsg.Sprintf( "xbSql::SqlSelect() Exception Caught. Error Stop = [%d] rc = [%d]", iErrorStop, iRc ); + xbase->WriteLogMessage( sMsg.Str() ); + xbase->WriteLogMessage( GetErrorMessage( iRc )); + } + + return iRc; +} + +/***********************************************************************/ +} /* namespace */ +#endif /* XB_SQL_SUPPORT */ + diff --git a/src/sql/xbsql.cpp b/src/sql/xbsql.cpp index 25cd2c8..5261b1a 100755 --- a/src/sql/xbsql.cpp +++ b/src/sql/xbsql.cpp @@ -57,7 +57,20 @@ xbInt16 xbSql::ExecuteNonQuery( const xbString &sCmdLine ) { // std::cout << "node 1 = " << sNode1.Str() << std::endl; - if( sNode1 == "CREATE" ){ + if( sNode1 == "ALTER" ){ + xbString sNode2; + sNode2.ExtractElement( sCmd.Str(), ' ', 2, 0 ); + sNode2.ToUpperCase(); + sNode2.Trim(); + + if( sNode2 == "TABLE" ) + iRc = SqlAlterTable( sCmd ); + else + iRc = XB_INVALID_FUNCTION; + + + + } else if( sNode1 == "CREATE" ){ xbString sNode2; sNode2.ExtractElement( sCmd.Str(), ' ', 2, 0 ); @@ -65,8 +78,11 @@ xbInt16 xbSql::ExecuteNonQuery( const xbString &sCmdLine ) { sNode2.Trim(); if( sNode2 == "TABLE" ) iRc = SqlCreateTable( sCmd ); + + #ifdef XB_INDEX_SUPPORT else if( sNode2 == "INDEX" || sNode2 == "UNIQUE" ) iRc = SqlCreateIndex( sCmd ); + #endif // XB_INDEX_SUPPORT else iRc = XB_INVALID_FUNCTION; @@ -81,22 +97,35 @@ xbInt16 xbSql::ExecuteNonQuery( const xbString &sCmdLine ) { if( sNode2 == "TABLE" ) iRc = SqlDropTable( sCmd ); + #ifdef XB_INDEX_SUPPORT else if( sNode2 == "INDEX" ) iRc = SqlDropIndex( sCmd ); + #endif // XB_INDEX_SUPPORT + + else + iRc = XB_INVALID_FUNCTION; + + } else if( sNode1 == "DELETE" || sNode1 == "UNDELETE" ){ + + iRc = SqlDelete( sCmd ); + } else if( sNode1 == "HELP" ) SqlHelp(); else if( sNode1 == "INSERT" ){ - iRc = SqlInsert( sCmd ); // else if( sNode1 == "UPDATE" ) // iRc = SqlUpdate( sCmd ); } + else if( sNode1 == "USE" ) iRc = SqlUse( sCmd ); + else if( sNode1 == "SELECT" ) + iRc = SqlSelect( sCmd ); + else if( sNode1 == "SET" ) iRc = SqlSet( sCmd ); @@ -114,11 +143,23 @@ xbXBase *xbSql::GetXbasePtr() const { /***********************************************************************/ void xbSql::SqlHelp() const { - std::cout << "************************" << std::endl; - std::cout << "Valid XBase SQL commands" << std::endl << std::endl; - std::cout << "HELP" << std::endl; - std::cout << "USE /dir/to/dbf/tables" << std::endl; - std::cout << "CREATE TABLE" << std::endl << std::endl << std::endl; + std::cout << "************************" << std::endl; + std::cout << "Valid XBase SQL commands" << std::endl << std::endl; + std::cout << "HELP" << std::endl; + + std::cout << "ALTER TABLE tablename.DBF RENAME TO newtablename.DBF" << std::endl; + std::cout << "CREATE INDEX ixname.NDX ON tablename.dbf ( EXPRESSION ) [ASSOCIATE]" << std::endl; + std::cout << "CREATE [UNIQUE] INDEX tagname ON tablename.dbf ( EXPRESSION ) [DESC] [FILTER .NOT. DELETED()]" << std::endl; + std::cout << "CREATE TABLE tablename.DBF (Field1 CHAR(10), INTFLD1 INTEGER, ... )" << std::endl; + std::cout << "DELETE FROM tablename.DBF [WHERE expression]" << std::endl; + std::cout << "DROP INDEX [IF EXISTS] ixname.NDX ON tablename.DBF" << std::endl; + std::cout << "DROP TABLE [IF EXISTS] tablename.DBF" << std::endl; + std::cout << "INSERT INTO tablename (field1, field2, field3,...) VALUES ( 'charval', numval, {MM/DD/YY})" << std::endl; + std::cout << "SELECT FIELD1,FIELD2... FROM TABLE.DBF [WHERE expression] [ORDER BY TAG TAGNAME" << std::endl; + std::cout << "SET ATTRIBUTE = DATAVALUE" << std::endl; + std::cout << "SET ATTRIBUTE = ^ (to delete an entry)" << std::endl; + std::cout << "USE /dir/to/dbf/tables" << std::endl; + std::cout << "CREATE TABLE" << std::endl << std::endl << std::endl; } /***********************************************************************/ @@ -133,11 +174,6 @@ xbInt16 xbSql::SqlUse( const xbString &sCmdLine ){ } /***********************************************************************/ -/***********************************************************************/ -/***********************************************************************/ -/***********************************************************************/ -/***********************************************************************/ - -/***********************************************************************/ } /* namespace */ #endif /* XB_SQL_SUPPORT */ + diff --git a/src/tests/tstfuncs.cpp b/src/tests/tstfuncs.cpp index c499d3f..d9b108d 100755 --- a/src/tests/tstfuncs.cpp +++ b/src/tests/tstfuncs.cpp @@ -29,7 +29,7 @@ xbInt16 TestMethod( xbInt16 PrintOption, const char * title, xbDouble result, xb xbInt16 TestMethod( xbInt16 PrintOption, const char * title, xbDouble result, xbDouble expectedResult, xbDouble dEpsilon ); -xbInt16 FileCompare( xbXBase &x, xbInt16 iPo, const xbString &sFile1, const xbString &sFile2, const xbString &sSkipBytes ); +// xbInt16 FileCompare( xbXBase &x, xbInt16 iPo, const xbString &sFile1, const xbString &sFile2, const xbString &sSkipBytes ); #ifdef XB_LOCKING_SUPORT @@ -458,15 +458,15 @@ xbDouble ChronTime(){ } - +/* xbInt16 FileCompare( xbXBase &x, xbInt16 iPo, const xbString &sFile1, const xbString &sFile2, const xbString &sSkipBytes ){ -/* - iPo print option - sFile1 - File 1 - sFile2 - File 2 - sSkipBytes - comma separated list of bytes to skip the compare on -*/ + +// iPo print option +// sFile1 - File 1 +// sFile2 - File 2 +// sSkipBytes - comma separated list of bytes to skip the compare on + xbInt16 iRc = 0; xbInt16 iErrorStop = 0; @@ -577,5 +577,7 @@ xbInt16 FileCompare( xbXBase &x, xbInt16 iPo, const xbString &sFile1, const xbSt return iRc; } +*/ + diff --git a/src/tests/xb_test_dbf_v3_memos.cpp b/src/tests/xb_test_dbf_v3_memos.cpp index e364741..ad3e8e0 100755 --- a/src/tests/xb_test_dbf_v3_memos.cpp +++ b/src/tests/xb_test_dbf_v3_memos.cpp @@ -54,8 +54,7 @@ int main( int argCnt, char **av ) xbXBase x; -#ifdef XB_LOGGING_SUPPORT - + #ifdef XB_LOGGING_SUPPORT x.EnableMsgLogging(); if( po ){ std::cout << "Logfile is [" << x.GetLogFqFileName().Str() << "]" << std::endl; @@ -63,12 +62,15 @@ int main( int argCnt, char **av ) xbString sMsg; sMsg.Sprintf( "Program [%s] initializing...", av[0] ); x.WriteLogMessage( sMsg ); - -#endif + #endif x.SetDataDirectory( PROJECT_DATA_DIR ); x.EnableMsgLogging(); + + #ifdef XB_LOCKING_SUPPORT x.DisableDefaultAutoLock(); + #endif // XB_LOCKING_SUPPORT + InitTime(); if( po > 0 ) @@ -218,9 +220,33 @@ int main( int argCnt, char **av ) rc += TestMethod( po, "GetRecord()", V3Dbf.GetRecord( 7 ), XB_NO_ERROR ); rc += TestMethod( po, "DeleteRecord()", V3Dbf.DeleteRecord(), XB_NO_ERROR ); rc += TestMethod( po, "Pack()", V3Dbf.Pack(), XB_NO_ERROR ); + + xbString sDir; + V3Dbf.GetFileDirPart( sDir ); + xbString sDbfName; + xbString sDbtName; + sDbfName.Sprintf( "%snewV3nm.DBF", sDir.Str()); + sDbtName.Sprintf( "%snewV3nm.DBT", sDir.Str()); + + std::cout << "remove [" << sDbfName.Str() << "\n"; + std::cout << "remove [" << sDbtName.Str() << "\n"; + + V3Dbf.xbRemove( sDbfName ); + V3Dbf.xbRemove( sDbtName ); + + x.DisplayTableList(); + + rc += TestMethod( po, "Rename()", V3Dbf.Rename( "newV3nm.DBF" ), XB_NO_ERROR ); + x.DisplayTableList(); + + rc += TestMethod( po, "Close()", V3Dbf.Close(), XB_NO_ERROR ); + + } + + if( po > 0 || rc < 0 ) fprintf( stdout, "Total Errors = %d\n", rc * -1 ); diff --git a/src/tests/xb_test_dbf_v3_nomemos.cpp b/src/tests/xb_test_dbf_v3_nomemos.cpp index aab118f..e5adc48 100755 --- a/src/tests/xb_test_dbf_v3_nomemos.cpp +++ b/src/tests/xb_test_dbf_v3_nomemos.cpp @@ -71,7 +71,11 @@ int main( int argCnt, char **av ) x.SetDataDirectory( PROJECT_DATA_DIR ); x.EnableMsgLogging(); + + #ifdef XB_LOCKING_SUPPORT x.DisableDefaultAutoLock(); + #endif // XB_LOCKING_SUPPORT + InitTime(); if( po > 0 ) diff --git a/src/tests/xb_test_dbf_v4_memos.cpp b/src/tests/xb_test_dbf_v4_memos.cpp index e92b5b2..2b0e09c 100755 --- a/src/tests/xb_test_dbf_v4_memos.cpp +++ b/src/tests/xb_test_dbf_v4_memos.cpp @@ -61,7 +61,11 @@ int main( int argCnt, char **av ) x.SetDataDirectory( PROJECT_DATA_DIR ); x.EnableMsgLogging(); + + #ifdef XB_LOCKING_SUPPORT x.DisableDefaultAutoLock(); + #endif // XB_LOCKING_SUPPORT + InitTime(); @@ -318,8 +322,28 @@ int main( int argCnt, char **av ) rc += TestMethod( po, "GetRecord()", V4Dbf.GetRecord( 7 ), XB_NO_ERROR ); rc += TestMethod( po, "DeleteRecord()", V4Dbf.DeleteRecord(), XB_NO_ERROR ); - rc += TestMethod( po, "Pack()", V4Dbf.Pack(), XB_NO_ERROR ); + + xbString sDir; + V4Dbf.GetFileDirPart( sDir ); + xbString sDbfName; + xbString sDbtName; + sDbfName.Sprintf( "%snew4name.DBF", sDir.Str()); + sDbtName.Sprintf( "%snew4name.DBT", sDir.Str()); + +// std::cout << "remove [" << sDbfName.Str() << "\n"; +// std::cout << "remove [" << sDbtName.Str() << "\n"; + + V4Dbf.xbRemove( sDbfName ); + V4Dbf.xbRemove( sDbtName ); + + x.DisplayTableList(); + + rc += TestMethod( po, "Rename()", V4Dbf.Rename( "new4name.DBF" ), XB_NO_ERROR ); + + x.DisplayTableList(); + + rc += TestMethod( po, "Close()", V4Dbf.Close(), XB_NO_ERROR ); } diff --git a/src/tests/xb_test_dbf_v4_nomemos.cpp b/src/tests/xb_test_dbf_v4_nomemos.cpp index 68ecda0..4036588 100755 --- a/src/tests/xb_test_dbf_v4_nomemos.cpp +++ b/src/tests/xb_test_dbf_v4_nomemos.cpp @@ -58,7 +58,7 @@ int main( int argCnt, char **av ) xbXBase x; -#ifdef XB_LOGGING_SUPPORT + #ifdef XB_LOGGING_SUPPORT x.EnableMsgLogging(); if( po ){ std::cout << "Logfile is [" << x.GetLogFqFileName().Str() << "]" << std::endl; @@ -66,11 +66,15 @@ int main( int argCnt, char **av ) xbString sMsg; sMsg.Sprintf( "Program [%s] initializing...", av[0] ); x.WriteLogMessage( sMsg ); -#endif + #endif x.SetDataDirectory( PROJECT_DATA_DIR ); x.EnableMsgLogging(); + + #ifdef XB_LOCKING_SUPPORT x.DisableDefaultAutoLock(); + #endif // XB_LOCKING_SUPPORT + InitTime(); if( po > 0 ) diff --git a/src/tests/xb_test_expression.cpp b/src/tests/xb_test_expression.cpp index e3b47cc..75ed3e5 100755 --- a/src/tests/xb_test_expression.cpp +++ b/src/tests/xb_test_expression.cpp @@ -65,7 +65,9 @@ xbInt16 DevTester( xbXBase * xb, xbDbf * dbf, const char * sExpIn ){ std::cout << "dump nodes\n"; n = exp.GetNextNodeTest( NULL ); if( iRc == XB_NO_ERROR ){ + #ifdef XB_DEBUG_SUPPORT exp.DumpTree( xbTrue ); + #endif // XB_DEBUG_SUPPORT std::cout << "dump nodes\n"; n = exp.GetNextNodeTest( NULL ); if( !n ){ @@ -203,13 +205,17 @@ xbInt16 TestMethod( xbXBase *xb, xbDbf *d, xbInt16 PrintOption, const char * tit if( sResult != sExpectedResult ){ std::cout << std::endl << "[FAIL 5] " << title << std::endl; std::cout << " Expected Result = [" << sExpectedResult << "] Actual Result =[" << sResult.Str() << "]" << std::endl; + #ifdef XB_DEBUG_SUPPORT exp.DumpTree( 1 ); + #endif // XB_DEBUG_SUPPORT return -1; } if( exp.GetResultLen() != iExpectedResultLen ){ std::cout << std::endl << "[FAIL 6] " << title << std::endl; std::cout << " Expected Result Len = [" << iExpectedResultLen << "] Actual Result =[" << exp.GetResultLen() << "]" << std::endl; + #ifdef XB_DEBUG_SUPPORT exp.DumpTree( 1 ); + #endif // XB_DEBUG_SUPPORT return -1; } if( PrintOption == 2 ) @@ -255,7 +261,9 @@ xbInt16 TestMethod( xbXBase * xb, xbDbf * d, xbInt16 PrintOption, const char * t std::cout << std::endl << "[FAIL 5] " << title << std::endl; std::cout << " Expected Result = [" << dExpectedResult << "] Actual Result =[" << dResult << "]" << std::endl; // dump out the tree + #ifdef XB_DEBUG_SUPPORT exp.DumpTree( 1 ); + #endif // XB_DEBUG_SUPPORT return -1; } if( PrintOption == 2 ) @@ -297,7 +305,9 @@ xbInt16 TestMethod( xbXBase * xb, xbDbf * d, xbInt16 PrintOption, const char * t std::cout << std::endl << "[FAIL 5] " << title << std::endl; std::cout << " Expected Result = [" << dtExpectedResult.Str() << "] Actual Result =[" << dtResult.Str() << "]" << std::endl; // dump out the tree + #ifdef XB_DEBUG_SUPPORT exp.DumpTree( 1 ); + #endif // XB_DEBUG_SUPPORT return -1; } if( PrintOption == 2 ) @@ -341,7 +351,9 @@ xbInt16 TestMethod( xbXBase * xb, xbDbf * d, xbInt16 PrintOption, const char * t std::cout << std::endl << "[FAIL 5] " << title << std::endl; std::cout << " Expected Result = [" << bExpectedResult << "] Actual Result =[" << bResult << "]" << std::endl; // dump out the tree + #ifdef XB_DEBUG_SUPPORT exp.DumpTree( 1 ); + #endif //XB_DEBUG_SUPPORT return -1; } if( PrintOption == 2 ) @@ -634,7 +646,9 @@ int main( int argCnt, char **av ) iRc += TestMethod( &x, MyFile, po, "DateTest5", "DATE2 - DATE1", (xbDouble) 8528 ); dtTest1.Set( "20120705" ); + iRc += TestMethod( &x, MyFile, po, "DateTest6", "DATE2 - 3", dtTest1 ); + iRc += TestMethod( &x, MyFile, po, "DateTest7", "DATE2 -= 3", dtTest1 ); dtTest1.Set( "20120718" ); diff --git a/src/tests/xb_test_file.cpp b/src/tests/xb_test_file.cpp index ca32693..4614805 100755 --- a/src/tests/xb_test_file.cpp +++ b/src/tests/xb_test_file.cpp @@ -39,9 +39,9 @@ int main( int argCnt, char **av ) else if( av[1][0] == 'V' ) po = 2; } - -#ifdef XB_LOGGING_SUPPORT xbXBase x; + + #ifdef XB_LOGGING_SUPPORT x.EnableMsgLogging(); if( po ){ std::cout << "Logfile is [" << x.GetLogFqFileName().Str() << "]" << std::endl; @@ -49,7 +49,7 @@ int main( int argCnt, char **av ) xbString sMsg; sMsg.Sprintf( "Program [%s] initializing...", av[0] ); x.WriteLogMessage( sMsg ); -#endif + #endif InitTime(); xbFile f( &x ); @@ -57,13 +57,13 @@ int main( int argCnt, char **av ) xbString sWrkStr2; sWrkStr = PROJECT_DATA_DIR; f.SetDataDirectory( PROJECT_DATA_DIR ); - + #ifdef WIN32 sWrkStr.SwapChars( '/', '\\' ); #else sWrkStr.SwapChars( '\\', '/' ); #endif - + rc += TestMethod( po, "Set/GetDataDirectory()", f.GetDataDirectory(), sWrkStr, sWrkStr.Len()); f.SetFileName( "TestFile.txt" ); @@ -85,14 +85,13 @@ int main( int argCnt, char **av ) sWrkStr += "TestFile.txt"; rc += TestMethod( po, "GetFqFileName()", f.GetFqFileName(), sWrkStr, 26 ); -#ifdef WIN32 + #ifdef WIN32 sWrkStr = "\\some\\directory\\myfile.dat"; sWrkStr2 = "\\some\\directory\\"; -#else + #else sWrkStr = "/some/directory/myfile.dat"; sWrkStr2 = "/some/directory/"; -#endif - + #endif f.SetFqFileName( sWrkStr ); rc += TestMethod( po, "GetDirectory()", f.GetDirectory(), sWrkStr2, 16 ); @@ -107,7 +106,6 @@ int main( int argCnt, char **av ) rc += TestMethod( po, "xbFopen()", f.xbFopen( "w+b", XB_MULTI_USER ), XB_NO_ERROR ); - xbString sTest; sTest = "Test Data"; rc += TestMethod( po, "xbWrite()", f.xbFwrite( sTest.Str(), 9, 1 ), XB_NO_ERROR ); @@ -161,12 +159,10 @@ int main( int argCnt, char **av ) rc += TestMethod( po, "GetFileExtPart()", f2.GetFileExtPart( sFqnS , sFn ), XB_NO_ERROR ); rc += TestMethod( po, "GetFileExtPart()", f2.GetFileDirPart( sFqnS , sFn ), XB_NO_ERROR ); - rc += TestMethod( po, "SetBlockSize()", f.SetBlockSize( 100 ), XB_INVALID_BLOCK_SIZE ); rc += TestMethod( po, "SetBlockSize()", f.SetBlockSize( 512 ), XB_NO_ERROR ); rc += TestMethod( po, "GetBlockSize()", (xbInt32) f.GetBlockSize(), 512 ); - char BlockBuf[513]; memset( BlockBuf, 0x00, 513 ); rc += TestMethod( po, "xbFopen()", f.xbFopen( "w+b", XB_SINGLE_USER ), XB_NO_ERROR ); @@ -202,10 +198,10 @@ int main( int argCnt, char **av ) if( po > 0 || rc < 0 ) fprintf( stdout, "Total Errors = %d\n", rc * -1 ); -#ifdef XB_LOGGING_SUPPORT + #ifdef XB_LOGGING_SUPPORT sMsg.Sprintf( "Program [%s] terminating with [%d] errors...", av[0], rc * -1 ); x.WriteLogMessage( sMsg ); -#endif + #endif return rc; } diff --git a/src/tests/xb_test_filter.cpp b/src/tests/xb_test_filter.cpp index 2aeade3..ac4b896 100755 --- a/src/tests/xb_test_filter.cpp +++ b/src/tests/xb_test_filter.cpp @@ -52,7 +52,7 @@ int main( int argCnt, char **av ) xbXBase x; -#ifdef XB_LOGGING_SUPPORT + #ifdef XB_LOGGING_SUPPORT x.EnableMsgLogging(); if( iPo ){ std::cout << "Logfile is [" << x.GetLogFqFileName().Str() << "]" << std::endl; @@ -61,7 +61,7 @@ int main( int argCnt, char **av ) sMsg.Sprintf( "Program [%s] initializing...", av[0] ); x.WriteLogMessage( sMsg ); x.SetLogSize( 1000000 ); -#endif + #endif x.SetDataDirectory( PROJECT_DATA_DIR ); x.EnableMsgLogging(); @@ -74,16 +74,20 @@ int main( int argCnt, char **av ) if( iPo > 0 ) std::cout << "Default Data Directory is [" << x.GetDataDirectory().Str() << "]" << std::endl; - xbDbf *V4Dbf = new xbDbf4( &x ); + #ifdef XB_DBF4_SUPPORT + xbDbf *MyFile = new xbDbf4( &x ); + #else + xbDbf *MyFile = new xbDbf3( &x ); + #endif - iRc2 = V4Dbf->CreateTable( "TestFilt.DBF", "TestFilter", MyV4Record, XB_OVERLAY, XB_MULTI_USER ); + iRc2 = MyFile->CreateTable( "TestFilt.DBF", "TestFilter", MyV4Record, XB_OVERLAY, XB_MULTI_USER ); iRc += TestMethod( iPo, "CreateTable()", (xbInt32) iRc2, XB_NO_ERROR ); #ifdef XB_NDX_SUPPORT xbIx *ixPtr; void *ndx; - iRc2 = V4Dbf->CreateTag( "NDX", "TestFilt.NDX", "CFLD", "", 0, 0, XB_OVERLAY, &ixPtr, &ndx ); + iRc2 = MyFile->CreateTag( "NDX", "TestFilt.NDX", "CFLD", "", 0, 0, XB_OVERLAY, &ixPtr, &ndx ); iRc += TestMethod( iPo, "CreateTag()", (xbInt32) iRc2, XB_NO_ERROR ); if( iRc2 ) x.DisplayError( iRc2 ); @@ -99,79 +103,85 @@ int main( int argCnt, char **av ) c = j + 65; s = c; s.PadRight( c, (xbUInt32) i + 1 ); - V4Dbf->BlankRecord(); - V4Dbf->PutField( "CFLD", s ); - V4Dbf->PutLongField( "NFLD", ++lRecCnt ); - iRc = V4Dbf->AppendRecord(); + MyFile->BlankRecord(); + MyFile->PutField( "CFLD", s ); + MyFile->PutLongField( "NFLD", ++lRecCnt ); + iRc = MyFile->AppendRecord(); } } - iRc += TestMethod( iPo, "SetCurTag()", V4Dbf->SetCurTag( "" ), XB_NO_ERROR ); - xbFilter f1( &x, V4Dbf ); + #ifdef XB_INDEX_SUPPORT + iRc += TestMethod( iPo, "SetCurTag()", MyFile->SetCurTag( "" ), XB_NO_ERROR ); + #endif // XB_INDEX_SUPPORT + + xbFilter f1( &x, MyFile ); xbString sMyFilterExpression = "LEFT( CFLD, 2 ) = 'YY'"; iRc += TestMethod( iPo, "Set()", f1.Set( sMyFilterExpression ), XB_NO_ERROR ); - iRc += TestMethod( iPo, "SetCurTag()", V4Dbf->SetCurTag( "" ), XB_NO_ERROR ); + #ifdef XB_INDEX_SUPPORT + iRc += TestMethod( iPo, "SetCurTag()", MyFile->SetCurTag( "" ), XB_NO_ERROR ); + #endif // XB_INDEX_SUPPORT + iRc += TestMethod( iPo, "Set()", f1.Set( sMyFilterExpression ), XB_NO_ERROR ); iRc += TestMethod( iPo, "GetFirstRecord()", f1.GetFirstRecord(), XB_NO_ERROR ); - iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) V4Dbf->GetCurRecNo(), 28 ); + iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) MyFile->GetCurRecNo(), 28 ); iRc += TestMethod( iPo, "GetNextRecord()", f1.GetNextRecord(), XB_NO_ERROR ); - iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) V4Dbf->GetCurRecNo(), 54 ); + iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) MyFile->GetCurRecNo(), 54 ); iRc += TestMethod( iPo, "GetNextRecord()", f1.GetNextRecord(), XB_NO_ERROR ); - iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) V4Dbf->GetCurRecNo(), 80 ); + iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) MyFile->GetCurRecNo(), 80 ); iRc += TestMethod( iPo, "GetLast()", f1.GetLastRecord(), XB_NO_ERROR ); - iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) V4Dbf->GetCurRecNo(), 106 ); + iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) MyFile->GetCurRecNo(), 106 ); iRc += TestMethod( iPo, "GetPrev()", f1.GetPrevRecord(), XB_NO_ERROR ); - iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) V4Dbf->GetCurRecNo(), 80 ); + iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) MyFile->GetCurRecNo(), 80 ); sMyFilterExpression = "LEFT( CFLD, 2 ) = 'CC'"; iRc += TestMethod( iPo, "Set()", f1.Set( sMyFilterExpression ), XB_NO_ERROR ); iRc += TestMethod( iPo, "GetFirstRecord()", f1.GetFirstRecord(), XB_NO_ERROR ); - iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) V4Dbf->GetCurRecNo(), 50 ); + iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) MyFile->GetCurRecNo(), 50 ); iRc += TestMethod( iPo, "GetNextRecord()", f1.GetNextRecord(), XB_NO_ERROR ); - iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) V4Dbf->GetCurRecNo(), 76 ); + iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) MyFile->GetCurRecNo(), 76 ); iRc += TestMethod( iPo, "GetNextRecord()", f1.GetNextRecord(), XB_NO_ERROR ); - iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) V4Dbf->GetCurRecNo(), 102 ); + iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) MyFile->GetCurRecNo(), 102 ); iRc += TestMethod( iPo, "GetLast()", f1.GetLastRecord(), XB_NO_ERROR ); - iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) V4Dbf->GetCurRecNo(), 128 ); + iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) MyFile->GetCurRecNo(), 128 ); iRc += TestMethod( iPo, "GetPrev()", f1.GetPrevRecord(), XB_NO_ERROR ); - iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) V4Dbf->GetCurRecNo(), 102 ); + iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) MyFile->GetCurRecNo(), 102 ); #ifdef XB_NDX_SUPPORT f1.SetLimit( 0 ); // change things up a bit - iRc += TestMethod( iPo, "GetRecord()", V4Dbf->GetRecord( 32 ), XB_NO_ERROR ); - iRc += TestMethod( iPo, "PutField()", V4Dbf->PutField( "ZFLD", "Z" ), XB_NO_ERROR ); - iRc += TestMethod( iPo, "GetRecord()", V4Dbf->GetRecord( 52 ), XB_NO_ERROR ); - iRc += TestMethod( iPo, "PutField()", V4Dbf->PutField( "ZFLD", "Z" ), XB_NO_ERROR ); - iRc += TestMethod( iPo, "GetRecord()", V4Dbf->GetRecord( 76 ), XB_NO_ERROR ); - iRc += TestMethod( iPo, "PutField()", V4Dbf->PutField( "ZFLD", "Z" ), XB_NO_ERROR ); - iRc += TestMethod( iPo, "GetRecord()", V4Dbf->GetRecord( 103 ), XB_NO_ERROR ); - iRc += TestMethod( iPo, "PutField()", V4Dbf->PutField( "ZFLD", "Z" ), XB_NO_ERROR ); - iRc += TestMethod( iPo, "Commit()", V4Dbf->Commit(), XB_NO_ERROR ); - - iRc += TestMethod( iPo, "SetCurTag()", V4Dbf->SetCurTag( "TestFilt" ), XB_NO_ERROR ); + iRc += TestMethod( iPo, "GetRecord()", MyFile->GetRecord( 32 ), XB_NO_ERROR ); + iRc += TestMethod( iPo, "PutField()", MyFile->PutField( "ZFLD", "Z" ), XB_NO_ERROR ); + iRc += TestMethod( iPo, "GetRecord()", MyFile->GetRecord( 52 ), XB_NO_ERROR ); + iRc += TestMethod( iPo, "PutField()", MyFile->PutField( "ZFLD", "Z" ), XB_NO_ERROR ); + iRc += TestMethod( iPo, "GetRecord()", MyFile->GetRecord( 76 ), XB_NO_ERROR ); + iRc += TestMethod( iPo, "PutField()", MyFile->PutField( "ZFLD", "Z" ), XB_NO_ERROR ); + iRc += TestMethod( iPo, "GetRecord()", MyFile->GetRecord( 103 ), XB_NO_ERROR ); + iRc += TestMethod( iPo, "PutField()", MyFile->PutField( "ZFLD", "Z" ), XB_NO_ERROR ); + iRc += TestMethod( iPo, "Commit()", MyFile->Commit(), XB_NO_ERROR ); + + iRc += TestMethod( iPo, "SetCurTag()", MyFile->SetCurTag( "TestFilt" ), XB_NO_ERROR ); sMyFilterExpression = "ZFLD = 'Z'"; iRc += TestMethod( iPo, "Set()", f1.Set( sMyFilterExpression ), XB_NO_ERROR ); - iRc += TestMethod( iPo, "GetFirstRecord()", f1.GetFirstRecord(), XB_NO_ERROR ); - iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) V4Dbf->GetCurRecNo(), 52 ); - iRc += TestMethod( iPo, "GetNextRecord()", f1.GetNextRecord(), XB_NO_ERROR ); - iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) V4Dbf->GetCurRecNo(), 103 ); - iRc += TestMethod( iPo, "GetNextRecord()", f1.GetNextRecord(), XB_NO_ERROR ); - iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) V4Dbf->GetCurRecNo(), 76 ); - iRc += TestMethod( iPo, "GetLast()", f1.GetLastRecord(), XB_NO_ERROR ); - iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) V4Dbf->GetCurRecNo(), 32 ); - iRc += TestMethod( iPo, "GetPrev()", f1.GetPrevRecord(), XB_NO_ERROR ); - iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) V4Dbf->GetCurRecNo(), 76 ); + iRc += TestMethod( iPo, "GetFirstRecordIx()", f1.GetFirstRecordIx(), XB_NO_ERROR ); + iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) MyFile->GetCurRecNo(), 52 ); + iRc += TestMethod( iPo, "GetNextRecordIx()", f1.GetNextRecordIx(), XB_NO_ERROR ); + iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) MyFile->GetCurRecNo(), 103 ); + iRc += TestMethod( iPo, "GetNextRecordIx()", f1.GetNextRecordIx(), XB_NO_ERROR ); + iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) MyFile->GetCurRecNo(), 76 ); + iRc += TestMethod( iPo, "GetLastRecordIx()", f1.GetLastRecordIx(), XB_NO_ERROR ); + iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) MyFile->GetCurRecNo(), 32 ); + iRc += TestMethod( iPo, "GetPrevRecordIx()", f1.GetPrevRecordIx(), XB_NO_ERROR ); + iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) MyFile->GetCurRecNo(), 76 ); #endif // XB_NDX_SUPPORT - iRc += TestMethod( iPo, "Close()", V4Dbf->Close(), XB_NO_ERROR ); - delete V4Dbf; + iRc += TestMethod( iPo, "Close()", MyFile->Close(), XB_NO_ERROR ); + delete MyFile; if( iPo > 0 || iRc < 0 ) fprintf( stdout, "Total Errors = %d\n", iRc * -1 ); diff --git a/src/tests/xb_test_funcs.cpp b/src/tests/xb_test_funcs.cpp index 07e2c17..e8b73b0 100755 --- a/src/tests/xb_test_funcs.cpp +++ b/src/tests/xb_test_funcs.cpp @@ -92,7 +92,11 @@ int main( int argCnt, char **av ) iRc += TestMethod( po, "PutField()", MyFile->PutField( "DATE1", "19890303" ), XB_NO_ERROR ); iRc += TestMethod( po, "PutField()", MyFile->PutField ( "DATE2", "20120708" ), XB_NO_ERROR ); + #ifdef XB_LOCKING_SUPPORT MyFile->SetAutoLock( xbFalse ); + #endif // XB_LOCKING_SUPPORT + + iRc += TestMethod( po, "AppendRecord()", MyFile->AppendRecord(), XB_NO_ERROR ); iRc += TestMethod( po, "ABS( -222, dResult )", x.ABS( -222, dResult ), XB_NO_ERROR ); diff --git a/src/tests/xb_test_mdx.cpp b/src/tests/xb_test_mdx.cpp index 9351e4d..af191ad 100755 --- a/src/tests/xb_test_mdx.cpp +++ b/src/tests/xb_test_mdx.cpp @@ -227,11 +227,22 @@ int main( int argCnt, char **av ) iRc += TestMethod( iPo, "GetFirstKey()", V4DbfX1->GetFirstKey(), XB_NO_ERROR ); iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) V4DbfX1->GetCurRecNo(), (xbInt32) 1 ); + xbString sDir; + V4DbfX1->GetFileDirPart( sDir ); + xbString sDbfName; + xbString sMdxName; + sDbfName.Sprintf( "%sTestMdxR.DBF", sDir.Str()); + sMdxName.Sprintf( "%sTestMdxR.MDX", sDir.Str()); + V4DbfX1->xbRemove( sDbfName ); + V4DbfX1->xbRemove( sMdxName ); - x.CloseAllTables(); - delete V4DbfX1; + iRc += TestMethod( iPo, "Rename()", V4DbfX1->Rename( "TestMdxR.DBF" ), XB_NO_ERROR ); - if( iPo > 0 || iRc < 0 ) + + x.CloseAllTables(); + delete V4DbfX1; + + if( iPo > 0 || iRc < 0 ) fprintf( stdout, "Total Errors = %d\n", iRc * -1 ); #ifdef XB_LOGGING_SUPPORT diff --git a/src/tests/xb_test_ndx.cpp b/src/tests/xb_test_ndx.cpp index 31306c0..b8b97f6 100755 --- a/src/tests/xb_test_ndx.cpp +++ b/src/tests/xb_test_ndx.cpp @@ -53,22 +53,26 @@ int main( int argCnt, char **av ) { "",0,0,0 } }; - xbXBase x; -#ifdef XB_LOGGING_SUPPORT + xbString sMsg; + + #ifdef XB_LOGGING_SUPPORT x.EnableMsgLogging(); if( iPo ){ std::cout << "Logfile is [" << x.GetLogFqFileName().Str() << "]" << std::endl; } - xbString sMsg; sMsg.Sprintf( "Program [%s] initializing...", av[0] ); x.WriteLogMessage( sMsg ); x.SetLogSize( 1000000 ); -#endif + #endif x.SetDataDirectory( PROJECT_DATA_DIR ); x.EnableMsgLogging(); -// x.DisableDefaultAutoLock(); + + #ifdef XB_LOCKING_SUPPORT + x.DisableDefaultAutoLock(); + #endif + InitTime(); char c; @@ -116,6 +120,9 @@ int main( int argCnt, char **av ) iRc2 = V3Dbf->AssociateIndex( "NDX", "TestNdxN.NDX", 0 ); iRc += TestMethod( iPo, "Associate()", (xbInt32) iRc2, XB_NO_ERROR ); + #ifdef XB_LOCKING_SUPPORT + iRc += TestMethod( iPo, "LockTable()", V3Dbf->LockTable( XB_LOCK ), XB_NO_ERROR ); + #endif iRc += TestMethod( iPo, "GetCurTagName()", V3Dbf->GetCurTagName().Str(), "TestNdxC", 8 ); iRc += TestMethod( iPo, "SetCurTag()", V3Dbf->SetCurTag( "TestNdxN" ), XB_NO_ERROR ); @@ -177,7 +184,6 @@ int main( int argCnt, char **av ) iRc += TestMethod( iPo, "SetCurTag()", V3Dbf->SetCurTag( "TestNdxD" ), XB_NO_ERROR ); iRc += TestMethod( iPo, "GetCurTagName()", V3Dbf->GetCurTagName().Str(), "TestNdxD", 8 ); - std::cout << d.Str() << "\n"; iRc += TestMethod( iPo, "Find( '19890420' )", V3Dbf->Find( d ), XB_NOT_FOUND ); V3Dbf->GetRecord( 26 ); @@ -315,16 +321,84 @@ int main( int argCnt, char **av ) } } - iRc += TestMethod( iPo, "Close()", V3Dbf->Close(), XB_NO_ERROR ); + #ifdef XB_LOCKING_SUPPORT + iRc += TestMethod( iPo, "LockTable()", V3Dbf->LockTable( XB_UNLOCK ), XB_NO_ERROR ); + #endif + + xbString sDir; + V3Dbf->GetFileDirPart( sDir ); + xbString sDbfName; + xbString sInfName; + sDbfName.Sprintf( "%sTestNdxR.DBF", sDir.Str()); + sInfName.Sprintf( "%sTestNdxR.INF", sDir.Str()); + + V3Dbf->xbRemove( sDbfName ); + V3Dbf->xbRemove( sInfName ); + + iRc += TestMethod( iPo, "Rename()", V3Dbf->Rename( "TestNdxR.DBF" ), XB_NO_ERROR ); + + iRc += TestMethod( iPo, "DeleteTable()", V3Dbf->DeleteTable(), XB_NO_ERROR ); + // iRc += TestMethod( iPo, "Close()", V3Dbf->Close(), XB_NO_ERROR ); // did a delete instead of close + delete V3Dbf; + x.SetUniqueKeyOpt( XB_EMULATE_DBASE ); + V3Dbf = new xbDbf3( &x ); + + iRc2 = V3Dbf->CreateTable( "TestNdx.DBF", "TestNdx", MyV3Record, XB_OVERLAY, XB_MULTI_USER ); + iRc += TestMethod( iPo, "CreateTable()", (xbInt32) iRc2, XB_NO_ERROR ); + + if( iRc2 ) + x.DisplayError( iRc2 ); + + iRc2 = V3Dbf->CreateTag( "NDX", "TestNdxC.NDX", "CFLD", "", 0, xbTrue, XB_OVERLAY, &ixPtr, &ndx ); + iRc += TestMethod( iPo, "CreateTag()", (xbInt32) iRc2, XB_NO_ERROR ); + if( iRc2 ) + x.DisplayError( iRc2 ); + + iRc2 = V3Dbf->AssociateIndex( "NDX", "TestNdxC.NDX", 0 ); + iRc += TestMethod( iPo, "Associate()", (xbInt32) iRc2, XB_NO_ERROR ); + + + iRc += TestMethod( iPo, "BlankRecord()", V3Dbf->BlankRecord(), XB_NO_ERROR ); + iRc += TestMethod( iPo, "Putfield()", V3Dbf->PutField( "CFLD", "AAA" ), XB_NO_ERROR ); + iRc += TestMethod( iPo, "Putfield()", V3Dbf->PutField( "DFLD", "19611109" ), XB_NO_ERROR ); + iRc += TestMethod( iPo, "PutfieldDouble()", V3Dbf->PutDoubleField( "NFLD", 50 ), XB_NO_ERROR ); + iRc += TestMethod( iPo, "AppendRecord()", V3Dbf->AppendRecord(), XB_NO_ERROR ); + + iRc += TestMethod( iPo, "BlankRecord()", V3Dbf->BlankRecord(), XB_NO_ERROR ); + iRc += TestMethod( iPo, "Putfield()", V3Dbf->PutField( "CFLD", "BBB" ), XB_NO_ERROR ); + iRc += TestMethod( iPo, "Putfield()", V3Dbf->PutField( "DFLD", "19611109" ), XB_NO_ERROR ); + iRc += TestMethod( iPo, "PutfieldDouble()", V3Dbf->PutDoubleField( "NFLD", 50 ), XB_NO_ERROR ); + iRc += TestMethod( iPo, "AppendRecord()", V3Dbf->AppendRecord(), XB_NO_ERROR ); + + iRc += TestMethod( iPo, "BlankRecord()", V3Dbf->BlankRecord(), XB_NO_ERROR ); + iRc += TestMethod( iPo, "Putfield()", V3Dbf->PutField( "CFLD", "BBB" ), XB_NO_ERROR ); + iRc += TestMethod( iPo, "Putfield()", V3Dbf->PutField( "DFLD", "19611109" ), XB_NO_ERROR ); + iRc += TestMethod( iPo, "PutfieldDouble()", V3Dbf->PutDoubleField( "NFLD", 50 ), XB_NO_ERROR ); + iRc += TestMethod( iPo, "AppendRecord()", V3Dbf->AppendRecord(), XB_NO_ERROR ); + + + ixl = V3Dbf->GetIxList(); + while( ixl ){ + if( *ixl->sFmt == "NDX" ){ + ix = (xbIxNdx *) ixl->ix; + //ix->GetTagName( 0, sTagName ); + sMsg.Sprintf( "CheckTagIntegrity() - [%s]", ix->GetTagName(ix->GetCurTag()).Str()); + iRc += TestMethod( iPo, sMsg, ix->CheckTagIntegrity( ix->GetCurTag(), 2 ), XB_NO_ERROR ); + ixl = ixl->next; + } + } + + iRc += TestMethod( iPo, "DeleteTable()", V3Dbf->DeleteTable(), XB_NO_ERROR ); + if( iPo > 0 || iRc < 0 ) fprintf( stdout, "Total Errors = %d\n", iRc * -1 ); -#ifdef XB_LOGGING_SUPPORT + #ifdef XB_LOGGING_SUPPORT sMsg.Sprintf( "Program [%s] terminating with [%d] errors...", av[0], iRc * -1 ); x.WriteLogMessage( sMsg, 2 ); -#endif + #endif return iRc; } diff --git a/src/tests/xb_test_ndx2.cpp b/src/tests/xb_test_ndx2.cpp deleted file mode 100755 index f406b05..0000000 --- a/src/tests/xb_test_ndx2.cpp +++ /dev/null @@ -1,145 +0,0 @@ -/* xb_test_ndx2.cpp - -XBase64 Software Library - -Copyright (c) 1997,2003,2014, 2022 Gary A Kunkel - -The xb64 software library is covered under the terms of the GPL Version 3, 2007 license. - -Email Contact: - - xb64-devel@lists.sourceforge.net - xb64-users@lists.sourceforge.net - -*/ - -// This program tests the class xbIxNdx - -// usage: xb_test_ndx QUITE|NORMAL|VERBOSE - - - -// fix me - this program needs to test GetUnique - -#include "xbase.h" - -using namespace xb; - -#include "tstfuncs.cpp" - - -int main( int argCnt, char **av ) -{ - int iRc = 0; - int iRc2 = 0; - int po = 1; /* print option */ - /* 0 - QUIET */ - /* 1 - NORMAL */ - /* 2 - VERBOSE */ - - if( argCnt > 1 ) { - if( av[1][0] == 'Q' ) - po = 0; - else if( av[1][0] == 'V' ) - po = 2; - } - - - xbSchema MyV3Record[] = - { - { "CFLD", XB_CHAR_FLD, 30, 0 }, - { "DFLD", XB_DATE_FLD, 8, 0 }, - { "NFLD", XB_NUMERIC_FLD, 12, 0 }, - { "",0,0,0 } - }; - - - xbXBase x; -#ifdef XB_LOGGING_SUPPORT - x.EnableMsgLogging(); - if( po ){ - std::cout << "Logfile is [" << x.GetLogFqFileName().Str() << "]" << std::endl; - } - xbString sMsg; - sMsg.Sprintf( "Program [%s] initializing...", av[0] ); - x.WriteLogMessage( sMsg ); - x.SetLogSize( 1000000 ); -#endif - - x.SetDataDirectory( PROJECT_DATA_DIR ); - x.EnableMsgLogging(); -// x.DisableDefaultAutoLock(); - - x.SetUniqueKeyOpt( XB_EMULATE_DBASE ); - InitTime(); - xbString s; - iRc = 0; - - if( po > 0 ) - std::cout << "Default Data Directory is [" << x.GetDataDirectory().Str() << "]" << std::endl; - - xbDbf *V3Dbf = new xbDbf3( &x ); - xbIx *ixPtr; - void *ndx; - - iRc2 = V3Dbf->CreateTable( "TestNdx.DBF", "TestNdx", MyV3Record, XB_OVERLAY, XB_MULTI_USER ); - iRc += TestMethod( po, "CreateTable()", (xbInt32) iRc2, XB_NO_ERROR ); - - if( iRc2 ) - x.DisplayError( iRc2 ); - - iRc2 = V3Dbf->CreateTag( "NDX", "TestNdxC.NDX", "CFLD", "", 0, xbTrue, XB_OVERLAY, &ixPtr, &ndx ); - iRc += TestMethod( po, "CreateTag()", (xbInt32) iRc2, XB_NO_ERROR ); - if( iRc2 ) - x.DisplayError( iRc2 ); - - iRc2 = V3Dbf->AssociateIndex( "NDX", "TestNdxC.NDX", 0 ); - iRc += TestMethod( po, "Associate()", (xbInt32) iRc2, XB_NO_ERROR ); - - - iRc += TestMethod( po, "BlankRecord()", V3Dbf->BlankRecord(), XB_NO_ERROR ); - iRc += TestMethod( po, "Putfield()", V3Dbf->PutField( "CFLD", "AAA" ), XB_NO_ERROR ); - iRc += TestMethod( po, "Putfield()", V3Dbf->PutField( "DFLD", "19611109" ), XB_NO_ERROR ); - iRc += TestMethod( po, "PutfieldDouble()", V3Dbf->PutDoubleField( "NFLD", 50 ), XB_NO_ERROR ); - iRc += TestMethod( po, "AppendRecord()", V3Dbf->AppendRecord(), XB_NO_ERROR ); - - - iRc += TestMethod( po, "BlankRecord()", V3Dbf->BlankRecord(), XB_NO_ERROR ); - iRc += TestMethod( po, "Putfield()", V3Dbf->PutField( "CFLD", "BBB" ), XB_NO_ERROR ); - iRc += TestMethod( po, "Putfield()", V3Dbf->PutField( "DFLD", "19611109" ), XB_NO_ERROR ); - iRc += TestMethod( po, "PutfieldDouble()", V3Dbf->PutDoubleField( "NFLD", 50 ), XB_NO_ERROR ); - iRc += TestMethod( po, "AppendRecord()", V3Dbf->AppendRecord(), XB_NO_ERROR ); - - iRc += TestMethod( po, "BlankRecord()", V3Dbf->BlankRecord(), XB_NO_ERROR ); - iRc += TestMethod( po, "Putfield()", V3Dbf->PutField( "CFLD", "BBB" ), XB_NO_ERROR ); - iRc += TestMethod( po, "Putfield()", V3Dbf->PutField( "DFLD", "19611109" ), XB_NO_ERROR ); - iRc += TestMethod( po, "PutfieldDouble()", V3Dbf->PutDoubleField( "NFLD", 50 ), XB_NO_ERROR ); - iRc += TestMethod( po, "AppendRecord()", V3Dbf->AppendRecord(), XB_NO_ERROR ); - - - xbIxList *ixl = V3Dbf->GetIxList(); - xbIxNdx *ix; - xbString sTagName; - while( ixl ){ - if( *ixl->sFmt == "NDX" ){ - ix = (xbIxNdx *) ixl->ix; - //ix->GetTagName( 0, sTagName ); - sMsg.Sprintf( "CheckTagIntegrity() - [%s]", ix->GetTagName(ix->GetCurTag()).Str()); - iRc += TestMethod( po, sMsg, ix->CheckTagIntegrity( ix->GetCurTag(), 2 ), XB_NO_ERROR ); - ixl = ixl->next; - } - } - - iRc += TestMethod( po, "Close()", V3Dbf->Close(), XB_NO_ERROR ); - delete V3Dbf; - - if( po > 0 || iRc < 0 ) - fprintf( stdout, "Total Errors = %d\n", iRc * -1 ); - -#ifdef XB_LOGGING_SUPPORT - sMsg.Sprintf( "Program [%s] terminating with [%d] errors...", av[0], iRc * -1 ); - x.WriteLogMessage( sMsg, 2 ); -#endif - - return iRc; -} diff --git a/src/tests/xb_test_sql.cpp b/src/tests/xb_test_sql.cpp index 630cc89..20c8514 100755 --- a/src/tests/xb_test_sql.cpp +++ b/src/tests/xb_test_sql.cpp @@ -35,6 +35,8 @@ int main( int argCnt, char **av ) /* 1 - NORMAL */ /* 2 - VERBOSE */ + xbString sSql; + if( argCnt > 1 ) { if( av[1][0] == 'Q' ) po = 0; @@ -56,7 +58,7 @@ int main( int argCnt, char **av ) xbXBase x; -#ifdef XB_LOGGING_SUPPORT + #ifdef XB_LOGGING_SUPPORT x.EnableMsgLogging(); if( po ){ std::cout << "Logfile is [" << x.GetLogFqFileName().Str() << "]" << std::endl; @@ -64,7 +66,7 @@ int main( int argCnt, char **av ) xbString sMsg; sMsg.Sprintf( "Program [%s] initializing...", av[0] ); x.WriteLogMessage( sMsg ); -#endif + #endif @@ -77,26 +79,108 @@ int main( int argCnt, char **av ) if( po > 0 ) std::cout << "Default Data Directory is [" << x.GetDataDirectory().Str() << "]" << std::endl; + xbDbf4 SqlDbf( &x ); // version 4 dbf file + + + // clean up any things possibly needing cleaned up + xbString sDir; + SqlDbf.GetFileDirPart( sDir ); + xbString sDbfName; + xbString sDbtName; + xbString sMdxName; + sDbfName.Sprintf( "%sTestSQL.DBF", sDir.Str()); + sDbtName.Sprintf( "%sTestSQL.DBR", sDir.Str()); + sMdxName.Sprintf( "%sTestSQL.MDX", sDir.Str()); + SqlDbf.xbRemove( sDbfName ); + SqlDbf.xbRemove( sDbtName ); + SqlDbf.xbRemove( sMdxName ); + sDbfName.Sprintf( "%sTestSqlR.DBF", sDir.Str()); + sDbtName.Sprintf( "%sTestSqlR.DBT", sDir.Str()); + sMdxName.Sprintf( "%sTestSqlR.MDX", sDir.Str()); + SqlDbf.xbRemove( sDbfName ); + SqlDbf.xbRemove( sDbtName ); + SqlDbf.xbRemove( sMdxName ); + + iRc2 = SqlDbf.CreateTable( "TestSQL.DBF", "TestSQL", MySqlRecord, XB_OVERLAY, XB_MULTI_USER ); iRc += TestMethod( po, "CreateTable()", (xbInt32) iRc2, XB_NO_ERROR ); if( iRc2 ) x.DisplayError( iRc2 ); + #ifdef XB_MDX_SUPPORT + sSql = "CREATE INDEX tag1 ON TestSQL.DBF( CITY, STATE, DTOS( LASTUPDATE )) FILTER .NOT. DELETED()"; + // xbString sSql = "CREATE INDEX tag1 ON TestSQL.DBF( CITY, STATE )"; - xbString sSql = "INSERT INTO TestSQL (CITY, STATE, ZIPCODE, NOTES, LASTUPDATE, ACTIVE ) VALUES ( 'San Diego', 'CA', 92007, 'San Diego is a cool place', '1989-02-09', 'Y')"; + iRc2 = sql.ExecuteNonQuery( sSql ); + iRc += TestMethod( po, "SqL CreateIndex()", (xbInt32) iRc2, XB_NO_ERROR ); + if( iRc2 ) + x.DisplayError( iRc2 ); + #endif // XB_MDX_SUPPORT + sSql = "INSERT INTO TestSQL (CITY, STATE, ZIPCODE, NOTES, LASTUPDATE, ACTIVE ) VALUES ( 'San Diego', 'CA', 92007, 'San Diego is a cool place', '1989-02-09', 'Y')"; iRc2 = sql.ExecuteNonQuery( sSql ); - iRc += TestMethod( po, "Insert()", (xbInt32) iRc2, XB_NO_ERROR ); + iRc += TestMethod( po, "SqlInsert()", (xbInt32) iRc2, XB_NO_ERROR ); if( iRc2 ) x.DisplayError( iRc2 ); + sSql = "INSERT INTO TestSQL (CITY, STATE, ZIPCODE, NOTES, LASTUPDATE, ACTIVE ) VALUES ( 'Dallas', 'TX', 76248, 'Dallas is hot in the summer', '1989-02-09', 'N')"; + iRc2 = sql.ExecuteNonQuery( sSql ); + iRc += TestMethod( po, "SqlInsert()", (xbInt32) iRc2, XB_NO_ERROR ); + if( iRc2 ) + x.DisplayError( iRc2 ); + + sSql = "ALTER TABLE TestSQL.DBF RENAME TO TestSqlR.DBF"; + + iRc2 = sql.ExecuteNonQuery( sSql ); + iRc += TestMethod( po, "SqlAlterTable()", (xbInt32) iRc2, XB_NO_ERROR ); + if( iRc2 ) + x.DisplayError( iRc2 ); + + x.DisplayTableList(); + + + sSql = "DELETE FROM TestSqlR.DBF WHERE CITY='San Diego'"; + iRc2 = sql.ExecuteNonQuery( sSql ); + iRc += TestMethod( po, "SqlDelete()", (xbInt32) iRc2, XB_NO_ERROR ); + if( iRc2 ) + x.DisplayError( iRc2 ); + + sSql = "UNDELETE FROM TestSqlR.DBF WHERE CITY='San Diego'"; + iRc2 = sql.ExecuteNonQuery( sSql ); + iRc += TestMethod( po, "SqlUndelete()", (xbInt32) iRc2, XB_NO_ERROR ); + if( iRc2 ) + x.DisplayError( iRc2 ); + + sSql = "DELETE FROM TestSqlR.DBF"; + iRc2 = sql.ExecuteNonQuery( sSql ); + iRc += TestMethod( po, "SqlDelete()", (xbInt32) iRc2, XB_NO_ERROR ); + if( iRc2 ) + x.DisplayError( iRc2 ); + + sSql = "UNDELETE FROM TestSqlR.DBF"; + iRc2 = sql.ExecuteNonQuery( sSql ); + iRc += TestMethod( po, "SqlDelete()", (xbInt32) iRc2, XB_NO_ERROR ); + if( iRc2 ) + x.DisplayError( iRc2 ); + + + sSql = "DELETE FROM TestSqlR.DBF WHERE BAD='EXPRESSION'"; + iRc2 = sql.ExecuteNonQuery( sSql ); + iRc += TestMethod( po, "SqlDelete()", (xbInt32) iRc2, XB_INVALID_FIELD_NAME ); +// if( iRc2 ) +// x.DisplayError( iRc2 ); + + +// sSql = "SELECT CITY, STATE ZIPCODE FROM TestSQL.DBF WHERE CITY IS NOT NULL"; +// iRc += TestMethod( po, "Select()", SqlDbf.Select( sSql ), XB_NO_ERROR ); + + iRc += TestMethod( po, "Close()", SqlDbf.Close(), XB_NO_ERROR ); if( po > 0 || iRc < 0 ) fprintf( stdout, "Total Errors = %d\n", iRc * -1 ); - #ifdef XB_LOGGING_SUPPORT sMsg.Sprintf( "Program [%s] terminating with [%d] errors...", av[0], iRc * -1 ); x.WriteLogMessage( sMsg ); @@ -105,3 +189,4 @@ int main( int argCnt, char **av ) return iRc; } +
\ No newline at end of file diff --git a/src/tests/xb_test_string.cpp b/src/tests/xb_test_string.cpp index f39c101..9d730db 100755 --- a/src/tests/xb_test_string.cpp +++ b/src/tests/xb_test_string.cpp @@ -43,13 +43,13 @@ int main( int argCnt, char **av = NULL ) } xbXBase x; + xbString sMsg; #ifdef XB_LOGGING_SUPPORT x.EnableMsgLogging(); if( po ){ std::cout << "Logfile is [" << x.GetLogFqFileName().Str() << "]" << std::endl; } - xbString sMsg; sMsg.Sprintf( "Program [%s] initializing...", av[0] ); x.WriteLogMessage( sMsg ); #endif @@ -305,7 +305,6 @@ int main( int argCnt, char **av = NULL ) s1.Left( 0 ); rc += TestMethod( po, "Left(0) ", s1, "", 0 ); - char buf[5]; buf[0] = 'W'; buf[1] = 'X'; @@ -362,7 +361,6 @@ int main( int argCnt, char **av = NULL ) free( p ); rc += TestMethod( po, "Set", s1, "1234", 4 ); - xbDouble d = 12345678.876543; xbString sD( d ); rc += TestMethod( po, "xbDouble Constructor", sD, "12345678.876543", 15 ); @@ -380,6 +378,13 @@ int main( int argCnt, char **av = NULL ) s3.Sprintf( "%s and %s", s1.Str(), s2.Str()); rc += TestMethod( po, "Sprintf", s3, "string 1 and string 2.0", 23 ); + s1.Set( "abcdef.dbf" ); + s1.Replace( "def", "DEF" ); + rc += TestMethod( po, "Replace", s1, "abcDEF.dbf", 10 ); + s1.Replace( ".dbf", ".DBF" ); + rc += TestMethod( po, "Replace", s1, "abcDEF.DBF", 10 ); + + xbInt16 iErrorStop = 10; xbInt16 iRc = -100; sMsg.Sprintf( "class::method() Exception Caught. Error Stop = [%d] iRc = [%d] Expression = [%s]", iErrorStop, iRc, s3.Str() ); @@ -387,10 +392,10 @@ int main( int argCnt, char **av = NULL ) if( po > 0 || rc < 0 ) fprintf( stdout, "Total Errors = %d\n", rc * -1 ); -#ifdef XB_LOGGING_SUPPORT + #ifdef XB_LOGGING_SUPPORT sMsg.Sprintf( "Program [%s] terminating with [%d] errors...", av[0], rc * -1 ); x.WriteLogMessage( sMsg ); -#endif + #endif return rc; } diff --git a/src/tests/xb_test_tblmgr.cpp b/src/tests/xb_test_tblmgr.cpp index 26ec96a..451432c 100755 --- a/src/tests/xb_test_tblmgr.cpp +++ b/src/tests/xb_test_tblmgr.cpp @@ -54,11 +54,11 @@ int main( int argCnt, char **av ) if( po == 2 ){ std::cout << "DisplayError Test ==> "; x.DisplayError( 0 ); - #ifdef WIN32 - std::cout << "WIN32 environment" << std::endl; - #else - std::cout << "Not WIN32 environment" << std::endl; - #endif + #ifdef WIN32 + std::cout << "WIN32 environment" << std::endl; + #else + std::cout << "Not WIN32 environment" << std::endl; + #endif } xbDbf * d1; @@ -77,8 +77,8 @@ int main( int argCnt, char **av ) rc += TestMethod( po, "AddTblToTblLst()", x.AddTblToTblList( d1, "TestTableA" ), 0 ); rc += TestMethod( po, "AddTblToTblLst()", x.AddTblToTblList( d1, "TestTableB" ), 0 ); rc += TestMethod( po, "AddTblToTblLst()", x.AddTblToTblList( d1, "TestTableD" ), 0 ); - - + + // Next line should generate an exception rc += TestMethod( po, "AddTblToTblLst()", x.AddTblToTblList( d1, "TestTableC" ), XB_DUP_TABLE_OR_ALIAS ); diff --git a/src/tests/xb_test_xbase.cpp b/src/tests/xb_test_xbase.cpp index 6dad3f7..9d523c5 100755 --- a/src/tests/xb_test_xbase.cpp +++ b/src/tests/xb_test_xbase.cpp @@ -39,25 +39,22 @@ int main( int argCnt, char **av ) po = 2; } - xbXBase x; + xbString sMsg; - -#ifdef XB_LOGGING_SUPPORT + #ifdef XB_LOGGING_SUPPORT x.EnableMsgLogging(); if( po ){ std::cout << "Logfile is [" << x.GetLogFqFileName().Str() << "]" << std::endl; } - xbString sMsg; sMsg.Sprintf( "Program [%s] initializing...", av[0] ); x.WriteLogMessage( sMsg ); -#endif + #endif InitTime(); x.SetDefaultDateFormat( "YY-MM-DD" ); iRc += TestMethod( po, "SetDefaultDateFormat", x.GetDefaultDateFormat(), "YY-MM-DD", 8 ); - if( po == 2 ){ if( x.GetEndianType() == 'L' ) std::cout << "Little Endian Architecture" << std::endl; @@ -70,7 +67,7 @@ int main( int argCnt, char **av ) iRc += TestMethod( po, "GetErrorMessage", x.GetErrorMessage( XB_DBF_FILE_NOT_OPEN ), "DBF File Not Open", 17 ); -#ifdef XB_LOGGING_SUPPORT + #ifdef XB_LOGGING_SUPPORT xbString sLogDir = PROJECT_LOG_DIR; iRc += TestMethod( po, "GetDefaultLogDirectory()", x.GetDefaultLogDirectory(), sLogDir, sLogDir.Len()); @@ -81,11 +78,10 @@ int main( int argCnt, char **av ) iRc += TestMethod( po, "GetDefaultLogFileName()", x.GetDefaultLogFileName(), sLogName, sLogName.Len()); x.WriteLogMessage( "test" ); -#endif + #endif x.xbSleep( 250 ); - if( po == 2 ){ std::cout << "DisplayError Test ==> "; diff --git a/src/utils/checkndx.cpp b/src/utils/checkndx.cpp deleted file mode 100755 index adb5e1c..0000000 --- a/src/utils/checkndx.cpp +++ /dev/null @@ -1,71 +0,0 @@ -/* - Xbase64 project source code - - Copyright (C) 1997,2003 Gary A. Kunkel - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - Contact: - - Email: - - xbase64-devel@lists.sourceforge.net - xbase64-users@lists.sourceforge.net - -*/ - - -// FIXME - program needs to be updated - -#include <xbase64/xbase64.h> - -int main(int ac,char** av) -{ -#ifdef XBASE_DEBUG - xbXBase x; - xbDbf d( &x ); - xbNdx i( &d ); - xbInt16 rc; - - if( 3 != ac ){ - std::cout << - "\nUsage: checkndx dbf_file index_file\n"; - return 1; - } - - if(( rc = d.Open( av[1] )) != XB_NO_ERROR ) - { - std::cout << "\nCould not open file " << av[1] << " rc = " << rc << "\n"; - return 2; - } - - if(( rc = i.OpenIndex( av[2] )) != XB_NO_ERROR ) - { - std::cout << "\nCould not open file " << av[2] << " rc = " << rc << "\n"; - return 3; - } - - std::cout << "\nRunning...\n"; - rc = i.CheckIndexIntegrity( 1 ); - std::cout << "\nNdx integrity check = " << rc << "\n"; - - i.DumpHdrNode(0); - - d.Close(); -#else - std::cout << "\nXBASE_DEBUG is not compiled in\n"; -#endif - return 0; -} diff --git a/src/utils/dbfxtrct.cpp b/src/utils/dbfxtrct.cpp deleted file mode 100755 index 17752c1..0000000 --- a/src/utils/dbfxtrct.cpp +++ /dev/null @@ -1,182 +0,0 @@ -/* - Xbase64 project source code - - This program extracts data from a dbf data file and puts it in - a comma delimited output file, suitable for input into an awk or - perl script - - This program excludes all memo fields - - Copyright (C) 1997,2003 Gary A. Kunkel - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - Contact: - - Email: - - xbase64-devel@lists.sourceforge.net - xbase64-users@lists.sourceforge.net - -*/ - -#include <xbase64/xbase64.h> - - -// FIXME - program need to be updated - -/*************************************************************************/ -void Usage(); -void Usage() -{ - std::cout << "\nUsage: dbfxtrct -iDATABASE.DBF -sINDEX.N[TD]X -f -F -dMM/DD/YY\n"; - std::cout << "\nWhere DATABASE.DBF is the name of the database file to dump\n"; - std::cout << "INDEX.NTX or .NDX is an optional index sort paramater\n"; - std::cout << "-f optional field name list in first record\n"; - std::cout << "-F optional field name and attributes in first record\n"; - std::cout << "MM/DD/YY is an optional output date format for any date fields\n"; - std::cout << "\nThis program creates output suitable for awk and perl scripts\n"; - std::cout << "\nThis program does not support memo fields (yet).\n"; -} -/*************************************************************************/ -int main(int ac,char** av) -{ - xbXBase x; - xbDbf d( &x ); - xbInt16 rc, FieldOption = 0; - xbIndex *ix = 0; - xbNdx z(&d); - - char *dbfname = NULL; - char *ixname = NULL; - char *p; - char buf[200]; - xbExpn exp( &x ); - -/* Get the input paramaters - - -i input datafile name - -s optional sort index name - -f optional field names in record one - -F optional field names and attributes in record one - -d date format -*/ - for( int i = 1; i < ac; i++ ) - { - p = av[i]; - if( *p != '-' ){ - std::cout << "Invalid paramater " << *p << std::endl; - Usage(); - return 1; - } - p++; - if( *p == 'i' ) - dbfname = ++p; - else if( *p == 's' ) - ixname = ++p; - else if( *p == 'f' ) - FieldOption = 1; - else if( *p == 'F' ) - FieldOption = 2; - else if( *p == 'd' ) - x.SetDefaultDateFormat( ++p ); - else{ - std::cout << "Invalid paramater " << *p << std::endl; - Usage(); - return 1; - } - } - -/* if missing params, display a usage message and exit */ - - if( !dbfname ){ - Usage(); - return 1; - } - -/* open the database file */ - - if(( rc = d.Open( dbfname )) != XB_NO_ERROR ) - { - std::cout << "\nCould not open file " << dbfname << " rc = " << rc - << "\n"; - return 2; - } - -/* if an index was specified, open the index file */ - - if( ixname ){ - -#ifdef XB_INDEX_NTX - if( strstr( ixname, "NTX" )) - ix = new xbNtx( &d ); -#endif - -#ifdef XB_INDEX_NDX - if( strstr( ixname, "NDX" )) - ix = new xbNdx( &d ); -#endif - if( !ix ){ - std::cout << "Unknown index type. .NTX and .NDX index file support only\n"; - return 3; - } - if(( rc = ix->OpenIndex( ixname )) != XB_NO_ERROR ) - { - std::cout << "\nCould not open index " << ixname << " rc = " << rc - << "\n"; - return 4; - } - } - - -/* if -f or -F paramater, dump the header information */ - if( FieldOption ){ - for( xbLong l = 0; l < d.FieldCount(); l++ ){ - if( l ) std::cout << ","; - std::cout << d.GetFieldName(l); - if( FieldOption == 2 ){ - std::cout << "|" << d.GetFieldType(l) << "|" << d.GetFieldLen(l); - std::cout << "|" << d.GetFieldDecimal(l); - } - } - std::cout << std::endl; - } - -/* if an index used, then loop thru each record, based on index, else - dump in dbf sort order */ - if( ixname ) - rc = ix->GetFirstKey(); - else - rc = d.GetFirstRecord(); - - while( rc == XB_NO_ERROR ){ - for( xbLong l = 0; l < d.FieldCount(); l++ ){ - if( l ) std::cout << ","; - strcpy( buf, exp.LTRIM( d.GetStringField( l ))); - if( d.GetFieldType( l ) == 'D' ) - std::cout << exp.DTOC( buf ); - else - std::cout << exp.TRIM( buf ); - } - if( ixname ) - rc = ix->GetNextKey(); - else - rc = d.GetNextRecord(); - std::cout << std::endl; - } - - d.Close(); - return 0; -} diff --git a/src/utils/preamble.txt b/src/utils/preamble.txt deleted file mode 100755 index e2aeda8..0000000 --- a/src/utils/preamble.txt +++ /dev/null @@ -1,19 +0,0 @@ -/* xbXXXXX.XXX - -XBase64 Software Library - -Copyright (c) 1997,2003,2014,2017 Gary A Kunkel - -The xb64 software library is covered under -the terms of the GPL Version 3, 2007 license. - -Email Contact: - - xb64-devel@lists.sourceforge.net - xb64-users@lists.sourceforge.net - -*/ - - -namespace xb{ - diff --git a/src/utils/reindex.cpp b/src/utils/reindex.cpp deleted file mode 100755 index 3013167..0000000 --- a/src/utils/reindex.cpp +++ /dev/null @@ -1,83 +0,0 @@ -/* - Xbase64 project source code - - This sample program packs an Xbase DBF file - - Copyright (C) 1997,2003 Gary A. Kunkel - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - Contact: - - Email: - - xbase64-devel@lists.sourceforge.net - xbase64-users@lists.sourceforge.net -*/ - - -// FIXME - program needs to be updated - -#include <xbase64/xbase64.h> - -static void -showStatus(xbLong itemNum, xbLong numItems) -{ - printf("indexing record %ld of %ld\r", itemNum, numItems); - fflush(stdout); -} - -int main(int ac,char** av) -{ - if (3 != ac) { - std::cout << - "\nUsage: reindex dbf_file ndx_file\n" - ; - return 1; - } - - char* filename = av[1]; - char* filename2 = av[2]; - - xbXBase x; - xbDbf MyFile( &x ); - xbNdx MyIndex( &MyFile ); - - if( MyFile.Open( filename )) { - std::cout << "Could not open file " << filename << "\n"; - return 0; - } - if( MyIndex.OpenIndex( filename2 )) { - std::cout << "Could not open index file " << filename2 << "\n"; - return 0; - } - - xbInt16 rc = MyIndex.ReIndex(showStatus); - printf("\n"); - if( rc != XB_NO_ERROR ) { - std::cout << "\nError reindexing index ==> " << filename2; - std::cout << " Return Code = " << rc; - } - - /* or - if(( rc = MyFile.RebuildAllIndicis()) != XB_NO_ERROR ) - { - std::cout << "\nError reindexing..."; - std::cout << "\nReturn Code = " << rc; - } - */ - MyFile.Close(); - return 0; -} diff --git a/src/utils/xb_dbfutil.cpp b/src/utils/xb_dbfutil.cpp index e008155..9c04fe3 100755 --- a/src/utils/xb_dbfutil.cpp +++ b/src/utils/xb_dbfutil.cpp @@ -87,6 +87,7 @@ class xbUtil{ void CopyDbfStructure(); void UpdateTableAutoCommit(); void DisplayTableInfo(); + void RenameTable(); // 4 - RecordMenu options void GetRecord(); @@ -136,18 +137,18 @@ class xbUtil{ #ifdef XB_INDEX_SUPPORT void LockIndices(); void UnlockIndices(); - #endif // XB_INDEX_SUPPORT + #endif // XB_INDEX_SUPPORT #ifdef XB_MEMO_SUPPORT void LockMemo(); void UnlockMemo(); - #endif + #endif // XB_MEMO_SUPPORT void LockHeader(); void UnlockHeader(); void xbFileLock(); void xbFileUnlock(); - #endif + #endif // XB_LOCKING_SUPPORT // 7 - Expression Menu options #ifdef XB_EXPRESSION_SUPPORT @@ -159,8 +160,8 @@ class xbUtil{ void IsLeapYear(); #ifdef XB_DEBUG_SUPPORT void DumpExpressionTree(); - #endif - #endif + #endif // XB_DEBUG_SUPPORT + #endif // XB_EXPRESSION_SUPPORT // 8 - Index Menu Options #ifdef XB_INDEX_SUPPORT @@ -345,10 +346,12 @@ void xbUtil::UnlockIndices(){ x.DisplayError( iRc ); } -#endif // XB_LOCKING_SUPPORT +#endif // XB_LOCKING_SUPPORT +#endif // XB_INDEX_SUPPORT /*************************************************************************************/ +#ifdef XB_EXPRESSION_SUPPORT void xbUtil::ParseExpression( xbInt16 iOption ){ if( iOption == 0 ) @@ -395,9 +398,9 @@ void xbUtil::ProcessParsedExpression( xbInt16 iOption ){ if( !exp ) return; - std::cout << "Dump from w/i dbfutil before processing expression\n"; - exp->DumpTree( xbTrue ); - std::cout << "-- end of dumptree in dbfutil before processExpression\n"; + // std::cout << "Dump from w/i dbfutil before processing expression\n"; + //exp->DumpTree( xbTrue ); + //std::cout << "-- end of dumptree in dbfutil before processExpression\n"; xbInt16 iRc = exp->ProcessExpression(); if( iRc != XB_NO_ERROR ){ @@ -405,9 +408,9 @@ void xbUtil::ProcessParsedExpression( xbInt16 iOption ){ return; } - std::cout << "Dump from w/i dbfutil after processing expression\n"; - exp->DumpTree( xbTrue ); - std::cout << "-- end of dumptree in dbfutil\n"; + //std::cout << "Dump from w/i dbfutil after processing expression\n"; + //exp->DumpTree( xbTrue ); + //std::cout << "-- end of dumptree in dbfutil\n"; xbString sResult; xbDouble dResult; @@ -455,7 +458,6 @@ void xbUtil::DumpExpressionTree(){ } #endif // XB_DEBUG_SUPPORT - void xbUtil::JulToDate8(){ std::cout << "Convert Julian Date to Date8 (CCYYMMDD) format" << std::endl; std::cout << "Enter Julian Value" << std::endl; @@ -1427,6 +1429,31 @@ void xbUtil::DisplayTableInfo(){ } /*************************************************************************************/ +void xbUtil::RenameTable(){ + + if( !dActiveTable ) + dActiveTable = GetTablePtr( " - select table" ); + + if( !dActiveTable ){ + std::cout << "No table selected" << std::endl; + return; + } + + char cBuf[128]; + std::cout << "Enter new tablefile name (filename.DBF)" << std::endl; + std::cin.getline( cBuf, 128 ); + + if( cBuf[0] ){ + dActiveTable->Rename( cBuf ); + dActiveTable->Close(); + dActiveTable = NULL; + std::cout << "Table closed. Reopen if needed.\n"; + } + + +} + +/*************************************************************************************/ void xbUtil::GetRecord(){ char cBuf[15]; @@ -1528,7 +1555,7 @@ void xbUtil::UpdateTableAutoCommit(){ std::cout << "ON]" << std::endl; else std::cout << "OFF]" << std::endl; - std::cout << " 0 ==> Disable Auto Commit for table" << std::endl; + std::cout << " 0 ==> Disable Auto Commit for table" << std::endl; std::cout << " 1 ==> Enable Auto Commit for table" << std::endl; std::cout << "Current setting is [" << d->GetAutoCommit() << "]" << std::endl; char cBuf[15]; @@ -1546,7 +1573,7 @@ void xbUtil::UpdateTableAutoCommit(){ } d->SetAutoCommit( iAuto ); std::cout << "Auto Commit set to [" << d->GetAutoCommit(0) << "]" << std::endl; - if( d->GetAutoCommit() ) + if( d->GetAutoCommit() ) std::cout << "Auto Commit enabled for table" << std::endl; else std::cout << "Auto Commit disabled for table" << std::endl; @@ -1582,7 +1609,7 @@ void xbUtil::CopyDbfStructure(){ return; } std::cout << "Copy Table" << std::endl; - std::cout << "Enter new DBF file name (ie; myfile.dbf or MYFILE.DBF): "; + std::cout << "Enter new DBF file name (ie; MYFILE.DBF): "; std::cin.getline( filename, 128 ); f.SetFileName( filename ); if( strlen( filename ) == 0 ){ @@ -1725,7 +1752,7 @@ void xbUtil::Open(){ unsigned char cFileTypeByte; std::cout << "Open Table" << std::endl; - std::cout << "Enter DBF file name (.dbf or .DBF): "; + std::cout << "Enter DBF file name (.DBF): "; std::cin.getline( filename, 128 ); f.SetFileName( filename ); @@ -2138,6 +2165,8 @@ void xbUtil::ProcessOption( const xbString &sOption ){ UpdateTableAutoCommit(); else if( sOption == "=3.14" ) DisplayTableInfo(); + else if( sOption == "=3.15" ) + RenameTable(); else if( sOption == "=4" ) RecordMenu(); else if( sOption == "=4.1" ) @@ -2169,7 +2198,7 @@ void xbUtil::ProcessOption( const xbString &sOption ){ else if( sOption == "=4.14" ) CommitRecord(); #ifdef XB_FILTER_SUPPORT - else if( sOption == "=4.20" ) + else if( sOption == "=4.20" ) SetFilter(); else if( sOption == "=4.21" ) GetFirstFilterRec(); @@ -2238,8 +2267,8 @@ void xbUtil::ProcessOption( const xbString &sOption ){ xbFileLock(); else if( sOption == "=6.21" ) xbFileUnlock(); - #endif - #endif + #endif // XB_DEBUG_SUPPORT + #endif // XB_LOCKING_SUPPORT #ifdef XB_EXPRESSION_SUPPORT else if( sOption == "=7" ) @@ -2250,6 +2279,7 @@ void xbUtil::ProcessOption( const xbString &sOption ){ ProcessParsedExpression( 0 ); else if( sOption == "=7.3" ) ParseAndProcessExpression(); + #ifdef XB_DEBUG_SUPPORT else if (sOption == "=7.4" ) DumpExpressionTree(); @@ -2263,7 +2293,6 @@ void xbUtil::ProcessOption( const xbString &sOption ){ #endif // XB_EXPRESSION_SUPPORT #ifdef XB_INDEX_SUPPORT - else if( sOption == "=8" ) IndexMenu(); else if( sOption == "=8.1" ) @@ -2408,11 +2437,12 @@ void xbUtil::IndexMenu() std::cout << " 10 - Get Prev Key" << std::endl; std::cout << " 11 - Get Last Key" << std::endl; std::cout << " 12 - Find Key" << std::endl; - std::cout << " 13 - Check Index Integrity" << std::endl; + std::cout << " 13 - Check Index Integrity" << std::endl; std::cout << " 14 - Reindex" << std::endl; std::cout << " 15 - Delete Tag" << std::endl; std::cout << " 16 - Associate NDX file" << std::endl; - + + #ifdef XB_DEBUG_SUPPORT std::cout << std::endl; std::cout << " 20 - Dump Header" << std::endl; @@ -2768,6 +2798,8 @@ void xbUtil::FileMenu() std::cout << "12 - Copy Dbf Structure" << std::endl; std::cout << "13 - Update Table Auto Commit Setting" << std::endl; std::cout << "14 - Display Table Info" << std::endl; + std::cout << "15 - Rename Table" << std::endl; + std::cout << "99 - Exit Menu" << std::endl; option = GetOption(); @@ -2787,6 +2819,7 @@ void xbUtil::FileMenu() case 12: CopyDbfStructure(); break; case 13: UpdateTableAutoCommit(); break; case 14: DisplayTableInfo(); break; + case 15: RenameTable(); break; case 99: break; default: std::cout << "Invalid Option" << std::endl; @@ -2886,7 +2919,10 @@ void xbUtil::SystemMenu() void xbUtil::MainMenu() { int option = 0; - std::cout << std::endl<< std::endl << "XBase64 Utility Program"; + std::cout << std::endl<< std::endl << "XBase64 Utility Program " << + xbase_VERSION_MAJOR << "." << xbase_VERSION_MINOR << "." << + xbase_VERSION_PATCH << "\n"; + DisplayActiveTable(); while( option != 99 ) { std::cout << std::endl << std::endl << " 0 - Main Menu" << std::endl; @@ -2968,6 +3004,7 @@ void xbUtil::MainMenu() } } /*************************************************************************************/ + #ifdef XB_INDEX_SUPPORT void xbUtil::DisplayOpenIndexFiles(){ @@ -3425,8 +3462,8 @@ void xbUtil::AssociateNonProdIx(){ std::cout << "See InfFile menu option, option 11 from the main menu or =11 from here\n"; } -#ifdef XB_DEBUG_SUPPORT +#ifdef XB_DEBUG_SUPPORT void xbUtil::DumpRecsByIx( xbInt16 iOpt ){ // iDirection = 0 - Forward - MDX // = 1 - Reverse - MDX diff --git a/src/utils/xb_pack.cpp b/src/utils/xb_pack.cpp index ba61837..ccec5a3 100755 --- a/src/utils/xb_pack.cpp +++ b/src/utils/xb_pack.cpp @@ -22,11 +22,7 @@ int main(int ac,char** av) if (ac <= 1) { std::cout << "\nUsage: xb_pack filename...\n" - "\nThis program does not automatically reindex any NDX indexes." - "\nUse the reindex program to reindex any indexes associated" - "\nwith the database, or build your own program which executes " - "\nthe Pack() method after opening all the index files " - "\nassociated with the database.\n\n"; + "\nThis program does automatically reindexes any open NDX or MDX indexes."; return 1; } @@ -44,6 +40,13 @@ int main(int ac,char** av) std::cout << " Return Code = " << iRc << std::endl; } + #ifdef XB_INDEX_SUPPORT + if(( iRc = MyFile->Reindex( 1 )) != XB_NO_ERROR ) { + std::cout << "\nError reindexing DBF database ==> " << av[1] << std::endl; + std::cout << " Return Code = " << iRc << std::endl; + } + #endif // XB_INDEX_SUPPORT + MyFile->Close(); delete MyFile; diff --git a/src/utils/xb_tblinfo.cpp b/src/utils/xb_tblinfo.cpp index 884ce5e..6b88403 100755 --- a/src/utils/xb_tblinfo.cpp +++ b/src/utils/xb_tblinfo.cpp @@ -23,11 +23,17 @@ int main( int ac, char ** av ){ xbXBase x; xbBool bHdr = xbFalse; - xbBool bMdxFound = xbFalse; xbInt16 iRc; xbString sTagName; xbDbf *MyFile = NULL; + #ifdef XB_MDX_SUPPORT + #ifdef XB_DEBUG_SUPPORT + xbBool bMdxFound = xbFalse; + #endif // XB_DEBUG_SUPPORT + #endif // XB_MDX_SUPPORT + + x.EnableMsgLogging(); x.SetLogSize( 1000000L ); @@ -63,6 +69,7 @@ int main( int ac, char ** av ){ } MyFile->DumpHeader( 4 ); + #ifdef XB_MDX_SUPPORT // for each mdx file, dump the header xbIxList *ixl = MyFile->GetIxList(); xbIx *ixp; @@ -71,18 +78,23 @@ int main( int ac, char ** av ){ ixp = ixl->ix; ixp->GetFileType( sFileType ); + #ifdef XB_DEBUG_SUPPORT if( sFileType == "MDX" ){ bMdxFound = xbTrue; if( bHdr ){ - // std::cout << "MDX header\n"; ixp->DumpHeader( 1, 3 ); } } + #endif // XB_DEBUG_SUPPORT ixl = ixl->next; - } + } + #ifdef XB_DEBUG_SUPPORT if( !bMdxFound ) std::cout << "No MDX index for file." << std::endl; + #endif // XB_DEBUG_SUPPORT + #endif // XB_MDX_SUPPORT + MyFile->Close(); delete MyFile; |