summaryrefslogtreecommitdiff
path: root/sql/sql_db.cc
diff options
context:
space:
mode:
authorMichael Widenius <monty@mariadb.org>2014-03-23 15:43:57 +0200
committerMichael Widenius <monty@askmonty.org>2014-03-23 15:43:57 +0200
commitb18a1b0e6ccc326ced01620edd842d899139feec (patch)
tree1c2d5fab29f5064c7050861aede99c526cc6dfd2 /sql/sql_db.cc
parent797a44a9ec5a601a4745b9520c2dea321f96d155 (diff)
downloadmariadb-git-b18a1b0e6ccc326ced01620edd842d899139feec.tar.gz
MDEV-5850: MySQL Bug#21317: SHOW CREATE DATABASE does not obey to lower_case_table_names
Bug #3329 Incomplete lower_case_table_names=2 implementation The problem was that check_db_name() converted database names to lower case also in case of lower_case_table_names=2. Fixed by removing the conversion in check_db_name for lower_case_table_names = 2 and instead converting db name to lower case at same places as table names are converted. Fixed bug that SHOW CREATE DATABASE FOO showed information for database 'foo'. I also removed some checks of lower_case_table_names when it was enough to use table_alias_charset. mysql-test/mysql-test-run.pl: Added --use-copy argument to force mysql-test-run to copy files instead of doing symlinks. This is needed when you run with test directory on another file system mysql-test/r/lowercase_table.result: Updated results mysql-test/r/lowercase_table2.result: Updated results mysql-test/suite/parts/r/partition_mgm_lc2_innodb.result: Updated results mysql-test/suite/parts/r/partition_mgm_lc2_memory.result: Updated results mysql-test/suite/parts/r/partition_mgm_lc2_myisam.result: Updated results mysql-test/t/lowercase_table.test: Added tests with mixed case databases mysql-test/t/lowercase_table2.test: Added tests with mixed case databases sql/log.cc: Don't check lower_case_table_names when we can use table_alias_charset sql/sql_base.cc: Don't check lower_case_table_names when we can use table_alias_charset sql/sql_db.cc: Use cmp_db_names() for checking if current database changed. mysql_rm_db() now converts db to lower case if lower_case_table_names was used. Changed database options cache to use table_alias_charset. This fixed a bug where SHOW CREATE DATABASE showed wrong information. sql/sql_parse.cc: Change also db name to lower case when file names are changed. Don't need to story copy of database name anymore when lower_case_table_names == 2 as check_db_name() don't convert in this case. Updated arguments to mysqld_show_create_db(). When adding table to TABLE_LIST also convert db name to lower case if needed (same way as we do with table names). sql/sql_show.cc: mysqld_show_create_db() now also takes original name as argument for output to user. sql/sql_show.h: Updated prototype for mysqld_show_create_db() sql/sql_table.cc: In mysql_rename_table(), do same conversions to database name as we do for the file name
Diffstat (limited to 'sql/sql_db.cc')
-rw-r--r--sql/sql_db.cc60
1 files changed, 33 insertions, 27 deletions
diff --git a/sql/sql_db.cc b/sql/sql_db.cc
index bf55a20f2d9..6c823e0480c 100644
--- a/sql/sql_db.cc
+++ b/sql/sql_db.cc
@@ -78,6 +78,29 @@ typedef struct my_dbopt_st
} my_dbopt_t;
+/**
+ Return TRUE if db1_name is equal to db2_name, FALSE otherwise.
+
+ The function allows to compare database names according to the MariaDB
+ rules. The database names db1 and db2 are equal if:
+ - db1 is NULL and db2 is NULL;
+ or
+ - db1 is not-NULL, db2 is not-NULL, db1 is equal to db2 in
+ table_alias_charset
+
+ This is the same rules as we use for filenames.
+*/
+
+static inline bool
+cmp_db_names(const char *db1_name,
+ const char *db2_name)
+{
+ return ((!db1_name && !db2_name) ||
+ (db1_name && db2_name &&
+ my_strcasecmp(table_alias_charset, db1_name, db2_name) == 0));
+}
+
+
/*
Function we use in the creation of our hash to get key.
*/
@@ -159,8 +182,7 @@ bool my_dboptions_cache_init(void)
if (!dboptions_init)
{
dboptions_init= 1;
- error= my_hash_init(&dboptions, lower_case_table_names ?
- &my_charset_bin : system_charset_info,
+ error= my_hash_init(&dboptions, table_alias_charset,
32, 0, 0, (my_hash_get_key) dboptions_get_key,
free_dbopt,0);
}
@@ -192,8 +214,7 @@ void my_dbopt_cleanup(void)
{
mysql_rwlock_wrlock(&LOCK_dboptions);
my_hash_free(&dboptions);
- my_hash_init(&dboptions, lower_case_table_names ?
- &my_charset_bin : system_charset_info,
+ my_hash_init(&dboptions, table_alias_charset,
32, 0, 0, (my_hash_get_key) dboptions_get_key,
free_dbopt,0);
mysql_rwlock_unlock(&LOCK_dboptions);
@@ -762,7 +783,6 @@ bool mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent)
Drop_table_error_handler err_handler;
DBUG_ENTER("mysql_rm_db");
-
if (lock_schema_name(thd, db))
DBUG_RETURN(true);
@@ -966,7 +986,7 @@ exit:
SELECT DATABASE() in the future). For this we free() thd->db and set
it to 0.
*/
- if (thd->db && !strcmp(thd->db, db) && !error)
+ if (thd->db && cmp_db_names(thd->db, db) && !error)
mysql_change_db_impl(thd, NULL, 0, thd->variables.collation_server);
my_dirend(dirp);
DBUG_RETURN(error);
@@ -993,6 +1013,13 @@ static bool find_db_tables_and_rm_known_files(THD *thd, MY_DIR *dirp,
/* Now put the tables in the list */
tot_list_next_local= tot_list_next_global= &tot_list;
+ if (lower_case_table_names)
+ {
+ /* Change database name to lower case for comparision */
+ db.str= thd->strmake(db.str, db.length);
+ db.length= my_casedn_str(files_charset_info, db.str);
+ }
+
for (size_t idx=0; idx < files.elements(); idx++)
{
LEX_STRING *table= files.at(idx);
@@ -1300,27 +1327,6 @@ static void backup_current_db_name(THD *thd,
/**
- Return TRUE if db1_name is equal to db2_name, FALSE otherwise.
-
- The function allows to compare database names according to the MySQL
- rules. The database names db1 and db2 are equal if:
- - db1 is NULL and db2 is NULL;
- or
- - db1 is not-NULL, db2 is not-NULL, db1 is equal (ignoring case) to
- db2 in system character set (UTF8).
-*/
-
-static inline bool
-cmp_db_names(const char *db1_name,
- const char *db2_name)
-{
- return ((!db1_name && !db2_name) ||
- (db1_name && db2_name &&
- my_strcasecmp(system_charset_info, db1_name, db2_name) == 0));
-}
-
-
-/**
@brief Change the current database and its attributes unconditionally.
@param thd thread handle