QueryTest

<< Click to Display Table of Contents >>

Navigation:  Apollo VCL Components > Apollo VCL Component Reference > TApolloTable > TApolloTable Methods >

QueryTest

Declaration

function QueryTest( sExpression: String ): Integer;

Description

Tests if a given xBase expression will result in an optimized query set or not. Some queries may result in partial optimization.

 

The function is useful in determining whether a permanent index should be built using the tested expression if the query syntax is used often enough to warrant the addition of an index.

Parameters

sExpression: A standard xBase expression that defines the query filter conditions and evaluates as logical True or False.

An index used in query optimization does not have to be the controlling index and the query conditional expression may use fields that reference more than one index.

Conditional expressions that contain references to aliased fields in tables linked to the current work area via SetRelation are not optimized.

image\tip.gif To clear a query, pass the query expression as a NULL string ('' or #0).

 

Clearing a query also clears filters set with SetFilter.

Return Value

QueryTest returns one of the following defined constants:

 

  OPTIMIZE_NONE  0

  OPTIMIZE_PART  1

  OPTIMIZE_FULL  2

 

If NONE, no indexes are available that match the query condition. If PART is returned, part of the query expression may be used in constructing a bitmap. When records are read, the other part (not optimized) is evaluated as a standard filter within the optimized set. If FULL optimization is possible, all parts of the expression will utilize open index file(s) to construct the query set.

Delphi Example

// Test if query can be optimized

procedure Form1.Button1Click(Sender: TObject);

var

 qResult: Integer; 

begin

 if QueryBox.Text = '' then 

 begin 

         ShowMessage( 'No query to test' ); 

         Exit; 

 end; 

 qResult := ApTbl.QueryTest( QueryBox.Text );

 case qResult of 

         OPTIMIZE_NONE: TestBox.Text := 'NONE'; 

         OPTIMIZE_PART: TestBox.Text := 'PART'; 

         OPTIMIZE_FULL: TestBox.Text := 'FULL'; 

 end; 

end;

C++Builder Example

// Test if query can be optimized

void __fastcall TForm1::Button1Click(TObject *Sender)

{

 int qResult; 

 

 if (QueryBox->Text == "") 

 

         ShowMessage( "No query to test" ); 

         return; 

 

 qResult = ApTbl->QueryTest( QueryBox->Text );

 switch( qResult ) 

 

         case OPTIMIZE_NONE:  

                 TestBox->Text = "NONE"; 

                 break; 

         case OPTIMIZE_PART:  

                 TestBox->Text = "PART"; 

                 break; 

         case OPTIMIZE_FULL:  

                 TestBox->Text = "FULL"; 

                 break; 

         }  

}

See Also

FilterDlg, Query, QueryRecCount