summaryrefslogtreecommitdiff
path: root/src/core/xbixndx.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/xbixndx.cpp')
-rwxr-xr-xsrc/core/xbixndx.cpp54
1 files changed, 34 insertions, 20 deletions
diff --git a/src/core/xbixndx.cpp b/src/core/xbixndx.cpp
index 9d946dd..b28dd9d 100755
--- a/src/core/xbixndx.cpp
+++ b/src/core/xbixndx.cpp
@@ -2,7 +2,7 @@
XBase64 Software Library
-Copyright (c) 1997,2003,2014,2022 Gary A Kunkel
+Copyright (c) 1997,2003,2014,2022,2023 Gary A Kunkel
The xb64 software library is covered under the terms of the GPL Version 3, 2007 license.
@@ -309,8 +309,8 @@ xbInt16 xbIxNdx::CheckForDupKey( void *vpTag )
\param vpTag Tag to create key for.
\param iOpt Output message destination<br>
- 0 = stdout<br>
- 1 = Syslog<br>
+ 0 = Syslog<br>
+ 1 = Stdout<br>
2 = Both<br>
\returns <a href="xbretcod_8h.html">Return Codes</a>
*/
@@ -609,7 +609,8 @@ xbInt16 xbIxNdx::CreateTag( const xbString &sName, const xbString &sKey,
npTag->iUnique = iUnique;
npTag->ulRootBlock = 1L;
- npTag->ulTotalBlocks = 2l;
+ //npTag->ulTotalBlocks = 2l;
+ npTag->ulTotalBlocks = 2L;
npTag->sKeyExpression = sKey;
GetFileNamePart( npTag->sTagName );
@@ -2426,62 +2427,75 @@ xbInt16 xbIxNdx::Reindex( void **vpTag ){
xbInt16 iRc = XB_NO_ERROR;
xbInt16 iErrorStop = 0;
- //xbNdxTag * npTag;
- //vpTag ? npTag = (xbNdxTag *) vpTag : npTag = ndxTag;
+ xbNdxTag *npTag = ndxTag;
try{
- xbString sFileName = GetFqFileName();
- xbString sKey; // = GetKeyExpression( vpTag );
- sKey.Set( GetKeyExpression( *vpTag ));
xbInt16 iUnique = GetUnique( *vpTag );
- xbString sFilter = "";
- void *vpTag2;
- if(( iRc = CreateTag( sFileName, sKey, sFilter, 0, iUnique, xbTrue, &vpTag2 )) != XB_NO_ERROR ){
+ npTag->npNodeChain = FreeNodeChain( npTag->npNodeChain );
+ npTag->npCurNode = NULL;
+ npTag->ulRootBlock = 1L;
+ npTag->ulTotalBlocks = 2L;
+
+ if(( iRc = xbTruncate( 1024 )) != XB_NO_ERROR ){
iErrorStop = 100;
throw iRc;
}
+ if(( iRc = WriteHeadBlock( 1 )) != XB_NO_ERROR ){
+ iErrorStop = 110;
+ throw iRc;
+ }
+ char buf[512];
+ memset( buf, 0x00, 512 );
+
+ if(( iRc = WriteBlock( 1, 0, buf )) != XB_NO_ERROR ){
+ iErrorStop = 120;
+ throw iRc;
+ }
+
xbUInt32 ulRecCnt = 0;
if(( iRc = dbf->GetRecordCnt( ulRecCnt )) != XB_NO_ERROR ){
- iErrorStop = 110;
+ iErrorStop = 130;
throw iRc;
}
for( xbUInt32 l = 1; l <= ulRecCnt; l++ ){
if(( iRc = dbf->GetRecord( l )) != XB_NO_ERROR ){
- iErrorStop = 120;
+ iErrorStop = 140;
throw iRc;
}
- if(( iRc = CreateKey( vpTag2, 1 )) != XB_NO_ERROR ){
- iErrorStop = 130;
+ if(( iRc = CreateKey( npTag, 1 )) != XB_NO_ERROR ){
+ iErrorStop = 150;
throw iRc;
}
if( iUnique ){
- iRc = CheckForDupKey( vpTag2 );
+ // iRc = CheckForDupKey( vpTag2 );
+ iRc = CheckForDupKey( npTag );
if( iRc != 0 ){
if( iRc < 0 ){
- iErrorStop = 140;
+ iErrorStop = 160;
throw iRc;
}
return XB_KEY_NOT_UNIQUE;
}
}
- if(( iRc = AddKey( vpTag2, l )) != XB_NO_ERROR ){
+ if(( iRc = AddKey( npTag, l )) != XB_NO_ERROR ){
iErrorStop = 150;
throw iRc;
}
}
- *vpTag = vpTag2;
+ *vpTag = npTag;
}
catch (xbInt16 iRc ){
xbString sMsg;
sMsg.Sprintf( "xbIxNdx::Reindex() Exception Caught. Error Stop = [%d] iRc = [%d]", iErrorStop, iRc );
xbase->WriteLogMessage( sMsg.Str() );
xbase->WriteLogMessage( GetErrorMessage( iRc ));
+ this->DeleteTag( NULL ); // Don't leave the index in an incomplete state
}
return iRc;
}