From d8f3934148a1a92458fc0f206c6b0a804f30a001 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 25 Jan 2005 14:25:40 -0800 Subject: [PATCH] Change 'mysql' client to output XML like the 'mysqldump' tool does, with the column names as attributes on elements, instead of trying to use the column name as the element name. Also fix some encoding issues. (Bug #7811) client/mysql.cc: Quote > and " in XML output, and use instead of , to make the output more like mysqldump --xml and avoid having to turn XXX into a sensible element name. --- client/mysql.cc | 12 +++--- mysql-test/r/client_xml.result | 75 ++++++++++++++++++++++++++++++++++ mysql-test/t/client_xml.test | 18 ++++++++ 3 files changed, 99 insertions(+), 6 deletions(-) create mode 100644 mysql-test/r/client_xml.result create mode 100644 mysql-test/t/client_xml.test diff --git a/client/mysql.cc b/client/mysql.cc index 635973e946c..1223a952264 100644 --- a/client/mysql.cc +++ b/client/mysql.cc @@ -154,6 +154,8 @@ static char mysql_charsets_dir[FN_REFLEN+1]; static const char *xmlmeta[] = { "&", "&", "<", "<", + ">", ">", + "\"", """, 0, 0 }; static const char *day_names[]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"}; @@ -2116,13 +2118,11 @@ print_table_data_xml(MYSQL_RES *result) (void) tee_fputs("\n \n", PAGER); for (uint i=0; i < mysql_num_fields(result); i++) { - tee_fprintf(PAGER, "\t<%s>", (fields[i].name ? - (fields[i].name[0] ? fields[i].name : - "   ") : "NULL")); + tee_fprintf(PAGER, "\t"); xmlencode_print(cur[i], lengths[i]); - tee_fprintf(PAGER, "\n", (fields[i].name ? - (fields[i].name[0] ? fields[i].name : - "   ") : "NULL")); + tee_fprintf(PAGER, "\n"); } (void) tee_fputs(" \n", PAGER); } diff --git a/mysql-test/r/client_xml.result b/mysql-test/r/client_xml.result new file mode 100644 index 00000000000..b6cebab98e1 --- /dev/null +++ b/mysql-test/r/client_xml.result @@ -0,0 +1,75 @@ +create table t1 ( +`a&b` int, +`ab` text +); +insert into t1 values (1, 2, 'a&b ab'); + + + + + 1 + 2 + a&b a<b a>b + + + + + + + + + + + + + + 1 + 2 + a&b a<b a>b + + + + + + + + + 1 + + + + + + + 1 + + + + + + + 0 + + + + + + + 1 + + + + + + + NULL + + +drop table t1; diff --git a/mysql-test/t/client_xml.test b/mysql-test/t/client_xml.test new file mode 100644 index 00000000000..3628a510557 --- /dev/null +++ b/mysql-test/t/client_xml.test @@ -0,0 +1,18 @@ +# Test of the xml output of the 'mysql' and 'mysqldump' clients -- makes +# sure that basic encoding issues are handled properly +create table t1 ( + `a&b` int, + `ab` text +); +insert into t1 values (1, 2, 'a&b ab'); +--exec $MYSQL --xml test -e 'select * from t1' +--exec $MYSQL_DUMP --xml test + +--exec $MYSQL --xml test -e 'select count(*) from t1' +--exec $MYSQL --xml test -e 'select 1 < 2 from dual' +--exec $MYSQL --xml test -e 'select 1 > 2 from dual' +--exec $MYSQL --xml test -e 'select 1 & 3 from dual' +--exec $MYSQL --xml test -e 'select null from dual' + +drop table t1;