List:Internals« Previous MessageNext Message »
From:gluh Date:May 10 2005 11:58am
Subject:bk commit into 5.0 tree (gluh:1.1952) BUG#9586
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of gluh. When gluh 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.1952 05/05/10 11:57:42 gluh@stripped +5 -0
  Fix for bug#9586: information_schema doesn't contain table with trigger information
  (see also wl#1996 TRIGGERS view)

  sql/sql_yacc.yy
    1.371 05/05/10 11:57:37 gluh@stripped +2 -0
    Fix for bug#9586: information_schema doesn't contain table with trigger information
    (see also wl#1996 TRIGGERS view)

  sql/sql_trigger.h
    1.5 05/05/10 11:57:37 gluh@stripped +5 -0
    Fix for bug#9586: information_schema doesn't contain table with trigger information
    (see also wl#1996 TRIGGERS view)

  sql/sql_show.cc
    1.244 05/05/10 11:57:37 gluh@stripped +83 -0
    Fix for bug#9586: information_schema doesn't contain table with trigger information
    (see also wl#1996 TRIGGERS view)
        schema table 'TRIGGERS' is added

  mysql-test/t/information_schema.test
    1.36 05/05/10 11:57:36 gluh@stripped +33 -0
    Fix for bug#9586: information_schema doesn't contain table with trigger information
    (see also wl#1996 TRIGGERS view)

  mysql-test/r/information_schema.result
    1.50 05/05/10 11:57:36 gluh@stripped +53 -1
    Fix for bug#9586: information_schema doesn't contain table with trigger information
    (see also wl#1996 TRIGGERS view)

# 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:	gluh
# Host:	mobby.(none)
# Root:	/home/gluh/MySQL/Devel/5.0.1996

--- 1.243/sql/sql_show.cc	2005-05-07 14:22:26 +00:00
+++ 1.244/sql/sql_show.cc	2005-05-10 11:57:37 +00:00
@@ -21,6 +21,7 @@
 #include "sql_select.h"                         // For select_describe
 #include "repl_failsafe.h"
 #include "sp_head.h"
+#include "sql_trigger.h"
 #include <my_dir.h>
 
 #ifdef HAVE_BERKELEY_DB
@@ -2968,6 +2969,63 @@
   DBUG_RETURN(res);
 }
 
+static const char *trg_action_time_type_name[]= {"BEFORE", "AFTER"};
+static uint action_time_type_count= 
+  sizeof(trg_action_time_type_name)/sizeof(char*);
+static const char *trg_event_type_name[]= {"INSERT", "UPDATE", "DELETE"};
+static uint action_event_type_count=
+  sizeof(trg_event_type_name)/sizeof(char*);
+
+
+static int get_schema_triggers_record(THD *thd, struct st_table_list *tables,
+                                      TABLE *table, bool res,
+                                      const char *base_name,
+                                      const char *file_name)
+{
+  CHARSET_INFO *cs= system_charset_info;
+  DBUG_ENTER("get_schema_triggers_record");
+  if (!res)
+  {
+    if (tables->table->triggers)
+    {
+      for (uint i= 0; i < action_event_type_count; i++)
+      {
+        for (uint j= 0; j < action_time_type_count; j++)
+        { 
+          sp_head *trg= (tables->table->triggers->
+                         get_trigger((enum trg_event_type) i,
+                                     (enum trg_action_time_type) j));
+          if (trg)
+          {
+            restore_record(table, s->default_values);
+            table->field[1]->store(trg->m_db.str, trg->m_db.length, cs);
+            table->field[2]->store(trg->m_name.str, trg->m_name.length, cs);
+            table->field[3]->store(trg_event_type_name[i], 
+                                   strlen(trg_event_type_name[i]), cs);
+            table->field[5]->store(base_name, strlen(base_name), cs);
+            table->field[6]->store(file_name, strlen(file_name), cs);
+            table->field[9]->store(trg->m_body.str, trg->m_body.length, cs);
+            table->field[10]->store("ROW", 3, cs);
+            table->field[11]->store(trg_action_time_type_name[j],
+                                    strlen(trg_action_time_type_name[j]), cs);
+            if (schema_table_store_record(thd, table))
+              DBUG_RETURN(1);
+          }
+        }
+      }
+    }
+  }
+  else
+  {
+    if (tables->table->triggers)
+      push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, 
+                   thd->net.last_errno, thd->net.last_error);
+    thd->clear_error();
+  }
+  DBUG_RETURN(0);
+}
+
+
 
 int fill_open_tables(THD *thd, TABLE_LIST *tables, COND *cond)
 {
@@ -3739,6 +3797,29 @@
 };
 
 
+ST_FIELD_INFO trigger_fields_info[]=
+{
+  {"TRIGGER_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 0},
+  {"TRIGGER_SCHEMA", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 0},
+  {"TRIGGER_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 0},
+  {"EVENT_MANIPULATION", 6, MYSQL_TYPE_STRING, 0, 0, 0},
+  {"EVENT_OBJECT_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 0},
+  {"EVENT_OBJECT_SCHEMA", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 0},
+  {"EVENT_OBJECT_TABLE", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 0},
+  {"ACTION_ORDER", 10, MYSQL_TYPE_LONG, 0, 1, 0},
+  {"ACTION_CONDITION", NAME_LEN, MYSQL_TYPE_STRING, 0, 1, 0},
+  {"ACTION_STATEMENT", 65535, MYSQL_TYPE_STRING, 0, 0, 0},
+  {"ACTION_ORIENTATION", 3, MYSQL_TYPE_STRING, 0, 0, 0},
+  {"ACTION_TIMING", 6, MYSQL_TYPE_STRING, 0, 0, 0},
+  {"ACTION_REFERENCE_OLD_TABLE", NAME_LEN, MYSQL_TYPE_STRING, 0, 1, 0},
+  {"ACTION_REFERENCE_NEW_TABLE", NAME_LEN, MYSQL_TYPE_STRING, 0, 1, 0},
+  {"ACTION_REFERENCE_OLD_ROW", NAME_LEN, MYSQL_TYPE_STRING, 0, 1, 0},
+  {"ACTION_REFERENCE_NEW_ROW", NAME_LEN, MYSQL_TYPE_STRING, 0, 1, 0},
+  {"CREATED", 0, MYSQL_TYPE_TIMESTAMP, 0, 1, 0},
+  {0, 0, MYSQL_TYPE_STRING, 0, 0, 0}
+};
+
+
 /*
   Description of ST_FIELD_INFO in table.h
 */
@@ -3783,6 +3864,8 @@
    make_old_format, 0, -1, -1, 1},
   {"VARIABLES", variables_fields_info, create_schema_table, fill_variables,
    make_old_format, 0, -1, -1, 1},
+  {"TRIGGERS", trigger_fields_info, create_schema_table, 
+    get_all_tables, 0, get_schema_triggers_record, 1, 2, 0},
   {0, 0, 0, 0, 0, 0, 0, 0, 0}
 };
 

--- 1.370/sql/sql_yacc.yy	2005-05-07 15:50:16 +00:00
+++ 1.371/sql/sql_yacc.yy	2005-05-10 11:57:37 +00:00
@@ -1275,7 +1275,9 @@
             
             bzero((char *)&lex->sp_chistics, sizeof(st_sp_chistics));
             lex->sphead->m_chistics= &lex->sp_chistics;
+            lex->tok_start= lex->ptr; /* point at next item */
             lex->sphead->m_body_begin= lex->tok_start;
+            sp->m_name= $3;
           }
           sp_proc_stmt
           {

--- 1.4/sql/sql_trigger.h	2005-03-04 13:34:54 +00:00
+++ 1.5/sql/sql_trigger.h	2005-05-10 11:57:37 +00:00
@@ -71,6 +71,11 @@
             bodies[TRG_EVENT_DELETE][TRG_ACTION_AFTER]);
   }
 
+  sp_head *get_trigger(trg_event_type event, trg_action_time_type time_type)
+  {
+    return bodies[event][time_type];
+  }
+
   friend class Item_trigger_field;
 
 private:

--- 1.49/mysql-test/r/information_schema.result	2005-05-07 15:14:28 +00:00
+++ 1.50/mysql-test/r/information_schema.result	2005-05-10 11:57:36 +00:00
@@ -47,6 +47,7 @@
 COLUMN_PRIVILEGES
 TABLE_CONSTRAINTS
 KEY_COLUMN_USAGE
+TRIGGERS
 columns_priv
 db
 func
@@ -76,6 +77,7 @@
 TABLES	TABLES
 TABLE_PRIVILEGES	TABLE_PRIVILEGES
 TABLE_CONSTRAINTS	TABLE_CONSTRAINTS
+TRIGGERS	TRIGGERS
 tables_priv	tables_priv
 time_zone	time_zone
 time_zone_leap_second	time_zone_leap_second
@@ -93,6 +95,7 @@
 TABLES	TABLES
 TABLE_PRIVILEGES	TABLE_PRIVILEGES
 TABLE_CONSTRAINTS	TABLE_CONSTRAINTS
+TRIGGERS	TRIGGERS
 tables_priv	tables_priv
 time_zone	time_zone
 time_zone_leap_second	time_zone_leap_second
@@ -110,6 +113,7 @@
 TABLES	TABLES
 TABLE_PRIVILEGES	TABLE_PRIVILEGES
 TABLE_CONSTRAINTS	TABLE_CONSTRAINTS
+TRIGGERS	TRIGGERS
 tables_priv	tables_priv
 time_zone	time_zone
 time_zone_leap_second	time_zone_leap_second
@@ -573,6 +577,7 @@
 TABLES
 TABLE_PRIVILEGES
 TABLE_CONSTRAINTS
+TRIGGERS
 create database information_schema;
 ERROR HY000: Can't create database 'information_schema'; database exists
 use information_schema;
@@ -581,6 +586,7 @@
 TABLES	TEMPORARY
 TABLE_PRIVILEGES	TEMPORARY
 TABLE_CONSTRAINTS	TEMPORARY
+TRIGGERS	TEMPORARY
 create table t1(a int);
 ERROR 42S02: Unknown table 't1' in information_schema
 use test;
@@ -592,6 +598,7 @@
 TABLES
 TABLE_PRIVILEGES
 TABLE_CONSTRAINTS
+TRIGGERS
 select table_name from tables where table_name='user';
 table_name
 user
@@ -686,7 +693,7 @@
 CREATE VIEW a1 (t_CRASHME) AS SELECT f1 FROM t_crashme GROUP BY f1;
 CREATE VIEW a2 AS SELECT t_CRASHME FROM a1;
 count(*)
-100
+101
 drop view a2, a1;
 drop table t_crashme;
 select table_schema,table_name, column_name from
@@ -697,6 +704,7 @@
 information_schema	ROUTINES	ROUTINE_DEFINITION
 information_schema	ROUTINES	SQL_MODE
 information_schema	VIEWS	VIEW_DEFINITION
+information_schema	TRIGGERS	ACTION_STATEMENT
 select table_name, column_name, data_type from information_schema.columns
 where data_type = 'datetime';
 table_name	column_name	data_type
@@ -705,6 +713,7 @@
 TABLES	CHECK_TIME	datetime
 ROUTINES	CREATED	datetime
 ROUTINES	LAST_ALTERED	datetime
+TRIGGERS	CREATED	datetime
 SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES A
 WHERE NOT EXISTS 
 (SELECT * FROM INFORMATION_SCHEMA.COLUMNS B
@@ -748,3 +757,46 @@
 KEY_COLUMN_USAGE	TABLE_NAME	select
 delete from mysql.user where user='mysqltest_4';
 flush privileges;
+create table t1 (i int, j int);
+create trigger trg1 before insert on t1 for each row
+begin
+if new.j > 10 then
+set new.j := 10;
+end if;
+end|
+create trigger trg2 before update on t1 for each row
+begin
+if old.i % 2 = 0 then
+set new.j := -1;
+end if;
+end|
+create trigger trg3 after update on t1 for each row
+begin
+if new.j = -1 then
+set @fired:= "Yes";
+end if;
+end|
+select * from information_schema.triggers;
+TRIGGER_CATALOG	TRIGGER_SCHEMA	TRIGGER_NAME	EVENT_MANIPULATION	EVENT_OBJECT_CATALOG	EVENT_OBJECT_SCHEMA	EVENT_OBJECT_TABLE	ACTION_ORDER	ACTION_CONDITION	ACTION_STATEMENT	ACTION_ORIENTATION	ACTION_TIMING	ACTION_REFERENCE_OLD_TABLE	ACTION_REFERENCE_NEW_TABLE	ACTION_REFERENCE_OLD_ROW	ACTION_REFERENCE_NEW_ROW	CREATED
+NULL	test	trg1	INSERT	NULL	test	t1	NULL	NULL	
+begin
+if new.j > 10 then
+set new.j := 10;
+end if;
+end	ROW	BEFORE	NULL	NULL	NULL	NULL	NULL
+NULL	test	trg2	UPDATE	NULL	test	t1	NULL	NULL	
+begin
+if old.i % 2 = 0 then
+set new.j := -1;
+end if;
+end	ROW	BEFORE	NULL	NULL	NULL	NULL	NULL
+NULL	test	trg3	UPDATE	NULL	test	t1	NULL	NULL	
+begin
+if new.j = -1 then
+set @fired:= "Yes";
+end if;
+end	ROW	AFTER	NULL	NULL	NULL	NULL	NULL
+drop trigger t1.trg1;
+drop trigger t1.trg2;
+drop trigger t1.trg3;
+drop table t1;

--- 1.35/mysql-test/t/information_schema.test	2005-05-07 15:14:28 +00:00
+++ 1.36/mysql-test/t/information_schema.test	2005-05-10 11:57:36 +00:00
@@ -486,3 +486,36 @@
 connection default;
 delete from mysql.user where user='mysqltest_4';
 flush privileges;
+
+#
+# TRIGGERS table test
+#
+
+create table t1 (i int, j int);
+
+delimiter |;
+create trigger trg1 before insert on t1 for each row
+begin
+  if new.j > 10 then
+    set new.j := 10;
+  end if;
+end|
+create trigger trg2 before update on t1 for each row
+begin
+  if old.i % 2 = 0 then
+    set new.j := -1;
+  end if;
+end|
+create trigger trg3 after update on t1 for each row
+begin
+  if new.j = -1 then
+    set @fired:= "Yes";
+  end if;
+end|
+delimiter ;|
+select * from information_schema.triggers;
+
+drop trigger t1.trg1;
+drop trigger t1.trg2;
+drop trigger t1.trg3;
+drop table t1;
Thread
bk commit into 5.0 tree (gluh:1.1952) BUG#9586gluh10 May