summaryrefslogtreecommitdiffstats
path: root/mysql-test/suite/atomic/create_trigger2.test
blob: b694207bbfcab3629843e0074d1a42b2419775f9 (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
81
82
83
84
85
86
87
88
89
--source include/have_debug.inc

#
# Testing of atomic CREATE TRIGGER when write fails in create_definition_file
#

let $MYSQLD_DATADIR= `SELECT @@datadir`;

let $engine_count=1;
let $engines='aria';
let $old_debug=`select @@debug_dbug`;

let $e=0;
--disable_query_log

create table t1 (a int not null, b int not null);
insert into t1 values(1,1);
flush tables;

# sql_create_definition_file is called twice per CREATE TRIGGER and 1 more
# in case we drop an existing trigger, so we need to test 3*2 +1 failures
# and also when there is no failures (= 8)
let $try_count=8;

let $r=0;
while ($r < $try_count)
{
  inc $r;

  echo "position: $r";
  --eval set @@debug_dbug="+d,definition_file_simulate_write_error",@debug_error_counter=$r;
  let $errno=0;
  delimiter |;
  --error 0,3
  create trigger t1_trg before insert on t1 for each row
  begin
    if isnull(new.a) then
      set new.a:= 1000;
    end if;
  end|
  delimiter ;|
  let $error=$errno;
  if ($error == 0)
  {
    delimiter |;
    --error 0,3
    create or replace trigger t2_trg before insert on t1 for each row
    begin
      if isnull(new.b) then
        set new.b:= 2000;
      end if;
    end|
    delimiter ;|
    let $error=$errno;
  }
  if ($error == 0)
  {
    delimiter |;
    --error 0,3
    create or replace trigger t2_trg before insert on t1 for each row
    begin
      if isnull(new.b) then
        set new.b:= 3000;
      end if;
    end|
    delimiter ;|
    let $error=$errno;
  }
  --eval set @@debug_dbug="$old_debug"

  # Check which tables still exists
  --list_files $MYSQLD_DATADIR/test *TR*
  --list_files $MYSQLD_DATADIR/test *sql*

  --replace_column 7 #
  --error 0,ER_TRG_DOES_NOT_EXIST
  SHOW CREATE TRIGGER t1_trg;
  --replace_column 7 #
  --error 0,ER_TRG_DOES_NOT_EXIST
  SHOW CREATE TRIGGER t2_trg;
  --disable_warnings
  drop trigger if exists t1_trg;
  drop trigger if exists t2_trg;
  --enable_warnings
}

drop table t1;

--enable_query_log