Board index » delphi » How to Pack a Database File (Paradox Format) in Delphi 1.0

How to Pack a Database File (Paradox Format) in Delphi 1.0

I would like to know can I pack a database file which is Paradox format
in Delphi 1.0
I have try  'DbiDoRestructure', but I don't how to use.

 

Re:How to Pack a Database File (Paradox Format) in Delphi 1.0


Ken,

Try something like the code below. This was extracted from the
SelfCheck Data Maintenance API product which is available from Logic
Process. It was edited to eliminate features which did not apply to
your question, so there may be a gotcha or two missed in the process.
If you are interested in source like this for many Paradox table
maintenance functions (table/index repair, copy, empty, delete, etc),
you might want to take a look at the SelfCheck API product. A free
full-featured trial version is available (along with DataSentry -- a
companion table maintenance app built around the API) from our web
site at www.logicprocess.com. The API comes with full source and can
be integrated into your own 16-bit or 32-bit apps royalty-free (object
code format). The trial version does not include the API source, but
does have an extensive help file describing (with example calling
syntax) all API functions.

Hope this helps you get started.

Call the following routine like:

if (DBPackTable('c:\tmp\', 'mytable.db'. '') then
begin
 ...
end
else
  MessageDlg('Problem packing table', mtError, [mbOK], 0);

uses BDE;

function DBPackTable(strDataBase, strTableName, strPassword: String):
Boolean;
var
  hDb                  : hDbiDb;
  TblDesc              : CRTblDesc;
  TmpFilePath          : String;
  DBRslt               : DBIResult;
  DBName               : DBIPATH;
  TableName            : DBITBLNAME;
begin
  Result := True; { assume success for now }

  try
    { Open a NULL database handle }
    DBRslt := DbiOpenDatabase(nil, nil, dbiReadWrite, dbiOpenExcl,
nil, 0, nil, nil, hDb);
    if DBRslt = DBIERR_NONE then
    begin
         { set the database directory }
        StrPCopy(DBName, strDatabase);
        DBRslt := DbiSetDirectory(hDb, DBName);
        if DBRslt = DBIERR_NONE then
        begin
          FillChar(TblDesc, sizeof(CRTblDesc), #0);

          StrPCopy(TblDesc.szTblName, strTableName);
           StrPCopy(TblDesc.szTblType, szParadox);

          { set password information }
          if (Length(strPassword) > 0) then
          begin
            TblDesc.bProtected := True;
            StrPCopy(TblDesc.szPassword, strPassword);
          end
          else
          begin
            TblDesc.bProtected := False;
            StrPCopy(TblDesc.szPassword, '');
          end;

          { Set Flag to pack table }
          TblDesc.bPack := TRUE;

          { Do a Restructure, this will pack the table without making
any field or index changes because
            the table descriptor (TblDesc) is null }
          DBRslt := DbiDoRestructure(hDb, 1, @TblDesc, nil, nil, nil,
False);
            Result := (DBRslt = DBIERR_NONE);
          end
         end
        else
          Result := False;

      finally { Close the database object }
        DbiCloseDatabase(hDb);
      end;
    end
    else
      Result := False;
 end;

Jim McCullin
Logic Process Corporation
sa...@logicprocess.com
www.logicprocess.com

On Tue, 30 Sep 1997 18:16:01 +0800, Kenneth Lee <sk...@hkstar.com>
wrote:

Quote
>I would like to know can I pack a database file which is Paradox format
>in Delphi 1.0
>I have try  'DbiDoRestructure', but I don't how to use.

Re:How to Pack a Database File (Paradox Format) in Delphi 1.0


There's no need to pack Paradox tables just liek DBase.

Heiko

Kenneth Lee <sk...@hkstar.com> schrieb im Beitrag
<3430D161.BA4E4...@hkstar.com>...

Quote
> I would like to know can I pack a database file which is Paradox format
> in Delphi 1.0
> I have try  'DbiDoRestructure', but I don't how to use.

Re:How to Pack a Database File (Paradox Format) in Delphi 1.0


Quote
Kenneth Lee wrote:

> I would like to know can I pack a database file which is Paradox format
> in Delphi 1.0
> I have try  'DbiDoRestructure', but I don't how to use.

Try the following:
{-------------------------------------------------------------
PACK_TABLE   -}
{   Pack (ie compress) a table and optionally encrypt it.  It must be
closed
    and not in use.  Pword is the password for the table, if any.}
procedure Pack_Table (TT : Ttable; const Pword : Str80);
var
  TblDesc       : CRTblDesc;
  hDb           : hDbiDb;       {handle to the DB}
  Tname         : Str100;
begin
  Tname := TT.DatabaseName + '\' + TT.TableName;
  if pos('.',Tname) = 0
  then Tname := Tname + '.DB';
  fillChar (TblDesc, SizeOf(CRTblDesc), 0);
  with TblDesc do begin
    strPCopy (szTblName, Tname);
    bPack := true;
    if Pword <> '' then begin           {encrypt as well}
      strPcopy (szPassword, Pword);
      bProtected := true;
      end;
    end;
  hDb := nil;
  Dbi(DbiOpenDatabase (nil, 'STANDARD', dbiReadWrite,
     dbiOpenExcl, nil, 0, nil, nil, hDb));      {get a DB handle}
  Dbi(DbiDoRestructure (hDb, 1,
      @TblDesc, nil, nil, nil, FALSE));         {reconstruct the table}
  Dbi(DbiCloseDatabase (hDb));                  {release the handle}
  end; {Pack_Table}

--
Andrew Gabb
 email:      ag...@tpgi.com.au
 phone1:     +61 8 8342-1021
 phone2:     +61 8 8269-1635
-----

Re:How to Pack a Database File (Paradox Format) in Delphi 1.0


Quote
Heiko Lttge wrote:

> There's no need to pack Paradox tables just liek DBase.

> Heiko

> Kenneth Lee <sk...@hkstar.com> schrieb im Beitrag
> <3430D161.BA4E4...@hkstar.com>...
> > I would like to know can I pack a database file which is Paradox format
> > in Delphi 1.0
> > I have try  'DbiDoRestructure', but I don't how to use.

DbiDoRestructure will work however if your paradox table includes a
Primary Key you can trick delphi into packing the table.

Simply:

Table.Addindex( '', 'Field Name', [] );

Notice the relatively small size of your primary key table? They are
especially small if they are based on single field Integers. Each
Paradox table is made up of blocks which contain 3 or more records.
Often with small records you may have 100's of records in a block.

The value of the primary key for the first record in each block is
copied into your pk table.

OK OK

Adding the pk index forces the BDE to rewrite the entire paradox table
since each page MUST contain pk ordered records for the pk scheme to
work.

If the PK table exists don't be concerned Delphi lets you add it anyway.

Garry Kernan

Other Threads