~ubuntu-branches/ubuntu/trusty/mysql-5.6/trusty

« back to all changes in this revision

Viewing changes to mysql-test/include/write_var_to_file.inc

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-02-12 11:54:27 UTC
  • Revision ID: package-import@ubuntu.com-20140212115427-oq6tfsqxl1wuwehi
Tags: upstream-5.6.15
ImportĀ upstreamĀ versionĀ 5.6.15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# ==== Purpose ====
 
2
#
 
3
# Write the contents of $write_var to file $write_to_file.
 
4
#
 
5
# ==== Usage ====
 
6
#
 
7
# --let $write_var = <value>
 
8
# --let $write_to_file = [<file>|GENERATE]
 
9
# --source include/write_var_to_file.inc
 
10
#
 
11
# Parameters:
 
12
#
 
13
#   $write_var
 
14
#     This mysqltest variable is written to the file.  The variable is
 
15
#     evaluated in sql 'string' context, so escapes like \n are
 
16
#     interpolated.
 
17
#
 
18
#   $write_to_file
 
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
 
22
#     retrieved later.
 
23
#
 
24
# ==== Implementation ====
 
25
#
 
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
 
31
# expect.
 
32
 
 
33
if (!$write_to_file)
 
34
{
 
35
  --die You must set the mysqltest variable \$write_to_file before you source include/write_var_to_file.inc
 
36
}
 
37
 
 
38
if ($write_to_file == 'GENERATE')
 
39
{
 
40
  --let $_wvtf_suffix= `SELECT UUID()`
 
41
  --let $write_to_file= $MYSQLTEST_VARDIR/tmp/_var_file_$_wvtf_suffix.inc
 
42
}
 
43
 
 
44
--error 0,1
 
45
--remove_file $write_to_file
 
46
 
 
47
if (`SELECT LENGTH(@@secure_file_priv) > 0`)
 
48
{
 
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
 
52
 
 
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
 
56
}
 
57
if (`SELECT LENGTH(@@secure_file_priv) = 0`)
 
58
{
 
59
  --eval SELECT '$write_var' INTO DUMPFILE '$write_to_file'
 
60
}