Commit 0643d1f3 authored by Sergei Golubchik's avatar Sergei Golubchik

another post-fix patch for MDEV-5850: MySQL Bug#21317: SHOW CREATE DATABASE...

another post-fix patch for MDEV-5850: MySQL Bug#21317: SHOW CREATE DATABASE does not obey to lower_case_table_names
(for case-insensitive filesystems)

sql/events.cc:
  for "SHOW EVENTS IN db_name"
sql/sp_head.h:
  for "CREATE EVENT", and everything SP-related
sql/sql_acl.cc:
  privilege check for mysql_change_db()
sql/sql_db.cc:
  for metadata locking of db names
sql/sql_parse.cc:
  any_db is a constant, it is not writable
sql/sql_show.cc:
  for SHOW CREATE TRIGGER and other trigger-related statements
parent 73f48615
......@@ -764,6 +764,9 @@ Events::fill_schema_events(THD *thd, TABLE_LIST *tables, COND * /* cond */)
NULL, NULL, 0, 0))
DBUG_RETURN(1);
db= thd->lex->select_lex.db;
if (lower_case_table_names)
my_casedn_str(system_charset_info, db);
}
ret= db_repository->fill_schema_events(thd, tables, db);
......
......@@ -122,6 +122,8 @@ public:
sp_name(LEX_STRING db, LEX_STRING name, bool use_explicit_name)
: m_db(db), m_name(name), m_explicit_name(use_explicit_name)
{
if (lower_case_table_names && m_db.str)
m_db.length= my_casedn_str(files_charset_info, m_db.str);
m_qname.str= 0;
m_qname.length= 0;
}
......
......@@ -7118,16 +7118,22 @@ bool check_grant_db(THD *thd, const char *db)
{
Security_context *sctx= thd->security_ctx;
char helping [SAFE_NAME_LEN + USERNAME_LENGTH+2], *end;
char helping2 [SAFE_NAME_LEN + USERNAME_LENGTH+2];
char helping2 [SAFE_NAME_LEN + USERNAME_LENGTH+2], *tmp_db;
uint len, UNINIT_VAR(len2);
bool error= TRUE;
end= strmov(helping, sctx->priv_user) + 1;
end= strnmov(end, db, helping + sizeof(helping) - end);
tmp_db= strmov(helping, sctx->priv_user) + 1;
end= strnmov(tmp_db, db, helping + sizeof(helping) - tmp_db);
if (end >= helping + sizeof(helping)) // db name was truncated
return 1; // no privileges for an invalid db name
if (lower_case_table_names)
{
end = tmp_db + my_casedn_str(files_charset_info, tmp_db);
db=tmp_db;
}
len= (uint) (end - helping) + 1;
/*
......
......@@ -579,7 +579,17 @@ int mysql_create_db(THD *thd, char *db, HA_CREATE_INFO *create_info,
DBUG_RETURN(-1);
}
if (lock_schema_name(thd, db))
char db_tmp[SAFE_NAME_LEN], *dbnorm;
if (lower_case_table_names)
{
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))
DBUG_RETURN(-1);
/* Check directory */
......@@ -783,7 +793,17 @@ 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))
char db_tmp[SAFE_NAME_LEN], *dbnorm;
if (lower_case_table_names)
{
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))
DBUG_RETURN(true);
length= build_table_filename(path, sizeof(path) - 1, db, "", "", 0);
......@@ -808,7 +828,7 @@ bool mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent)
}
}
if (find_db_tables_and_rm_known_files(thd, dirp, db, path, &tables))
if (find_db_tables_and_rm_known_files(thd, dirp, dbnorm, path, &tables))
goto exit;
/*
......@@ -825,7 +845,7 @@ bool mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent)
/* Lock all tables and stored routines about to be dropped. */
if (lock_table_names(thd, tables, NULL, thd->variables.lock_wait_timeout,
0) ||
lock_db_routines(thd, db))
lock_db_routines(thd, dbnorm))
goto exit;
if (!in_bootstrap)
......@@ -872,10 +892,10 @@ bool mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent)
ha_drop_database(path);
tmp_disable_binlog(thd);
query_cache_invalidate1(thd, db);
(void) sp_drop_db_routines(thd, db); /* @todo Do not ignore errors */
query_cache_invalidate1(thd, dbnorm);
(void) sp_drop_db_routines(thd, dbnorm); /* @todo Do not ignore errors */
#ifdef HAVE_EVENT_SCHEDULER
Events::drop_schema_events(thd, db);
Events::drop_schema_events(thd, dbnorm);
#endif
reenable_binlog(thd);
......@@ -1013,13 +1033,6 @@ 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);
......
......@@ -6758,7 +6758,7 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd,
{
if (table->table.length)
table->table.length= my_casedn_str(files_charset_info, table->table.str);
if (ptr->db_length)
if (ptr->db_length && ptr->db != any_db)
ptr->db_length= my_casedn_str(files_charset_info, ptr->db);
}
......
......@@ -9381,6 +9381,9 @@ TABLE_LIST *get_trigger_table(THD *thd, const sp_name *trg_name)
db= trg_name->m_db;
db.str= thd->strmake(db.str, db.length);
if (lower_case_table_names)
db.length= my_casedn_str(files_charset_info, db.str);
tbl_name.str= thd->strmake(tbl_name.str, tbl_name.length);
if (db.str == NULL || tbl_name.str == NULL)
......
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