1
1
/*
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.
3
3
4
4
This program is free software; you can redistribute it and/or modify
5
5
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);
591
591
static int dump_tablespaces (char * ts_where );
592
592
static void print_comment (FILE * sql_file , my_bool is_error , const char * format ,
593
593
...);
594
+ static const char * fix_identifier_with_newline (char * );
594
595
595
596
596
597
/*
@@ -705,7 +706,7 @@ static void write_header(FILE *sql_file, char *db_name)
705
706
MACHINE_TYPE );
706
707
print_comment (sql_file , 0 , "-- Host: %s Database: %s\n" ,
707
708
current_host ? current_host : "localhost" ,
708
- db_name ? db_name : "" );
709
+ db_name ? fix_identifier_with_newline ( db_name ) : "" );
709
710
print_comment (sql_file , 0 ,
710
711
"-- ------------------------------------------------------\n"
711
712
);
@@ -2150,6 +2151,30 @@ static void print_comment(FILE *sql_file, my_bool is_error, const char *format,
2150
2151
print_xml_comment (sql_file , strlen (comment_buff ), comment_buff );
2151
2152
}
2152
2153
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
+ }
2153
2178
2154
2179
/*
2155
2180
create_delimiter
@@ -2218,7 +2243,8 @@ static uint dump_events_for_db(char *db)
2218
2243
db , (ulong )strlen (db ), '\'' );
2219
2244
/* nice comments */
2220
2245
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 ));
2222
2248
2223
2249
/*
2224
2250
not using "mysql_query_with_error_report" because we may have not
@@ -2431,7 +2457,8 @@ static uint dump_routines_for_db(char *db)
2431
2457
db , (ulong )strlen (db ), '\'' );
2432
2458
/* nice comments */
2433
2459
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 ));
2435
2462
2436
2463
/*
2437
2464
not using "mysql_query_with_error_report" because we may have not
@@ -2490,7 +2517,7 @@ static uint dump_routines_for_db(char *db)
2490
2517
query_buff );
2491
2518
print_comment (sql_file , 1 ,
2492
2519
"-- does %s have permissions on mysql.proc?\n\n" ,
2493
- current_user );
2520
+ fix_identifier_with_newline ( current_user ) );
2494
2521
maybe_die (EX_MYSQLERR ,"%s has insufficent privileges to %s!" , current_user , query_buff );
2495
2522
}
2496
2523
else if (strlen (row [2 ]))
@@ -2696,12 +2723,12 @@ static uint get_table_structure(char *table, char *db, char *table_type,
2696
2723
2697
2724
if (strcmp (table_type , "VIEW" ) == 0 ) /* view */
2698
2725
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 ) );
2701
2728
else
2702
2729
print_comment (sql_file , 0 ,
2703
2730
"\n--\n-- Table structure for table %s\n--\n\n" ,
2704
- result_table );
2731
+ fix_identifier_with_newline ( result_table ) );
2705
2732
2706
2733
if (opt_drop )
2707
2734
{
@@ -2988,7 +3015,7 @@ static uint get_table_structure(char *table, char *db, char *table_type,
2988
3015
2989
3016
print_comment (sql_file , 0 ,
2990
3017
"\n--\n-- Table structure for table %s\n--\n\n" ,
2991
- result_table );
3018
+ fix_identifier_with_newline ( result_table ) );
2992
3019
if (opt_drop )
2993
3020
fprintf (sql_file , "DROP TABLE IF EXISTS %s;\n" , result_table );
2994
3021
if (!opt_xml )
@@ -3704,14 +3731,15 @@ static void dump_table(char *table, char *db)
3704
3731
{
3705
3732
print_comment (md_result_file , 0 ,
3706
3733
"\n--\n-- Dumping data for table %s\n--\n" ,
3707
- result_table );
3734
+ fix_identifier_with_newline ( result_table ) );
3708
3735
3709
3736
dynstr_append_checked (& query_string , "SELECT /*!40001 SQL_NO_CACHE */ * FROM " );
3710
3737
dynstr_append_checked (& query_string , result_table );
3711
3738
3712
3739
if (where )
3713
3740
{
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 ));
3715
3743
3716
3744
dynstr_append_checked (& query_string , " WHERE " );
3717
3745
dynstr_append_checked (& query_string , where );
@@ -3728,7 +3756,8 @@ static void dump_table(char *table, char *db)
3728
3756
}
3729
3757
if (order_by )
3730
3758
{
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 ));
3732
3761
3733
3762
dynstr_append_checked (& query_string , " ORDER BY " );
3734
3763
dynstr_append_checked (& query_string , order_by );
@@ -4572,7 +4601,8 @@ static int init_dumping(char *database, int init_func(char*))
4572
4601
char * qdatabase = quote_name (database ,quoted_database_buf ,opt_quoted );
4573
4602
4574
4603
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 ));
4576
4606
4577
4607
/* Call the view or table specific function */
4578
4608
init_func (qdatabase );
@@ -5802,7 +5832,7 @@ static my_bool get_view_structure(char *table, char* db)
5802
5832
5803
5833
print_comment (sql_file , 0 ,
5804
5834
"\n--\n-- Final view structure for view %s\n--\n\n" ,
5805
- result_table );
5835
+ fix_identifier_with_newline ( result_table ) );
5806
5836
5807
5837
verbose_msg ("-- Dropping the temporary view structure created\n" );
5808
5838
fprintf (sql_file , "/*!50001 DROP VIEW IF EXISTS %s*/;\n" , opt_quoted_table );
0 commit comments