[阅读: 416] 2004-12-23 03:10:37
{ ************* Comment *************
Creator: H.Congyu
CreateDate: 2004-12-22 18:05:38
Description: 去除系统的中临时表,临时表格式Temp
Params: AHours 小时数,删除这个小时数以前的临时表
************************************ }
procedure THcyDBFuns.DropTempTable(AHours: Integer);
var
I: Integer;
FTableNames: TStrings;
SQLString: string;
TableNameLike: string;
TableNameMax: string;
begin
FTableNames := TStringList.Create;
//获取一定天数以前的临时表
// 2004-12-24 9:50:33 H.Congyu
// 这里不知道是SQLServer和ADO之间有什么问题
//按照习惯,这里一般使用参数的方式,但是使用参数出来的结果就会不正确,不知道为什么
TableNameLike := 'Temp[12][09][09][0-9][01][0-9][0123][0-9][012][0-9][0-6][0-9][0-6][0-9]%';
TableNameMax := 'Temp' + FormatDateTime('yyyymmddhhnnss', now - AHours/24);
SQLString := 'select Table_Name '
+ ' from Information_Schema.Tables '
+ ' where (Table_type = ''BASE TABLE'') '
+ ' and Table_Name like ''' + TableNameLike + ''''
+ ' and Table_Name < ''' + TableNameMax + '''';
//写成如下就不行了
// SQLString := 'select Table_Name '
// + ' from Information_Schema.Tables '
// + ' where (Table_type = ''BASE TABLE'') '
// + ' and Table_Name like :p0 '
// + ' and Table_Name < :p1 ';
// GetSQLValues(SQLString, [TableNameLike, TableNameMax], FTableNames);
GetSQLValues(SQLString, FTableNames);
for I := 0 to FTableNames.Count - 1 do // Iterate
begin
DropTable(FTableNames[I]);
end; // for
FreeAndNil(FTableNames);
end;