3 # Write the contents of $write_var to file $write_to_file.
8 # --let $write_var = <value>
9 # --let $write_to_file = [<file>|GENERATE]
10 # --source include/write_var_to_file.inc
12 # $write_var is evaluated in sql 'string' context, so escapes like \n
15 # $write_to_file can be either a filename, or the special string
16 # GENERATE. If it is GENERATE, a unique filename is generated (based
17 # on UUID()). The filename is saved in $write_to_file so that it can
21 # ==== Implementation ====
23 # We can't use mysqltest's write_file because it does not evaluate
24 # variables. We can't use '--exec echo $write_var > $write_file'
25 # because it will use \n\r line terminator under windows. So the only
26 # working way is mysql's SELECT INTO DUMPFILE, which is subject to
27 # @@secure_file_priv. That makes this more complex than you might
30 if (`SELECT '$write_to_file' = ''`)
32 --die You must set the mysqltest variable \$write_to_file before you source include/write_var_to_file.inc
35 if (`SELECT '$write_to_file' = 'GENERATE'`)
37 --let $_wvtf_suffix= `SELECT UUID()`
38 --let $write_to_file= $MYSQLTEST_VARDIR/tmp/_var_file_$_wvtf_suffix.inc
42 --remove_file $write_to_file
44 if (`SELECT LENGTH(@@secure_file_priv) > 0`)
46 --let $_wvtf_secure_file_priv= `SELECT @@secure_file_priv`
47 --let $_wvtf_suffix= `SELECT UUID()`
48 --let $_wvtf_tmp_file= $_wvtf_secure_file_priv/_wvtf_$_wvtf_suffix
50 --eval SELECT '$write_var' INTO DUMPFILE '$_wvtf_tmp_file'
51 --copy_file $_wvtf_tmp_file $write_to_file
52 --remove_file $_wvtf_tmp_file
54 if (`SELECT LENGTH(@@secure_file_priv) = 0`)
56 --eval SELECT '$write_var' INTO DUMPFILE '$write_to_file'