List:Commits« Previous MessageNext Message »
From:Ignacio Galarza Date:October 17 2006 9:58pm
Subject:bk commit into 5.0 tree (iggy:1.2295) BUG#19745
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of iggy. When iggy 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-10-17 17:58:39-04:00, iggy@stripped +3 -0
  Bug#19745: mysqldump --xml produces invalid xml
  
  The mysqldump command with both the --xml and --hex-blob options will output blob data encoded as hexBinary.  
  The proper XML datatype is xs:hexBinary.  
  The correct XML datatype is specified be setting the xsi_type attribute equal to xs:hexBinary for each encoded element.

  client/mysqldump.c@stripped, 2006-10-17 17:58:36-04:00, iggy@stripped +87 -36
    Bug#19745: mysqldump --xml produces invalid xml
    - Moved hex-blob code to it's own function.  Added XML specific formatting
      option.
    - Changed print_xml_tag function to accept a second optional attribute/value
      pair.
    - --xml option respects the --hex-blob option by ouputting blob data in hex
      encoded format.  Each hex encoded field tag will also contain an xsi:type
      attribute with an xs:hexBinary value.
    - --extended-insert and --xml are mutually exclusive. Otherwise, the xml file
      will contain INSERT commands.
    - Minor comment cleanup.

  mysql-test/r/mysqldump.result@stripped, 2006-10-17 17:58:37-04:00, iggy@stripped +22 -0
    Bug#19745: mysqldump --xml produces invalid xml
    -Added results.

  mysql-test/t/mysqldump.test@stripped, 2006-10-17 17:58:37-04:00, iggy@stripped +15 -0
    Bug#19745: mysqldump --xml produces invalid xml
    -Added test.

# 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:	iggy
# Host:	rolltop.ignatz42.dyndns.org
# Root:	/mnt/storeage/bug19745/my50-bug19745

