List:Internals« Previous MessageNext Message »
From:Patrick Galbraith Date:September 2 2005 3:24am
Subject:bk commit into 5.0 tree (patg:1.1936) BUG#12597
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of patg. When patg 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.1936 05/09/02 03:24:16 patg@stripped +1 -0
  BUG #12597
  
  Fixed problem with triggers being in a dump prior to a table a trigger uses.

  client/mysqldump.c
    1.196 05/09/02 03:23:58 patg@stripped +83 -35
    BUG #12597
    
    Created function 'dump_triggers_for_table', and call it AFTER the tables
    are dumped.

# 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:	patg
# Host:	radha.local
# Root:	/Users/patg/mysql-build/mysql-5.0.bug12597

--- 1.195/client/mysqldump.c	2005-08-26 14:45:19 +02:00
+++ 1.196/client/mysqldump.c	2005-09-02 03:23:58 +02:00
@@ -1330,41 +1330,6 @@
       fprintf(sql_file, "%s;\n", row[1]);
       check_io(sql_file);
       mysql_free_result(tableRes);
-      if (opt_dump_triggers &&
-          mysql_get_server_version(sock) >= 50009)
-      {
-        my_snprintf(query_buff, sizeof(query_buff),
-                    "SHOW TRIGGERS LIKE %s",
-                    quote_for_like(table, name_buff));
-
-
-        if (mysql_query_with_error_report(sock, &tableRes, query_buff))
-        {
-          if (path)
-            my_fclose(sql_file, MYF(MY_WME));
-          safe_exit(EX_MYSQLERR);
-          DBUG_RETURN(0);
-        }
-        if (mysql_num_rows(tableRes))
-          fprintf(sql_file, "\n/*!50003 SET @OLD_SQL_MODE=@@SQL_MODE*/;\n\
-DELIMITER //;\n");
-        while ((row=mysql_fetch_row(tableRes)))
-        {
-          fprintf(sql_file, "/*!50003 SET SESSION SQL_MODE=\"%s\"*/ //\n\
-/*!50003 CREATE TRIGGER %s %s %s ON %s FOR EACH ROW%s*/ //\n\n",
-                  row[6], /* sql_mode */
-                  quote_name(row[0], name_buff, 0), /* Trigger */
-                  row[4], /* Timing */
-                  row[1], /* Event */
-                  result_table,
-                  row[3] /* Statement */);
-        }
-        if (mysql_num_rows(tableRes))
-          fprintf(sql_file,
-                  "DELIMITER ;//\n\
-/*!50003 SET SESSION SQL_MODE=@OLD_SQL_MODE*/;");
-        mysql_free_result(tableRes);
-      }
     }
     my_snprintf(query_buff, sizeof(query_buff), "show fields from %s",
 		result_table);
@@ -1657,6 +1622,68 @@
 } /* get_table_structure */
 
 
+/*
+
+  dump_triggers_for_table
+
+  Dumps the triggers given a table/db name. This should be called after
+  the tables have been dumped in case a trigger depends on the existence
+  of a table
+
+  INPUT
+    char * tablename and db name
+  RETURNS
+   0 Failure
+   1 Succes
+
+*/
+
+dump_triggers_for_table (char *table, char *db)
+{
+  MYSQL_RES  *result;
+  MYSQL_ROW  row;
+  char	     *result_table;
+  char	     name_buff[NAME_LEN+3], table_buff[NAME_LEN*2+3];
+  char       query_buff[512];
+  FILE       *sql_file = md_result_file;
+
+  DBUG_ENTER("dump_triggers_for_table");
+  DBUG_PRINT("enter", ("db: %s, table: %s", db, table));
+  result_table=     quote_name(table, table_buff, 1);
+
+  my_snprintf(query_buff, sizeof(query_buff),
+              "SHOW TRIGGERS LIKE %s",
+              quote_for_like(table, name_buff));
+
+  if (mysql_query_with_error_report(sock, &result, query_buff))
+  {
+    if (path)
+      my_fclose(sql_file, MYF(MY_WME));
+    safe_exit(EX_MYSQLERR);
+    DBUG_RETURN(0);
+  }
+  if (mysql_num_rows(result))
+    fprintf(sql_file, "\n/*!50003 SET @OLD_SQL_MODE=@@SQL_MODE*/;\n\
+DELIMITER //;\n");
+  while ((row=mysql_fetch_row(result)))
+  {
+    fprintf(sql_file, "/*!50003 SET SESSION SQL_MODE=\"%s\" */ //\n\
+/*!50003 CREATE TRIGGER %s %s %s ON %s FOR EACH ROW%s */ //\n\n",
+            row[6], /* sql_mode */
+            quote_name(row[0], name_buff, 0), /* Trigger */
+            row[4], /* Timing */
+            row[1], /* Event */
+            result_table,
+            row[3] /* Statement */);
+  }
+  if (mysql_num_rows(result))
+    fprintf(sql_file,
+            "DELIMITER ;//\n\
+/*!50003 SET SESSION SQL_MODE=@OLD_SQL_MODE */;");
+  mysql_free_result(result);
+  DBUG_RETURN(1);
+}
+
 static char *add_load_option(char *ptr,const char *object,
 			     const char *statement)
 {
@@ -2378,6 +2405,17 @@
       order_by= 0;
     }
   }
+  /* dump the triggers _AFTER_ the tables have been dumped */
+  if (opt_dump_triggers &&
+      mysql_get_server_version(sock) >= 50009)
+  {
+    while ((table= getTableName(0)))
+    {
+      DBUG_PRINT("info", ("dump_triggers_for_table(%s, %s)", table, database));
+      int retval= dump_triggers_for_table(table, database);
+    }
+  }
+
   if (opt_xml)
   {
     fputs("</database>\n", md_result_file);
@@ -2569,6 +2607,16 @@
     DBUG_PRINT("info",("Dumping table %s", table_name));
     numrows= get_table_structure(table_name, db);
     dump_table(numrows, table_name);
+  }
+  if (opt_dump_triggers &&
+      mysql_get_server_version(sock) >= 50009)
+  {
+    for (i= 0; i < dump_tables.records; i++)
+    {
+      DBUG_PRINT("info",("Dumping trigger(s) for table %s", table_name));
+      table_name= hash_element(&dump_tables, i);
+      dump_triggers_for_table(table_name, db);
+    }
   }
 
   /* Dump each selected view */
Thread
bk commit into 5.0 tree (patg:1.1936) BUG#12597Patrick Galbraith2 Sep