Filtering, SetScope, SetRange and Query

<< Click to Display Table of Contents >>

Navigation:  Apollo VCL Components > Installing and Using Apollo VCL >

Filtering, SetScope, SetRange and Query

The following explains the various techniques for viewing a subset of records from a table.

 

Filtering

Filtering is the slowest technique for viewing a subset of records. The reason why it is so slow is because filtering doesn't work on a subset of records from a table - it works on the entire table whether or not the records is part of the filter. The only use for SetFilter is if you wanted to specifically issue a non-optimized filter (i.e. perhaps for your own speed comparisons).

SetRangeUsing_TApolloTable_Like_TTable

SetRange maps internally to SetScope.

Query

Instead of TApolloTable's SetFilter, you should use the Query method instead. The Query method tries to optimize the query using available indexes if possible. If it is unable to use an index, the Query method will treat the query string as a normal filter, just like SetFilter. The Query rountine actually uses a bitmap to filter the data (See: Query Optimization Tips, RYO Indexes).

SetScope

SetScope is the fastest and most efficient technique to viewing a subset of records. An index on the key field you wish to "scope" must exist and must be set active.

 

SetScope Example:

A sample on how to set a master/detail relationship easily and efficiently using TApolloTable.SetScope.

 

Customer (master table)

Orders (detail table)

 

procedure TForm1.CustomerTableAfterScroll(DataSet: TDataSet);

var

   key : string;

begin

  // get the key field that you want to "link" on

   key := CustomerTable.FieldByName('CustID').AsString;

  // SetScope( LowValue, HighValue )

   OrdersTable.SetScope( key , key );

  // FYI:  SetScope( '', '')  to clear the scope

end;