Below is the list of changes that have just been committed into a local
5.0 repository of tomash. When tomash does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html
ChangeSet
1.2136 06/04/12 19:31:00 kroki@stripped +7 -0
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().
sql/item_func.h
1.137 06/04/12 19:30:52 kroki@stripped +12 -0
Re-implement CONNECTION_ID() as Item_func_connection_id
(was Item_static_int_func).
sql/item_func.cc
1.277 06/04/12 19:30:51 kroki@stripped +25 -0
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_create.cc
1.59 06/04/12 19:30:51 kroki@stripped +2 -8
Use new implementation of CONNECTION_ID().
sql/item.h
1.191 06/04/12 19:30:51 kroki@stripped +0 -12
Remove now unused class Item_static_int_func.
sql/item.cc
1.213 06/04/12 19:30:51 kroki@stripped +0 -16
Remove now unused class Item_static_int_func.
mysql-test/t/trigger.test
1.40 06/04/12 19:30:51 kroki@stripped +28 -0
Add test case for bug#16461.
mysql-test/r/trigger.result
1.35 06/04/12 19:30:50 kroki@stripped +13 -0
Add result for bug#16461.
# This is a BitKeeper patch. What follows are the unified diffs for the
# set of deltas contained in the patch. The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User: kroki
# Host: moonlight.intranet
# Root: /home/tomash/src/mysql_ab/mysql-5.0-bug16461
--- 1.212/sql/item.cc 2006-03-31 23:54:22 +04:00
+++ 1.213/sql/item.cc 2006-04-12 19:30:51 +04:00
@@ -644,22 +644,6 @@
}
-Item *Item_static_int_func::safe_charset_converter(CHARSET_INFO *tocs)
-{
- Item_string *conv;
- char buf[64];
- String *s, tmp(buf, sizeof(buf), &my_charset_bin);
- s= val_str(&tmp);
- if ((conv= new Item_static_string_func(func_name, s->ptr(), s->length(),
- s->charset())))
- {
- conv->str_value.copy();
- conv->str_value.mark_as_const();
- }
- return conv;
-}
-
-
Item *Item_static_float_func::safe_charset_converter(CHARSET_INFO *tocs)
{
Item_string *conv;
--- 1.190/sql/item.h 2006-03-31 13:39:28 +04:00
+++ 1.191/sql/item.h 2006-04-12 19:30:51 +04:00
@@ -1387,18 +1387,6 @@
};
-class Item_static_int_func :public Item_int
-{
- const char *func_name;
-public:
- Item_static_int_func(const char *str_arg, longlong i, uint length)
- :Item_int(NullS, i, length), func_name(str_arg)
- {}
- Item *safe_charset_converter(CHARSET_INFO *tocs);
- void print(String *str) { str->append(func_name); }
-};
-
-
class Item_uint :public Item_int
{
public:
--- 1.58/sql/item_create.cc 2005-09-14 20:24:30 +04:00
+++ 1.59/sql/item_create.cc 2006-04-12 19:30:51 +04:00
@@ -71,14 +71,8 @@
Item *create_func_connection_id(void)
{
- THD *thd=current_thd;
- thd->lex->safe_to_cache_query= 0;
- return new Item_static_int_func("connection_id()",
- (longlong)
- ((thd->slave_thread) ?
- thd->variables.pseudo_thread_id :
- thd->thread_id),
- 10);
+ current_thd->lex->safe_to_cache_query= 0;
+ return new Item_func_connection_id();
}
Item *create_func_conv(Item* a, Item *b, Item *c)
--- 1.276/sql/item_func.cc 2006-03-23 23:44:54 +03:00
+++ 1.277/sql/item_func.cc 2006-04-12 19:30:51 +04:00
@@ -559,6 +559,31 @@
}
+void Item_func_connection_id::fix_length_and_dec()
+{
+ Item_int_func::fix_length_and_dec();
+ max_length= 10;
+}
+
+
+bool Item_func_connection_id::fix_fields(THD *thd, Item **ref)
+{
+ if (Item_int_func::fix_fields(thd, ref))
+ return TRUE;
+
+ /*
+ To replicate CONNECTION_ID() properly we should use
+ pseudo_thread_id on slave, which contains the value of thread_id
+ on master.
+ */
+ value= ((thd->slave_thread) ?
+ thd->variables.pseudo_thread_id :
+ thd->thread_id);
+
+ return FALSE;
+}
+
+
/*
Check arguments here to determine result's type for a numeric
function of two arguments.
--- 1.136/sql/item_func.h 2006-03-10 13:52:00 +03:00
+++ 1.137/sql/item_func.h 2006-04-12 19:30:52 +04:00
@@ -279,6 +279,18 @@
};
+class Item_func_connection_id :public Item_int_func
+{
+ longlong value;
+
+public:
+ const char *func_name() const { return "connection_id"; }
+ void fix_length_and_dec();
+ bool fix_fields(THD *thd, Item **ref);
+ longlong val_int() { DBUG_ASSERT(fixed == 1); return value; }
+};
+
+
class Item_func_signed :public Item_int_func
{
public:
--- 1.34/mysql-test/r/trigger.result 2006-03-29 14:54:58 +04:00
+++ 1.35/mysql-test/r/trigger.result 2006-04-12 19:30:50 +04:00
@@ -952,3 +952,16 @@
drop table t1;
drop function f1;
drop function f2;
+DROP TABLE IF EXISTS t1;
+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);
+INSERT INTO t1 (conn_id, trigger_conn_id) VALUES (CONNECTION_ID(), -1);
+SELECT * FROM t1 WHERE conn_id != trigger_conn_id;
+conn_id trigger_conn_id
+DROP TRIGGER t1_bi;
+DROP TABLE t1;
--- 1.39/mysql-test/t/trigger.test 2006-03-29 14:54:59 +04:00
+++ 1.40/mysql-test/t/trigger.test 2006-04-12 19:30:51 +04:00
@@ -1114,3 +1114,31 @@
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
| Thread |
|---|
| • bk commit into 5.0 tree (kroki:1.2136) BUG#16461 | kroki | 12 Apr |