Alternate PACK Command

Discuss anything else that does not suite other forums.

Moderator: Rathinagiri

Post Reply
User avatar
sudip
Posts: 1454
Joined: Sat Mar 07, 2009 11:52 am
Location: Kolkata, WB, India

Alternate PACK Command

Post by sudip »

Hello All,

Recently I was looking at the PACK command. It removes deleted records from a database file (dbf). Some experts say it is a dangerous command, because (AFIK) during deletion it doesn't maintain a backup file. So during PACK if there is power failure (without having UPS), there may be serious damage to our data.

I checked our good old UDF, written be Clipper Guru Rick Spence with minor modification by me. I used it long time ago but later abandoned due to it's slow speed at that time (also I transferred my main development platform to VFP). Recently I found this works very well with more security (not the best) than PACK command.

Can we make it a more feature rich and secure UDF? Eg, backup option, way to show the progress etc.

Here is the old code:

Code: Select all

Function Pack_dbf(dbf_name)
   local save_sel

   save_sel := select()

   if select(dbf_name) > 0
      select (dbf_name)
      use
   endif

   rename (dbf_name + ".dbf") to _temp.dbf
   if file(dbf_name + ".dbt")
      rename (dbf_name + ".dbt") to _temp.dbt
   endif

   use _temp new exclusive
   copy to (dbf_name) for !deleted()
   use

   delete file _temp.dbf
   if file("_temp.dbt")
      delete file _temp.dbt
   endif

   select (save_sel)
   return nil
Thanks in advance.

With best regards.

Sudip
With best regards,
Sudip
Post Reply