CreateIndex does not erase temporary files

CreateIndex does not erase temporary files

Postby ellano » Wed Feb 13, 2019 8:07 pm

I have the following problem when using CreateIndex to create temporary indexes:

Code: Select all  Expand view  RUN
//1st function

       USE Clients Alias clients SHARED NEW
       DATABASE oDbfC
       //temporary index CreateIndex( [cFile], cTag, cKey, [lUnique], [lDescend], [lMemory] )
       
       oDbfC:CreateIndex( nil, "Clients", "Client->Name" , nil, nil, .T.)
       oDbfH:LOAD()
       oDbfH:GoTop()
       
       BrowseTable( oDbfC )
       oDbfC:CLOSE()


// 2nd function:

  SELECT animals
  DATABASE oDbfG

   //create temporary index CreateIndex( [cFile], cTag, cKey, [lUnique], [lDescend], [lMemory] )
  oDbfG:CreateIndex( nil,"Main",    "animals->number"                                            , nil, nil,.T.)    //error here since tmp.cdx exist
  oDbfG:CreateIndex( nil,"Name",    "Left(PADR(ALLTRIM(animals->Name),25),25)"  , nil, nil,.T.)
  oDbfG:CreateIndex( nil,"Color",     "Left(PADR(ALLTRIM(animals->Color),25),25)" , nil, nil,.T.)
  oDbfG:CreateIndex( nil,"Brand",    "Left(PADR(ALLTRIM(animals->Brand),3),3)"    , nil, nil,.T.)
  oDbfG:CreateIndex( nil,"Born",      "DTOS(animals->Born)"                                   , nil, nil,.T.)
  oDbfG:CreateIndex( nil,"BornNum", "DTOS(animals->Born) + animals->number"     , nil, nil,.T.)
...
 


Since the temporary index file is not erased at the end of the process, I forced it by adding the following code to erase it manually:

Code: Select all  Expand view  RUN
//1st function

       USE Clients Alias clients SHARED NEW
       DATABASE oDbfC
       //temporary index CreateIndex( [cFile], cTag, cKey, [lUnique], [lDescend], [lMemory] )
       if File( GetcurDir()+"\tmp.cdx" )  //should have been done by Fivewin since this is a temp index
          FErase( GetcurDir()+"\tmp.cdx" )
       endif
       oDbfC:CreateIndex( nil, "Clients", "Client->Name" , nil, nil, .T.)
       oDbfH:LOAD()
       oDbfH:GoTop()
       
       BrowseTable( oDbfC )

       oDbfC:CLOSE()
       oDbfC:End() //this was added to see if the temporary index file was erased (did not work)


// 2nd program:

  SELECT animals
  DATABASE oDbfG

   //create temporary index CreateIndex( [cFile], cTag, cKey, [lUnique], [lDescend], [lMemory] )
  if File( GetcurDir()+"\tmp.cdx" )
     FErase( GetcurDir()+"\tmp.cdx" )
  endif
  oDbfG:CreateIndex( nil,"Main",    "animals->number"                                            , nil, nil,.T.)    //No error since I erased tmp.cdx
  oDbfG:CreateIndex( nil,"Name",    "Left(PADR(ALLTRIM(animals->Name),25),25)"  , nil, nil,.T.)
  oDbfG:CreateIndex( nil,"Color",     "Left(PADR(ALLTRIM(animals->Color),25),25)" , nil, nil,.T.)
  oDbfG:CreateIndex( nil,"Brand",    "Left(PADR(ALLTRIM(animals->Brand),3),3)"    , nil, nil,.T.)
  oDbfG:CreateIndex( nil,"Born",      "DTOS(animals->Born)"                                   , nil, nil,.T.)
  oDbfG:CreateIndex( nil,"BornNum", "DTOS(animals->Born) + animals->number"     , nil, nil,.T.)

...
 


Isn't FW supposed to erase the temporary index file by itself?

Emiliano Llano Díaz
ellano
 
Posts: 107
Joined: Tue Sep 15, 2009 7:52 am

Re: CreateIndex does not erase temporary files

Postby nageswaragunupudi » Thu Feb 14, 2019 1:38 am

Temporary (memory) indexes are automatically erased by the system. We need not manually delete them.

The real problem here is that there is a bug in the method CreateIndex(...) of TDatabase. Though you wanted to create Memory Index, the method is creating it is a normal index on the disk due to this bug.

Please apply this fix to your copy of the database.prg.
Please locate this line of code in the METHOD td_CreateIndex( ... )
Code: Select all  Expand view  RUN
OrdCondSet(,,,,,,0,,,,lDescend,lAdditive,,,,,lMemory,,)


Please replace this line with the correct code as below:
Code: Select all  Expand view  RUN
OrdCondSet(,,,,,,0,,,,lDescend,nil,lAdditive,,,,,lMemory,,)


With this fix, the index is created in memory and not on disk. There will be no need to manually erase those index files.

This bug is fixed at our end in version FWH 1902.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10655
Joined: Sun Nov 19, 2006 5:22 am
Location: India


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 34 guests