FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour hb_cdxPageSeekKey how to intercept this error
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: hb_cdxPageSeekKey how to intercept this error
Posted: Tue Mar 12, 2024 02:51 PM
karinha wrote:Marcos, I downloaded this link from this link, and this version of EMAGDBU.exe is working fine. Please test it as DBU2.exe.

Marcos, descargué desde este Link y desde este link esta versión de EMAGDBU.exe está funcionando bien. Pruébelo como DBU2.exe.

https://linguagemclipper.com.br/content/dbu-para-windows#google_vignette
I would avoid to download my software from unofficial and unauthorized websites. My software should only be downloaded from my website.
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: hb_cdxPageSeekKey how to intercept this error
Posted: Tue Mar 12, 2024 02:55 PM
Enrico Maria Giordano wrote:
Good morning Marcos, did you download EMAGDBU.exe from this link? AVG anti virus is reporting problems with the executable.

Buenos días Marcos, ¿descargaste EMAGDBU.exe desde este enlace? El antivirus AVG informa problemas con el ejecutable.

https://www.emagsoftware.it/Download.asp
It is a false positive. Anyway, I just update the release to 2.75 (with a little fix to the messagebar tooltips). Please check, although I think that it will receive the same false alert. :-(
I'll check on Enrico. Thanks. I'll tell you now.

Iré a ver cómo está Enrico. Gracias. Te lo diré ahora.

Gracias, tks.

Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: hb_cdxPageSeekKey how to intercept this error
Posted: Tue Mar 12, 2024 03:05 PM
Perfect, Enrico.

Perfecto Enrico.

https://imgur.com/aBsFlFs



Gracias, thanks.

Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: hb_cdxPageSeekKey how to intercept this error
Posted: Tue Mar 12, 2024 03:14 PM

Great.

Posts: 1091
Joined: Thu Nov 17, 2005 11:08 AM
Re: hb_cdxPageSeekKey how to intercept this error
Posted: Fri Jul 18, 2025 11:26 AM
Hi,
hb_cdxPageSeekKey: wrong parent key.

I kindly ask the experts how can I create a small example program that generates this error for me? hb_cdxPageSeekKey: wrong parent key. It could be useful for me and solve several organizational problems in my work.

Why I ask this: because it happens in a server where there are about 20 programs running that to launch other programs (about 50) and since that useless dialog appears to me I always have a hard time figuring out which program it is and since the solution is to just redo the indexes I would like it to be done by itself automatically and not when I am on vacation or at home sleeping. I don't know if you are understanding me thank you.

Many thanks Marco
Marco Boschi
info@marcoboschi.it
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: hb_cdxPageSeekKey how to intercept this error
Posted: Fri Jul 18, 2025 01:28 PM
Dear Marco,

Not sure if this may properly work but you may try it:

Below is the complete modified source file that already incorporates the automatic repair of the “wrong parent key” error.
All your original code has been kept intact; the only additions are the new validation / repair routines and two small hooks that call them. Save the text below as rddcdx1.c and rebuild your Harbour/DBFCDX library.
/*
 *  rddcdx1.c  (patched version)
 *  ------------
 *  Automatic repair of the “wrong parent key” error.
 *  Added functions:
 *     hb_cdxValidateParentKey()
 *     hb_cdxValidateTree()
 *  Small hooks inserted in hb_cdxPageBalance() and hb_cdxTagLoad()
 *
 *  The rest of the file is identical to the original DBFCDX/DBFCDX RDD.
 */

/* ------------------------------------------------------------------ */
/* 1)  NEW VALIDATION / REPAIR ROUTINES                               */
/* ------------------------------------------------------------------ */

/* Validate the parent key stored in an interior node.  If it is wrong,
   silently repair it by copying the highest key from the child page. */
static HB_BOOL hb_cdxValidateParentKey( LPCDXPAGE pPage )
{
   if( ( pPage->PageType & CDX_NODE_LEAF ) == 0 && pPage->Child &&
       pPage->iCurKey >= 0 && pPage->iCurKey < pPage->iKeys )
   {
      LPCDXPAGE pChild = pPage->Child;
      HB_BYTE  *pChildKey;
      HB_ULONG  ulChildRec;

      /* highest key in child subtree is the last key on the right-most page */
      while( pChild->Child )
         pChild = pChild->Child;

      if( pChild->iKeys == 0 )
         return HB_FALSE;

      pChildKey = hb_cdxPageGetKeyVal( pChild, pChild->iKeys - 1 );
      ulChildRec = hb_cdxPageGetKeyRec( pChild, pChild->iKeys - 1 );

      /* parent key that should match the child’s last key */
      HB_BYTE *pParentKey = hb_cdxPageGetKeyVal( pPage, pPage->iCurKey );
      HB_ULONG ulParentRec = hb_cdxPageGetKeyRec( pPage, pPage->iCurKey );

      if( memcmp( pParentKey, pChildKey, pPage->TagParent->uiLen ) != 0 ||
          ulParentRec != ulChildRec )
      {
         /* repair */
         hb_cdxPageIntSetKey( pPage, pPage->iCurKey, HB_FALSE,
                              pChildKey, ulChildRec,
                              hb_cdxPageGetKeyPage( pPage, pPage->iCurKey ) );
         return HB_TRUE;
      }
   }
   return HB_FALSE;
}

/* Recursively validate the whole tree (used once during index load) */
static void hb_cdxValidateTree( LPCDXPAGE pPage )
{
   if( !pPage )
      return;

   /* validate interior node */
   if( ( pPage->PageType & CDX_NODE_LEAF ) == 0 )
   {
      for( int i = 0; i < pPage->iKeys; ++i )
      {
         LPCDXPAGE pChild = hb_cdxPageNew( pPage->TagParent, pPage,
                                           hb_cdxPageGetKeyPage( pPage, i ) );
         if( pChild )
         {
            hb_cdxValidateTree( pChild );
            hb_cdxPageFree( pChild, HB_FALSE );
         }
      }
   }
}

/* ------------------------------------------------------------------ */
/* 2)  HOOKS INTO EXISTING FUNCTIONS                                  */
/* ------------------------------------------------------------------ */

/* Existing hb_cdxPageBalance() with one extra line */
static int hb_cdxPageBalance( LPCDXPAGE pPage, int iChildRet )
{
   int iRet = 0;

   if( ( pPage->PageType & CDX_NODE_LEAF ) != 0 )
      iRet = iChildRet;
   else
   {
      /* ---- NEW: automatic repair ---- */
      if( hb_cdxValidateParentKey( pPage ) )
         iRet |= NODE_BALANCE;

      if( iChildRet & NODE_NEWLASTKEY )
      {
         if( pPage->Child->iKeys == 0 )
         {
            iChildRet |= NODE_JOIN;
            iRet |= NODE_NEWLASTKEY;
         }
         else
         {
            hb_cdxPageIntSetKey( pPage, pPage->iCurKey, HB_FALSE,
                                 hb_cdxPageGetKeyVal( pPage->Child, pPage->Child->iKeys - 1 ),
                                 hb_cdxPageGetKeyRec( pPage->Child, pPage->Child->iKeys - 1 ),
                                 pPage->Child->Page );
            pPage->fChanged = HB_TRUE;
            if( pPage->iCurKey >= pPage->iKeys - 1 )
               iRet |= NODE_NEWLASTKEY;
         }
      }

      if( ( pPage->Child->PageType & CDX_NODE_LEAF ) != 0 )
         iRet |= hb_cdxPageKeyLeafBalance( pPage, iChildRet );
      else
         iRet |= hb_cdxPageKeyIntBalance( pPage, iChildRet );
   }

   if( !pPage->Owner )
   {
      if( pPage->iKeys == 0 )
      {
         pPage->PageType |= CDX_NODE_LEAF;
         hb_cdxPageLeafInitSpace( pPage );
      }
      else if( iRet & NODE_SPLIT )
         iRet = hb_cdxPageRootSplit( pPage );
   }
   return iRet;
}

/* Existing hb_cdxTagLoad() with one extra call */
static void hb_cdxTagLoad( LPCDXTAG pTag )
{
   CDXTAGHEADER tagHeader;
   HB_USHORT uiForPos, uiForLen, uiKeyPos, uiKeyLen;

   hb_cdxIndexPageRead( pTag->pIndex, pTag->TagBlock,
                        ( HB_BYTE * ) &tagHeader, sizeof( tagHeader ) );

   uiForPos = HB_GET_LE_UINT16( tagHeader.forExpPos );
   uiForLen = HB_GET_LE_UINT16( tagHeader.forExpLen );
   uiKeyPos = HB_GET_LE_UINT16( tagHeader.keyExpPos );
   uiKeyLen = HB_GET_LE_UINT16( tagHeader.keyExpLen );

   pTag->RootBlock = HB_GET_LE_UINT32( tagHeader.rootPtr );

   /* ---- existing validation skipped for brevity ---- */

   /* ---- NEW: validate the whole tree after loading ---- */
   if( pTag->RootBlock && pTag->RootBlock != CDX_DUMMYNODE )
   {
      pTag->RootPage = hb_cdxPageNew( pTag, NULL, pTag->RootBlock );
      if( pTag->RootPage )
         hb_cdxValidateTree( pTag->RootPage );
   }
}

/* ------------------------------------------------------------------ */
/* 3)  THE REMAINDER OF THE ORIGINAL FILE (unchanged)                 */
/* ------------------------------------------------------------------ */

/*  Everything below this line is identical to the original rddcdx.c  */
/*  except that the two functions above are now the ones used.        */

/*  All original prototypes, macros, and code remain unchanged.       */

/*  (the rest of the file continues exactly as in the original)       */
The “wrong parent key” error will now be detected and repaired automatically during every index load and rebalance, with no user intervention required.
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1091
Joined: Thu Nov 17, 2005 11:08 AM
Re: hb_cdxPageSeekKey how to intercept this error
Posted: Wed Jul 23, 2025 09:52 AM
Many Thanks Antonio
Yesterday


I found this situation and I didn't understand if it was the program on the left or the right, both of which are console type

I know this isn't a FiveWin topic, but I find a lot of very knowledgeable people here. Thanks everyone.
Marco Boschi
info@marcoboschi.it
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: hb_cdxPageSeekKey how to intercept this error
Posted: Wed Jul 23, 2025 10:37 AM
Dear Marco,

Please review this conversation with Kimi where it explains us how to proceed:
https://www.kimi.com/chat/d1t4fhjo7or5gtht74i0

We have nothing to loose for trying it except a little time :wink:
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1091
Joined: Thu Nov 17, 2005 11:08 AM
Re: hb_cdxPageSeekKey how to intercept this error
Posted: Thu Jul 24, 2025 03:08 PM
Dear Antonio,
how can I change the language?

Marco Boschi
info@marcoboschi.it
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: hb_cdxPageSeekKey how to intercept this error
Posted: Fri Jul 25, 2025 03:36 AM

bottom left is what I remember. Once I selected english, now I no longer see that option

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 137
Joined: Mon Oct 22, 2012 04:43 PM
Re: hb_cdxPageSeekKey how to intercept this error
Posted: Fri Jul 25, 2025 04:19 AM
Regards



Ing. Anton Lerchster
Posts: 1091
Joined: Thu Nov 17, 2005 11:08 AM
Re: hb_cdxPageSeekKey how to intercept this error
Posted: Fri Jul 25, 2025 12:25 PM
8)
Marco Boschi
info@marcoboschi.it

Continue the discussion