Commit 2361f835 authored by Alexander Barkov's avatar Alexander Barkov

MDEV-12392 Duplicate code cleanup: add function normalize_db_name()

parent fb43180c
...@@ -583,15 +583,8 @@ mysql_create_db_internal(THD *thd, char *db, ...@@ -583,15 +583,8 @@ mysql_create_db_internal(THD *thd, char *db,
DBUG_RETURN(-1); DBUG_RETURN(-1);
} }
char db_tmp[SAFE_NAME_LEN], *dbnorm; char db_tmp[SAFE_NAME_LEN];
if (lower_case_table_names) char *dbnorm= normalize_db_name(db, db_tmp, sizeof(db_tmp));
{
strmake_buf(db_tmp, db);
my_casedn_str(system_charset_info, db_tmp);
dbnorm= db_tmp;
}
else
dbnorm= db;
if (lock_schema_name(thd, dbnorm)) if (lock_schema_name(thd, dbnorm))
DBUG_RETURN(-1); DBUG_RETURN(-1);
...@@ -824,15 +817,8 @@ mysql_rm_db_internal(THD *thd,char *db, bool if_exists, bool silent) ...@@ -824,15 +817,8 @@ mysql_rm_db_internal(THD *thd,char *db, bool if_exists, bool silent)
Drop_table_error_handler err_handler; Drop_table_error_handler err_handler;
DBUG_ENTER("mysql_rm_db"); DBUG_ENTER("mysql_rm_db");
char db_tmp[SAFE_NAME_LEN], *dbnorm; char db_tmp[SAFE_NAME_LEN];
if (lower_case_table_names) char *dbnorm= normalize_db_name(db, db_tmp, sizeof(db_tmp));
{
strmake_buf(db_tmp, db);
my_casedn_str(system_charset_info, db_tmp);
dbnorm= db_tmp;
}
else
dbnorm= db;
if (lock_schema_name(thd, dbnorm)) if (lock_schema_name(thd, dbnorm))
DBUG_RETURN(true); DBUG_RETURN(true);
...@@ -1891,3 +1877,14 @@ bool check_db_dir_existence(const char *db_name) ...@@ -1891,3 +1877,14 @@ bool check_db_dir_existence(const char *db_name)
return my_access(db_dir_path, F_OK); return my_access(db_dir_path, F_OK);
} }
char *normalize_db_name(char *db, char *buffer, size_t buffer_size)
{
DBUG_ASSERT(buffer_size > 1);
if (!lower_case_table_names)
return db;
strmake(buffer, db, buffer_size - 1);
my_casedn_str(system_charset_info, buffer);
return buffer;
}
...@@ -45,6 +45,8 @@ CHARSET_INFO *get_default_db_collation(THD *thd, const char *db_name); ...@@ -45,6 +45,8 @@ CHARSET_INFO *get_default_db_collation(THD *thd, const char *db_name);
bool my_dbopt_init(void); bool my_dbopt_init(void);
void my_dbopt_cleanup(void); void my_dbopt_cleanup(void);
char *normalize_db_name(char *db, char *buffer, size_t buffer_size);
#define MY_DB_OPT_FILE "db.opt" #define MY_DB_OPT_FILE "db.opt"
#endif /* SQL_DB_INCLUDED */ #endif /* SQL_DB_INCLUDED */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment