首页  编辑  

压缩Paradox或者dBase数据库

Tags: /超级猛料/Database.数据库相关/Paradox & dBase/   Date Created:

function dgPackParadoxTable(Tbl: TTable; Db: TDatabase): DBIResult;

{ Packs a Paradox table by calling the BDE DbiDoRestructure

function. The TTable passed as the first parameter must

be closed. The TDatabase passed as the second parameter

must be connected. }

var

 TblDesc: CRTblDesc;

begin

 Result := DBIERR_NA;

 FillChar(TblDesc, SizeOf(CRTblDesc), 0);

 StrPCopy(TblDesc.szTblName, Tbl.TableName);

 TblDesc.bPack := True;

 Result        := DbiDoRestructure(Db.Handle, 1, @TblDesc, nil, nil, nil, False);

end;

function dgPackDbaseTable(Tbl: TTable): DBIResult;

{ Pack a dBASE table by calling DbiPackTable. The table

passed as a parameter will be opened if it isn't open. }

begin

 Result := DBIERR_NA;

 if Tbl.Active = False then

   Tbl.Open;

 Result := DbiPackTable(Tbl.DBHandle, Tbl.Handle,

   nil, nil, True);

end;

****************************

要压缩dBase数据库很简单,只要下面的操作即可:

DBIPackTable(Table1.DbHandle, Table1.Handle, 'TABLENAME.DBF', szDBASE, TRUE);

当然,Table必须用exclusive方式打开!

对于Paradox数据库,就麻烦一些了:

// Pack a Paradox or dBASE table

// The table must be opened execlusively before calling this function...

procedure PackTable(Table: TTable);

var

 Props: CURProps;

 hDb: hDBIDb;

 TableDesc: CRTblDesc;

begin

 // Make sure the table is open exclusively so we can get the db handle...

 if Table.Active = False then

   raise EDatabaseError.Create('Table must be opened to pack');

 if Table.Exclusive = False then

   raise EDatabaseError.Create('Table must be opened exclusively to pack');

 // Get the table properties to determine table type...

 Check(DbiGetCursorProps(Table.Handle, Props));

 // If the table is a Paradox table, you must call DbiDoRestructure...

 if Props.szTableType = szPARADOX then

 begin

   // Blank out the structure...

   FillChar(TableDesc, sizeof(TableDesc), 0);

   //  Get the database handle from the table's cursor handle...

   Check(DbiGetObjFromObj(hDBIObj(Table.Handle), objDATABASE, hDBIObj(hDb)));

   // Put the table name in the table descriptor...

   StrPCopy(TableDesc.szTblName, Table.TableName);

   // Put the table type in the table descriptor...

   StrPCopy(TableDesc.szTblType, Props.szTableType);

   // Set the Pack option in the table descriptor to TRUE...

   TableDesc.bPack := True;

   // Close the table so the restructure can complete...

   Table.Close;

   // Call DbiDoRestructure...

   Check(DbiDoRestructure(hDb, 1, @TableDesc, nil, nil, nil, FALSE));

 end

 else

   // If the table is a dBASE table, simply call DbiPackTable...

   if Props.szTableType = szDBASE then

     Check(DbiPackTable(Table.DBHandle, Table.Handle, nil, szDBASE, TRUE))

   else

     // Pack only works on PAradox or dBASE; nothing else...

     raise EDatabaseError.Create('Table must be either of Paradox or dBASE ' +

              'type to pack');

 Table.Open;

end;