3 # Write the contents of $write_var to file $write_to_file.
7 # --let $write_var = <value>
8 # --let $write_to_file = [<file>|GENERATE]
9 # --source include/write_var_to_file.inc
14 # This mysqltest variable is written to the file. The variable is
15 # evaluated in sql 'string' context, so escapes like \n are
19 # The variable is written to this file. If this is set to
20 # GENERATE, a unique filename is generated (based on UUID()), and
21 # the filename is saved in $write_to_file so that it can be
24 # ==== Implementation ====
26 # We can't use mysqltest's write_file because it does not evaluate
27 # variables. We can't use '--exec echo $write_var > $write_file'
28 # because it will use \n\r line terminator under windows. So the only
29 # working way is mysql's SELECT INTO DUMPFILE, which is subject to
30 # @@secure_file_priv. That makes this more complex than you might
35 --die You must
set the mysqltest variable \$write_to_file before you source include/write_var_to_file.inc
38 if ($write_to_file ==
'GENERATE')
40 --let $_wvtf_suffix= `SELECT UUID()`
41 --let $write_to_file= $MYSQLTEST_VARDIR/tmp/_var_file_$_wvtf_suffix.inc
45 --remove_file $write_to_file
47 if (`SELECT LENGTH(@@secure_file_priv) > 0`)
49 --let $_wvtf_secure_file_priv= `SELECT @@secure_file_priv`
50 --let $_wvtf_suffix= `SELECT UUID()`
51 --let $_wvtf_tmp_file= $_wvtf_secure_file_priv/_wvtf_$_wvtf_suffix
53 --eval SELECT
'$write_var' INTO DUMPFILE
'$_wvtf_tmp_file'
54 --copy_file $_wvtf_tmp_file $write_to_file
55 --remove_file $_wvtf_tmp_file
57 if (`SELECT LENGTH(@@secure_file_priv) = 0`)
59 --eval SELECT
'$write_var' INTO DUMPFILE
'$write_to_file'