sql-server - 中止具有处理时间限制的 SQL 查询

标签 sql-server delphi ado

我可以使用处理时间有限的 DELPHI、dbgo DB 组件和 SQL Server 数据库服务器编写 SQL 查询吗?

喜欢

select * from table where ......  

process_time_limit = 5秒

最好在时间限制内给我 10% 的行,而不是等待数小时以获得完整的查询数据集

最佳答案

ADO 组件:

我会尝试异步数据获取。当您执行查询时,您会记得何时开始以及每次OnFetchProgress事件触发后,您将检查 EventStatus 是否仍处于 esOK 状态并检查查询执行所用的时间。如果超过了,您可以使用 Cancel 取消数据获取。数据集上的方法。

我打算使用类似以下(未经测试的)伪代码的内容:

var
  FQueryStart: DWORD;

procedure TForm1.FormCreate(Sender: TObject);
begin
  // configure the asynchronous data fetch for dataset
  ADOQuery1.ExecuteOptions := [eoAsyncExecute, eoAsyncFetchNonBlocking];
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  // store the query execution starting time and execute a query
  FQueryStart := GetTickCount;
  ADOQuery1.SQL.Text := 'SELECT * FROM Table';
  ADOQuery1.Open;
end;

procedure TForm1.ADOQuery1FetchProgress(DataSet: TCustomADODataSet; Progress,
  MaxProgress: Integer; var EventStatus: TEventStatus);
begin
  // if the fetch progress is in esOK (adStatusOK) status and the time since
  // the query has been executed (5000 ms) elapsed, cancel the query
  if (EventStatus = esOK) and (GetTickCount - FQueryStart >= 5000) then
    DataSet.Cancel;
end;

关于sql-server - 中止具有处理时间限制的 SQL 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14674469/

相关文章:

sql-server - sql : select rows based on another table if is populated or empty

sql - 使用数据修改列类型,而不删除数据

c - 如何在C++Builder项目的Delphi单元中使用Crtl? (或链接到 C++Builder C 运行时库)

delphi - 如何检查单行是否为空值

database - 这在编程上是个坏主意吗?

SQL 窗口函数 : MAX(date) over Partition BY Clause

sql - SSIS:需要在其他SQL查询中使用SQL查询结果来获取数据

delphi - 为什么加载PNG图像格式图标会导致 "Out of system resources"异常?

mysql - FireDAC 中错误的 sha() 函数与 '!' 字符结合使用

ms-access - MS Access : Why is ADODB. Recordset.BatchUpdate 比 Application.ImportXML 慢这么多?