mirror of
https://github.com/MariaDB/server.git
synced 2025-01-16 12:02:42 +01:00
Change 'mysql' client to output XML like the 'mysqldump'
tool does, with the column names as attributes on <field> 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 <field name="XXX"></field> instead of <XXX></XXX>, to make the output more like mysqldump --xml and avoid having to turn XXX into a sensible element name.
This commit is contained in:
parent
4bb1c716e8
commit
d8f3934148
3 changed files with 99 additions and 6 deletions
|
@ -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 <row>\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<field name=\"");
|
||||
xmlencode_print(fields[i].name, strlen(fields[i].name));
|
||||
tee_fprintf(PAGER, "\">");
|
||||
xmlencode_print(cur[i], lengths[i]);
|
||||
tee_fprintf(PAGER, "</%s>\n", (fields[i].name ?
|
||||
(fields[i].name[0] ? fields[i].name :
|
||||
" ") : "NULL"));
|
||||
tee_fprintf(PAGER, "</field>\n");
|
||||
}
|
||||
(void) tee_fputs(" </row>\n", PAGER);
|
||||
}
|
||||
|
|
75
mysql-test/r/client_xml.result
Normal file
75
mysql-test/r/client_xml.result
Normal file
|
@ -0,0 +1,75 @@
|
|||
create table t1 (
|
||||
`a&b` int,
|
||||
`a<b` int,
|
||||
`a>b` text
|
||||
);
|
||||
insert into t1 values (1, 2, 'a&b a<b a>b');
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<resultset statement="select * from t1
|
||||
">
|
||||
<row>
|
||||
<field name="a&b">1</field>
|
||||
<field name="a<b">2</field>
|
||||
<field name="a>b">a&b a<b a>b</field>
|
||||
</row>
|
||||
</resultset>
|
||||
<?xml version="1.0"?>
|
||||
<mysqldump>
|
||||
<database name="test">
|
||||
<table_structure name="t1">
|
||||
<field Field="a&b" Type="int(11)" Null="YES" Key="" Extra="" />
|
||||
<field Field="a<b" Type="int(11)" Null="YES" Key="" Extra="" />
|
||||
<field Field="a>b" Type="text" Null="YES" Key="" Extra="" />
|
||||
<options Name="t1" Engine="MyISAM" Version="9" Row_format="Dynamic" Rows="1" Avg_row_length="28" Data_length="28" Max_data_length="4294967295" Index_length="1024" Data_free="0" Create_time="2005-01-26 01:21:39" Update_time="2005-01-26 01:21:39" Collation="latin1_swedish_ci" Create_options="" Comment="" />
|
||||
</table_structure>
|
||||
<table_data name="t1">
|
||||
<row>
|
||||
<field name="a&b">1</field>
|
||||
<field name="a<b">2</field>
|
||||
<field name="a>b">a&b a<b a>b</field>
|
||||
</row>
|
||||
</table_data>
|
||||
</database>
|
||||
</mysqldump>
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<resultset statement="select count(*) from t1
|
||||
">
|
||||
<row>
|
||||
<field name="count(*)">1</field>
|
||||
</row>
|
||||
</resultset>
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<resultset statement="select 1 < 2 from dual
|
||||
">
|
||||
<row>
|
||||
<field name="1 < 2">1</field>
|
||||
</row>
|
||||
</resultset>
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<resultset statement="select 1 > 2 from dual
|
||||
">
|
||||
<row>
|
||||
<field name="1 > 2">0</field>
|
||||
</row>
|
||||
</resultset>
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<resultset statement="select 1 & 3 from dual
|
||||
">
|
||||
<row>
|
||||
<field name="1 & 3">1</field>
|
||||
</row>
|
||||
</resultset>
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<resultset statement="select null from dual
|
||||
">
|
||||
<row>
|
||||
<field name="NULL">NULL</field>
|
||||
</row>
|
||||
</resultset>
|
||||
drop table t1;
|
18
mysql-test/t/client_xml.test
Normal file
18
mysql-test/t/client_xml.test
Normal file
|
@ -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,
|
||||
`a<b` int,
|
||||
`a>b` text
|
||||
);
|
||||
insert into t1 values (1, 2, 'a&b a<b a>b');
|
||||
--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;
|
Loading…
Reference in a new issue