有关数据库的一个问题(50分)

O

O_O

Unregistered / Unconfirmed
GUEST, unregistred user!
我对paradox的表不太熟,发现如下一个问题:
当对表添加数个graphic字段的数据,再对这些字段赋空(assign(nil),亦append了),
发现文件的大小并没有变小,具体是.mb文件还是添入数据的那么大,好象它只能变大不
能变小似的,不知用什么命令才可以真正将数据清空?
 
打开这个表,还有数据吗?如果没有,则是因为没有pack的缘故,可以用
下面这个程序段解决。

以下程序来自我的程序单元myUnit.pas
=================================
// Pack a Paradox or dBASE table
// 调用前,请自行设置表Active=True; Exclusive=True;使用表处于独占开启状态
procedure PackATable(Table: TTable);
var
Props: CURProps;
hDb: hDBIDb;
TableDesc: CRTblDesc;
begin
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');
//校验表的打开和独占访问状态

Check(DbiGetCursorProps(Table.Handle, Props));
//Check()用于校正和报告DBI底层错误;DbiGetCursorProps()用于取表光标属性
if (Props.szTableType = szPARADOX)
then // If the table is a Paradox table, you must call DbiDoRestructure...
begin
FillChar(TableDesc, sizeof(TableDesc), 0);
Check(DbiGetObjFromObj(hDBIObj(Table.Handle), objDATABASE, hDBIObj(hDb)));
// Get the database handle from the table's cursor handle...

StrPCopy(TableDesc.szTblName, Table.TableName);
StrPCopy(TableDesc.szTblType, Props.szTableType);
TableDesc.bPack := True;
//设置表的描述结构的Name/Type/bPack属性

//关闭表并调用api
Table.Close;
Application.ProcessMessages;
//对于巨型数据表,提供最后一次处理系统事件的机会
Check(DbiDoRestructure(hDb, 1, @TableDesc, nil, nil, nil, False));
Application.ProcessMessages;
Table.Open;
end
else // If the table is a dBASE table, simply call DbiPackTable...
if (Props.szTableType = szDBASE)
then
begin
Application.ProcessMessages;
//对于巨型数据表,提供最后一次处理系统事件的机会
Check(DbiPackTable(Table.DBHandle, Table.Handle, nil, szDBASE, True));
Application.ProcessMessages;
end
else //不是dBase和Paradox表
raise EDatabaseError.Create('Table must be either of Paradox or dBASE ' + 'type to pack');
end;
 
顶部