Sys(3054)
This cool function, introduced in VFP 5, makes it easier to tell whether your queries are as fast as they could be. It displays optimization information (known as "SQL ShowPlan") in the main VFP window. VFP 7 enhanced this function to make it even easier to get the information you need.
Usage |
cSetting = SYS( 3054 [, nSetting [, cOutputVar ] ] ) |
Parameter |
Value |
Meaning |
nSetting |
0 |
Turn off SQL ShowPlan. |
1 |
Turn on SQL ShowPlan for filters only. |
|
2 |
Turn on SQL ShowPlan for filters only and display the original query along with the ShowPlan output. |
|
11 |
Turn on SQL ShowPlan for filters and joins. |
|
12 |
Turn on SQL ShowPlan for filters and joins and display the original query along with the ShowPlan output. |
|
Omitted |
In VFP 6 and later, return the current ShowPlan setting. In VFP 5, same as passing 1. |
|
cOutputVar |
Character |
The name of a variable to hold the output when a query is run. |
cSetting |
Character |
In VFP 6 and later, the value of nSetting passed in, as a character string. In VFP 5, the empty string. |
In some cases, with nSetting = 2 or nSetting = 12, the output cuts off the query arbitrarily. The optimization information is always complete, though. |
You can use SYS(3054) on views as well as queries, but passing 2 or 12 for nSetting doesn't include the query itself in that case. |
You pass the variable name to SYS(3054), not the variable itself. That's because VFP doesn't have a mechanism for us to pass variables to built-in functions by reference, and the function needs to change the specified variable, not use its value. |
There's no way to find out what variable you've set ShowPlan to. |
Passing a variable name to SYS(3054) is good for only one query. That is, if you issue a call like SYS(3054,12,"cMyVar"), then run two queries, cMyVar contains information only about the first query. Microsoft says this is by design, but we think it's a really stupid design. The major reason we want to store this information in a variable is to run a whole process and check all the optimization. If you need to check on multiple queries, storing the results for each, you have to issue SYS(3054) before each one and either use separate variables or store the results from the variable before the next query. |
Example |
?SYS(3054,11) && Echoes 11 in VFP 6 and later * Using TasTrade data SELECT * ; FROM customer JOIN orders ; ON customer.customer_id = orders.customer_id ; WHERE UPPER(company_name) = "C" ; INTO CURSOR test ?SYS(3054,0) SYS(3054,2,"cResult") && Filters, including query – use var SELECT * ; FROM customer JOIN orders ; ON customer.customer_id = orders.customer_id ; WHERE UPPER(company_name) = "C" ; INTO CURSOR test SYS(3054,0) MESSAGEBOX(cResult) |
See Also |