From e5d0e337f8cabe2824dd324888bca22fd628b350 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 22 Jun 2005 20:22:54 +0200 Subject: [PATCH] BUG#9657 mysqldump xml ( -x ) does not format NULL fields correctly - Importing the bug fixes by patch due to merge problems. client/mysqldump.c: Import patch patch mysql-test/r/mysqldump.result: Import patch patch mysql-test/t/mysqldump.test: Import patch patch --- client/mysqldump.c | 48 +++++++++++++++++++++++++-- mysql-test/r/mysqldump.result | 62 +++++++++++++++++++++++++++++++++-- mysql-test/t/mysqldump.test | 13 ++++++++ 3 files changed, 118 insertions(+), 5 deletions(-) diff --git a/client/mysqldump.c b/client/mysqldump.c index 207235983da..f4116253f8f 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -463,7 +463,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) @@ -1050,6 +1053,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. @@ -1870,7 +1907,14 @@ static void dumpTable(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 50399c91ec9..e465760736f 100644 --- a/mysql-test/r/mysqldump.result +++ b/mysql-test/r/mysqldump.result @@ -2,7 +2,7 @@ DROP TABLE IF EXISTS t1, `"t"1`; CREATE TABLE t1(a int); INSERT INTO t1 VALUES (1), (2); - + @@ -103,7 +103,7 @@ DROP TABLE t1; CREATE TABLE t1(a int, b text, c varchar(3)); INSERT INTO t1 VALUES (1, "test", "tes"), (2, "TEST", "TES"); - + @@ -128,7 +128,7 @@ DROP TABLE t1; CREATE TABLE t1 (`a"b"` char(2)); INSERT INTO t1 VALUES ("1\""), ("\"2"); - + @@ -1436,3 +1436,59 @@ MYSQL_DUMP_DIR: Got error: 1049: Unknown database 'mysqldump_test_d' when select MYSQL_DUMP_DIR: 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 349b1e96239..2ee7fee2802 100644 --- a/mysql-test/t/mysqldump.test +++ b/mysql-test/t/mysqldump.test @@ -636,3 +636,16 @@ 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; +