List:Commits« Previous MessageNext Message »
From:Alexander Nozdrin Date:August 24 2006 4:32pm
Subject:bk commit into 5.0 tree (anozdrin:1.2244) BUG#16899
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of alik. When alik 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@stripped, 2006-08-24 18:32:11+04:00, anozdrin@alik. +2 -0
  Polishing (was the part of original patch for BUG#16899):
  Changed trigger-handling code so that there will be the one
  place for generate statement string for replication log
  and for trigger file.

  sql/sql_trigger.cc@stripped, 2006-08-24 18:32:09+04:00, anozdrin@alik. +58 -61
    Changed trigger-handling code so that there will be the one
    place for generate statement string for replication log
    and for trigger file.

  sql/sql_trigger.h@stripped, 2006-08-24 18:32:09+04:00, anozdrin@alik. +2 -4
    Changed trigger-handling code so that there will be the one
    place for generate statement string for replication log
    and for trigger file.

# 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:	anozdrin
# Host:	alik.
# Root:	/mnt/raid/alik/MySQL/devel/5.0-rt-bug16899

--- 1.54/sql/sql_trigger.cc	2006-08-24 18:32:15 +04:00
+++ 1.55/sql/sql_trigger.cc	2006-08-24 18:32:15 +04:00
@@ -158,11 +158,13 @@ bool mysql_create_or_drop_trigger(THD *t
 {
   TABLE *table;
   bool result= TRUE;
-  LEX_STRING definer_user;
-  LEX_STRING definer_host;
+  String stmt_query;
 
   DBUG_ENTER("mysql_create_or_drop_trigger");
 
+  /* Charset of the buffer for statement must be system one. */
+  stmt_query.set_charset(system_charset_info);
+
   /*
     QQ: This function could be merged in mysql_alter_table() function
     But do we want this ?
@@ -264,8 +266,8 @@ bool mysql_create_or_drop_trigger(THD *t
   }
 
   result= (create ?
-           table->triggers->create_trigger(thd, tables, &definer_user,
&definer_host):
-           table->triggers->drop_trigger(thd, tables));
+           table->triggers->create_trigger(thd, tables, &stmt_query):
+           table->triggers->drop_trigger(thd, tables, &stmt_query));
 
 end:
   VOID(pthread_mutex_unlock(&LOCK_open));
@@ -277,32 +279,9 @@ end:
     {
       thd->clear_error();
 
-      String log_query(thd->query, thd->query_length, system_charset_info);
-
-      if (create)
-      {
-        log_query.set((char *) 0, 0, system_charset_info); /* reset log_query */
-
-        log_query.append(STRING_WITH_LEN("CREATE "));
-
-        if (definer_user.str && definer_host.str)
-        {
-          /*
-            Append definer-clause if the trigger is SUID (a usual trigger in
-            new MySQL versions).
-          */
-
-          append_definer(thd, &log_query, &definer_user, &definer_host);
-        }
-
-        log_query.append(thd->lex->stmt_definition_begin,
-                         (char *)thd->lex->sphead->m_body_begin -
-                         thd->lex->stmt_definition_begin +
-                         thd->lex->sphead->m_body.length);
-      }
-
       /* Such a statement can always go directly to binlog, no trans cache. */
-      Query_log_event qinfo(thd, log_query.ptr(), log_query.length(), 0, FALSE);
+      Query_log_event qinfo(thd, stmt_query.ptr(), stmt_query.length(), 0,
+                            FALSE);
       mysql_bin_log.write(&qinfo);
     }
 
@@ -322,22 +301,8 @@ end:
                      LEX)
       tables       - table list containing one open table for which the
                      trigger is created.
-      definer_user - [out] after a call it points to 0-terminated string or
-                     contains the NULL-string:
-                       - 0-terminated is returned if the trigger is SUID. The
-                         string contains user name part of the actual trigger
-                         definer.
-                       - NULL-string is returned if the trigger is non-SUID.
-                     Anyway, the caller is responsible to provide memory for
-                     storing LEX_STRING object.
-      definer_host - [out] after a call it points to 0-terminated string or
-                     contains the NULL-string:
-                       - 0-terminated string is returned if the trigger is
-                         SUID. The string contains host name part of the
-                         actual trigger definer.
-                       - NULL-string is returned if the trigger is non-SUID.
-                     Anyway, the caller is responsible to provide memory for
-                     storing LEX_STRING object.
+      stmt_query   - [OUT] after successful return, this string
contains
+                     well-formed
statement for creation this trigger.
 
   NOTE
     - Assumes that trigger name is fully qualified.
