How to prevent Delphi ADO from loading the entire table into memory?

前端 未结 7 2165
后悔当初
后悔当初 2021-02-09 01:22

I am not a Delphi programmer, but I I got an old Delphi 7 application that I need to fix and it is using ADO.

The database table (MS Accesss) contains +100,000 rows and

相关标签:
7条回答
  • 2021-02-09 01:32

    You could use that adoTable with an Server OpenForwardOnly cursor and an TCLientDataset with PacketRecords set to nonzero value. Worked wonderfully when I had to write an app to pump data from MSSQL to Oracle on a customized way with tables with millions of records.

    EDIT -> It would be something on the lines of this:

    procedure ConfigCDSFromAdoQuery(p_ADOQ: TADOQuery; p_CDS: TClientDataset; p_Prov: TDatasetProvider);
    begin
      If p_ADOQ.Active then p_ADOQ.Close;
      p_ADOQ.CursorLocation := clServer;
      p_ADOQ.CursorType := ctOpenForwardOnly;
      p_Prov.Dataset := p_ADOQ;
      p_CDS.SetProvider(p_Prov);
      p_CDS.PacketRecords := 100;
      p_CDS.Open; 
    end ;
    

    I've done this all by code, but most of that you can do in design-time.

    0 讨论(0)
  • 2021-02-09 01:32

    I have found ADO + Access w/Delphi to be painfully slow, for lots of things (big table reads like you're describing, but also inserts as well, etc). My answer became "Quit using ADO and Access altogether."

    Never did understand why it performed so poorly, especially when earlier technologies seemed not to.

    0 讨论(0)
  • 2021-02-09 01:36
    1. On your datamodule where "MeasurementsADOTable" currently resides, drop a TADOQuery and name it "MeasurementsADOQuery"
    2. Set the Connection property of MeasurementsADOQuery to MyADOConnection (assuming this is the case based on the little code snippet provided.)
    3. I'm also assuming that you are displaying a grid or otherwise using a DataSource - change the DataSource component's "DataSet" property from MeasurementsADOTable to MeasurementsADOQuery
    4. Edit the actual query to be executed by setting the SQL property of MeasurementsADOQuery. (In runtime before opening: Measurements.SQL.Text := 'select top 10 * from measurements order by whatever')
    5. Analyze/change all references in code from MeasurementsADOTable to MeasurementsADOQuery
    0 讨论(0)
  • 2021-02-09 01:38

    use adoquery If you do not need any row and just want insert new row use sql command like this 'select * from myTable where id=-1' Since Id is autonumber no rows will return . or 'select * from myTable where 1=-1' But I think it is not good way for Insering data. Using adocommand is sure much better.

    if you want X rows 'select top X * from myTable '

    0 讨论(0)
  • 2021-02-09 01:42

    This article is BDE specific, but applies to ADO or most client data access libraries.

    http://dn.codegear.com/article/28160

    I would recommend using TADODataSet (it's "closer" to the ADO layer than TADOQuery) and selecting only the data the client needs by providing a custom search form (date range, list of specific items, etc)

    Good luck

    0 讨论(0)
  • 2021-02-09 01:48

    You could use TADOQuery to limit the result set with a sql query. Or you could use TADOTable and set the CursorLocation to a Server side cursor to prevent the client loading the complete resultset in memory.

    0 讨论(0)
提交回复
热议问题