11/*
2- Copyright (c) 2000, 2016 , Oracle and/or its affiliates. All rights reserved.
2+ Copyright (c) 2000, 2017 , Oracle and/or its affiliates. All rights reserved.
33
44 This program is free software; you can redistribute it and/or modify
55 it under the terms of the GNU General Public License as published by
@@ -591,6 +591,7 @@ static int dump_tablespaces_for_databases(char** databases);
591591static int dump_tablespaces (char * ts_where );
592592static void print_comment (FILE * sql_file , my_bool is_error , const char * format ,
593593 ...);
594+ static const char * fix_identifier_with_newline (char * );
594595
595596
596597/*
@@ -705,7 +706,7 @@ static void write_header(FILE *sql_file, char *db_name)
705706 MACHINE_TYPE );
706707 print_comment (sql_file , 0 , "-- Host: %s Database: %s\n" ,
707708 current_host ? current_host : "localhost" ,
708- db_name ? db_name : "" );
709+ db_name ? fix_identifier_with_newline ( db_name ) : "" );
709710 print_comment (sql_file , 0 ,
710711 "-- ------------------------------------------------------\n"
711712 );
@@ -2150,6 +2151,30 @@ static void print_comment(FILE *sql_file, my_bool is_error, const char *format,
21502151 print_xml_comment (sql_file , strlen (comment_buff ), comment_buff );
21512152}
21522153
2154+ /*
2155+ This function accepts object names and prefixes -- wherever \n
2156+ character is found.
2157+
2158+ @param[in] object_name
2159+
2160+ @return
2161+ @retval fixed object name.
2162+ */
2163+
2164+ static const char * fix_identifier_with_newline (char * object_name )
2165+ {
2166+ static char buff [COMMENT_LENGTH ]= {0 };
2167+ char * ptr = buff ;
2168+ memset (buff , 0 , 255 );
2169+ while (* object_name )
2170+ {
2171+ * ptr ++ = * object_name ;
2172+ if (* object_name == '\n' )
2173+ ptr = my_stpcpy (ptr , "-- " );
2174+ object_name ++ ;
2175+ }
2176+ return buff ;
2177+ }
21532178
21542179/*
21552180 create_delimiter
@@ -2218,7 +2243,8 @@ static uint dump_events_for_db(char *db)
22182243 db , (ulong )strlen (db ), '\'' );
22192244 /* nice comments */
22202245 print_comment (sql_file , 0 ,
2221- "\n--\n-- Dumping events for database '%s'\n--\n" , db );
2246+ "\n--\n-- Dumping events for database '%s'\n--\n" ,
2247+ fix_identifier_with_newline (db ));
22222248
22232249 /*
22242250 not using "mysql_query_with_error_report" because we may have not
@@ -2431,7 +2457,8 @@ static uint dump_routines_for_db(char *db)
24312457 db , (ulong )strlen (db ), '\'' );
24322458 /* nice comments */
24332459 print_comment (sql_file , 0 ,
2434- "\n--\n-- Dumping routines for database '%s'\n--\n" , db );
2460+ "\n--\n-- Dumping routines for database '%s'\n--\n" ,
2461+ fix_identifier_with_newline (db ));
24352462
24362463 /*
24372464 not using "mysql_query_with_error_report" because we may have not
@@ -2490,7 +2517,7 @@ static uint dump_routines_for_db(char *db)
24902517 query_buff );
24912518 print_comment (sql_file , 1 ,
24922519 "-- does %s have permissions on mysql.proc?\n\n" ,
2493- current_user );
2520+ fix_identifier_with_newline ( current_user ) );
24942521 maybe_die (EX_MYSQLERR ,"%s has insufficent privileges to %s!" , current_user , query_buff );
24952522 }
24962523 else if (strlen (row [2 ]))
@@ -2696,12 +2723,12 @@ static uint get_table_structure(char *table, char *db, char *table_type,
26962723
26972724 if (strcmp (table_type , "VIEW" ) == 0 ) /* view */
26982725 print_comment (sql_file , 0 ,
2699- "\n--\n-- Temporary view structure for view %s\n--\n\n" ,
2700- result_table );
2726+ "\n--\n-- Temporary table structure for view %s\n--\n\n" ,
2727+ fix_identifier_with_newline ( result_table ) );
27012728 else
27022729 print_comment (sql_file , 0 ,
27032730 "\n--\n-- Table structure for table %s\n--\n\n" ,
2704- result_table );
2731+ fix_identifier_with_newline ( result_table ) );
27052732
27062733 if (opt_drop )
27072734 {
@@ -2988,7 +3015,7 @@ static uint get_table_structure(char *table, char *db, char *table_type,
29883015
29893016 print_comment (sql_file , 0 ,
29903017 "\n--\n-- Table structure for table %s\n--\n\n" ,
2991- result_table );
3018+ fix_identifier_with_newline ( result_table ) );
29923019 if (opt_drop )
29933020 fprintf (sql_file , "DROP TABLE IF EXISTS %s;\n" , result_table );
29943021 if (!opt_xml )
@@ -3704,14 +3731,15 @@ static void dump_table(char *table, char *db)
37043731 {
37053732 print_comment (md_result_file , 0 ,
37063733 "\n--\n-- Dumping data for table %s\n--\n" ,
3707- result_table );
3734+ fix_identifier_with_newline ( result_table ) );
37083735
37093736 dynstr_append_checked (& query_string , "SELECT /*!40001 SQL_NO_CACHE */ * FROM " );
37103737 dynstr_append_checked (& query_string , result_table );
37113738
37123739 if (where )
37133740 {
3714- print_comment (md_result_file , 0 , "-- WHERE: %s\n" , where );
3741+ print_comment (md_result_file , 0 , "-- WHERE: %s\n" ,
3742+ fix_identifier_with_newline (where ));
37153743
37163744 dynstr_append_checked (& query_string , " WHERE " );
37173745 dynstr_append_checked (& query_string , where );
@@ -3728,7 +3756,8 @@ static void dump_table(char *table, char *db)
37283756 }
37293757 if (order_by )
37303758 {
3731- print_comment (md_result_file , 0 , "-- ORDER BY: %s\n" , order_by );
3759+ print_comment (md_result_file , 0 , "-- ORDER BY: %s\n" ,
3760+ fix_identifier_with_newline (order_by ));
37323761
37333762 dynstr_append_checked (& query_string , " ORDER BY " );
37343763 dynstr_append_checked (& query_string , order_by );
@@ -4572,7 +4601,8 @@ static int init_dumping(char *database, int init_func(char*))
45724601 char * qdatabase = quote_name (database ,quoted_database_buf ,opt_quoted );
45734602
45744603 print_comment (md_result_file , 0 ,
4575- "\n--\n-- Current Database: %s\n--\n" , qdatabase );
4604+ "\n--\n-- Current Database: %s\n--\n" ,
4605+ fix_identifier_with_newline (qdatabase ));
45764606
45774607 /* Call the view or table specific function */
45784608 init_func (qdatabase );
@@ -5802,7 +5832,7 @@ static my_bool get_view_structure(char *table, char* db)
58025832
58035833 print_comment (sql_file , 0 ,
58045834 "\n--\n-- Final view structure for view %s\n--\n\n" ,
5805- result_table );
5835+ fix_identifier_with_newline ( result_table ) );
58065836
58075837 verbose_msg ("-- Dropping the temporary view structure created\n" );
58085838 fprintf (sql_file , "/*!50001 DROP VIEW IF EXISTS %s*/;\n" , opt_quoted_table );
0 commit comments