如何真正删除dbf文件记录

阅读:1227次   时间:2003-08-06 00:00:00   字体:[ ]
在delphi4.0中如何真正删除dbf文件记录,DBIPACKTABLE具体如何用(100分) 
问题的分类是:数据库 - 文件型 , 分坛主: SeaSky, 分坛主: yifeng 
  
来自:sxzww 时间:00-3-11 11:11:10 ID:197921 
我的语句如下:
 sql.clear;
 SQL.ADD('delete from xz_jybj');
 q2.execsql;
 close;
执行后,只在数据文件xz_jybj中做了删除标记,
我查询过这个站点关于delete 记录的有关内容,似乎可以用DBIPACKTABLE
函数,但我看不懂,谁能帮助我,谢谢 。
 
 



--------------------------------------------------------------------------------
来自:xWolf 时间:00-3-11 11:37:56 ID:197934 
procedure PackTable(Table: TTable);
var
  Props: CURProps;
begin
  // 必须以独占方式打开
  if (not Table.Active) or (not Table.Exclusive) then Exit;
  Check(DBIGetCursorProps(Table.Handle, Props));
  // 必须是dBase或FoxPro
  if Props.szTableType <> szDBASE then Exit;
  Check(DBIPackTable(Table.DBHandle, Table.Handle, nil, szDBASE, True));
  Table.Open;
end;
 
 

--------------------------------------------------------------------------------
来自:xWolf 时间:00-3-11 11:47:51 ID:197941 
function DbiPackTable (hDb: hDBIDb; hCursor: hDBICur; pszTableName: PChar; pszDriverType: PChar; bRegenIdxs: Bool): DBIResult stdcall;
参数说明:
  hDB: 数据库句柄,可以由TTable.DBHandle得到
  hCursor: 数据表关联的游标,若为nil则数据表依赖于pszTableName和pszDriverType
  bRegenIdxs决定是否关联外接的索引文件尤其是MDX多索引文件
  

以下摘自Delphi Help
Example 1: Pack a Paradox or dBASE table.

This example will pack a Paradox or dBASE table therfore removing already deleted rows in a table. This function will also regenerate all out-of-date indexes (maintained indexes). This example uses the following input:

  PackTable(Table1)

The function is defined as follows: 

// 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 not Table.Active then
    raise EDatabaseError.Create('Table must be opened to pack');
  if not Table.Exclusive 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, nilnilnilFalse));
  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;
 
 

--------------------------------------------------------------------------------
来自:sxzww 时间:00-3-11 15:36:04 ID:198012 
接受答案了.
 
 
 源码推荐
关于本站 - 广告服务 - 会员指南 - 联系方法
Copyright ©2003-2011 源码天空 All Rights Reserved