Documentation Home
The MySQL Test Framework, Version 2.0
Download this Manual
PDF (US Ltr) - 0.6Mb
PDF (A4) - 0.6Mb
EPUB - 134.9Kb

The MySQL Test Framework, Version 2.0  /  mysqltest Language Reference  /  mysqltest Flow Control Constructs

6.4 mysqltest Flow Control Constructs

The syntax for if and while blocks looks like this:

if (expr)
  command list
while (expr)
  command list

An expression result is true if nonzero, false if zero. If the expression begins with !, the sense of the test is reversed.

If the expression is a string that does not begin with a numeric digit (possibly preceeded by a plus or minus sign), it evaluates as true if non-empty. Any white space is ignored in this case, so a string consisting of only white space is false.

There is no provision for else with if.

For a while loop, make sure that the loop includes some exit condition that eventually occurs. This can be done by writing expr so that it becomes false at some point.

The allowable syntax for expr is $var_name, !$var_name, a string or integer, or `query`.

From MySQL 5.5, the expression can also be a simple comparison, where the left hand side must be a variable, and the right hand side can be any type valid for the single expression except the negated variable. The supported operators are ==, !=, <, <=, > and >=. Only the first two may be used if the right hand side does not evaluate to an integer. With ==, strings must match exactly.

If you use a string on the right hand side of the comparison, it does not have to be quoted even if it contains spaces. It may optionally be enclosed in single or double quotation marks which will then be stripped off before comparison. This is in contrast to let statements, where quoting is not stripped. The optional quoting is not available in the first release of MySQL 5.5 GA (5.5.8), but can be used from 5.5.9.

Examples of the expression syntax with comparisons (only the header shown):

while ($counter<5) ...
if ($value == 'No such row') ...
if ($slave_count != $master_count) ...

The opening { (curly brace) must be separated from the preceding ) (right parenthesis) by whitespace, such as a space or a line break.

Variable references that occur within `query` are expanded before the query is sent to the server for execution.