| 1 |
################################################################################ |
| 2 |
# inc/partition_trigg1.inc # |
| 3 |
# # |
| 4 |
# Purpose: # |
| 5 |
# Auxiliary script, only useful when sourced by inc/partition_check.inc. # |
| 6 |
# One trigger uses new values (--> event UPDATE, INSERT only) # |
| 7 |
# One trigger uses old values (--> event UPDATE, DELETE only) # |
| 8 |
# # |
| 9 |
# 1. Create a trigger # |
| 10 |
# 2. Execute a statement, which activates the trigger # |
| 11 |
# 3. Check the results of the trigger activity # |
| 12 |
# 4. Revert the modifications # |
| 13 |
# # |
| 14 |
#------------------------------------------------------------------------------# |
| 15 |
# Original Author: mleich # |
| 16 |
# Original Date: 2006-03-05 # |
| 17 |
# Change Author: # |
| 18 |
# Change Date: # |
| 19 |
# Change: # |
| 20 |
################################################################################ |
| 21 |
|
| 22 |
# Test for operations, which have new values (INSERT+UPDATE, but not DELETE) |
| 23 |
if ($no_debug) |
| 24 |
{ |
| 25 |
--disable_query_log |
| 26 |
} |
| 27 |
eval SELECT INSTR('$statement','DELETE') = 0 INTO @aux; |
| 28 |
let $run1= `SELECT @aux`; |
| 29 |
--enable_query_log |
| 30 |
if ($run1) |
| 31 |
{ |
| 32 |
# Insert three records which are only needed for UPDATE TRIGGER test |
| 33 |
eval INSERT INTO $tab_has_trigg(f_int1,f_int2,f_char1,f_char2,f_charbig) |
| 34 |
SELECT -f_int1,-f_int1,CAST(-f_int1 AS CHAR),CAST(-f_int1 AS CHAR), |
| 35 |
'just inserted' FROM t0_template |
| 36 |
WHERE f_int1 BETWEEN @max_row_div2 - 1 AND @max_row_div2 + 1; |
| 37 |
delimiter |; |
| 38 |
eval CREATE TRIGGER trg_1 $event ON $tab_has_trigg FOR EACH ROW |
| 39 |
BEGIN |
| 40 |
UPDATE $tab_in_trigg SET f_int1 = -f_int1, f_int2 = -f_int2, |
| 41 |
f_charbig = 'updated by trigger' |
| 42 |
WHERE f_int1 = new.f_int1; |
| 43 |
END| |
| 44 |
delimiter ;| |
| 45 |
|
| 46 |
eval $statement; |
| 47 |
|
| 48 |
# Check of preceding statement via Select |
| 49 |
if ($no_debug) |
| 50 |
{ |
| 51 |
--disable_query_log |
| 52 |
} |
| 53 |
eval SELECT '# check trigger-$num success: ' AS "", COUNT(*) = 3 AS "" |
| 54 |
FROM $tab_in_trigg |
| 55 |
WHERE f_int1 = f_int2 AND CAST(f_char1 AS SIGNED INT) = -f_int1; |
| 56 |
--enable_query_log |
| 57 |
|
| 58 |
DROP TRIGGER trg_1; |
| 59 |
|
| 60 |
# Revert the changes |
| 61 |
eval UPDATE $tab_in_trigg SET f_int1 = CAST(f_char1 AS SIGNED INT), |
| 62 |
f_int2 = CAST(f_char1 AS SIGNED INT), |
| 63 |
f_charbig = 'just inserted' |
| 64 |
WHERE f_int1 <> CAST(f_char1 AS SIGNED INT); |
| 65 |
eval DELETE FROM $tab_has_trigg |
| 66 |
WHERE ABS(f_int1) BETWEEN @max_row_div2 - 1 AND @max_row_div2 + 1; |
| 67 |
inc $num; |
| 68 |
} |
| 69 |
|
| 70 |
# Test for operations, which have old values (UPDATE+DELETE, but not INSERT) |
| 71 |
if ($no_debug) |
| 72 |
{ |
| 73 |
--disable_query_log |
| 74 |
} |
| 75 |
eval SELECT INSTR('$statement','INSERT') = 0 INTO @aux; |
| 76 |
let $run1= `SELECT @aux`; |
| 77 |
--enable_query_log |
| 78 |
if ($run1) |
| 79 |
{ |
| 80 |
# Insert three records which are only needed for UPDATE/DELETE TRIGGER test |
| 81 |
eval INSERT INTO $tab_has_trigg(f_int1,f_int2,f_char1,f_char2,f_charbig) |
| 82 |
SELECT -f_int1,-f_int1,CAST(-f_int1 AS CHAR),CAST(-f_int1 AS CHAR), |
| 83 |
'just inserted' FROM t0_template |
| 84 |
WHERE f_int1 BETWEEN @max_row_div2 - 1 AND @max_row_div2 + 1; |
| 85 |
|
| 86 |
delimiter |; |
| 87 |
eval CREATE TRIGGER trg_1 $event ON $tab_has_trigg FOR EACH ROW |
| 88 |
BEGIN |
| 89 |
UPDATE $tab_in_trigg SET f_int1 = -f_int1, f_int2 = -f_int2, |
| 90 |
f_charbig = 'updated by trigger' |
| 91 |
WHERE f_int1 = - old.f_int1; |
| 92 |
END| |
| 93 |
delimiter ;| |
| 94 |
|
| 95 |
eval $statement; |
| 96 |
|
| 97 |
# Check of preceding statement via Select |
| 98 |
if ($no_debug) |
| 99 |
{ |
| 100 |
--disable_query_log |
| 101 |
} |
| 102 |
eval SELECT '# check trigger-$num success: ' AS "", COUNT(*) = 3 AS "" |
| 103 |
FROM $tab_in_trigg |
| 104 |
WHERE f_int1 = f_int2 AND CAST(f_char1 AS SIGNED INT) = -f_int1; |
| 105 |
--enable_query_log |
| 106 |
DROP TRIGGER trg_1; |
| 107 |
# Revert the changes |
| 108 |
eval UPDATE $tab_in_trigg SET f_int1 = CAST(f_char1 AS SIGNED INT), |
| 109 |
f_int2 = CAST(f_char1 AS SIGNED INT), |
| 110 |
f_charbig = 'just inserted' |
| 111 |
WHERE f_int1 <> CAST(f_char1 AS SIGNED INT); |
| 112 |
eval DELETE FROM $tab_has_trigg |
| 113 |
WHERE ABS(f_int1) BETWEEN @max_row_div2 - 1 AND @max_row_div2 + 1; |
| 114 |
inc $num; |
| 115 |
} |