--- 1.243/client/mysqldump.c	2006-10-17 17:58:44 -04:00
+++ 1.244/client/mysqldump.c	2006-10-17 17:58:44 -04:00
@@ -524,6 +524,8 @@ static void write_header(FILE *sql_file,
   {
     fputs("<?xml version=\"1.0\"?>\n", sql_file);
     fputs("<mysqldump ", sql_file);
+    /* Schema reference.  Allows use of xsi:nil for NULL values and 
+       xsi:type to define an element's data type. */
     fputs("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"",
           sql_file);
     fputs(">\n", sql_file);
@@ -1123,7 +1125,7 @@ static char *quote_for_like(const char *
 
   SYNOPSIS
     print_quoted_xml()
-    output      - output file
+    xml_file    - output file
     str         - string to print
     len         - its length
 
@@ -1160,34 +1162,49 @@ static void print_quoted_xml(FILE *xml_f
 
 
 /*
-  Print xml tag with one attribute.
+  Print xml tag with one required attribute and one optional attribute.
 
   SYNOPSIS
-    print_xml_tag1()
-    xml_file    - output file
-    sbeg        - line beginning
-    stag_atr    - tag and attribute
-    sval        - value of attribute
-    send        - line ending
+    print_xml_tag()
+    xml_file     - output file
+    sbeg         - line beginning
+    stag_atr     - tag and attribute
+    sval         - value of attribute
+    stag_atr_opt - optional attribute
+    sval_opt     - value of optional attribute
+    send         - line ending
 
   DESCRIPTION
-    Print tag with one attribute to the xml_file. Format is:
-      sbeg<stag_atr="sval">send
+    Print tag with one required attribute to the xml_file.  If specified,
+    print a second attribute along with the tag.
+
+    Format is:
+      sbeg<stag_atr="sval" stag_atr_opt="sval_opt">send
   NOTE
-    sval MUST be a NULL terminated string.
-    sval string will be qouted before output.
+    sval and sval_opt MUST be a NULL terminated string.
+    sval and sval_opt strings will be quoted before output.
 */
 
-static void print_xml_tag1(FILE * xml_file, const char* sbeg,
-                           const char* stag_atr, const char* sval,
-                           const char* send)
+static void print_xml_tag(FILE * xml_file, const char* sbeg,
+                          const char* stag_atr, const char* sval,
+                          const char* stag_atr_opt, const char* sval_opt,
+                          const char* send)
 {
   fputs(sbeg, xml_file);
-  fputs("<", xml_file);
+  fputc('<', xml_file);
   fputs(stag_atr, xml_file);
-  fputs("\"", xml_file);
+  fputc('\"', xml_file);
   print_quoted_xml(xml_file, sval, strlen(sval));
-  fputs("\">", xml_file);
+  fputc('\"', xml_file);
+  if (stag_atr_opt)
+  {
+    fputc(' ', xml_file);
+    fputs(stag_atr_opt, xml_file);
+    fputc('\"', xml_file);
+    print_quoted_xml(xml_file, sval_opt, strlen(sval_opt));
+    fputc('\"', xml_file);
+  }
+  fputc('>', xml_file);
   fputs(send, xml_file);
   check_io(xml_file);
 }
@@ -1271,6 +1288,32 @@ static void print_xml_row(FILE *xml_file
 }
 
 /*
+  Print hex value for blob data.
+
+  SYNOPSIS
+    print_blob_as_hex()
+    output_file         - output file
+    use_xml_hex_grammar - TRUE to use XML hex grammar. FALSE otherwise.
+    str                 - string to print
+    len                 - its length
+
+  DESCRIPTION
+    Print hex value for blob data.
+*/
+
+static void print_blob_as_hex(FILE *output_file, my_bool use_xml_hex_grammar, 
+        const char *str, ulong len)
+{
+    /* sakaik got the idea to to provide blob's in hex notation. */
+    char *ptr= str, *end= ptr + len;
+    if (!use_xml_hex_grammar)
+        fputs("0x", output_file);
+    for (; ptr < end ; ptr++)
+      fprintf(output_file, "%02X", *((uchar *)ptr));
+    check_io(output_file);
+}
+
+/*
   dump_routines_for_db
   -- retrievs list of routines for a given db, and prints out
   the CREATE PROCEDURE definition into the output (the dump).
@@ -1714,7 +1757,8 @@ static uint get_table_structure(char *ta
       if (!opt_xml)
         fprintf(sql_file, "CREATE TABLE %s (\n", result_table);
       else
-        print_xml_tag1(sql_file, "\t", "table_structure name=", table, "\n");
+        print_xml_tag(sql_file, "\t", "table_structure name=", table, 
+                NULL, NULL, "\n");
       check_io(sql_file);
     }
 
@@ -2283,7 +2327,8 @@ static void dump_table(char *table, char
     rownr=0;
     init_length=(uint) insert_pat.length+4;
     if (opt_xml)
-      print_xml_tag1(md_result_file, "\t", "table_data name=", table, "\n");
+      print_xml_tag(md_result_file, "\t", "table_data name=", table,
+              NULL, NULL, "\n");
 
     if (opt_autocommit)
     {
@@ -2338,7 +2383,7 @@ static void dump_table(char *table, char
                    field->type == MYSQL_TYPE_LONG_BLOB ||
                    field->type == MYSQL_TYPE_MEDIUM_BLOB ||
                    field->type == MYSQL_TYPE_TINY_BLOB)) ? 1 : 0;
-        if (extended_insert)
+        if (extended_insert && !opt_xml)
         {
           if (i == 0)
             dynstr_set(&extended_row,"(");
@@ -2427,19 +2472,23 @@ static void dump_table(char *table, char
             {
               if (opt_xml)
               {
-                print_xml_tag1(md_result_file, "\t\t", "field name=",
-                              field->name, "");
-                print_quoted_xml(md_result_file, row[i], length);
+                if (opt_hex_blob && is_blob && length)
+                {
+                    /* Define xsi:type="xs:hexBinary" for hex encoded data */
+                    print_xml_tag(md_result_file, "\t\t", "field name=", 
+                            field->name, "xsi:type=", "xs:hexBinary", "");
+                    print_blob_as_hex(md_result_file, TRUE, row[i], length);
+                }
+                else
+                {
+                    print_xml_tag(md_result_file, "\t\t", "field name=", 
+                            field->name, NULL, NULL, "");
+                    print_quoted_xml(md_result_file, row[i], length);
+                }
                 fputs("</field>\n", md_result_file);
               }
               else if (opt_hex_blob && is_blob && length)
-              {
-                /* sakaik got the idea to to provide blob's in hex notation. */
-                char *ptr= row[i], *end= ptr + length;
-                fputs("0x", md_result_file);
-                for (; ptr < end ; ptr++)
-                  fprintf(md_result_file, "%02X", *((uchar *)ptr));
-              }
+                print_blob_as_hex(md_result_file, FALSE, row[i], length);
               else
                 unescape(md_result_file, row[i], length);
             }
@@ -2449,8 +2498,8 @@ static void dump_table(char *table, char
               char *ptr= row[i];
               if (opt_xml)
               {
-                print_xml_tag1(md_result_file, "\t\t", "field name=",
-                               field->name, "");
+                print_xml_tag(md_result_file, "\t\t", "field name=",
+                               field->name, NULL, NULL, "");
                 fputs(!my_isalpha(charset_info, *ptr) ? ptr: "NULL",
                       md_result_file);
                 fputs("</field>\n", md_result_file);
@@ -2781,7 +2830,8 @@ static int dump_all_tables_in_db(char *d
   if (init_dumping(database, init_dumping_tables))
     return 1;
   if (opt_xml)
-    print_xml_tag1(md_result_file, "", "database name=", database, "\n");
+    print_xml_tag(md_result_file, "", "database name=", database, NULL, NULL,
+            "\n");
   if (lock_tables)
   {
     DYNAMIC_STRING query;
@@ -2858,7 +2908,8 @@ static my_bool dump_all_views_in_db(char
   if (init_dumping(database, init_dumping_views))
     return 1;
   if (opt_xml)
-    print_xml_tag1(md_result_file, "", "database name=", database, "\n");
+    print_xml_tag(md_result_file, "", "database name=", database, NULL, NULL,
+            "\n");
   if (lock_tables)
   {
     DYNAMIC_STRING query;
@@ -2997,7 +3048,7 @@ static int dump_selected_tables(char *db
      /* We shall countinue here, if --force was given */
   }
   if (opt_xml)
-    print_xml_tag1(md_result_file, "", "database name=", db, "\n");
+    print_xml_tag(md_result_file, "", "database name=", db, NULL, NULL, "\n");
 
   /* Dump each selected table */
   for (pos= dump_tables; pos < end; pos++)

--- 1.116/mysql-test/r/mysqldump.result	2006-10-17 17:58:44 -04:00
+++ 1.117/mysql-test/r/mysqldump.result	2006-10-17 17:58:44 -04:00
@@ -3196,5 +3196,27 @@ UNLOCK TABLES;
 
 DROP TABLE `t1`;
 #
+# Bug #19745: mysqldump --xml produces invalid xml
+#
+DROP TABLE IF EXISTS t1;
+CREATE TABLE t1 (f1 int(10), data MEDIUMBLOB);
+INSERT INTO t1 VALUES(1,0xff00fef0);
+<?xml version="1.0"?>
+<mysqldump xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+<database name="test">
+	<table_structure name="t1">
+		<field Field="f1" Type="int(10)" Null="YES" Key="" Extra="" />
+		<field Field="data" Type="mediumblob" Null="YES" Key="" Extra="" />
+	</table_structure>
+	<table_data name="t1">
+	<row>
+		<field name="f1">1</field>
+		<field name="data" xsi:type="xs:hexBinary">FF00FEF0</field>
+	</row>
+	</table_data>
+</database>
+</mysqldump>
+DROP TABLE t1;
+#
 # End of 5.0 tests
 #

--- 1.105/mysql-test/t/mysqldump.test	2006-10-17 17:58:44 -04:00
+++ 1.106/mysql-test/t/mysqldump.test	2006-10-17 17:58:44 -04:00
@@ -1413,5 +1413,20 @@ DROP TABLE `t1`;
 --enable_warnings
 
 --echo #
+--echo # Bug #19745: mysqldump --xml produces invalid xml
+--echo #
+
+--disable_warnings
+DROP TABLE IF EXISTS t1;
+--enable_warnings
+
+CREATE TABLE t1 (f1 int(10), data MEDIUMBLOB);
+INSERT INTO t1 VALUES(1,0xff00fef0);
+
+--exec $MYSQL_DUMP --xml --hex-blob --skip-create-options test t1
+
+DROP TABLE t1;
+
+--echo #
 --echo # End of 5.0 tests
 --echo #
Thread
bk commit into 5.0 tree (iggy:1.2295) BUG#19745Ignacio Galarza17 Oct