# ==== Purpose ====
#
# Execute a statement and write the result to a file. This is useful
# if the output needs more advanced parsing than can be done by
# mysqltest commands.
#
# ==== Usage ====
#
# --let $statement= <STATEMENT>
# --let $output_file= {<FILE>|GENERATE}
# [--let $server_number= <NUMBER>]
# [--let $dont_print_statement= 1]
# --source include/write_result_to_file.inc
#
# Parameters:
# $statement
# The statement to execute.
#
# $server_number
# 1for the master, 2for the slave, 3for next server, etc.
# If omitted, uses current connection.
#
# $output_file
# Name offileto write. If omitted, generates a new filename and
# stores the name both in the mysqltest variable $output_fileand
# in the environment variable $OUTPUT_FILE.
#
# $dont_print_statement
# By default, the statement is echoed to the result log. If the
# statement contains non-deterministic output, set this variable
# to suppress it.
if ($statement == '')
{
--die !!!ERROR IN TEST: mysqltest variable 'statement'notsetin write_result_to_file.inc
}
--let _WRTF_STATEMENT= $statement
if (!$output_file)
{
--die !!!ERROR IN TEST: mysqltest variable 'output_file'notsetin write_result_to_file.inc
} if ($output_file == GENERATE)
{
--let $output_file= `SELECT UUID()`
--let $output_file= $MYSQLTEST_VARDIR/tmp/_stmt_file_$output_file
}
--let _WRTF_OUTPUT_FILE= $output_file
perl;
my $stmt= $ENV{'_WRTF_STATEMENT'};
my $server_number= $ENV{'_WRTF_SERVER_NUMBER'};
my $mysql = $ENV{'MYSQL'}; $mysql =~ s/( --|$)/ --defaults-group-suffix=.$server_number$1/;
my $outfile = $ENV{'_WRTF_OUTPUT_FILE'};
open MYSQL, "| $mysql > $outfile"or die "Failed to open pipe to client on server '$server_number': $!";
print MYSQL $stmt, ';'or die "Error printing statement to MYSQL pipe: $!";
close MYSQL or die "Error closing MYSQL pipe: $!";
EOF
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.