sx_QueryTest

<< Click to Display Table of Contents >>

Navigation:  Apollo API Listing >

sx_QueryTest

VB Declaration

Declare Function sx_QueryTest Lib "Apollo9.dll"

(ByVal cpExpression As Any)

As Integer

C Declaration

SHORT FAR PASCAL sx_QueryTest

(BYTEP cpExpression);

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

cpExpression: 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 sx_SetRelation are not optimized.

Note: To clear a query, pass the query expression as a NULL string (0&).

Clearing a query also clears filters set with sx_SetFilter.

Return Value

sx_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.

VB Example

' test if query can be optimized

Sub bTest_Click ()

Dim qResult As Integer

If QueryBox.Text = "" Then

MsgBox "No query to test"

Exit Sub

End If

FoundBox.Text = 0

qResult = sx_QueryTest(CStr(QueryBox.Text))

If qResult = OPTIMIZE_NONE Then TestBox.Text = "NONE"

If qResult = OPTIMIZE_PART Then TestBox.Text = "PART"

If qResult = OPTIMIZE_FULL Then TestBox.Text = "FULL"

End Sub

C Example

case IDC_TESTBUTTON:

{

SHORT iOptLevel;

GetDlgItemText(hdlg, IDC_EDIT1, (LPSTR) caString,

sizeof(caString));

if (lstrlen((LPSTR) caString))

{

iOptLevel = sx_QueryTest(caString);

if (iOptLevel == OPTIMIZE_NONE)

lstrcpy(caExpression, "No optimizing.");

if (iOptLevel == OPTIMIZE_PART)

lstrcpy(caExpression, "Partial optimizing.");

if (iOptLevel == OPTIMIZE_FULL)

lstrcpy(caExpression, "Full optimizing.");

SendMessage(hStatBar, SBM_DISPLAYTEXT, (WPARAM) 0,

(LPARAM) ((LPCSTR) caExpression));

return(FALSE);

}

else

return(TRUE);

}

See Also

sx_FilterDlg, sx_Query, sx_QueryRecCount