Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi ADO Query

Is there any faster way to iterate through an ADO Dataset than

while (not ADOQuery1.Eof) do
    begin
      /* Do something */
      ADOQuery1.Next;
    end;

I need to scan a dataset of around 9000 items and only extract records matching a pre-defined set of branch numbers.

like image 996
Pieter van Wyk Avatar asked Feb 22 '10 16:02

Pieter van Wyk


People also ask

What is ADO in Delphi?

ADO, (Microsoft ActiveX Data Objects) is a set of COM objects that access data through an OLE DB provider. The dbGo components encapsulate these ADO objects in the Delphi database architecture.


3 Answers

Be sure that you use DisableControls/EnableControls if it's not necesary for not spend time updating visible controls associated at DataSet.

try
  ADOQuery1.DisableControls;
  while (not ADOQuery1.Eof) do
    begin
      /* Do something */
      ADOQuery1.Next;
    end;
finally
  ADOQuery1.EnableControls;
end;

Regards.

like image 158
Germán Estévez -Neftalí- Avatar answered Nov 05 '22 05:11

Germán Estévez -Neftalí-


@Pieter, two options

1) you can modify your sql sentence before to execute, adding the where condition wich match with the pre-defined set of branch numbers.

2) using the Filter property of TAdoQuery.

AdoQuery1.close;
AdoQuery1.filter := 'your condition goes here';
AdoQuery1.filtered := true;
AdoQuery1.Open;
like image 29
RRUZ Avatar answered Nov 05 '22 05:11

RRUZ


It is much faster to use ADORecordset for such tasks:

 while not ADOQuery1.Recordset.EOF do
  begin
    ADOQuery1.Recordset.MoveNext;
    // get value
    SomeVar := ADOQuery1.Recordset.Fields['FieldName'].Value;  
  end;
like image 37
Linas Avatar answered Nov 05 '22 07:11

Linas