Regarding a very slow query, how to indicate the percentage of progress

I am using ZEOS components to connect to an (ancient) MDB database.
I am making a query that reads in a lot of data to go to another database.

Is there a way to indicate progress as a percentage?

procedure TForm13.ActionReadInMemoryExecute(Sender: TObject);
var
  QueryLine: string;
  FullQuery: string;
  Tablename: string;
  i: integer;
begin
  i:= 0;
  TableMeter.DisableControls;
  try
    TableMeter.First;
    FullQuery:= '';
    while not TableMeter.eof do begin
      Tablename:= TableMeter.FieldByName('tabelnaam').AsString;
      QueryLine:= ReplaceStr(ImportQuerySjabloon, cTabelname, Tablename);
      FullQuery:= FullQuery + QueryLine;
      if (TableMeter.RecNo < (TableMeter.RecordCount -1)) then begin
        FullQuery:= FullQuery + ' UNION ALL ';
      end;
      TableMeter.Next;
    end; {while}
    QueryImportMeterreadings.Close;
    QueryImportMeterreadings.SQL.Text:= FullQuery;
    QueryImportMeterreadings.Open;  <<-- takes a long time
  finally
    TableMeter.EnableControls;
  end;
end;

Is there a way to indicate the progress of the request, or can I do this only if I split the individual requests and eliminate it UNION.
It takes about 1 minute, including 8 unions.

I do not see any event that I can use for this purpose:

OnCalcField Query, ( , ).
? nope, Access DB

+5
2

, , , , avg * , / , x y ( : -time -)

+3

; clientdataset (cds). CD- dbgrid. , - , , , , . - , . - , - -.

const
 field1 = 'id';
 field2 = 'customer name';
 field3 = 'total debt';

procedure TTotalCustDebt.FormCreate(Sender: TObject);
var
 strings: tstrings;

begin
 with qTotalDebt do   // this is the clientdataset
  begin
   fielddefs.add (field1, ftInteger, 0, false);
   fielddefs.add (field2, ftString, 32, false);
   fielddefs.add (field3, ftInteger, 0, false);
   createdataset;
   fieldbyname (field1).visible:= false;
   open;
   addindex ('idx0', field2, [], '', '', 0);
   addindex ('idx1', field2, [ixDescending], '', '', 0);
   addindex ('idx2', field3, [], '', '', 0);
   addindex ('idx3', field3, [ixDescending], '', '', 0);
   strings:= tstringlist.create;
   getindexnames (strings);
   strings.free;
  end;
end;

procedure TTotalCustDebt.PopulateCDS;
begin
 dsTotalDebt.dataset:= nil;
 with qTotalDebt do
  begin
   emptydataset;
   indexfieldnames:= field1;  // initially sort by customer.id
  end;

 with qDBills do
  begin
   params[0].asdate:= dt;
   open;
   while not eof do
    begin
     qTotalDebt.append;
     qTotalDebt.fieldbyname (field1).asinteger:= qDBillsID.asinteger;
     qTotalDebt.fieldbyname (field2).asstring:= qDBillsName.asstring;
     qTotalDebt.fieldbyname (field3).asinteger:= qDBillsTot.asinteger;
     qTotalDebt.post;
     next
    end;
   close
  end;

  // show progress indicator

  with qDReceipts do
   begin
    params[0].asdate:= dt;
    open;
    while not eof do
     begin
      if qTotalDebt.findkey ([qDReceiptsID.asinteger]) then
       begin  // customer already exists
        qTotalDebt.edit;
        qTotalDebt.fieldbyname (field3).asinteger:= - qDReceiptsTot.asinteger
                                  + qTotalDebt.fieldbyname (field3).asinteger;
      end
     else
      begin  // add new record
       qTotalDebt.append;
       qTotalDebt.fieldbyname (field1).asinteger:= qDReceiptsID.asinteger;
       qTotalDebt.fieldbyname (field2).asstring:= qDReceiptsName.asstring;
       qTotalDebt.fieldbyname (field3).asinteger:= - qDReceiptsTot.asinteger;
      end;
     qTotalDebt.post;
     next
    end;
   close
  end;

 // show progress indicator
 // more queries
 // at end, attach the clientdataset to the TDataSource
 dsTotalDebt.dataset:= qTotalDebt;
end;
+3

All Articles