Documentation Home
The MySQL Test Framework, Version 1.0
Download this Manual
PDF (US Ltr) - 443.9Kb
PDF (A4) - 445.6Kb

6.3 mysqltest Variables

You can define variables and refer to their values. You can also refer to environment variables, and there is a built-in variable that contains the result of the most recent SQL statement.

To define a variable, use the let command. Examples:

let $a= 14;
let $b= this is a string;
--let $a= 14
--let $b= this is a string

The variable name cannot contain whitespace or the = character.

If a variable has a numeric value, you can increment or decrement the value:

inc $a;
dec $a;
--inc $a
--dec $a

inc and dec are commonly used in while loops to modify the value of a counter variable that controls loop execution.

The result from executing a query can be assigned to a variable by enclosing the query within backtick (`) characters:

let $q= `select version()`;

References to variables can occur in the echo, eval, exec, and system commands. Variable references are replaced by their values. As of MySQL 5.0.26/5.1.12, a nonquery value assigned to a variable in a let command also can refer to variables.

As of MySQL 4.1.23/5.0.42/5.1.18, variable references that occur within `query` are expanded before the query is sent to the server for execution.

You can refer to environment variables. For example, this command displays the value of the $PATH variable from the environment:

--echo $PATH

$mysql_errno is a built-in variable that contains the numeric error returned by the most recent SQL statement sent to the server, or 0 if the command executed successfully. $mysql_errno has a value of −1 if no statement has yet been sent.

mysqltest first checks mysqltest variables and then environment variables. mysqltest variable names are not case sensitive. Environment variable names are case sensitive.