mirror of
https://github.com/MariaDB/server.git
synced 2025-01-16 12:02:42 +01:00
8be53a389c
This is similar to MysQL Worklog 3253, but with a different implementation. The disk format and SQL syntax is identical with MySQL 5.7. Fetures supported: - "Any" ammount of any trigger - Supports FOLLOWS and PRECEDES to be able to put triggers in a certain execution order. Implementation details: - Class Trigger added to hold information about a trigger. Before this trigger information was stored in a set of lists in Table_triggers_list and in Table_triggers_list::bodies - Each Trigger has a next field that poinst to the next Trigger with the same action and time. - When accessing a trigger, we now always access all linked triggers - The list are now only used to load and save trigger files. - MySQL trigger test case (trigger_wl3253) added and we execute these identically. - Even more gracefully handling of wrong trigger files than before. This is useful if a trigger file uses functions or syntax not provided by the server. - Each trigger now has a "Created" field that shows when the trigger was created, with 2 decimals. Other comments: - Many of the changes in test files was done because of the new "Created" field in the trigger file. This shows up in SHOW ... TRIGGER and when using information_schema.trigger. - Don't check if all memory is released if on uses --gdb; This is needed to be able to get a list from safemalloc of not freed memory while debugging. - Added option to trim_whitespace() to know how many prefix characters was skipped. - Changed a few ulonglong sql_mode to sql_mode_t, to find some wrong usage of sql_mode.
36 lines
1.5 KiB
Text
36 lines
1.5 KiB
Text
CREATE DATABASE db1;
|
|
USE db1;
|
|
CREATE TABLE t1 (val INT);
|
|
CREATE TRIGGER IF NOT EXISTS val_sum BEFORE INSERT ON t1 FOR EACH ROW SET @sum = @sum + NEW.val;
|
|
SET @sum=0;
|
|
INSERT INTO t1 VALUES (10), (20), (30);
|
|
SELECT @sum;
|
|
@sum
|
|
60
|
|
CREATE TRIGGER IF NOT EXISTS val_sum_new BEFORE INSERT ON t1 FOR EACH ROW SET @sum = @sum + NEW.val;
|
|
CREATE TRIGGER IF NOT EXISTS val_sum AFTER INSERT ON t1 FOR EACH ROW SET @sum = @sum + 1 + NEW.val;
|
|
Warnings:
|
|
Note 1359 Trigger already exists
|
|
CREATE OR REPLACE TRIGGER IF NOT EXISTS val_sum BEFORE INSERT ON t1 FOR EACH ROW SET @sum = @sum + 2 + NEW.val;
|
|
ERROR HY000: Incorrect usage of OR REPLACE and IF NOT EXISTS
|
|
SELECT ACTION_STATEMENT FROM INFORMATION_SCHEMA.TRIGGERS WHERE TRIGGER_NAME='val_sum';
|
|
ACTION_STATEMENT
|
|
SET @sum = @sum + NEW.val
|
|
CREATE OR REPLACE TRIGGER val_sum BEFORE INSERT ON t1 FOR EACH ROW SET @sum = @sum + 3 + NEW.val;
|
|
SELECT ACTION_STATEMENT FROM INFORMATION_SCHEMA.TRIGGERS WHERE TRIGGER_NAME='val_sum';
|
|
ACTION_STATEMENT
|
|
SET @sum = @sum + 3 + NEW.val
|
|
CREATE TRIGGER val_sum BEFORE INSERT ON t1 FOR EACH ROW SET @sum = @sum + 4 + NEW.val;
|
|
ERROR HY000: Trigger already exists
|
|
SELECT ACTION_STATEMENT FROM INFORMATION_SCHEMA.TRIGGERS WHERE TRIGGER_NAME='val_sum';
|
|
ACTION_STATEMENT
|
|
SET @sum = @sum + 3 + NEW.val
|
|
# Clearing up
|
|
DROP TRIGGER IF EXISTS val_sum;
|
|
SELECT ACTION_STATEMENT FROM INFORMATION_SCHEMA.TRIGGERS WHERE TRIGGER_NAME='val_sum';
|
|
ACTION_STATEMENT
|
|
DROP TRIGGER IF EXISTS val_sum;
|
|
Warnings:
|
|
Note 1360 Trigger does not exist
|
|
DROP TABLE t1;
|
|
DROP DATABASE db1;
|