How to get a record counter from an ADO request?

Possible duplicate:
How to see the progress of a request during processing?

I would like to show a progress bar indicating how long it takes to get the results from the database.

I use TADOQuery and open it in Async mode. While the status of the request is stFetching , is there a way to find out [number of records / total records]?

+4
source share
2 answers

Write a handler for the OnFetchProgress event. From the reference:

Write an OnFetchProgress event handler to perform certain actions during an asynchronous data retrieval operation. The OnFetchProgress event is fired periodically when data is retrieved to ensure its progress. Create a handler for this event to respond to this event. periodic notification, for example, providing the user with a visual indication of data retrieval progress.

Note that the MaxProgress value that will be passed to the OnFetchProgress event is the best guess. From How to Use the ADO Events of FetchProgress and FetchComplete :

MaxProgress is not equal to the actual number of records that will be returned. ADO must receive records in order to get this value. This means that MaxProgress is just the best guess. MaxProgress is usually equal to Progress plus the background sample size.

You can send Select Count() .. to the database, as indicated in the Diego answer , before opening your query to get the exact total number of records to be retrieved, but this is not always advisable, as this may lead to over-scanning of the table and significant runtime of complex queries.

+4
source

Don’t think you can predict the future :)

Before downloading, send an invoice to the database to find out how many records will be downloaded.

Create a load on the batches and on each batch, compare the batch size * the number of batches with the total number of records.

+1
source

Source: https://habr.com/ru/post/1440736/


All Articles