diff --git a/client/mysqldump.c b/client/mysqldump.c index ef58621cf59..66bc4fcb896 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -469,7 +469,10 @@ static void write_header(FILE *sql_file, char *db_name) if (opt_xml) { fputs("\n", sql_file); - fputs("\n", sql_file); + fputs("\n", sql_file); check_io(sql_file); } else if (!opt_compact) @@ -1075,6 +1078,40 @@ static void print_xml_tag1(FILE * xml_file, const char* sbeg, } +/* + Print xml tag with for a field that is null + + SYNOPSIS + print_xml_null_tag() + xml_file - output file + sbeg - line beginning + stag_atr - tag and attribute + sval - value of attribute + send - line ending + + DESCRIPTION + Print tag with one attribute to the xml_file. Format is: + + NOTE + sval MUST be a NULL terminated string. + sval string will be qouted before output. +*/ + +static void print_xml_null_tag(FILE * xml_file, const char* sbeg, + const char* stag_atr, const char* sval, + const char* send) +{ + fputs(sbeg, xml_file); + fputs("<", xml_file); + fputs(stag_atr, xml_file); + fputs("\"", xml_file); + print_quoted_xml(xml_file, sval, strlen(sval)); + fputs("\" xsi:nil=\"true\" />", xml_file); + fputs(send, xml_file); + check_io(xml_file); +} + + /* Print xml tag with many attributes. @@ -1935,7 +1972,14 @@ static void dump_table(uint numFields, char *table) } } else - fputs("NULL", md_result_file); + { + /* The field value is NULL */ + if (!opt_xml) + fputs("NULL", md_result_file); + else + print_xml_null_tag(md_result_file, "\t\t", "field name=", + field->name, "\n"); + } check_io(md_result_file); } } diff --git a/mysql-test/r/mysqldump.result b/mysql-test/r/mysqldump.result index 737c957bede..097976ad383 100644 --- a/mysql-test/r/mysqldump.result +++ b/mysql-test/r/mysqldump.result @@ -5,7 +5,7 @@ drop view if exists v1, v2; CREATE TABLE t1(a int); INSERT INTO t1 VALUES (1), (2); - + @@ -108,7 +108,7 @@ DROP TABLE t1; CREATE TABLE t1(a int, b text, c varchar(3)); INSERT INTO t1 VALUES (1, "test", "tes"), (2, "TEST", "TES"); - + @@ -133,7 +133,7 @@ DROP TABLE t1; CREATE TABLE t1 (`a"b"` char(2)); INSERT INTO t1 VALUES ("1\""), ("\"2"); - + @@ -1580,3 +1580,59 @@ mysqldump: Got error: 1049: Unknown database 'mysqldump_test_d' when selecting t mysqldump: Got error: 1102: Incorrect database name 'mysqld\ump_test_db' when selecting the database drop table t1, t2, t3; drop database mysqldump_test_db; +create table t1 (a int(10)); +create table t2 (pk int primary key auto_increment, +a int(10), b varchar(30), c datetime, d blob, e text); +insert into t1 values (NULL), (10), (20); +insert into t2 (a, b) values (NULL, NULL),(10, NULL),(NULL, "twenty"),(30, "thirty"); + + + + + + + + + 10 + + + 20 + + + + + 1 + + + + + + + + 2 + 10 + + + + + + + 3 + + twenty + + + + + + 4 + 30 + thirty + + + + + + + +drop table t1, t2; diff --git a/mysql-test/t/mysqldump.test b/mysql-test/t/mysqldump.test index a904ffcc366..97711de7072 100644 --- a/mysql-test/t/mysqldump.test +++ b/mysql-test/t/mysqldump.test @@ -565,7 +565,6 @@ INSERT INTO t1 VALUES (1),(2),(3); --exec $MYSQL_DUMP --add-drop-database --skip-comments --databases test DROP TABLE t1; - # # Bug #10213 mysqldump crashes when dumping VIEWs(on MacOS X) # @@ -666,3 +665,16 @@ select '------ Testing with illegal database names ------' as test_sequence ; drop table t1, t2, t3; drop database mysqldump_test_db; + +# +# Bug #9657 mysqldump xml ( -x ) does not format NULL fields correctly +# + +create table t1 (a int(10)); +create table t2 (pk int primary key auto_increment, +a int(10), b varchar(30), c datetime, d blob, e text); +insert into t1 values (NULL), (10), (20); +insert into t2 (a, b) values (NULL, NULL),(10, NULL),(NULL, "twenty"),(30, "thirty"); +--exec $MYSQL_DUMP --skip-comments --xml --no-create-info test +drop table t1, t2; +