This topic describes the commands commonly used for writing test cases.
error
Verifies expected failures. Some test cases are written to verify SQL statement execution failures. You can add --error [error code] before an SQL statement. --error can be followed by two types of values: error code or SQL state. If --error is followed by an SQL state, the SQL state must be prefixed with S.
Sample code:
--error 65535
create table t1(pk createtime primary key, a int);
--error SHY000
select a from t1 union select * from t2;
let
Assigns numeric or string values to variables.
Sample code:
let $var_name = value
inc/dec
inc specifies to increase an integer by 1 and dec specifies to decrease an integer by 1. They are the only operations supported by mysqltest.
Sample code:
inc $varname
dec $varname
eval
Executes SQL statements with variables.
Sample code:
eval insert intot1(i,c1,c256,dt,d) values(0,'1','$i','2012-10-10 12:00:00','2012-10-10');
echo
Prints variables in the terminal. It is usually used to add comments to result files.
Sample code:
echo $tableName;
--echo merge happens
alter system major freeze;
while
Performs loop control.
Sample code:
let $cnt=10000;
while($cnt)
{
eval create table tt_$cnt (pk int primary key, c1 int);
dec $cnt;
}
select pk,b from t1;
disable_warnings/enable_warnings
Specifies whether to generate unfiltered warnings in the server. Default value: enable_warnings.
Sample code:
--disable_warnings
real_sleep/sleep
Specifies the sleep time.
Sample code:
real_sleep 20;
replace_column
Replaces the values of some columns in the result set. Some results change based on the execution time, such as create_time or modify_time. You can use this command to replace the value with a constant.
Sample code:
--replace_column 2 searched
# You can replace multiple values at a time.
--replace_column 1 create_time 2modify_time 3 tenant_id 6 zone 8 zone 7 zone
query_get_value(query,col_name,row_num)
Obtains the value in a specific row and column of the query result.
Sample code:
let $idx1 =query_get_value(select a.table_name from oceanbase.__all_table as a innerjoin (select * from oceanbase.__all_table where table_name='t1') b ona.data_table_id=b.table_id, table_name, 1);
let $idx2 =query_get_value(select a.table_name from oceanbase.__all_table as a innerjoin (select * from oceanbase.__all_table where table_name='t1') b ona.data_table_id=b.table_id, table_name, 2);
connect/disconnect/connection
Establishes or terminates a connection.
You may use the connect or disconnect command when you test sessions to establish or terminate a connection. The connection command specifies the connection for executing SQL statements. You can switch between connections. This command is usually used in concurrent transaction processing.
disable_abort_on_error/enable_abort_on_error
If abort_on_error is enabled, after the execution of an SQL statement fails, mysqltest exits and does not execute the subsequent content or generate a reject file. If abort_on_error is disabled, after the execution of an SQL statement fails, mysqltest continues to execute the subsequent content and generates a reject file.
disable_query_log/enable_query_log
If query_log is enabled, all SQL statements are recorded in the result file. In some cases, when many queries exist in a loop, you can use disable_query_log.
Sample code:
--disable_query_log
let $cnt5=74;
while ($cnt5)
{
eval drop table ttl$cnt5;
dec $cnt5;
}
--enable_query_log
if(exptr){do sql}
If the value of exptr is not 0, mysqltest executes the content enclosed by braces.
Notice
mysqltest does not provide the `else if` or `else` option. In earlier versions of mysqltest, the value of `exptr` cannot be a comparison expression.
Sample code:
if($valuenow== $valueorig)
{
--echo succeed
}
disable_result_log/enable_result_log
Specifies whether to write the execution result to the result file. By default, all SQL statement execution results will be written to the result file. If the result file is extremely long and unworthy of or unsuitable for verification, you can use the disable_result_log command to avoid writing the result to the result file.
Sample code:
--disable_result_log
select count(*) from oceanbase.__all_server_table_stat where table_id>0;
select count(*) from oceanbase.__all_server_table_stat where table_id<=0;
select count(*) from oceanbase.__all_server_table_stat ;
--enable_result_log
exit
Exits a test case. After you exit, mysqltest will not execute subsequent content of the test case. This command is usually used for loop or if judgments.