Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>i found the performance problems with ADOExpress years ago:</p> <ul> <li><a href="http://groups.google.com/group/borland.public.delphi.database.ado/browse_thread/thread/c912b61b28472829" rel="nofollow">ADO vs ADOExpress time trials. Not good for ADOExpress</a> (6/7/2005)</li> <li><a href="http://groups.google.com/group/borland.public.delphi.database.ado/browse_thread/thread/5932d926801a407f/720a59662558ad05" rel="nofollow">ADO vs ADO Express Time Trials (redux)</a> (12/30/2007)</li> </ul> <blockquote> <p><strong>Note:</strong> Before ADO became a standard part of Delphi, Borland was selling it as an addon called <strong>ADOExpress</strong>. It was simply object wrappers around Microsoft's ActiveX Data Objects (ADO) COM objects.</p> </blockquote> <p>i had tested three scenarios</p> <ul> <li>using ADO directly (i.e. Microsoft's COM objects directly)</li> <li>using ADOExpress (Borland's object wrappers around ADO)</li> <li>specifying <code>.DisableControls</code> on the <code>TADOQuery</code> before calling <code>Open</code></li> </ul> <p>i discovered</p> <ul> <li>use <code>Query.DisableControls</code> to make each call <code>.Next</code> 50x faster</li> <li>use <code>Query.Recordset.Fields.Items['columnName'].Value</code> rather than <code>Query.FieldByName('columnName')</code> to make each value lookup 2.7x faster</li> <li><p>using <code>TADODataSet</code> (verses <code>TADOQuery</code>) makes no difference</p> <pre><code> Loop Results Get Values ADOExpress: 28.0s 46.6s ADOExpress w/DisableControls: 0.5s 17.0s ADO (direct use of interfaces): 0.2s 4.7s </code></pre></li> </ul> <p><strong>Note</strong>: These values are for looping 20,881 rows, and looking up the values of 21 columns.</p> <p><strong>Baseline Bad Code:</strong></p> <pre><code>var qry: TADOQuery; begin qry := TADOQuery.Create(nil); try qry.SQL.Add(CommandText); qry.Open; while not qry.EOF do begin ... qry.Next; end; </code></pre> <p><strong>Use DisableControls to make looping 5000% faster</strong>:</p> <pre><code>var qry: TADOQuery; begin qry := TADOQuery.Create(nil); try qry.DisableControls; qry.SQL.Add(CommandText); qry.Open; while not qry.EOF do begin ... qry.Next; end; </code></pre> <p><strong>Use Fields collection to make value lookups 270% faster</strong>:</p> <pre><code>var qry: TADOQuery; begin qry := TADOQuery.Create(nil); try qry.DisableControls; qry.SQL.Add(CommandText); qry.Open; while not qry.EOF do begin value1 := VarAsString(qry.Recordset.Fields['FieldOne'].Value); value2 := VarAsInt(qry.Recordset.Fields['FieldTwo'].Value); value3 := VarAsInt64(qry.Recordset.Fields['FieldTwo'].Value); value4 := VarAsFloat(qry.Recordset.Fields['FieldThree'].Value); value5 := VarAsWideString(qry.Recordset.Fields['FieldFour'].Value); ... value56 := VarAsMoney(qry.Recordset.Fields['FieldFive'].Value); qry.Next; end; </code></pre> <hr> <p>Since it is a common enough problem, we created a helper method to solve the issue:</p> <pre><code>class function TADOHelper.Execute(const Connection: TADOConnection; const CommandText: WideString): TADOQuery; var rs: _Recordset; query: TADOQuery; nRecords: OleVariant; begin Query := TADOQuery.Create(nil); Query.DisableControls; //speeds up Query.Next by a magnitude Query.Connection := Connection; Query.SQL.Text := CommandText; try Query.Open(); except on E:Exception do begin Query.Free; raise; end; end; Result := Query; end; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload