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
With best regards.
Sudip