Commit 876502d7 authored by Nirbhay Choubey's avatar Nirbhay Choubey

Bug#11766310 : 59398: MYSQLDUMP 5.1 CAN'T HANDLE A DASH

               ("-") IN DATABASE NAMES IN ALTER DATABASE.

mysqldump did not quote database name in 'ALTER DATABASE'
statements in its output. This can further cause a failure
while loading if database name contains a hyphen '-'.

This happened as, while printing the 'ALTER DATABASE'
statements, the database name was not quoted.

Fixed by quoting the database name.


client/mysqldump.c:
  Bug#11766310 : 59398: MYSQLDUMP 5.1 CAN'T HANDLE A DASH
                 ("-") IN DATABASE NAMES IN ALTER DATABASE.
  
  Modified the print statement in order to print the quoted
  database name for 'ALTER DATABASE' statements.
mysql-test/r/mysqldump.result:
  Added a test case for bug#11766310.
mysql-test/t/mysqldump.test:
  Added a test case for bug#11766310.
parent e2e6eb8f
......@@ -1134,6 +1134,9 @@ static int switch_db_collation(FILE *sql_file,
{
if (strcmp(current_db_cl_name, required_db_cl_name) != 0)
{
char quoted_db_buf[NAME_LEN * 2 + 3];
char *quoted_db_name= quote_name(db_name, quoted_db_buf, FALSE);
CHARSET_INFO *db_cl= get_charset_by_name(required_db_cl_name, MYF(0));
if (!db_cl)
......@@ -1141,7 +1144,7 @@ static int switch_db_collation(FILE *sql_file,
fprintf(sql_file,
"ALTER DATABASE %s CHARACTER SET %s COLLATE %s %s\n",
(const char *) db_name,
(const char *) quoted_db_name,
(const char *) db_cl->csname,
(const char *) db_cl->name,
(const char *) delimiter);
......@@ -1162,6 +1165,9 @@ static int restore_db_collation(FILE *sql_file,
const char *delimiter,
const char *db_cl_name)
{
char quoted_db_buf[NAME_LEN * 2 + 3];
char *quoted_db_name= quote_name(db_name, quoted_db_buf, FALSE);
CHARSET_INFO *db_cl= get_charset_by_name(db_cl_name, MYF(0));
if (!db_cl)
......@@ -1169,7 +1175,7 @@ static int restore_db_collation(FILE *sql_file,
fprintf(sql_file,
"ALTER DATABASE %s CHARACTER SET %s COLLATE %s %s\n",
(const char *) db_name,
(const char *) quoted_db_name,
(const char *) db_cl->csname,
(const char *) db_cl->name,
(const char *) delimiter);
......
......@@ -4591,5 +4591,41 @@ CREATE TABLE `comment_table` (i INT COMMENT 'FIELD COMMENT') COMMENT = 'TABLE CO
</mysqldump>
DROP TABLE `comment_table`;
#
# BUG#11766310 : 59398: MYSQLDUMP 5.1 CAN'T HANDLE A DASH ("-") IN
# DATABASE NAMES IN ALTER DATABASE
#
CREATE DATABASE `test-database`;
USE `test-database`;
CREATE TABLE `test` (`c1` VARCHAR(10)) ENGINE=MYISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
CREATE TRIGGER `trig` BEFORE INSERT ON `test` FOR EACH ROW BEGIN
END |
ALTER DATABASE `test-database` CHARACTER SET latin1 COLLATE latin1_swedish_ci;
ALTER DATABASE `test-database` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `test` (
`c1` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
ALTER DATABASE `test-database` 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 = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = '' */ ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `trig` BEFORE INSERT ON `test` FOR EACH ROW 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 `test-database` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
DROP DATABASE `test-database`;
#
# End of 5.1 tests
#
......@@ -2173,6 +2173,27 @@ CREATE TABLE `comment_table` (i INT COMMENT 'FIELD COMMENT') COMMENT = 'TABLE CO
--exec $MYSQL_DUMP --compact --skip-create --xml test
DROP TABLE `comment_table`;
--echo #
--echo # BUG#11766310 : 59398: MYSQLDUMP 5.1 CAN'T HANDLE A DASH ("-") IN
--echo # DATABASE NAMES IN ALTER DATABASE
--echo #
CREATE DATABASE `test-database`;
USE `test-database`;
CREATE TABLE `test` (`c1` VARCHAR(10)) ENGINE=MYISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
DELIMITER |;
CREATE TRIGGER `trig` BEFORE INSERT ON `test` FOR EACH ROW BEGIN
END |
DELIMITER ;|
ALTER DATABASE `test-database` CHARACTER SET latin1 COLLATE latin1_swedish_ci;
ALTER DATABASE `test-database` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
--exec $MYSQL_DUMP --quote-names --compact test-database
DROP DATABASE `test-database`;
--echo #
--echo # End of 5.1 tests
--echo #
......
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