@@ -352,8 +317,7 @@ end:
     True  - error
 */
 bool Table_triggers_list::create_trigger(THD *thd, TABLE_LIST *tables,
-                                         LEX_STRING *definer_user,
-                                         LEX_STRING *definer_host)
+                                         String *stmt_query)
 {
   LEX *lex= thd->lex;
   TABLE *table= tables->table;
@@ -361,6 +325,8 @@ bool Table_triggers_list::create_trigger
        trigname_path[FN_REFLEN];
   LEX_STRING dir, file, trigname_file;
   LEX_STRING *trg_def, *name;
+  LEX_STRING definer_user;
+  LEX_STRING definer_host;
   ulonglong *trg_sql_mode;
   char trg_definer_holder[USER_HOST_BUFF_SIZE];
   LEX_STRING *trg_definer;
@@ -508,8 +474,6 @@ bool Table_triggers_list::create_trigger
       definers_list.push_back(trg_definer, &table->mem_root))
     goto err_with_cleanup;
 
-  trg_def->str= thd->query;
-  trg_def->length= thd->query_length;
   *trg_sql_mode= thd->variables.sql_mode;
 
 #ifndef NO_EMBEDDED_ACCESS_CHECKS
@@ -529,27 +493,54 @@ bool Table_triggers_list::create_trigger
   {
     /* SUID trigger. */
 
-    *definer_user= lex->definer->user;
-    *definer_host= lex->definer->host;
+    definer_user= lex->definer->user;
+    definer_host= lex->definer->host;
 
     trg_definer->str= trg_definer_holder;
-    trg_definer->length= strxmov(trg_definer->str, definer_user->str, "@",
-                                 definer_host->str, NullS) - trg_definer->str;
+    trg_definer->length= strxmov(trg_definer->str, definer_user.str, "@",
+                                 definer_host.str, NullS) - trg_definer->str;
   }
   else
   {
     /* non-SUID trigger. */
 
-    definer_user->str= 0;
-    definer_user->length= 0;
+    definer_user.str= 0;
+    definer_user.length= 0;
 
-    definer_host->str= 0;
-    definer_host->length= 0;
+    definer_host.str= 0;
+    definer_host.length= 0;
 
     trg_definer->str= (char*) "";
     trg_definer->length= 0;
   }
 
+  /*
+    Create well-formed trigger definition query. Original query is not
+    appropriated, because definer-clause can be not truncated.
+  */
+
+  stmt_query->append(STRING_WITH_LEN("CREATE "));
+
+  if (trg_definer)
+  {
+    /*
+      Append definer-clause if the trigger is SUID (a usual trigger in
+      new MySQL versions).
+    */
+
+    append_definer(thd, stmt_query, &definer_user, &definer_host);
+  }
+
+  stmt_query->append(thd->lex->stmt_definition_begin,
+                     (char *) thd->lex->sphead->m_body_begin -
+                     thd->lex->stmt_definition_begin +
+                     thd->lex->sphead->m_body.length);
+
+  trg_def->str= stmt_query->c_ptr();
+  trg_def->length= stmt_query->length();
+
+  /* Create trigger definition file. */
+
   if (!sql_create_definition_file(&dir, &file, &triggers_file_type,
                                   (gptr)this, triggers_file_parameters, 0))
     return 0;
@@ -647,15 +638,19 @@ static bool save_trigger_file(Table_trig
 
   SYNOPSIS
     drop_trigger()
-      thd    - current thread context (including trigger definition in LEX)
-      tables - table list containing one open table for which trigger is
-               dropped.
+      thd         - current thread context
+                    (including trigger definition in LEX)
+      tables      - table list containing one open table for which trigger
+                    is dropped.
+      stmt_query  - [OUT] after successful return, this string
contains
+                    well-formed
statement for creation this trigger.
 
   RETURN VALUE
     False - success
     True  - error
 */
-bool Table_triggers_list::drop_trigger(THD *thd, TABLE_LIST *tables)
+bool Table_triggers_list::drop_trigger(THD *thd, TABLE_LIST *tables,
+                                       String *stmt_query)
 {
   LEX *lex= thd->lex;
   LEX_STRING *name;
@@ -664,6 +659,8 @@ bool Table_triggers_list::drop_trigger(T
   List_iterator<ulonglong>       it_mod(definition_modes_list);
   List_iterator<LEX_STRING>      it_definer(definers_list);
   char path[FN_REFLEN];
+
+  stmt_query->append(thd->query, thd->query_length);
 
   while ((name= it_name++))
   {

--- 1.20/sql/sql_trigger.h	2006-08-24 18:32:15 +04:00
+++ 1.21/sql/sql_trigger.h	2006-08-24 18:32:15 +04:00
@@ -92,10 +92,8 @@ public:
   }
   ~Table_triggers_list();
 
-  bool create_trigger(THD *thd, TABLE_LIST *table,
-                      LEX_STRING *definer_user,
-                      LEX_STRING *definer_host);
-  bool drop_trigger(THD *thd, TABLE_LIST *table);
+  bool create_trigger(THD *thd, TABLE_LIST *table, String *stmt_query);
+  bool drop_trigger(THD *thd, TABLE_LIST *table, String *stmt_query);
   bool process_triggers(THD *thd, trg_event_type event,
                         trg_action_time_type time_type,
                         bool old_row_is_record1);
Thread
bk commit into 5.0 tree (anozdrin:1.2244) BUG#16899Alexander Nozdrin24 Aug