@@ -1735,11 +1735,11 @@ static my_bool test_if_special_chars(const char *str)
1735
1735
} /* test_if_special_chars */
1736
1736
1737
1737
1738
-
1739
1738
/*
1740
1739
quote_name(name, buff, force)
1741
1740
1742
- Quotes char string, taking into account compatible mode
1741
+ Quotes a string, if it requires quoting. To force quoting regardless
1742
+ of the characters within the string, the force flag can be set to true.
1743
1743
1744
1744
Args
1745
1745
@@ -1748,8 +1748,8 @@ static my_bool test_if_special_chars(const char *str)
1748
1748
force Flag to make it ignore 'test_if_special_chars'
1749
1749
1750
1750
Returns
1751
-
1752
- buff quoted string
1751
+ A pointer to the quoted string, or the original string if nothing has
1752
+ changed.
1753
1753
1754
1754
*/
1755
1755
static char * quote_name (const char * name , char * buff , my_bool force )
@@ -1815,6 +1815,26 @@ static char *quote_for_like(const char *name, char *buff)
1815
1815
return buff ;
1816
1816
}
1817
1817
1818
+ static char * quote_for_equal (const char * name , char * buff )
1819
+ {
1820
+ char * to = buff ;
1821
+ * to ++ = '\'' ;
1822
+ while (* name )
1823
+ {
1824
+ if (* name == '\\' )
1825
+ {
1826
+ * to ++ = '\\' ;
1827
+ }
1828
+ if (* name == '\'' )
1829
+ * to ++ = '\\' ;
1830
+ * to ++ = * name ++ ;
1831
+ }
1832
+ to [0 ]= '\'' ;
1833
+ to [1 ]= 0 ;
1834
+ return buff ;
1835
+
1836
+ }
1837
+
1818
1838
1819
1839
/**
1820
1840
Quote and print a string.
@@ -3341,8 +3361,10 @@ static int dump_triggers_for_table(char *table_name, char *db_name)
3341
3361
/* Get list of triggers. */
3342
3362
3343
3363
my_snprintf (query_buff , sizeof (query_buff ),
3344
- "SHOW TRIGGERS LIKE %s" ,
3345
- quote_for_like (table_name , name_buff ));
3364
+ "SELECT TRIGGER_NAME FROM INFORMATION_SCHEMA.TRIGGERS "
3365
+ "WHERE EVENT_OBJECT_SCHEMA = DATABASE() AND "
3366
+ "EVENT_OBJECT_TABLE = %s" ,
3367
+ quote_for_equal (table_name , name_buff ));
3346
3368
3347
3369
if (mysql_query_with_error_report (mysql , & show_triggers_rs , query_buff ))
3348
3370
goto done ;
@@ -4695,29 +4717,37 @@ static my_bool dump_all_views_in_db(char *database)
4695
4717
4696
4718
4697
4719
/*
4698
- get_actual_table_name -- executes a SHOW TABLES LIKE '%s' to get the actual
4699
- table name from the server for the table name given on the command line.
4700
- we do this because the table name given on the command line may be a
4701
- different case (e.g. T1 vs t1)
4702
-
4703
- RETURN
4704
- pointer to the table name
4705
- 0 if error
4720
+ See get_actual_table_name. Used to retrieve the correct table name
4721
+ from the database schema.
4706
4722
*/
4707
-
4708
- static char * get_actual_table_name (const char * old_table_name , MEM_ROOT * root )
4723
+ static char * get_actual_table_name_helper (const char * old_table_name ,
4724
+ my_bool case_sensitive ,
4725
+ MEM_ROOT * root )
4709
4726
{
4710
4727
char * name = 0 ;
4711
4728
MYSQL_RES * table_res ;
4712
4729
MYSQL_ROW row ;
4713
4730
char query [50 + 2 * NAME_LEN ];
4714
4731
char show_name_buff [FN_REFLEN ];
4715
- DBUG_ENTER ("get_actual_table_name " );
4732
+ DBUG_ENTER ("get_actual_table_name_helper " );
4716
4733
4717
4734
/* Check memory for quote_for_like() */
4718
4735
DBUG_ASSERT (2 * sizeof (old_table_name ) < sizeof (show_name_buff ));
4719
- my_snprintf (query , sizeof (query ), "SHOW TABLES LIKE %s" ,
4720
- quote_for_like (old_table_name , show_name_buff ));
4736
+
4737
+ if (case_sensitive )
4738
+ {
4739
+ DBUG_PRINT ("info" , ("case sensitive search" ));
4740
+ my_snprintf (query , sizeof (query ),
4741
+ "SELECT table_name FROM INFORMATION_SCHEMA.TABLES "
4742
+ "WHERE table_schema = DATABASE() AND table_name = %s" ,
4743
+ quote_for_equal (old_table_name , show_name_buff ));
4744
+ }
4745
+ else
4746
+ {
4747
+ DBUG_PRINT ("info" , ("case insensitive search" ));
4748
+ my_snprintf (query , sizeof (query ), "SHOW TABLES LIKE %s" ,
4749
+ quote_for_like (old_table_name , show_name_buff ));
4750
+ }
4721
4751
4722
4752
if (mysql_query_with_error_report (mysql , 0 , query ))
4723
4753
return NullS ;
@@ -4742,13 +4772,68 @@ static char *get_actual_table_name(const char *old_table_name, MEM_ROOT *root)
4742
4772
DBUG_RETURN (name );
4743
4773
}
4744
4774
4775
+ /*
4776
+ get_actual_table_name -- executes a SELECT .. FROM I_S.tables to check
4777
+ if the table name given on the command line matches the one in the database.
4778
+ If the table is not found, it falls back to a slower SHOW TABLES LIKE '%s' to
4779
+ get the actual table name from the server.
4780
+
4781
+ We do this because the table name given on the command line may be a
4782
+ different case (e.g. T1 vs t1), but checking this takes a long time
4783
+ when there are many tables present.
4784
+
4785
+ RETURN
4786
+ pointer to the table name
4787
+ 0 if error
4788
+ */
4789
+
4790
+ static char * get_actual_table_name (const char * old_table_name ,
4791
+ int lower_case_table_names ,
4792
+ MEM_ROOT * root )
4793
+ {
4794
+ char * name = 0 ;
4795
+ DBUG_ENTER ("get_actual_table_name" );
4796
+
4797
+ name = get_actual_table_name_helper (old_table_name , TRUE, root );
4798
+ if (!name && !lower_case_table_names )
4799
+ name = get_actual_table_name_helper (old_table_name , FALSE, root );
4800
+ DBUG_RETURN (name );
4801
+ }
4802
+
4803
+ /*
4804
+ Retrieve the value for the server system variable lower_case_table_names.
4805
+
4806
+ RETURN
4807
+ 0 case sensitive.
4808
+ > 0 case insensitive
4809
+ */
4810
+ static int get_sys_var_lower_case_table_names ()
4811
+ {
4812
+ int lower_case_table_names = 0 ;
4813
+ MYSQL_RES * table_res ;
4814
+ MYSQL_ROW row ;
4815
+ const char * show_var_query = "SHOW VARIABLES LIKE 'lower_case_table_names'" ;
4816
+ if (mysql_query_with_error_report (mysql , & table_res , show_var_query ))
4817
+ return 0 ; /* In case of error, assume default value of 0 */
4818
+
4819
+ if ((row = mysql_fetch_row (table_res )))
4820
+ {
4821
+ lower_case_table_names = atoi (row [1 ]);
4822
+ mysql_free_result (table_res );
4823
+ }
4824
+
4825
+ return lower_case_table_names ;
4826
+ }
4827
+
4828
+
4745
4829
4746
4830
static int dump_selected_tables (char * db , char * * table_names , int tables )
4747
4831
{
4748
4832
char table_buff [NAME_LEN * 2 + 3 ];
4749
4833
DYNAMIC_STRING lock_tables_query ;
4750
4834
MEM_ROOT root ;
4751
4835
char * * dump_tables , * * pos , * * end ;
4836
+ int lower_case_table_names ;
4752
4837
DBUG_ENTER ("dump_selected_tables" );
4753
4838
4754
4839
if (init_dumping (db , init_dumping_tables ))
@@ -4758,11 +4843,15 @@ static int dump_selected_tables(char *db, char **table_names, int tables)
4758
4843
if (!(dump_tables = pos = (char * * ) alloc_root (& root , tables * sizeof (char * ))))
4759
4844
die (EX_EOM , "alloc_root failure." );
4760
4845
4846
+ /* Figure out how to compare table names. */
4847
+ lower_case_table_names = get_sys_var_lower_case_table_names ();
4848
+
4761
4849
init_dynamic_string_checked (& lock_tables_query , "LOCK TABLES " , 256 , 1024 );
4762
4850
for (; tables > 0 ; tables -- , table_names ++ )
4763
4851
{
4764
4852
/* the table name passed on commandline may be wrong case */
4765
- if ((* pos = get_actual_table_name (* table_names , & root )))
4853
+ if ((* pos = get_actual_table_name (* table_names , lower_case_table_names ,
4854
+ & root )))
4766
4855
{
4767
4856
/* Add found table name to lock_tables_query */
4768
4857
if (lock_tables )
@@ -5369,8 +5458,10 @@ char check_if_ignore_table(const char *table_name, char *table_type)
5369
5458
5370
5459
/* Check memory for quote_for_like() */
5371
5460
DBUG_ASSERT (2 * sizeof (table_name ) < sizeof (show_name_buff ));
5372
- my_snprintf (buff , sizeof (buff ), "show table status like %s" ,
5373
- quote_for_like (table_name , show_name_buff ));
5461
+ my_snprintf (buff , sizeof (buff ),
5462
+ "SELECT engine FROM INFORMATION_SCHEMA.TABLES "
5463
+ "WHERE table_name = %s" ,
5464
+ quote_for_equal (table_name , show_name_buff ));
5374
5465
if (mysql_query_with_error_report (mysql , & res , buff ))
5375
5466
{
5376
5467
if (mysql_errno (mysql ) != ER_PARSE_ERROR )
@@ -5388,7 +5479,7 @@ char check_if_ignore_table(const char *table_name, char *table_type)
5388
5479
mysql_free_result (res );
5389
5480
DBUG_RETURN (result ); /* assume table is ok */
5390
5481
}
5391
- if (!(row [1 ]))
5482
+ if (!(row [0 ]))
5392
5483
strmake (table_type , "VIEW" , NAME_LEN - 1 );
5393
5484
else
5394
5485
{
@@ -5398,7 +5489,7 @@ char check_if_ignore_table(const char *table_name, char *table_type)
5398
5489
these types, but we do want to use delayed inserts in the dump if
5399
5490
the table type is _NOT_ one of these types
5400
5491
*/
5401
- strmake (table_type , row [1 ], NAME_LEN - 1 );
5492
+ strmake (table_type , row [0 ], NAME_LEN - 1 );
5402
5493
if (opt_delayed )
5403
5494
{
5404
5495
if (strcmp (table_type ,"MyISAM" ) &&
0 commit comments