Board index » delphi » PACK of dBase III-table?

PACK of dBase III-table?

How can I PACK dBase III-tables with Delphi 2 (and SQL)?

The SQL-command DELETE just deletes the record with a mask, but the
record remain fysically. I want to clean up these tables with some sort
of PACK-command.

It is of course possible to copy the active records in the table to a
temporary table and rename it back, but I hope for an easier way.

Thank you!

Gjermund Omholt
g...@envitech.no

 

Re:PACK of dBase III-table?


In article <362DD2BE.C6BCF...@envitech.no>, EnviTech AS <p...@envitech.no>
writes:

Quote
>How can I PACK dBase III-tables with Delphi 2 (and SQL)?

You have to use a BDE function on a table opened exclusively. This is the
procedure I use satisfactorily. As I use filters I have to lift and replace
those. I also re-number some unique Ids in the table  If you're using only SQL
and for your purposes you don't need to do either of those.

var
  i : integer;
  OldOnFilterRecord : TFilterRecordEvent;
  OldFilter : string;
begin
  with MembList do begin  // MembList is my table
    Cancel;
    Close;
    Exclusive := true;
    {store existing OnFilterRecord and set to nil}
    OldOnFilterRecord := OnFilterRecord;     OnFilterRecord := nil;
    {store existing Filter and set to blank}
    OldFilter := Filter;                     Filter := '';
    Open;
    {pack the database}
    Check(DbiPackTable(DbHandle, Handle, Nil, szDBASE, TRUE));
    {re-number IDs}
    First;
    i := 1;
    while not EOF do begin
      Edit;
      MembListID.AsInteger := i;
      inc(i);
      Next;
    end;
    Close;
    Exclusive := false;
    {restore OnFilterRecord & Filter properties}
    OnFilterRecord := OldOnFilterRecord;      Filter := OldFilter;
    Open;
    FillTreeView;  // re-display contents of data-table in a treeview
  end {with MembList}
end;

Alan Lloyd
alangll...@aol.com

Re:PACK of dBase III-table?


  Pack...  --  It's in the BDE files....  (look under dbiDoRestructure, and
you'll find the dBase instructions (which is pack))

--
Jason Wallace
SL Software
Dark...@SLSoftware.reno.nv.us
--
"We are Microsoft.  You will be assimilated.  Resistance is Futile."
--

Quote
EnviTech AS wrote in message <362DD2BE.C6BCF...@envitech.no>...
>How can I PACK dBase III-tables with Delphi 2 (and SQL)?

>The SQL-command DELETE just deletes the record with a mask, but the
>record remain fysically. I want to clean up these tables with some sort
>of PACK-command.

>It is of course possible to copy the active records in the table to a
>temporary table and rename it back, but I hope for an easier way.

>Thank you!

>Gjermund Omholt
>g...@envitech.no

Re:PACK of dBase III-table?


Quote
EnviTech AS wrote:

> How can I PACK dBase III-tables with Delphi 2 (and SQL)?

> The SQL-command DELETE just deletes the record with a mask, but the
> record remain fysically. I want to clean up these tables with some sort
> of PACK-command.

> It is of course possible to copy the active records in the table to a
> temporary table and rename it back, but I hope for an easier way.

> Thank you!

> Gjermund Omholt
> g...@envitech.no

You can use the BDE functions but as a long time workstation based
database programmer I can tell you that it is safer to perform
the following routine. (I use Apollo but sequence is the same).

Open DBF Exclusive (Ensure no-one can use DBF)
Copy DBF-To-be-packed To Temp for not deleted (so only active records
are copied)
Close DBF
Change File Name of DBF object to TEMP
Open Temp
Copy Temp To DBF
Close Temp
Change Name of DBF object back to original
Open DBF Exclusive
Reindex
Close DBF

Now some may say this looks cumbersome but it is far less cumbersome
than trying to recover if the system crashed midway through a pack
on the LIVE database as you can always recover in this scenario.

Regards
GregF

Other Threads