Commit 4d99f793 authored by unknown's avatar unknown

Bug #9558 mysqldump --no-data db t1 t2 format still dumps data

    - Check the Dflag variable inside of function dump_table to see if data should be
dumped or not.
    - Add test for --xml and --no-data as well
    Reapplying patch!


client/mysqldump.c:
  Move the check of --no-data flag and "number of fields" inside of the dump_table
  function.
mysql-test/r/mysqldump.result:
  Update test results add ouput for --xml and --no-data
mysql-test/t/mysqldump.test:
  Add tests for XML and --no-data as well.
parent 3790b7bc
...@@ -1595,6 +1595,26 @@ static void dump_table(uint numFields, char *table) ...@@ -1595,6 +1595,26 @@ static void dump_table(uint numFields, char *table)
const char *table_type; const char *table_type;
int error= 0; int error= 0;
/* Check --no-data flag */
if (dFlag)
{
if (verbose)
fprintf(stderr,
"-- Skipping dump data for table '%s', --no-data was used\n",
table);
return;
}
/* Check that there are any fields in the table */
if(numFields == 0)
{
if (verbose)
fprintf(stderr,
"-- Skipping dump data for table '%s', it has no fields\n",
table);
return;
}
result_table= quote_name(table,table_buff, 1); result_table= quote_name(table,table_buff, 1);
opt_quoted_table= quote_name(table, table_buff2, 0); opt_quoted_table= quote_name(table, table_buff2, 0);
...@@ -2204,7 +2224,6 @@ static int dump_all_tables_in_db(char *database) ...@@ -2204,7 +2224,6 @@ static int dump_all_tables_in_db(char *database)
if (include_table(hash_key, end - hash_key)) if (include_table(hash_key, end - hash_key))
{ {
numrows = get_table_structure(table, database); numrows = get_table_structure(table, database);
if (!dFlag && numrows > 0)
dump_table(numrows,table); dump_table(numrows,table);
my_free(order_by, MYF(MY_ALLOW_ZERO_PTR)); my_free(order_by, MYF(MY_ALLOW_ZERO_PTR));
order_by= 0; order_by= 0;
...@@ -2392,6 +2411,7 @@ static int dump_selected_tables(char *db, char **table_names, int tables) ...@@ -2392,6 +2411,7 @@ static int dump_selected_tables(char *db, char **table_names, int tables)
} }
if (opt_xml) if (opt_xml)
print_xml_tag1(md_result_file, "", "database name=", db, "\n"); print_xml_tag1(md_result_file, "", "database name=", db, "\n");
/* Dump each selected table */ /* Dump each selected table */
const char *table_name; const char *table_name;
for (i= 0; i < dump_tables.records; i++) for (i= 0; i < dump_tables.records; i++)
...@@ -2401,6 +2421,8 @@ static int dump_selected_tables(char *db, char **table_names, int tables) ...@@ -2401,6 +2421,8 @@ static int dump_selected_tables(char *db, char **table_names, int tables)
numrows = get_table_structure(table_name, db); numrows = get_table_structure(table_name, db);
dump_table(numrows, table_name); dump_table(numrows, table_name);
} }
/* Dump each selected view */
if (was_views) if (was_views)
{ {
for(i=0; i < dump_tables.records; i++) for(i=0; i < dump_tables.records; i++)
......
...@@ -1529,6 +1529,28 @@ CREATE TABLE `t2` ( ...@@ -1529,6 +1529,28 @@ CREATE TABLE `t2` (
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
<?xml version="1.0"?>
<mysqldump>
<database name="mysqldump_test_db">
<table_structure name="t1">
<field Field="a" Type="int(11)" Null="YES" Key="" Extra="" />
</table_structure>
<table_structure name="t2">
<field Field="a" Type="int(11)" Null="YES" Key="" Extra="" />
</table_structure>
</database>
</mysqldump>
<?xml version="1.0"?>
<mysqldump>
<database name="mysqldump_test_db">
<table_structure name="t1">
<field Field="a" Type="int(11)" Null="YES" Key="" Extra="" />
</table_structure>
<table_structure name="t2">
<field Field="a" Type="int(11)" Null="YES" Key="" Extra="" />
</table_structure>
</database>
</mysqldump>
DROP TABLE t1, t2; DROP TABLE t1, t2;
DROP DATABASE mysqldump_test_db; DROP DATABASE mysqldump_test_db;
create database mysqldump_test_db; create database mysqldump_test_db;
......
...@@ -600,6 +600,8 @@ INSERT INTO t1 VALUES (1), (2); ...@@ -600,6 +600,8 @@ INSERT INTO t1 VALUES (1), (2);
INSERT INTO t2 VALUES (1), (2); INSERT INTO t2 VALUES (1), (2);
--exec $MYSQL_DUMP --skip-comments --no-data mysqldump_test_db --exec $MYSQL_DUMP --skip-comments --no-data mysqldump_test_db
--exec $MYSQL_DUMP --skip-comments --no-data mysqldump_test_db t1 t2 --exec $MYSQL_DUMP --skip-comments --no-data mysqldump_test_db t1 t2
--exec $MYSQL_DUMP --skip-comments --skip-create --xml --no-data mysqldump_test_db
--exec $MYSQL_DUMP --skip-comments --skip-create --xml --no-data mysqldump_test_db t1 t2
DROP TABLE t1, t2; DROP TABLE t1, t2;
DROP DATABASE mysqldump_test_db; DROP DATABASE mysqldump_test_db;
......
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