diff --git a/harbour/source/rdd/dbfcdx/dbfcdx1.c b/harbour/source/rdd/dbfcdx/dbfcdx1.c index 333a1e0cf2..4e0f81102d 100644 --- a/harbour/source/rdd/dbfcdx/dbfcdx1.c +++ b/harbour/source/rdd/dbfcdx/dbfcdx1.c @@ -141,7 +141,10 @@ HB_INIT_SYMBOLS_BEGIN( dbfcdx1__InitSymbols ) { "_DBFCDX", HB_FS_PUBLIC, HB_FUNCNAME( _DBFCDX ), NULL }, { "DBFCDX_GETFUNCTABLE", HB_FS_PUBLIC, HB_FUNCNAME( DBFCDX_GETFUNCTABLE ), NULL } HB_INIT_SYMBOLS_END( dbfcdx1__InitSymbols ) -#if defined(_MSC_VER) + +#if defined(HB_STATIC_STARTUP) + #pragma startup dbfcdx1__InitSymbols +#elif defined(_MSC_VER) #if _MSC_VER >= 1010 #pragma data_seg( ".CRT$XIY" ) #pragma comment( linker, "/Merge:.CRT=.data" ) @@ -2728,7 +2731,10 @@ static LONG hb_cdxTagKeyFind( LPCDXTAG pTag, LPCDXKEYINFO pKey ) if ( pKey->Tag == CDX_MAX_REC_NUM ) { USHORT dav; hb_cdxPageRetrieveKey( pTag->RootPage, &pTag->CurKeyInfo ); - hb_cdxTagKeyRead( pTag, PREV_RECORD ); + if( pTag->AscendKey ) + hb_cdxTagKeyRead( pTag, PREV_RECORD ); + else + hb_cdxTagKeyRead( pTag, NEXT_RECORD ); if ( pTag->CurKeyInfo->Tag ) { if ( hb_cdxKeyCompare( pKey, pTag->CurKeyInfo, &dav, FALSE ) == 0 ) ret = pTag->CurKeyInfo->Tag; @@ -3977,7 +3983,7 @@ static BYTE hb_cdxPageKeyLeafBalance( LPCDXPAGEINFO pPage ) for ( j = i ; j < nChilds ; j++ ) { /* Delete parent key */ - pKey = hb_cdxPageGetKey( pPage, nFirstChild + j - 1 ); + pKey = hb_cdxPageGetKey( pPage, nFirstChild + i - 1 ); pKeyTmp = pKey->pNext; pKey->pNext = pKeyTmp->pNext; hb_cdxKeyFree( pKeyTmp ); @@ -6707,10 +6713,6 @@ ERRCODE hb_cdxSeek( CDXAREAP pArea, BOOL bSoftSeek, PHB_ITEM pKey, BOOL bFindLas LPCDXTAG pTag = hb_cdxGetActiveTag( pArea ); HB_TRACE(HB_TR_DEBUG, ("cdxSeek(%p, %d, %p, %d)", pArea, bSoftSeek, pKey, bFindLast)); - /*HB_SYMBOL_UNUSED( pArea ); */ - /*HB_SYMBOL_UNUSED( bSoftSeek ); */ - /*HB_SYMBOL_UNUSED( pKey ); */ - /*HB_SYMBOL_UNUSED( bFindLast ); */ if( FAST_GOCOLD( ( AREAP ) pArea ) == FAILURE ) return FAILURE; @@ -6733,6 +6735,13 @@ ERRCODE hb_cdxSeek( CDXAREAP pArea, BOOL bSoftSeek, PHB_ITEM pKey, BOOL bFindLas pKey2 = hb_cdxKeyNew(); hb_cdxKeyPutItem( pKey2, pKey ); + if ( !pTag->AscendKey ) + { + if ( bFindLast ) + bFindLast = 0; + else + bFindLast = 1; + } if( bFindLast ) pKey2->Tag = CDX_MAX_REC_NUM; else @@ -6742,20 +6751,8 @@ ERRCODE hb_cdxSeek( CDXAREAP pArea, BOOL bSoftSeek, PHB_ITEM pKey, BOOL bFindLas hb_cdxIndexLockRead( pTag->pIndex, pTag ); lRecno = hb_cdxTagKeyFind( pTag, pKey2 ); - /* - if( bFindLast ) - { - USHORT dav; - hb_cdxTagKeyRead( pTag, PREV_RECORD ); - if ( pTag->CurKeyInfo->Tag ) { - if ( hb_cdxKeyCompare( pKey2, pTag->CurKeyInfo, &dav, FALSE ) == 0 ) - lRecno = pTag->CurKeyInfo->Tag; - } - } - */ pArea->fEof = pTag->TagEOF; pArea->fBof = pTag->TagBOF; - /* hb_cdxKeyFree( pKey2 ); */ if( lRecno > 0 ) { @@ -6769,16 +6766,6 @@ ERRCODE hb_cdxSeek( CDXAREAP pArea, BOOL bSoftSeek, PHB_ITEM pKey, BOOL bFindLas lRecno = 0; pTag->TagEOF = 1; } - /*-----------------20/09/2002 11:38a.--------------- - * maybe this is not needed anymore after last changes - * -------------------------------------------------- - else if( strncmp( pKey->item.asString.value, pTag->CurKeyInfo->Value, - ( pKey->item.asString.length < pTag->CurKeyInfo->length ? - pKey->item.asString.length : pTag->CurKeyInfo->length) ) != 0 ) - { - lRecno = 0; - } - */ break; } } @@ -6818,7 +6805,6 @@ ERRCODE hb_cdxSeek( CDXAREAP pArea, BOOL bSoftSeek, PHB_ITEM pKey, BOOL bFindLas } } hb_cdxKeyFree( pKey2 ); - /* return retvalue; */ } else { @@ -6827,7 +6813,6 @@ ERRCODE hb_cdxSeek( CDXAREAP pArea, BOOL bSoftSeek, PHB_ITEM pKey, BOOL bFindLas if( bSoftSeek && !pTag->TagEOF ) { - //return SELF_GOTO( ( AREAP ) pArea, pTag->CurKeyInfo->Tag ); retvalue = SELF_GOTO( ( AREAP ) pArea, pTag->CurKeyInfo->Tag ); if( retvalue != FAILURE ) if ( hb_set.HB_SET_DELETED || pArea->dbfi.itmCobExpr != NULL ) @@ -6837,7 +6822,6 @@ ERRCODE hb_cdxSeek( CDXAREAP pArea, BOOL bSoftSeek, PHB_ITEM pKey, BOOL bFindLas else retvalue = SELF_SKIPFILTER( ( AREAP ) pArea, 1 ); } - /* return retvalue; */ } else { @@ -6851,7 +6835,6 @@ ERRCODE hb_cdxSeek( CDXAREAP pArea, BOOL bSoftSeek, PHB_ITEM pKey, BOOL bFindLas hb_cdxIndexUnLockRead( pTag->pIndex, pTag ); return retvalue; } - /*return SUCCESS; */ } // ( DBENTRYP_L ) hb_cdxSkip : NULL