summaryrefslogtreecommitdiff
path: root/mysql-test/t/trigger.test
diff options
context:
space:
mode:
authorunknown <kroki@mysql.com>2006-04-12 19:31:00 +0400
committerunknown <kroki@mysql.com>2006-04-12 19:31:00 +0400
commit886a35bd82c153253007040202116b5f634705f4 (patch)
tree79c3147160f25f4c191b0d31943796b18cc50c8d /mysql-test/t/trigger.test
parentdaac388624f52f9d95c43d186e9a759ff15fff18 (diff)
downloadmariadb-git-886a35bd82c153253007040202116b5f634705f4.tar.gz
Bug#16461: connection_id() does not work properly inside trigger
CONNECTION_ID() was implemented as a constant Item, i.e. an instance of Item_static_int_func class holding value computed at creation time. Since Items are created on parsing, and trigger statements are parsed on table open, the first connection to open a particular table would effectively set its own CONNECTION_ID() inside trigger statements for that table. Re-implement CONNECTION_ID() as a class derived from Item_int_func, and compute connection_id on every call to fix_fields(). mysql-test/r/trigger.result: Add result for bug#16461. mysql-test/t/trigger.test: Add test case for bug#16461. sql/item.cc: Remove now unused class Item_static_int_func. sql/item.h: Remove now unused class Item_static_int_func. sql/item_create.cc: Use new implementation of CONNECTION_ID(). sql/item_func.cc: Re-implement CONNECTION_ID() as Item_func_connection_id (was Item_static_int_func). Set max_length to 10, as it was before. Compute connection_id dynamically on every call to fix_fields(). sql/item_func.h: Re-implement CONNECTION_ID() as Item_func_connection_id (was Item_static_int_func).
Diffstat (limited to 'mysql-test/t/trigger.test')
-rw-r--r--mysql-test/t/trigger.test28
1 files changed, 28 insertions, 0 deletions
diff --git a/mysql-test/t/trigger.test b/mysql-test/t/trigger.test
index c5925bbd9d5..a0b67b2204d 100644
--- a/mysql-test/t/trigger.test
+++ b/mysql-test/t/trigger.test
@@ -1114,3 +1114,31 @@ load data infile '../std_data_ln/words.dat' into table t1 (a) set b:= f1();
drop table t1;
drop function f1;
drop function f2;
+
+#
+# Test for Bug #16461 connection_id() does not work properly inside trigger
+#
+--disable_warnings
+DROP TABLE IF EXISTS t1;
+--enable_warnings
+
+CREATE TABLE t1 (
+ conn_id INT,
+ trigger_conn_id INT
+);
+CREATE TRIGGER t1_bi BEFORE INSERT ON t1 FOR EACH ROW
+ SET NEW.trigger_conn_id = CONNECTION_ID();
+
+INSERT INTO t1 (conn_id, trigger_conn_id) VALUES (CONNECTION_ID(), -1);
+
+connect (con1,localhost,root,,);
+INSERT INTO t1 (conn_id, trigger_conn_id) VALUES (CONNECTION_ID(), -1);
+connection default;
+disconnect con1;
+
+SELECT * FROM t1 WHERE conn_id != trigger_conn_id;
+
+DROP TRIGGER t1_bi;
+DROP TABLE t1;
+
+# End of 5.0 tests