Commit 9f07c6b3 authored by Sergey Vojtovich's avatar Sergey Vojtovich

MDEV-9001 - [PATCH] Fix DB name quoting in mysqldump --routine

mysqldump --routine fails to dump databases containing backslash ("\")
character. This happened because escaped database name was being used as an
identifier while changing current database. Such identifers are not supposed
to be escaped, they must be properly quoted instead.
parent 33589b25
......@@ -1119,13 +1119,12 @@ static int fetch_db_collation(const char *db_name,
char query[QUERY_LENGTH];
MYSQL_RES *db_cl_res;
MYSQL_ROW db_cl_row;
char quoted_database_buf[NAME_LEN*2+3];
char *qdatabase= quote_name(db_name, quoted_database_buf, 1);
my_snprintf(query, sizeof (query), "use %s", qdatabase);
if (mysql_query_with_error_report(mysql, NULL, query))
return 1;
if (mysql_select_db(mysql, db_name))
{
DB_error(mysql, "when selecting the database");
return 1; /* If --force */
}
if (mysql_query_with_error_report(mysql, &db_cl_res,
"select @@collation_database"))
......@@ -2319,7 +2318,7 @@ static uint dump_routines_for_db(char *db)
/* Get database collation. */
if (fetch_db_collation(db_name_buff, db_cl_name, sizeof (db_cl_name)))
if (fetch_db_collation(db, db_cl_name, sizeof (db_cl_name)))
DBUG_RETURN(1);
if (switch_character_set_results(mysql, "binary"))
......@@ -2388,7 +2387,7 @@ static uint dump_routines_for_db(char *db)
if (mysql_num_fields(routine_res) >= 6)
{
if (switch_db_collation(sql_file, db_name_buff, ";",
if (switch_db_collation(sql_file, db, ";",
db_cl_name, row[5], &db_cl_altered))
{
DBUG_RETURN(1);
......@@ -2435,7 +2434,7 @@ static uint dump_routines_for_db(char *db)
if (db_cl_altered)
{
if (restore_db_collation(sql_file, db_name_buff, ";", db_cl_name))
if (restore_db_collation(sql_file, db, ";", db_cl_name))
DBUG_RETURN(1);
}
}
......
......@@ -5312,3 +5312,29 @@ Usage: mysqldump [OPTIONS] database [tables]
OR mysqldump [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]
OR mysqldump [OPTIONS] --all-databases [OPTIONS]
For more options, use mysqldump --help
#
# MDEV-9001 - [PATCH] Fix DB name quoting in mysqldump --routine
#
CREATE DATABASE `a\"'``b`;
USE `a\"'``b`;
CREATE PROCEDURE p1() BEGIN END;
ALTER DATABASE `a\"'``b` COLLATE utf8_general_ci;
ALTER DATABASE `a\"'``b` CHARACTER SET latin1 COLLATE latin1_swedish_ci ;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client = utf8 */ ;
/*!50003 SET character_set_results = utf8 */ ;
/*!50003 SET collation_connection = utf8_general_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `p1`()
BEGIN END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
/*!50003 SET character_set_client = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection = @saved_col_connection */ ;
ALTER DATABASE `a\"'``b` CHARACTER SET utf8 COLLATE utf8_general_ci ;
DROP DATABASE `a\"'``b`;
......@@ -2494,3 +2494,13 @@ DROP DATABASE db_20772273;
--exec $MYSQL_DUMP --user=foo 2>&1 > $MYSQLTEST_VARDIR/tmp/bug6056.out
--exec $MYSQL_DUMP --help > $MYSQLTEST_VARDIR/tmp/bug6056.out
--echo #
--echo # MDEV-9001 - [PATCH] Fix DB name quoting in mysqldump --routine
--echo #
CREATE DATABASE `a\"'``b`;
USE `a\"'``b`;
CREATE PROCEDURE p1() BEGIN END;
ALTER DATABASE `a\"'``b` COLLATE utf8_general_ci;
--exec $MYSQL_DUMP --routines --compact a\\\"\'\`b 2>&1
DROP DATABASE `a\"'``b`;
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