Commit 39bda9e3 authored by iggy@rolltop.ignatz42.dyndns.org's avatar iggy@rolltop.ignatz42.dyndns.org

Merge rolltop.ignatz42.dyndns.org:/mnt/storeage/bug19745/my50-bug19745

into  rolltop.ignatz42.dyndns.org:/mnt/storeage/mysql-5.0-maint
parents 9a50d74f 3c31c842
...@@ -45,6 +45,7 @@ ...@@ -45,6 +45,7 @@
#include <m_string.h> #include <m_string.h>
#include <m_ctype.h> #include <m_ctype.h>
#include <hash.h> #include <hash.h>
#include <stdarg.h>
#include "client_priv.h" #include "client_priv.h"
#include "mysql.h" #include "mysql.h"
...@@ -523,6 +524,8 @@ static void write_header(FILE *sql_file, char *db_name) ...@@ -523,6 +524,8 @@ static void write_header(FILE *sql_file, char *db_name)
if (opt_xml) if (opt_xml)
{ {
fputs("<?xml version=\"1.0\"?>\n", sql_file); fputs("<?xml version=\"1.0\"?>\n", sql_file);
/* Schema reference. Allows use of xsi:nil for NULL values and
xsi:type to define an element's data type. */
fputs("<mysqldump ", sql_file); fputs("<mysqldump ", sql_file);
fputs("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"", fputs("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"",
sql_file); sql_file);
...@@ -1123,7 +1126,7 @@ static char *quote_for_like(const char *name, char *buff) ...@@ -1123,7 +1126,7 @@ static char *quote_for_like(const char *name, char *buff)
SYNOPSIS SYNOPSIS
print_quoted_xml() print_quoted_xml()
output - output file xml_file - output file
str - string to print str - string to print
len - its length len - its length
...@@ -1160,34 +1163,63 @@ static void print_quoted_xml(FILE *xml_file, const char *str, ulong len) ...@@ -1160,34 +1163,63 @@ static void print_quoted_xml(FILE *xml_file, const char *str, ulong len)
/* /*
Print xml tag with one attribute. Print xml tag. Optionally add attribute(s).
SYNOPSIS SYNOPSIS
print_xml_tag1() print_xml_tag(xml_file, sbeg, send, tag_name, first_attribute_name,
..., attribute_name_n, attribute_value_n, NullS)
xml_file - output file xml_file - output file
sbeg - line beginning sbeg - line beginning
stag_atr - tag and attribute
sval - value of attribute
send - line ending send - line ending
tag_name - XML tag name.
first_attribute_name - tag and first attribute
first_attribute_value - (Implied) value of first attribute
attribute_name_n - attribute n
attribute_value_n - value of attribute n
DESCRIPTION DESCRIPTION
Print tag with one attribute to the xml_file. Format is: Print XML tag with any number of attribute="value" pairs to the xml_file.
sbeg<stag_atr="sval">send
Format is:
sbeg<tag_name first_attribute_name="first_attribute_value" ...
attribute_name_n="attribute_value_n">send
NOTE NOTE
sval MUST be a NULL terminated string. Additional arguments must be present in attribute/value pairs.
sval string will be qouted before output. The last argument should be the null character pointer.
All attribute_value arguments MUST be NULL terminated strings.
All attribute_value arguments will be quoted before output.
*/ */
static void print_xml_tag1(FILE * xml_file, const char* sbeg, static void print_xml_tag(FILE * xml_file, const char* sbeg, const char* send,
const char* stag_atr, const char* sval, const char* tag_name,
const char* send) const char* first_attribute_name, ...)
{ {
va_list arg_list;
char *attribute_name, *attribute_value;
fputs(sbeg, xml_file); fputs(sbeg, xml_file);
fputs("<", xml_file); fputc('<', xml_file);
fputs(stag_atr, xml_file); fputs(tag_name, xml_file);
fputs("\"", xml_file);
print_quoted_xml(xml_file, sval, strlen(sval)); va_start(arg_list, first_attribute_name);
fputs("\">", xml_file); attribute_name= first_attribute_name;
while (attribute_name != NullS)
{
attribute_value= va_arg(arg_list, char *);
DBUG_ASSERT(attribute_value != NullS);
fputc(' ', xml_file);
fputs(attribute_name, xml_file);
fputc('\"', xml_file);
print_quoted_xml(xml_file, attribute_value, strlen(attribute_value));
fputc('\"', xml_file);
attribute_name= va_arg(arg_list, char *);
}
va_end(arg_list);
fputc('>', xml_file);
fputs(send, xml_file); fputs(send, xml_file);
check_io(xml_file); check_io(xml_file);
} }
...@@ -1270,6 +1302,28 @@ static void print_xml_row(FILE *xml_file, const char *row_name, ...@@ -1270,6 +1302,28 @@ static void print_xml_row(FILE *xml_file, const char *row_name,
check_io(xml_file); check_io(xml_file);
} }
/*
Print hex value for blob data.
SYNOPSIS
print_blob_as_hex()
output_file - output file
str - string to print
len - its length
DESCRIPTION
Print hex value for blob data.
*/
static void print_blob_as_hex(FILE *output_file, const char *str, ulong len)
{
/* sakaik got the idea to to provide blob's in hex notation. */
char *ptr= str, *end= ptr + len;
for (; ptr < end ; ptr++)
fprintf(output_file, "%02X", *((uchar *)ptr));
check_io(output_file);
}
/* /*
dump_routines_for_db dump_routines_for_db
-- retrievs list of routines for a given db, and prints out -- retrievs list of routines for a given db, and prints out
...@@ -1714,7 +1768,8 @@ static uint get_table_structure(char *table, char *db, char *table_type, ...@@ -1714,7 +1768,8 @@ static uint get_table_structure(char *table, char *db, char *table_type,
if (!opt_xml) if (!opt_xml)
fprintf(sql_file, "CREATE TABLE %s (\n", result_table); fprintf(sql_file, "CREATE TABLE %s (\n", result_table);
else else
print_xml_tag1(sql_file, "\t", "table_structure name=", table, "\n"); print_xml_tag(sql_file, "\t", "\n", "table_structure", "name=", table,
NullS);
check_io(sql_file); check_io(sql_file);
} }
...@@ -2283,8 +2338,8 @@ static void dump_table(char *table, char *db) ...@@ -2283,8 +2338,8 @@ static void dump_table(char *table, char *db)
rownr=0; rownr=0;
init_length=(uint) insert_pat.length+4; init_length=(uint) insert_pat.length+4;
if (opt_xml) if (opt_xml)
print_xml_tag1(md_result_file, "\t", "table_data name=", table, "\n"); print_xml_tag(md_result_file, "\t", "\n", "table_data", "name=", table,
NullS);
if (opt_autocommit) if (opt_autocommit)
{ {
fprintf(md_result_file, "set autocommit=0;\n"); fprintf(md_result_file, "set autocommit=0;\n");
...@@ -2338,7 +2393,7 @@ static void dump_table(char *table, char *db) ...@@ -2338,7 +2393,7 @@ static void dump_table(char *table, char *db)
field->type == MYSQL_TYPE_LONG_BLOB || field->type == MYSQL_TYPE_LONG_BLOB ||
field->type == MYSQL_TYPE_MEDIUM_BLOB || field->type == MYSQL_TYPE_MEDIUM_BLOB ||
field->type == MYSQL_TYPE_TINY_BLOB)) ? 1 : 0; field->type == MYSQL_TYPE_TINY_BLOB)) ? 1 : 0;
if (extended_insert) if (extended_insert && !opt_xml)
{ {
if (i == 0) if (i == 0)
dynstr_set(&extended_row,"("); dynstr_set(&extended_row,"(");
...@@ -2427,18 +2482,25 @@ static void dump_table(char *table, char *db) ...@@ -2427,18 +2482,25 @@ static void dump_table(char *table, char *db)
{ {
if (opt_xml) if (opt_xml)
{ {
print_xml_tag1(md_result_file, "\t\t", "field name=", if (opt_hex_blob && is_blob && length)
field->name, ""); {
/* 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", NullS);
print_blob_as_hex(md_result_file, row[i], length);
}
else
{
print_xml_tag(md_result_file, "\t\t", "", "field", "name=",
field->name, NullS);
print_quoted_xml(md_result_file, row[i], length); print_quoted_xml(md_result_file, row[i], length);
}
fputs("</field>\n", md_result_file); fputs("</field>\n", md_result_file);
} }
else if (opt_hex_blob && is_blob && length) 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); fputs("0x", md_result_file);
for (; ptr < end ; ptr++) print_blob_as_hex(md_result_file, row[i], length);
fprintf(md_result_file, "%02X", *((uchar *)ptr));
} }
else else
unescape(md_result_file, row[i], length); unescape(md_result_file, row[i], length);
...@@ -2449,8 +2511,8 @@ static void dump_table(char *table, char *db) ...@@ -2449,8 +2511,8 @@ static void dump_table(char *table, char *db)
char *ptr= row[i]; char *ptr= row[i];
if (opt_xml) if (opt_xml)
{ {
print_xml_tag1(md_result_file, "\t\t", "field name=", print_xml_tag(md_result_file, "\t\t", "", "field", "name=",
field->name, ""); field->name, NullS);
fputs(!my_isalpha(charset_info, *ptr) ? ptr: "NULL", fputs(!my_isalpha(charset_info, *ptr) ? ptr: "NULL",
md_result_file); md_result_file);
fputs("</field>\n", md_result_file); fputs("</field>\n", md_result_file);
...@@ -2781,7 +2843,7 @@ static int dump_all_tables_in_db(char *database) ...@@ -2781,7 +2843,7 @@ static int dump_all_tables_in_db(char *database)
if (init_dumping(database, init_dumping_tables)) if (init_dumping(database, init_dumping_tables))
return 1; return 1;
if (opt_xml) if (opt_xml)
print_xml_tag1(md_result_file, "", "database name=", database, "\n"); print_xml_tag(md_result_file, "", "\n", "database", "name=", database, NullS);
if (lock_tables) if (lock_tables)
{ {
DYNAMIC_STRING query; DYNAMIC_STRING query;
...@@ -2858,7 +2920,7 @@ static my_bool dump_all_views_in_db(char *database) ...@@ -2858,7 +2920,7 @@ static my_bool dump_all_views_in_db(char *database)
if (init_dumping(database, init_dumping_views)) if (init_dumping(database, init_dumping_views))
return 1; return 1;
if (opt_xml) if (opt_xml)
print_xml_tag1(md_result_file, "", "database name=", database, "\n"); print_xml_tag(md_result_file, "", "\n", "database", "name=", database, NullS);
if (lock_tables) if (lock_tables)
{ {
DYNAMIC_STRING query; DYNAMIC_STRING query;
...@@ -2997,7 +3059,7 @@ static int dump_selected_tables(char *db, char **table_names, int tables) ...@@ -2997,7 +3059,7 @@ static int dump_selected_tables(char *db, char **table_names, int tables)
/* We shall countinue here, if --force was given */ /* We shall countinue here, if --force was given */
} }
if (opt_xml) if (opt_xml)
print_xml_tag1(md_result_file, "", "database name=", db, "\n"); print_xml_tag(md_result_file, "", "\n", "database", "name=", db, NullS);
/* Dump each selected table */ /* Dump each selected table */
for (pos= dump_tables; pos < end; pos++) for (pos= dump_tables; pos < end; pos++)
......
...@@ -3196,5 +3196,27 @@ UNLOCK TABLES; ...@@ -3196,5 +3196,27 @@ UNLOCK TABLES;
DROP TABLE `t1`; 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 # End of 5.0 tests
# #
...@@ -1412,6 +1412,21 @@ insert into t1 values (0815, 4711, 2006); ...@@ -1412,6 +1412,21 @@ insert into t1 values (0815, 4711, 2006);
DROP TABLE `t1`; DROP TABLE `t1`;
--enable_warnings --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 #
--echo # End of 5.0 tests --echo # End of 5.0 tests
--echo # --echo #
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment