summaryrefslogtreecommitdiffstats
path: root/mysql-test/suite/storage_engine/check_errors.inc
blob: e38ff2962f18a26f3797e4c95b0f59a93530d41c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#
# Since we run tests in disable_abort_on_error mode, we cannot use --error command,
# and need to check the result manually.
# Usage in a test:
# --let $error_codes = <comma-separated list>  # optional, default ''
# --let $mysql_errname = <error name>          # optional, default current $mysql_errname (from the last SQL command)
# --let $mysql_errno = <error code>            # optional, default current $mysql_errno (from the last SQL command)
#

if ($error_codes == '0')
{
  --let $error_codes =
}
if ($error_codes == '')
{
  if ($mysql_errname)
  {
    --echo # ERROR: Statement ended with errno $mysql_errno, errname $mysql_errname (expected to succeed)
  }

  # If both error_codes and mysql_errname are false, all is good, no logic needed
}

if ($error_codes != '')
{
  # If mysql_errname or mysql_errno is equal to $error_codes, it's good too, nothing to do

  if ($mysql_errname != $error_codes)
  {
    if ($mysql_errno != $error_codes)
    {
      --let $save_errno = $mysql_errno
      --let $save_errname = $mysql_errname

      --let $codeline = `SELECT CONCAT('\'',REPLACE('$error_codes',',','\',\''),'\'')`
      --let $result = `SELECT '$save_errname' IN($codeline) or '$save_errno' IN ($codeline)`  

      --let $mysql_errno = $save_errno
      --let $mysql_errname = $save_errname

      if (!$result)
      {
        if ($mysql_errname)
        {
          --echo # ERROR: Statement ended with errno $mysql_errno, errname $mysql_errname (expected results: $error_codes)
        }
        if (!$mysql_errname)
        {
          --echo # ERROR: Statement succeeded (expected results: $error_codes)
        }
      }
      # If a list contained more than one error, it could be on one of two reasons:
      # first, we do not care which code it is, as long as it is one of the listed errors.
      # In this case we will suggest to add an rdiff file if the message differs.
      # Second, check_errors might be called from a generalized include file or test, 
      # which runs with different parameters and thus might produce different results for the same statement.
      # Then, the message will be stricter, as the difference with the result file is actually a problem
      # which needs to be checked at least.
      if ($result)
      {
        if (!$strict_check)
        {
          --echo # Statement ended with one of expected results ($error_codes). 
          --echo # If you got a difference in error message, just add it to rdiff file
        }
        if ($strict_check)
        {
          --echo # WARNING: Statement ended with errno $mysql_errno, errname '$mysql_errname'. 
          --echo #          If it differs from the result file, it might indicate a problem.
        }
        
      }
    }
  }
}

# Don't want the variables to be accidentally reused later
--let $error_codes =
--let $strict_check =