mirror of
https://github.com/MariaDB/server.git
synced 2025-08-01 03:47:19 +03:00
mysqldump: comments and identifiers with new lines
don't let identifiers with new lines to break a comment
This commit is contained in:
@ -547,9 +547,7 @@ static int dump_all_tablespaces();
|
||||
static int dump_tablespaces_for_tables(char *db, char **table_names, int tables);
|
||||
static int dump_tablespaces_for_databases(char** databases);
|
||||
static int dump_tablespaces(char* ts_where);
|
||||
static void print_comment(FILE *sql_file, my_bool is_error, const char *format,
|
||||
...);
|
||||
|
||||
static void print_comment(FILE *, my_bool, const char *, ...);
|
||||
|
||||
/*
|
||||
Print the supplied message if in verbose mode
|
||||
@ -627,6 +625,30 @@ static void short_usage(FILE *f)
|
||||
}
|
||||
|
||||
|
||||
/** returns a string fixed to be safely printed inside a -- comment
|
||||
|
||||
that is, any new line in it gets prefixed with --
|
||||
*/
|
||||
static const char *fix_for_comment(const char *ident)
|
||||
{
|
||||
static char buf[1024];
|
||||
char c, *s= buf;
|
||||
|
||||
while ((c= *s++= *ident++))
|
||||
{
|
||||
if (s >= buf + sizeof(buf) - 10)
|
||||
{
|
||||
strmov(s, "...");
|
||||
break;
|
||||
}
|
||||
if (c == '\n')
|
||||
s= strmov(s, "-- ");
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
||||
static void write_header(FILE *sql_file, char *db_name)
|
||||
{
|
||||
if (opt_xml)
|
||||
@ -649,8 +671,8 @@ static void write_header(FILE *sql_file, char *db_name)
|
||||
DUMP_VERSION, MYSQL_SERVER_VERSION, SYSTEM_TYPE,
|
||||
MACHINE_TYPE);
|
||||
print_comment(sql_file, 0, "-- Host: %s Database: %s\n",
|
||||
current_host ? current_host : "localhost",
|
||||
db_name ? db_name : "");
|
||||
fix_for_comment(current_host ? current_host : "localhost"),
|
||||
fix_for_comment(db_name ? db_name : ""));
|
||||
print_comment(sql_file, 0,
|
||||
"-- ------------------------------------------------------\n"
|
||||
);
|
||||
@ -2094,7 +2116,8 @@ static uint dump_events_for_db(char *db)
|
||||
|
||||
/* nice comments */
|
||||
print_comment(sql_file, 0,
|
||||
"\n--\n-- Dumping events for database '%s'\n--\n", db);
|
||||
"\n--\n-- Dumping events for database '%s'\n--\n",
|
||||
fix_for_comment(db));
|
||||
|
||||
/*
|
||||
not using "mysql_query_with_error_report" because we may have not
|
||||
@ -2307,7 +2330,8 @@ static uint dump_routines_for_db(char *db)
|
||||
|
||||
/* nice comments */
|
||||
print_comment(sql_file, 0,
|
||||
"\n--\n-- Dumping routines for database '%s'\n--\n", db);
|
||||
"\n--\n-- Dumping routines for database '%s'\n--\n",
|
||||
fix_for_comment(db));
|
||||
|
||||
/*
|
||||
not using "mysql_query_with_error_report" because we may have not
|
||||
@ -2580,11 +2604,11 @@ static uint get_table_structure(char *table, char *db, char *table_type,
|
||||
if (strcmp (table_type, "VIEW") == 0) /* view */
|
||||
print_comment(sql_file, 0,
|
||||
"\n--\n-- Temporary table structure for view %s\n--\n\n",
|
||||
result_table);
|
||||
fix_for_comment(result_table));
|
||||
else
|
||||
print_comment(sql_file, 0,
|
||||
"\n--\n-- Table structure for table %s\n--\n\n",
|
||||
result_table);
|
||||
fix_for_comment(result_table));
|
||||
|
||||
if (opt_drop)
|
||||
{
|
||||
@ -2826,7 +2850,7 @@ static uint get_table_structure(char *table, char *db, char *table_type,
|
||||
|
||||
print_comment(sql_file, 0,
|
||||
"\n--\n-- Table structure for table %s\n--\n\n",
|
||||
result_table);
|
||||
fix_for_comment(result_table));
|
||||
if (opt_drop)
|
||||
fprintf(sql_file, "DROP TABLE IF EXISTS %s;\n", result_table);
|
||||
if (!opt_xml)
|
||||
@ -3530,21 +3554,21 @@ static void dump_table(char *table, char *db)
|
||||
{
|
||||
print_comment(md_result_file, 0,
|
||||
"\n--\n-- Dumping data for table %s\n--\n",
|
||||
result_table);
|
||||
fix_for_comment(result_table));
|
||||
|
||||
dynstr_append_checked(&query_string, "SELECT /*!40001 SQL_NO_CACHE */ * FROM ");
|
||||
dynstr_append_checked(&query_string, result_table);
|
||||
|
||||
if (where)
|
||||
{
|
||||
print_comment(md_result_file, 0, "-- WHERE: %s\n", where);
|
||||
print_comment(md_result_file, 0, "-- WHERE: %s\n", fix_for_comment(where));
|
||||
|
||||
dynstr_append_checked(&query_string, " WHERE ");
|
||||
dynstr_append_checked(&query_string, where);
|
||||
}
|
||||
if (order_by)
|
||||
{
|
||||
print_comment(md_result_file, 0, "-- ORDER BY: %s\n", order_by);
|
||||
print_comment(md_result_file, 0, "-- ORDER BY: %s\n", fix_for_comment(order_by));
|
||||
|
||||
dynstr_append_checked(&query_string, " ORDER BY ");
|
||||
dynstr_append_checked(&query_string, order_by);
|
||||
@ -4053,7 +4077,7 @@ static int dump_tablespaces(char* ts_where)
|
||||
if (first)
|
||||
{
|
||||
print_comment(md_result_file, 0, "\n--\n-- Logfile group: %s\n--\n",
|
||||
row[0]);
|
||||
fix_for_comment(row[0]));
|
||||
|
||||
fprintf(md_result_file, "\nCREATE");
|
||||
}
|
||||
@ -4122,7 +4146,8 @@ static int dump_tablespaces(char* ts_where)
|
||||
first= 1;
|
||||
if (first)
|
||||
{
|
||||
print_comment(md_result_file, 0, "\n--\n-- Tablespace: %s\n--\n", row[0]);
|
||||
print_comment(md_result_file, 0, "\n--\n-- Tablespace: %s\n--\n",
|
||||
fix_for_comment(row[0]));
|
||||
fprintf(md_result_file, "\nCREATE");
|
||||
}
|
||||
else
|
||||
@ -4326,7 +4351,8 @@ static int init_dumping(char *database, int init_func(char*))
|
||||
char *qdatabase= quote_name(database,quoted_database_buf,opt_quoted);
|
||||
|
||||
print_comment(md_result_file, 0,
|
||||
"\n--\n-- Current Database: %s\n--\n", qdatabase);
|
||||
"\n--\n-- Current Database: %s\n--\n",
|
||||
fix_for_comment(qdatabase));
|
||||
|
||||
/* Call the view or table specific function */
|
||||
init_func(qdatabase);
|
||||
@ -5356,7 +5382,7 @@ static my_bool get_view_structure(char *table, char* db)
|
||||
|
||||
print_comment(sql_file, 0,
|
||||
"\n--\n-- Final view structure for view %s\n--\n\n",
|
||||
result_table);
|
||||
fix_for_comment(result_table));
|
||||
|
||||
/* Table might not exist if this view was dumped with --tab. */
|
||||
fprintf(sql_file, "/*!50001 DROP TABLE IF EXISTS %s*/;\n", opt_quoted_table);
|
||||
|
126
mysql-test/r/mysqldump-nl.result
Normal file
126
mysql-test/r/mysqldump-nl.result
Normal file
@ -0,0 +1,126 @@
|
||||
create database `mysqltest1
|
||||
1tsetlqsym`;
|
||||
use `mysqltest1
|
||||
1tsetlqsym`;
|
||||
create table `t1
|
||||
1t` (`foobar
|
||||
raboof` int);
|
||||
create view `v1
|
||||
1v` as select * from `t1
|
||||
1t`;
|
||||
create procedure sp() select * from `v1
|
||||
1v`;
|
||||
flush tables;
|
||||
use test;
|
||||
|
||||
--
|
||||
-- Current Database: `mysqltest1
|
||||
-- 1tsetlqsym`
|
||||
--
|
||||
|
||||
/*!40000 DROP DATABASE IF EXISTS `mysqltest1
|
||||
1tsetlqsym`*/;
|
||||
|
||||
CREATE DATABASE /*!32312 IF NOT EXISTS*/ `mysqltest1
|
||||
1tsetlqsym` /*!40100 DEFAULT CHARACTER SET latin1 */;
|
||||
|
||||
USE `mysqltest1
|
||||
1tsetlqsym`;
|
||||
|
||||
--
|
||||
-- Table structure for table `t1
|
||||
-- 1t`
|
||||
--
|
||||
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8 */;
|
||||
CREATE TABLE `t1
|
||||
1t` (
|
||||
`foobar
|
||||
raboof` int(11) DEFAULT NULL
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
-- Dumping data for table `t1
|
||||
-- 1t`
|
||||
--
|
||||
|
||||
--
|
||||
-- Temporary table structure for view `v1
|
||||
-- 1v`
|
||||
--
|
||||
|
||||
SET @saved_cs_client = @@character_set_client;
|
||||
SET character_set_client = utf8;
|
||||
/*!50001 CREATE TABLE `v1
|
||||
1v` (
|
||||
`foobar
|
||||
raboof` tinyint NOT NULL
|
||||
) ENGINE=MyISAM */;
|
||||
SET character_set_client = @saved_cs_client;
|
||||
|
||||
--
|
||||
-- Dumping routines for database 'mysqltest1
|
||||
-- 1tsetlqsym'
|
||||
--
|
||||
/*!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 ;;
|
||||
CREATE DEFINER=`root`@`localhost` PROCEDURE `sp`()
|
||||
select * from `v1
|
||||
1v` ;;
|
||||
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 */ ;
|
||||
|
||||
--
|
||||
-- Current Database: `mysqltest1
|
||||
-- 1tsetlqsym`
|
||||
--
|
||||
|
||||
USE `mysqltest1
|
||||
1tsetlqsym`;
|
||||
|
||||
--
|
||||
-- Final view structure for view `v1
|
||||
-- 1v`
|
||||
--
|
||||
|
||||
/*!50001 DROP TABLE IF EXISTS `v1
|
||||
1v`*/;
|
||||
/*!50001 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!50001 SET @saved_cs_results = @@character_set_results */;
|
||||
/*!50001 SET @saved_col_connection = @@collation_connection */;
|
||||
/*!50001 SET character_set_client = latin1 */;
|
||||
/*!50001 SET character_set_results = latin1 */;
|
||||
/*!50001 SET collation_connection = latin1_swedish_ci */;
|
||||
/*!50001 CREATE ALGORITHM=UNDEFINED */
|
||||
/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */
|
||||
/*!50001 VIEW `v1
|
||||
1v` AS select `t1
|
||||
1t`.`foobar
|
||||
raboof` AS `foobar
|
||||
raboof` from `t1
|
||||
1t` */;
|
||||
/*!50001 SET character_set_client = @saved_cs_client */;
|
||||
/*!50001 SET character_set_results = @saved_cs_results */;
|
||||
/*!50001 SET collation_connection = @saved_col_connection */;
|
||||
show tables from `mysqltest1
|
||||
1tsetlqsym`;
|
||||
Tables_in_mysqltest1
|
||||
1tsetlqsym
|
||||
t1
|
||||
1t
|
||||
v1
|
||||
1v
|
||||
drop database `mysqltest1
|
||||
1tsetlqsym`;
|
38
mysql-test/t/mysqldump-nl.test
Normal file
38
mysql-test/t/mysqldump-nl.test
Normal file
@ -0,0 +1,38 @@
|
||||
#
|
||||
# New lines in identifiers
|
||||
#
|
||||
|
||||
# embedded server doesn't support external clients
|
||||
--source include/not_embedded.inc
|
||||
# cmd.exe doesn't like new lines on the command line
|
||||
--source include/not_windows.inc
|
||||
|
||||
create database `mysqltest1
|
||||
1tsetlqsym`;
|
||||
use `mysqltest1
|
||||
1tsetlqsym`;
|
||||
|
||||
create table `t1
|
||||
1t` (`foobar
|
||||
raboof` int);
|
||||
create view `v1
|
||||
1v` as select * from `t1
|
||||
1t`;
|
||||
|
||||
create procedure sp() select * from `v1
|
||||
1v`;
|
||||
|
||||
flush tables;
|
||||
use test;
|
||||
|
||||
exec $MYSQL_DUMP --compact --comment --routines --add-drop-database --databases 'mysqltest1
|
||||
1tsetlqsym';
|
||||
|
||||
exec $MYSQL_DUMP --compact --comment --routines --add-drop-database --databases 'mysqltest1
|
||||
1tsetlqsym' | $MYSQL;
|
||||
|
||||
show tables from `mysqltest1
|
||||
1tsetlqsym`;
|
||||
|
||||
drop database `mysqltest1
|
||||
1tsetlqsym`;
|
Reference in New Issue
Block a user