From c41b767a264ba74cd571d9ce0d9983643a4e1c86 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 19 May 2006 16:21:32 +0500 Subject: [PATCH] Fix for bug #18536: mysqldump does not maintain table orders as per --tables option client/mysqldump.c: Fix for bug #18536: mysqldump does not maintain table orders as per --tables option - use list to store table names instead of hash. mysql-test/r/mysqldump.result: Fix for bug #18536: mysqldump does not maintain table orders as per --tables option - test result. mysql-test/t/mysqldump.test: Fix for bug #18536: mysqldump does not maintain table orders as per --tables option - test case. --- client/mysqldump.c | 54 ++++++++++++++--------------------- mysql-test/r/mysqldump.result | 36 ++++++++++++++++++++++- mysql-test/t/mysqldump.test | 13 ++++++++- 3 files changed, 68 insertions(+), 35 deletions(-) diff --git a/client/mysqldump.c b/client/mysqldump.c index 64629bcf608..e8f96016153 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -2215,14 +2215,13 @@ static int dump_all_tables_in_db(char *database) different case (e.g. T1 vs t1) RETURN - int - 0 if a tablename was retrieved. 1 if not + pointer to the table name + 0 if error */ -static int get_actual_table_name(const char *old_table_name, - char *new_table_name, - int buf_size) +static char *get_actual_table_name(const char *old_table_name, MEM_ROOT *root) { - int retval; + char *name= 0; MYSQL_RES *tableRes; MYSQL_ROW row; char query[50 + 2*NAME_LEN]; @@ -2241,40 +2240,36 @@ static int get_actual_table_name(const char *old_table_name, } tableRes= mysql_store_result( sock ); - retval = 1; if (tableRes != NULL) { my_ulonglong numRows= mysql_num_rows(tableRes); if (numRows > 0) { row= mysql_fetch_row( tableRes ); - strmake(new_table_name, row[0], buf_size-1); - retval= 0; - DBUG_PRINT("info", ("new_table_name: %s", new_table_name)); + ulong *lengths= mysql_fetch_lengths(tableRes); + name= strmake_root(root, row[0], lengths[0]); } mysql_free_result(tableRes); } - DBUG_PRINT("exit", ("retval: %d", retval)); - DBUG_RETURN(retval); + DBUG_PRINT("exit", ("new_table_name: %s", name)); + DBUG_RETURN(name); } static int dump_selected_tables(char *db, char **table_names, int tables) { - uint numrows, i; + uint numrows; char table_buff[NAME_LEN*+3]; - char new_table_name[NAME_LEN]; DYNAMIC_STRING lock_tables_query; - HASH dump_tables; + MEM_ROOT root; + char **dump_tables, **pos; DBUG_ENTER("dump_selected_tables"); if (init_dumping(db)) return 1; - /* Init hash table for storing the actual name of tables to dump */ - if (hash_init(&dump_tables, charset_info, 16, 0, 0, - (hash_get_key) get_table_key, (hash_free_key) free_table_ent, - 0)) + init_alloc_root(&root, 8192, 0); + if (!(dump_tables= pos= (char**) alloc_root(&root, tables * sizeof(char *)))) exit(EX_EOM); init_dynamic_string(&lock_tables_query, "LOCK TABLES ", 256, 1024); @@ -2282,22 +2277,16 @@ static int dump_selected_tables(char *db, char **table_names, int tables) { /* the table name passed on commandline may be wrong case */ - if (!get_actual_table_name(*table_names, - new_table_name, sizeof(new_table_name) )) + if ((*pos= get_actual_table_name(*table_names, &root))) { /* Add found table name to lock_tables_query */ if (lock_tables) { dynstr_append(&lock_tables_query, - quote_name(new_table_name, table_buff, 1)); + quote_name(*pos, table_buff, 1)); dynstr_append(&lock_tables_query, " READ /*!32311 LOCAL */,"); } - - /* Add found table name to dump_tables list */ - if (my_hash_insert(&dump_tables, - (byte*)my_strdup(new_table_name, MYF(0)))) - exit(EX_EOM); - + pos++; } else { @@ -2326,15 +2315,14 @@ static int dump_selected_tables(char *db, char **table_names, int tables) print_xml_tag1(md_result_file, "", "database name=", db, "\n"); /* Dump each selected table */ - for (i= 0 ; i < dump_tables.records ; i++) + for (; dump_tables < pos; dump_tables++) { - const char *table_name= hash_element(&dump_tables, i); - DBUG_PRINT("info",("Dumping table %s", table_name)); - numrows= getTableStructure((char*) table_name, db); + DBUG_PRINT("info",("Dumping table %s", *dump_tables)); + numrows= getTableStructure(*dump_tables, db); if (!dFlag && numrows > 0) - dumpTable(numrows, (char*) table_name); + dumpTable(numrows, *dump_tables); } - hash_free(&dump_tables); + free_root(&root, MYF(0)); my_free(order_by, MYF(MY_ALLOW_ZERO_PTR)); order_by= 0; if (opt_xml) diff --git a/mysql-test/r/mysqldump.result b/mysql-test/r/mysqldump.result index 4109e9d13ec..ca2643b081a 100644 --- a/mysql-test/r/mysqldump.result +++ b/mysql-test/r/mysqldump.result @@ -1,4 +1,4 @@ -DROP TABLE IF EXISTS t1, `"t"1`; +DROP TABLE IF EXISTS t1, `"t"1`, t2, t3; CREATE TABLE t1(a int); INSERT INTO t1 VALUES (1), (2); @@ -1540,4 +1540,38 @@ t1 CREATE TABLE `t1` ( KEY `t1_name` (`t1_name`) ) ENGINE=MyISAM AUTO_INCREMENT=1003 DEFAULT CHARSET=latin1 drop table `t1`; +create table t1(a int); +create table t2(a int); +create table t3(a int); + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; +DROP TABLE IF EXISTS `t3`; +CREATE TABLE `t3` ( + `a` int(11) default NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1; +DROP TABLE IF EXISTS `t1`; +CREATE TABLE `t1` ( + `a` int(11) default NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1; +DROP TABLE IF EXISTS `t2`; +CREATE TABLE `t2` ( + `a` int(11) default NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1; + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + +drop table t1, t2, t3; End of 4.1 tests diff --git a/mysql-test/t/mysqldump.test b/mysql-test/t/mysqldump.test index 3b83f8fea01..f24899fd8ae 100644 --- a/mysql-test/t/mysqldump.test +++ b/mysql-test/t/mysqldump.test @@ -2,7 +2,7 @@ --source include/not_embedded.inc --disable_warnings -DROP TABLE IF EXISTS t1, `"t"1`; +DROP TABLE IF EXISTS t1, `"t"1`, t2, t3; --enable_warnings # XML output @@ -677,4 +677,15 @@ show create table `t1`; drop table `t1`; +# +# Bug #18536: wrong table order +# + +create table t1(a int); +create table t2(a int); +create table t3(a int); +--error 6 +--exec $MYSQL_DUMP --skip-comments --force --no-data test t3 t1 non_existing t2 +drop table t1, t2, t3; + --echo End of 4.1 tests