List:Commits« Previous MessageNext Message »
From:Nirbhay Choubey Date:March 18 2011 1:04pm
Subject:bzr commit into mysql-5.1 branch (nirbhay.choubey:3621) Bug#11760384
View as plain text  
#At file:///home/nirbhay/Project/mysql/repo/bugs/source/mysql-5.1.52792/ based on revid:vinay.fisrekar@stripped

 3621 Nirbhay Choubey	2011-03-18
      BUG#11760384 - 52792: mysqldump in XML mode does not dump
                     routines.
      
      mysqldump in xml mode did not dump routines, events or
      triggers.
      
      This patch fixes this issue by fixing the if conditions
      that disallowed the dump of above mentioned objects in
      xml mode, and added the required code to ebable dump
      in xml format.
     @ client/mysqldump.c
        BUG#11760384 - 52792: mysqldump in XML mode does not dump
                       routines.
        
        Fixed some if conditions to allow execution of dump methods
        for xml and further added the relevant code at places to produce
        the dump in xml format.
     @ mysql-test/r/mysqldump.result
        Added a test case for Bug#11760384.
     @ mysql-test/t/mysqldump.test
        Added a test case for Bug#11760384.

    modified:
      client/mysqldump.c
      mysql-test/r/mysqldump.result
      mysql-test/t/mysqldump.test
=== modified file 'client/mysqldump.c'
--- a/client/mysqldump.c	2011-02-21 07:07:24 +0000
+++ b/client/mysqldump.c	2011-03-18 13:04:35 +0000
@@ -505,6 +505,7 @@ static int dump_all_tablespaces();
 static int dump_tablespaces_for_tables(char *db, char **table_names, int tables);
 static int dump_tablespaces_for_databases(char** databases);
 static int dump_tablespaces(char* ts_where);
+static void replace_spaces(char * str);
 
 #include <help_start.h>
 
