How to pack/reindex DBase3 files?

How to pack/reindex DBase3 files?

Post by Craig Kinsma » Sun, 31 Dec 1899 09:00:00



Hi people,

Using Delphi C/S 3.0 on  NT4(SP3).

I'm manipulating DBase3 files using TTables and need to be able to
1) pack the .dbf files to get rid of deletions
2) re-create the NDX indices
(so that another application can be launched with the files in a good
state).

I can't see any way of doing this in Delphi - surely it's possible??

Any suggestions gratefully received,

Craig.

 
 
 

How to pack/reindex DBase3 files?

Post by Sandy Ferguso » Sun, 31 Dec 1899 09:00:00


Try this to reindex

begin
charges.open;
charges.active:=false;
try
if FileExists('charges.mdx') then
begin
 charges.deleteindex('chrgno');
 charges.deleteindex('inv');
end;
 finally
 charges.addindex('chrgno','id',[]);
 charges.addindex('inv','invoice',[]);
end;
It works for me

Packing tables is not so easy to explain but try this

In the uses list include
 DbiTypes, DbiProcs, DbiErrs;

In the var list
Error: DbiResult;
ErrorMsg: String;
Special: DBIMSG;

For a table called cattle

  cattle.Active := False;
  cattle.Exclusive := True;
  cattle.Active := True;
    Error := DbiPackTable(cattle.DBHandle, cattle.Handle, nil, szdBASE,
      True);
    cattle.Active := False;
    cattle.Exclusive := False;

To handle errors

 case Error of
    DBIERR_NONE:
      ErrorMsg := 'Successful';
    DBIERR_INVALIDPARAM:
      ErrorMsg := 'The specified table name or the pointer to the ' +
        'table name is NULL';
    DBIERR_INVALIDHNDL:
      ErrorMsg := 'The specified database handle or cursor handle is ' +
        'invalid or NULL';
    DBIERR_NOSUCHTABLE:
      ErrorMsg := 'Table name does not exist';
    DBIERR_UNKNOWNTBLTYPE:
      ErrorMsg := 'Table type is unknown';
    DBIERR_NEEDEXCLACCESS:
      ErrorMsg := 'The table is not open in exclusive mode';
  else
    DbiGetErrorString(Error, Special);
    ErrorMsg := '[' + IntToStr(Error) + ']: ' + Special;
  end;
  MessageDlg(ErrorMsg, mtWarning, [mbOk], 0);

There may be an easier way but this works for me

Sandy Ferguson
HIPER SOFTWARE

If you still have a problem email me.


>Hi people,

>Using Delphi C/S 3.0 on  NT4(SP3).

>I'm manipulating DBase3 files using TTables and need to be able to
>1) pack the .dbf files to get rid of deletions
>2) re-create the NDX indices
>(so that another application can be launched with the files in a good
>state).

>I can't see any way of doing this in Delphi - surely it's possible??

>Any suggestions gratefully received,

>Craig.


 
 
 

How to pack/reindex DBase3 files?

Post by olivier daha » Sun, 31 Dec 1899 09:00:00


Yes, you can do it.
you must use BDE low-level functions (dbiRegenIndex, dbidoRestructure...).
Take a look at the BDE help file (stored in the BDE folder), there are some
code samples for C++ and Delphi in this file.

|Using Delphi C/S 3.0 on  NT4(SP3).
|
|I'm manipulating DBase3 files using TTables and need to be able to
|1) pack the .dbf files to get rid of deletions
|2) re-create the NDX indices
|(so that another application can be launched with the files in a good
|state).
|
|I can't see any way of doing this in Delphi - surely it's possible??
|
|Any suggestions gratefully received,
|
|Craig.
|
|

 
 
 

How to pack/reindex DBase3 files?

Post by Craig Kinsma » Sun, 31 Dec 1899 09:00:00



>Try this to reindex

...
> finally
> charges.addindex('chrgno','id',[]);
> charges.addindex('inv','invoice',[]);
>end;

The problem with this is that it produces MDX files whereas I require NDX
files
since that is what the other application (Citect) uses. Maybe DBase3 only
supports .NDX indices?!

Quote:>Packing tables is not so easy to explain but try this

I haven't tried the packing yet but this looks like what I need - thanks
very much for the help

Cheers,
Craig.