@@ -582,6 +582,7 @@ static int dump_tablespaces_for_databases(char** databases);
582
582
static int dump_tablespaces (char * ts_where );
583
583
static void print_comment (FILE * sql_file , my_bool is_error , const char * format ,
584
584
...);
585
+ static const char * fix_identifier_with_newline (char * );
585
586
586
587
587
588
/*
@@ -682,7 +683,7 @@ static void write_header(FILE *sql_file, char *db_name)
682
683
MACHINE_TYPE );
683
684
print_comment (sql_file , 0 , "-- Host: %s Database: %s\n" ,
684
685
current_host ? current_host : "localhost" ,
685
- db_name ? db_name : "" );
686
+ db_name ? fix_identifier_with_newline ( db_name ) : "" );
686
687
print_comment (sql_file , 0 ,
687
688
"-- ------------------------------------------------------\n"
688
689
);
@@ -2036,6 +2037,30 @@ static void print_comment(FILE *sql_file, my_bool is_error, const char *format,
2036
2037
print_xml_comment (sql_file , strlen (comment_buff ), comment_buff );
2037
2038
}
2038
2039
2040
+ /*
2041
+ This function accepts object names and prefixes -- wherever \n
2042
+ character is found.
2043
+
2044
+ @param[in] object_name
2045
+
2046
+ @return
2047
+ @retval fixed object name.
2048
+ */
2049
+
2050
+ static const char * fix_identifier_with_newline (char * object_name )
2051
+ {
2052
+ static char buff [COMMENT_LENGTH ]= {0 };
2053
+ char * ptr = buff ;
2054
+ memset (buff , 0 , 255 );
2055
+ while (* object_name )
2056
+ {
2057
+ * ptr ++ = * object_name ;
2058
+ if (* object_name == '\n' )
2059
+ ptr = strmov (ptr , "-- " );
2060
+ object_name ++ ;
2061
+ }
2062
+ return buff ;
2063
+ }
2039
2064
2040
2065
/*
2041
2066
create_delimiter
@@ -2104,7 +2129,8 @@ static uint dump_events_for_db(char *db)
2104
2129
2105
2130
/* nice comments */
2106
2131
print_comment (sql_file , 0 ,
2107
- "\n--\n-- Dumping events for database '%s'\n--\n" , db );
2132
+ "\n--\n-- Dumping events for database '%s'\n--\n" ,
2133
+ fix_identifier_with_newline (db ));
2108
2134
2109
2135
/*
2110
2136
not using "mysql_query_with_error_report" because we may have not
@@ -2321,7 +2347,8 @@ static uint dump_routines_for_db(char *db)
2321
2347
2322
2348
/* nice comments */
2323
2349
print_comment (sql_file , 0 ,
2324
- "\n--\n-- Dumping routines for database '%s'\n--\n" , db );
2350
+ "\n--\n-- Dumping routines for database '%s'\n--\n" ,
2351
+ fix_identifier_with_newline (db ));
2325
2352
2326
2353
/*
2327
2354
not using "mysql_query_with_error_report" because we may have not
@@ -2380,7 +2407,7 @@ static uint dump_routines_for_db(char *db)
2380
2407
query_buff );
2381
2408
print_comment (sql_file , 1 ,
2382
2409
"-- does %s have permissions on mysql.proc?\n\n" ,
2383
- current_user );
2410
+ fix_identifier_with_newline ( current_user ) );
2384
2411
maybe_die (EX_MYSQLERR ,"%s has insufficent privileges to %s!" , current_user , query_buff );
2385
2412
}
2386
2413
else if (strlen (row [2 ]))
@@ -2593,12 +2620,12 @@ static uint get_table_structure(char *table, char *db, char *table_type,
2593
2620
2594
2621
if (strcmp (table_type , "VIEW" ) == 0 ) /* view */
2595
2622
print_comment (sql_file , 0 ,
2596
- "\n--\n-- Temporary view structure for view %s\n--\n\n" ,
2597
- result_table );
2623
+ "\n--\n-- Temporary table structure for view %s\n--\n\n" ,
2624
+ fix_identifier_with_newline ( result_table ) );
2598
2625
else
2599
2626
print_comment (sql_file , 0 ,
2600
2627
"\n--\n-- Table structure for table %s\n--\n\n" ,
2601
- result_table );
2628
+ fix_identifier_with_newline ( result_table ) );
2602
2629
2603
2630
if (opt_drop )
2604
2631
{
@@ -2833,7 +2860,7 @@ static uint get_table_structure(char *table, char *db, char *table_type,
2833
2860
2834
2861
print_comment (sql_file , 0 ,
2835
2862
"\n--\n-- Table structure for table %s\n--\n\n" ,
2836
- result_table );
2863
+ fix_identifier_with_newline ( result_table ) );
2837
2864
if (opt_drop )
2838
2865
fprintf (sql_file , "DROP TABLE IF EXISTS %s;\n" , result_table );
2839
2866
if (!opt_xml )
@@ -3531,21 +3558,23 @@ static void dump_table(char *table, char *db)
3531
3558
{
3532
3559
print_comment (md_result_file , 0 ,
3533
3560
"\n--\n-- Dumping data for table %s\n--\n" ,
3534
- result_table );
3561
+ fix_identifier_with_newline ( result_table ) );
3535
3562
3536
3563
dynstr_append_checked (& query_string , "SELECT /*!40001 SQL_NO_CACHE */ * FROM " );
3537
3564
dynstr_append_checked (& query_string , result_table );
3538
3565
3539
3566
if (where )
3540
3567
{
3541
- print_comment (md_result_file , 0 , "-- WHERE: %s\n" , where );
3568
+ print_comment (md_result_file , 0 , "-- WHERE: %s\n" ,
3569
+ fix_identifier_with_newline (where ));
3542
3570
3543
3571
dynstr_append_checked (& query_string , " WHERE " );
3544
3572
dynstr_append_checked (& query_string , where );
3545
3573
}
3546
3574
if (order_by )
3547
3575
{
3548
- print_comment (md_result_file , 0 , "-- ORDER BY: %s\n" , order_by );
3576
+ print_comment (md_result_file , 0 , "-- ORDER BY: %s\n" ,
3577
+ fix_identifier_with_newline (order_by ));
3549
3578
3550
3579
dynstr_append_checked (& query_string , " ORDER BY " );
3551
3580
dynstr_append_checked (& query_string , order_by );
@@ -4371,7 +4400,8 @@ static int init_dumping(char *database, int init_func(char*))
4371
4400
char * qdatabase = quote_name (database ,quoted_database_buf ,opt_quoted );
4372
4401
4373
4402
print_comment (md_result_file , 0 ,
4374
- "\n--\n-- Current Database: %s\n--\n" , qdatabase );
4403
+ "\n--\n-- Current Database: %s\n--\n" ,
4404
+ fix_identifier_with_newline (qdatabase ));
4375
4405
4376
4406
/* Call the view or table specific function */
4377
4407
init_func (qdatabase );
@@ -5597,7 +5627,7 @@ static my_bool get_view_structure(char *table, char* db)
5597
5627
5598
5628
print_comment (sql_file , 0 ,
5599
5629
"\n--\n-- Final view structure for view %s\n--\n\n" ,
5600
- result_table );
5630
+ fix_identifier_with_newline ( result_table ) );
5601
5631
5602
5632
verbose_msg ("-- Dropping the temporary view structure created\n" );
5603
5633
fprintf (sql_file , "/*!50001 DROP VIEW IF EXISTS %s*/;\n" , opt_quoted_table );
0 commit comments