@@ -1827,6 +1828,8 @@ static void print_xml_row(FILE *xml_file
   {
     if ((*row)[i])
     {
+      /* As XML does not allow spaces in element or attribute names. */
+      replace_spaces(field->name);
       fputc(' ', xml_file);
       print_quoted_xml(xml_file, field->name, field->name_length);
       fputs("=\"", xml_file);
@@ -1839,6 +1842,16 @@ static void print_xml_row(FILE *xml_file
   check_io(xml_file);
 }
 
+/* Replace spaces with underscores. */
+static void replace_spaces(char * str)
+{
+  while(*str != '\0')
+  {
+    if(my_isspace(charset_info, *str))
+      *str= '_';
+    str++;
+  }
+}
 
 /*
  create_delimiter
@@ -1906,7 +1919,7 @@ static uint dump_events_for_db(char *db)
   mysql_real_escape_string(mysql, db_name_buff, db, strlen(db));
 
   /* nice comments */
-  if (opt_comments)
+  if (!opt_xml && opt_comments)
     fprintf(sql_file, "\n--\n-- Dumping events for database '%s'\n--\n", db);
 
   /*
@@ -1922,7 +1935,8 @@ static uint dump_events_for_db(char *db)
   strcpy(delimiter, ";");
   if (mysql_num_rows(event_list_res) > 0)
   {
-    fprintf(sql_file, "/*!50106 SET @save_time_zone= @@TIME_ZONE */ ;\n");
+    if (!opt_xml)
+      fprintf(sql_file, "/*!50106 SET @save_time_zone= @@TIME_ZONE */ ;\n");
 
     /* Get database collation. */
 
@@ -1944,6 +1958,15 @@ static uint dump_events_for_db(char *db)
 
       while ((row= mysql_fetch_row(event_res)) != NULL)
       {
+        if (opt_xml)
+        {
+          print_xml_tag(sql_file, "\t", "\n", "event_structure", "name=",
+                        row[0], NullS);
+          print_xml_row(sql_file, "attributes", event_res, &row);
+          fputs("\t</event_structure>\n", sql_file);
+          continue;
+        }
+
         /*
           if the user has EXECUTE privilege he can see event names, but not the
           event body!
@@ -2022,8 +2045,11 @@ static uint dump_events_for_db(char *db)
       mysql_free_result(event_res);
 
     } /* end of list of events */
-    fprintf(sql_file, "DELIMITER ;\n");
-    fprintf(sql_file, "/*!50106 SET TIME_ZONE= @save_time_zone */ ;\n");
+    if (!opt_xml)
+    {
+      fprintf(sql_file, "DELIMITER ;\n");
+      fprintf(sql_file, "/*!50106 SET TIME_ZONE= @save_time_zone */ ;\n");
+    }
 
     if (switch_character_set_results(mysql, default_charset))
       DBUG_RETURN(1);
@@ -2091,7 +2117,7 @@ static uint dump_routines_for_db(char *d
   mysql_real_escape_string(mysql, db_name_buff, db, strlen(db));
 
   /* nice comments */
-  if (opt_comments)
+  if (!opt_xml && opt_comments)
     fprintf(sql_file, "\n--\n-- Dumping routines for database '%s'\n--\n", db);
 
   /*
@@ -2144,10 +2170,21 @@ static uint dump_routines_for_db(char *d
                              row[2] ? (int) strlen(row[2]) : 0));
           if (row[2] == NULL)
           {
-            fprintf(sql_file, "\n-- insufficient privileges to %s\n", query_buff);
-            fprintf(sql_file, "-- does %s have permissions on mysql.proc?\n\n", current_user);
+            if (!opt_xml)
+            {
+              fprintf(sql_file, "\n-- insufficient privileges to %s\n", query_buff);
+              fprintf(sql_file, "-- does %s have permissions on mysql.proc?\n\n", current_user);
+            }
             maybe_die(EX_MYSQLERR,"%s has insufficent privileges to %s!", current_user, query_buff);
           }
+          else if (opt_xml && strlen(row[2]))
+          {
+            print_xml_tag(sql_file, "\t", "\n", "routine_structure", "name=",
+                          routine_list_row[1], NullS);
+            print_xml_row(sql_file, "attributes", routine_res, &row);
+            fputs("\t</routine_structure>\n", sql_file);
+            check_io(sql_file);
+          }
           else if (strlen(row[2]))
           {
             char *query_str;
@@ -2774,6 +2811,16 @@ static void dump_trigger_old(FILE *sql_f
 
   DBUG_ENTER("dump_trigger_old");
 
+  if (opt_xml)
+  {
+    print_xml_tag(sql_file, "\t", "\n", "trigger_structure", "name=",
+                  (*show_trigger_row)[0], NullS);
+    print_xml_row(sql_file, "attributes", show_triggers_rs, show_trigger_row);
+    fputs("\t</trigger_structure>\n", sql_file);
+    check_io(sql_file);
+    return;
+  } 
+
   fprintf(sql_file,
           "--\n"
           "-- WARNING: old server version. "
@@ -2837,13 +2884,24 @@ static int dump_trigger(FILE *sql_file, 
                         const char *db_cl_name)
 {
   MYSQL_ROW row;
+  char *query_str;
   int db_cl_altered= FALSE;
 
   DBUG_ENTER("dump_trigger");
 
   while ((row= mysql_fetch_row(show_create_trigger_rs)))
   {
-    char *query_str= cover_definer_clause_in_trigger(row[2], strlen(row[2]));
+    if (opt_xml)
+    {
+      print_xml_tag(sql_file, "\t", "\n", "trigger_structure", "name=",
+                    row[0], NullS);
+      print_xml_row(sql_file, "attributes", show_create_trigger_rs, &row);
+      fputs("\t</trigger_structure>\n", sql_file);
+      check_io(sql_file);
+      continue;
+    }
+
+    query_str= cover_definer_clause_in_trigger(row[2], strlen(row[2]));
 
 
     if (switch_db_collation(sql_file, db_name, ";",
@@ -4084,7 +4142,7 @@ static int dump_all_tables_in_db(char *d
       dump_table(table,database);
       my_free(order_by, MYF(MY_ALLOW_ZERO_PTR));
       order_by= 0;
-      if (opt_dump_triggers && ! opt_xml &&
+      if (opt_dump_triggers &&
           mysql_get_server_version(mysql) >= 50009)
       {
         if (dump_triggers_for_table(table, database))
@@ -4096,13 +4154,13 @@ static int dump_all_tables_in_db(char *d
       }
     }
   }
-  if (opt_events && !opt_xml &&
+  if (opt_events &&
       mysql_get_server_version(mysql) >= 50106)
   {
     DBUG_PRINT("info", ("Dumping events for database %s", database));
     dump_events_for_db(database);
   }
-  if (opt_routines && !opt_xml &&
+  if (opt_routines &&
       mysql_get_server_version(mysql) >= 50009)
   {
     DBUG_PRINT("info", ("Dumping routines for database %s", database));

=== modified file 'mysql-test/r/mysqldump.result'
--- a/mysql-test/r/mysqldump.result	2011-03-17 10:58:16 +0000
+++ b/mysql-test/r/mysqldump.result	2011-03-18 13:04:35 +0000
@@ -4628,5 +4628,74 @@ ALTER DATABASE `test-database` CHARACTER
 DROP DATABASE `test-database`;
 USE `test`;
 #
+# BUG#11760384 : 52792: mysqldump in XML mode does not dump routines.
+#
+CREATE TABLE t1 (ID INT);
+INSERT INTO t1 VALUES (1),(2),(3);
+CREATE PROCEDURE simpleproc (OUT param1 INT)
+BEGIN
+SELECT COUNT(*) INTO param1 FROM t1;
+END//
+CREATE EVENT e1 ON SCHEDULE EVERY 1 SECOND DO DROP DATABASE test;
+CREATE FUNCTION `hello` (s CHAR(20))
+RETURNS CHAR(50) DETERMINISTIC
+RETURN CONCAT('Hello, ',s,'!');
+CREATE TRIGGER trig1 BEFORE INSERT ON t1
+FOR EACH ROW BEGIN
+INSERT INTO t1 VALUES(1);
+END;
+|
+CREATE VIEW test.v1 AS SELECT * FROM t1;
+
+# Dumping test database in xml format.
+
+<?xml version="1.0"?>
+<mysqldump xmlns:xsi="http://www.w3.org/0000/XMLSchema-instance">
+<database name="test">
+	<table_structure name="t1">
+		<field Field="ID" Type="int(00)" Null="YES" Key="" Extra="" Comment="" />
+		<options Name="t1" Engine="MyISAM" Version="00" Row_format="Fixed" Rows="3" Avg_row_length="7" Data_length="00" Max_data_length="0000000000000000" Index_length="0000" Data_free="0" Create_time="0000-00-00 00:00:00" Update_time="0000-00-00 00:00:00" Collation="latin1_swedish_ci" Create_options="" Comment="" />
+	</table_structure>
+	<table_data name="t1">
+	<row>
+		<field name="ID">1</field>
+	</row>
+	<row>
+		<field name="ID">2</field>
+	</row>
+	<row>
+		<field name="ID">3</field>
+	</row>
+	</table_data>
+	<trigger_structure name="trig1">
+		<attributes Trigger="trig1" sql_mode="" SQL_Original_Statement="CREATE DEFINER=`root`@`localhost` TRIGGER trig1 BEFORE INSERT ON t1
+FOR EACH ROW BEGIN
+INSERT INTO t1 VALUES(1);
+END" character_set_client="latin1" collation_connection="latin1_swedish_ci" Database_Collation="latin1_swedish_ci" />
+	</trigger_structure>
+	<table_structure name="v1">
+		<field Field="ID" Type="int(00)" Null="YES" Key="" Extra="" Comment="" />
+		<options Name="v1" Comment="VIEW" />
+	</table_structure>
+	<event_structure name="e1">
+		<attributes Event="e1" sql_mode="" time_zone="SYSTEM" Create_Event="CREATE EVENT `e1` ON SCHEDULE EVERY 1 SECOND STARTS '0000-00-00 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO DROP DATABASE test" character_set_client="latin1" collation_connection="latin1_swedish_ci" Database_Collation="latin1_swedish_ci" />
+	</event_structure>
+	<routine_structure name="hello">
+		<attributes Function="hello" sql_mode="" Create_Function="CREATE DEFINER=`root`@`localhost` FUNCTION `hello`(s CHAR(00)) RETURNS char(00) CHARSET latin1
+    DETERMINISTIC
+RETURN CONCAT('Hello, ',s,'!')" character_set_client="latin1" collation_connection="latin1_swedish_ci" Database_Collation="latin1_swedish_ci" />
+	</routine_structure>
+	<routine_structure name="simpleproc">
+		<attributes Procedure="simpleproc" sql_mode="" Create_Procedure="CREATE DEFINER=`root`@`localhost` PROCEDURE `simpleproc`(OUT param1 INT)
+BEGIN
+SELECT COUNT(*) INTO param1 FROM t1;
+END" character_set_client="latin1" collation_connection="latin1_swedish_ci" Database_Collation="latin1_swedish_ci" />
+	</routine_structure>
+</database>
+</mysqldump>
+DROP DATABASE test;
+CREATE DATABASE test;
+USE test;
+#
 # End of 5.1 tests
 #

=== modified file 'mysql-test/t/mysqldump.test'
--- a/mysql-test/t/mysqldump.test	2011-03-17 10:58:16 +0000
+++ b/mysql-test/t/mysqldump.test	2011-03-18 13:04:35 +0000
@@ -2197,6 +2197,44 @@ DROP DATABASE `test-database`;
 USE `test`;
 
 --echo #
+--echo # BUG#11760384 : 52792: mysqldump in XML mode does not dump routines.
+--echo #
+CREATE TABLE t1 (ID INT);
+INSERT INTO t1 VALUES (1),(2),(3);
+
+DELIMITER //;
+CREATE PROCEDURE simpleproc (OUT param1 INT)
+BEGIN
+  SELECT COUNT(*) INTO param1 FROM t1;
+END//
+DELIMITER ;//
+
+CREATE EVENT e1 ON SCHEDULE EVERY 1 SECOND DO DROP DATABASE test;
+
+CREATE FUNCTION `hello` (s CHAR(20))
+  RETURNS CHAR(50) DETERMINISTIC
+  RETURN CONCAT('Hello, ',s,'!');
+
+DELIMITER |;
+CREATE TRIGGER trig1 BEFORE INSERT ON t1
+  FOR EACH ROW BEGIN
+    INSERT INTO t1 VALUES(1);
+END;
+|
+DELIMITER ;|
+
+CREATE VIEW test.v1 AS SELECT * FROM t1;
+--echo
+--echo # Dumping test database in xml format.
+--echo
+--replace_regex /[0-9]{2}/00/
+--exec $MYSQL_DUMP --user=root --compact -R -E --triggers -X test
+
+DROP DATABASE test;
+CREATE DATABASE test;
+USE test;
+
+--echo #
 --echo # End of 5.1 tests
 --echo #
 


Attachment: [text/bzr-bundle]
Thread
bzr commit into mysql-5.1 branch (nirbhay.choubey:3621) Bug#11760384Nirbhay Choubey18 Mar