3 # Execute a statement and write the result to a file. This is useful
4 # if the output needs more advanced parsing than can be done by
7 # The statement is sent to mysqld on current connection using
8 # the mysql command line client.
12 # --let $statement= <STATEMENT>
13 # --let $output_file= {<FILE>|GENERATE}
14 # [--let $dont_print_statement= 1]
15 # --source include/write_result_to_file.inc
19 # The statement to execute.
22 # Name of file to write. If omitted, generates a new filename and
23 # stores the name both in the mysqltest variable $output_file and
24 # in the environment variable $OUTPUT_FILE.
26 # $dont_print_statement
27 # By default, the statement is echoed to the result log. If the
28 # statement contains non-deterministic output, set this variable
31 # Get the port and socket used by mysqld on current connection
32 --let _WRTF_SERVER_PORT= `SELECT @@PORT`
33 --let _WRTF_SERVER_SOCKET= `SELECT @@SOCKET`
35 --let $_write_result_msg= [connection=$CURRENT_CONNECTION]
36 if (!$dont_print_statement)
38 --let $_write_result_msg= [connection=$CURRENT_CONNECTION
statement=$statement]
41 --let $include_filename= write_result_to_file.inc $_write_result_msg
42 --source include/begin_include_file.inc
46 --die !!!ERROR IN TEST: mysqltest variable
'statement' not
set in write_result_to_file.inc
48 --let _WRTF_STATEMENT= $statement
52 --die !!!ERROR IN TEST: mysqltest variable
'output_file' not
set in write_result_to_file.inc
54 if ($output_file == GENERATE)
56 --let $output_file= `SELECT UUID()`
57 --let $output_file= $MYSQLTEST_VARDIR/tmp/_stmt_file_$output_file
59 --let _WRTF_OUTPUT_FILE= $output_file
63 my $stmt= $ENV{
'_WRTF_STATEMENT'};
64 # Connecting mysql to same mysqld as current connectiona
65 # by overriding port and socket
66 my $mysql = $ENV{
'MYSQL'};
67 my $server_port= $ENV{
'_WRTF_SERVER_PORT'};
68 my $server_socket= $ENV{
'_WRTF_SERVER_SOCKET'};
69 $mysql .=
" --port=$server_port --socket=$server_socket";
70 my $outfile = $ENV{
'_WRTF_OUTPUT_FILE'};
71 open
MYSQL,
"| $mysql > $outfile" or die
"Failed to open MYSQL pipe: '$mysql > $outfile'";
72 print MYSQL $stmt,
';' or die
"Error printing statement to MYSQL pipe: $!";
73 close MYSQL or die
"Error closing MYSQL pipe: $!";
76 --let $include_filename= write_result_to_file.inc [$write_result_msg]
77 --source include/end_include_file.inc