run

NAME

run(): Executes a QueryScript.

TYPE

Procedure

DESCRIPTION

This procedure accepts a QueryScript text, and invokes the script.

run() is the main entry point for QueryScript.

run() will first scan the code for script syntax errors. Any such error aborts operation. Only when satisfied, is the code executed. Hence, although a QueryScript code is interpreted, syntax errors are intercepted before any code executes. It should be noted that SQL syntax errors are not examined, only script syntax error. Read more on Execution.

Failure of execution or interpretation is prompted to the user. The @common_schema_error variables is set with the relevant error message.

Invoker of this procedure must have the privileges required for execution of queries in the script.

SYNOPSIS

run(IN query_script text)
  MODIFIES SQL DATA

Input:

  • query_script: a QueryScript text. run() also accepts a filename, if it starts with a slash (/) or a backslash (\).

Invocation of run() is likely to generate many warnings. These should be ignored, and are part of the general workflow (e.g. removing some temporary tables if they exist).

EXAMPLES

Execute an inlined script:

mysql> call run("
  foreach($x : 1:8)
  {
    CREATE DATABASE shard_:$x;
  }
  SHOW DATABASES LIKE 'shard_%';
");

+--------------------+
| Database (shard_%) |
+--------------------+
| shard_1            |
| shard_2            |
| shard_3            |
| shard_4            |
| shard_5            |
| shard_6            |
| shard_7            |
| shard_8            |
+--------------------+
The above assumes no ANSI_QUOTES in sql_mode.

Run script stored in user defined text variable. Repeatedly execute random queries until 5pm:

mysql> SET @script := "
while (TIME(SYSDATE()) < '17:00:00')
  SELECT * FROM world.City WHERE id = 1 + FLOOR((RAND()*4079));
";
mysql> call run(@script);

ENVIRONMENT

MySQL 5.1 or newer

SEE ALSO

Query Script, run_file()

AUTHOR

Shlomi Noach
 
common_schema documentation