From 0193067d9221a6a03a8ae78b2a594b4d2ad0bc1c Mon Sep 17 00:00:00 2001 From: "Alexander S.Kresin" Date: Mon, 14 May 2001 18:15:39 +0000 Subject: [PATCH] 2001-05-14 22:14 GMT+3 Alexander Kresin --- harbour/ChangeLog | 5 ++ harbour/source/rdd/dbfntx/dbfntx1.c | 115 +++++++++++++++++----------- 2 files changed, 74 insertions(+), 46 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 37512b854a..d952a90ec6 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,8 @@ +2001-05-14 22:14 GMT+3 Alexander Kresin + * source/rdd/dbfntx/dbfntx1.c + * bugs fixed, reported by John M. S. Chiang, related to indexing of + an empty file and packing + 2001-05-13 07:55 UTC-0800 Brian Hays * source/rdd/dbcmd.c diff --git a/harbour/source/rdd/dbfntx/dbfntx1.c b/harbour/source/rdd/dbfntx/dbfntx1.c index e99d289535..45bc120596 100644 --- a/harbour/source/rdd/dbfntx/dbfntx1.c +++ b/harbour/source/rdd/dbfntx/dbfntx1.c @@ -680,62 +680,76 @@ static void hb_ntxTagKeyRead( LPTAGINFO pTag, BYTE bTypRead ) } } pTag->TagBOF = pTag->TagEOF = FALSE; - if( pTag->Owner->Owner->fShared ) - while( !hb_fsLock( pTag->Owner->DiskFile, 0, 512, FL_LOCK ) ); - switch( bTypRead ) + if( pTag->Owner->Owner->ulRecCount ) { - case TOP_RECORD: - if( pTag->pForItem != NULL ) - printf( "hb_ntxTagKeyRead()" ); - else - pTag->TagBOF = !hb_ntxPageReadTopKey( NULL,0 ); - if( pTag->pForItem != NULL ) - printf( "hb_ntxTagTestRange()" ); - if( pTag->TagEOF ) - pTag->TagBOF = TRUE; - pTag->TagEOF = pTag->TagBOF; - break; - - case BTTM_RECORD: - if( pTag->pForItem != NULL ) - printf( "hb_ntxTagKeyRead()" ); - else - pTag->TagEOF = !hb_ntxPageReadBottomKey( NULL,0 ); - if( pTag->pForItem != NULL ) - printf( "hb_ntxTagTestRange()" ); - if( pTag->TagBOF ) - pTag->TagEOF = TRUE; - pTag->TagBOF = pTag->TagEOF; - break; - - case NEXT_RECORD: - while( TRUE ) - { - pTag->TagEOF = !hb_ntxPageReadNextKey( pTag ); + if( pTag->Owner->Owner->fShared ) + while( !hb_fsLock( pTag->Owner->DiskFile, 0, 512, FL_LOCK ) ); + switch( bTypRead ) + { + case TOP_RECORD: if( pTag->pForItem != NULL ) printf( "hb_ntxTagKeyRead()" ); else - break; - } - break; + pTag->TagBOF = !hb_ntxPageReadTopKey( NULL,0 ); + if( pTag->pForItem != NULL ) + printf( "hb_ntxTagTestRange()" ); + if( pTag->TagEOF ) + pTag->TagBOF = TRUE; + pTag->TagEOF = pTag->TagBOF; + break; - case PREV_RECORD: - while( TRUE ) - { - pTag->TagBOF = !hb_ntxPageReadPrevKey( pTag ); + case BTTM_RECORD: if( pTag->pForItem != NULL ) printf( "hb_ntxTagKeyRead()" ); else - break; - } - break; + pTag->TagEOF = !hb_ntxPageReadBottomKey( NULL,0 ); + if( pTag->pForItem != NULL ) + printf( "hb_ntxTagTestRange()" ); + if( pTag->TagBOF ) + pTag->TagEOF = TRUE; + pTag->TagBOF = pTag->TagEOF; + break; + case NEXT_RECORD: + while( TRUE ) + { + pTag->TagEOF = !hb_ntxPageReadNextKey( pTag ); + if( pTag->pForItem != NULL ) + printf( "hb_ntxTagKeyRead()" ); + else + break; + } + break; + + case PREV_RECORD: + while( TRUE ) + { + pTag->TagBOF = !hb_ntxPageReadPrevKey( pTag ); + if( pTag->pForItem != NULL ) + printf( "hb_ntxTagKeyRead()" ); + else + break; + } + break; + + } + if( pTag->Owner->Owner->fShared ) + { + hb_ntxPageFree( pTag->RootPage,TRUE ); + pTag->RootPage = NULL; + hb_fsLock( pTag->Owner->DiskFile, 0, 512, FL_UNLOCK ); + } } - if( pTag->Owner->Owner->fShared ) + else { - hb_ntxPageFree( pTag->RootPage,TRUE ); - pTag->RootPage = NULL; - hb_fsLock( pTag->Owner->DiskFile, 0, 512, FL_UNLOCK ); + if( bTypRead == PREV_RECORD) + { + pTag->TagBOF = TRUE; pTag->TagEOF = FALSE; + } + else + { + pTag->TagBOF = TRUE; pTag->TagEOF = TRUE; + } } if( pTag->TagBOF || pTag->TagEOF ) { @@ -1570,6 +1584,13 @@ static void hb_ntxBufferSave( LPTAGINFO pTag, LPNTXSORTINFO pSortInfo ) i * ( pTag->KeyLength + 8 ); buffer = pSortInfo->pageBuffers[0]; + if( !pKey ) + { + itemlist->item_count = 0; + pSortInfo->Tag += NTXBLOCKSIZE; + hb_fsWrite( pTag->Owner->DiskFile, (BYTE *) buffer, NTXBLOCKSIZE ); + } + /* printf( "\nhb_ntxBufferSave - 1 ( maxKeys=%d )",maxKeys ); */ while( pKey ) { @@ -1654,7 +1675,7 @@ static ERRCODE hb_ntxIndexCreate( LPNTXINDEX pIndex ) /* itemLength = sizeof( LPSORTITEM ) + sizeof( ULONG ) + pTag->KeyLength; */ sortInfo.itemLength = sizeof( LPSORTITEM ) + sizeof( ULONG ) + pTag->KeyLength; sortInfo.nItems = 0; - sortInfo.pKey1 = sortInfo.pKey2 = NULL; + sortInfo.pKey1 = sortInfo.pKey2 = sortInfo.pKeyFirst = NULL; sortInfo.sortBuffer = (BYTE*) hb_xalloc( ulRecCount * sortInfo.itemLength ); if( !sortInfo.sortBuffer ) { @@ -2717,6 +2738,8 @@ static ERRCODE ntxOrderListRebuild( NTXAREAP pArea ) pArea->fValidBuffer = TRUE; while( lpIndex ) { + if( lpIndex->CompoundTag->RootPage ) + hb_ntxPageFree( lpIndex->CompoundTag->RootPage,TRUE ); hb_fsSeek( lpIndex->DiskFile, NTXBLOCKSIZE, FS_SET ); hb_fsWrite( lpIndex->DiskFile, NULL, 0 ); hb_ntxIndexCreate( lpIndex );