diff --git a/sql/handler.cc b/sql/handler.cc index 1c8d56cafd1c1..b038d699be0f1 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -532,7 +532,8 @@ static int full_discover_for_existence(handlerton *, const char *, const char *) static int ext_based_existence(handlerton *, const char *, const char *) { return 0; } -static int hton_ext_based_table_discovery(handlerton *hton, LEX_CSTRING *db, +static int hton_ext_based_table_discovery(handlerton *hton, + const LEX_CSTRING *db, MY_DIR *dir, handlerton::discovered_list *result) { /* @@ -6679,7 +6680,7 @@ void Discovered_table_list::remove_duplicates() struct st_discover_names_args { - LEX_CSTRING *db; + const LEX_CSTRING *db; MY_DIR *dirp; Discovered_table_list *result; uint possible_duplicates; @@ -6724,7 +6725,7 @@ static my_bool discover_names(THD *thd, plugin_ref plugin, for DROP DATABASE (as it needs to know and delete non-table files). */ -int ha_discover_table_names(THD *thd, LEX_CSTRING *db, MY_DIR *dirp, +int ha_discover_table_names(THD *thd, const LEX_CSTRING *db, MY_DIR *dirp, Discovered_table_list *result, bool reusable) { int error; diff --git a/sql/handler.h b/sql/handler.h index 91349802c6533..e3031d77fb8d9 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -1621,7 +1621,8 @@ struct handlerton Returns 0 on success and 1 on error. */ - int (*discover_table_names)(handlerton *hton, LEX_CSTRING *db, MY_DIR *dir, + int (*discover_table_names)(handlerton *hton, const LEX_CSTRING *db, + MY_DIR *dir, discovered_list *result); /* @@ -5574,7 +5575,7 @@ class Discovered_table_list: public handlerton::discovered_list }; int ha_discover_table(THD *thd, TABLE_SHARE *share); -int ha_discover_table_names(THD *thd, LEX_CSTRING *db, MY_DIR *dirp, +int ha_discover_table_names(THD *thd, const LEX_CSTRING *db, MY_DIR *dirp, Discovered_table_list *result, bool reusable); bool ha_table_exists(THD *thd, const LEX_CSTRING *db, const LEX_CSTRING *table_name, diff --git a/sql/lex_ident.h b/sql/lex_ident.h index 33b8630f15cc4..626c75a6ce799 100644 --- a/sql/lex_ident.h +++ b/sql/lex_ident.h @@ -87,9 +87,16 @@ class DBNameBuffer: public CharBuffer { copy_casedn(&my_charset_utf8mb3_general_ci, db, casedn); } + Lex_ident_db to_lex_ident_db() const + { + const LEX_CSTRING tmp= to_lex_cstring(); + if (Lex_ident_fs(tmp).check_db_name()) + return Lex_ident_db(); + return Lex_ident_db(tmp.str, tmp.length); + } Lex_ident_db to_lex_ident_db_with_error() const { - LEX_CSTRING tmp= to_lex_cstring(); + const LEX_CSTRING tmp= to_lex_cstring(); if (Lex_ident_fs(tmp).check_db_name_with_error()) return Lex_ident_db(); return Lex_ident_db(tmp.str, tmp.length); diff --git a/sql/sql_show.cc b/sql/sql_show.cc index d5a5c93d46bf9..9dd99919cd7c9 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -948,7 +948,8 @@ enum find_files_result { static find_files_result -find_files(THD *thd, Dynamic_array *files, LEX_CSTRING *db, +find_files(THD *thd, Dynamic_array *files, + const Lex_ident_db *db, const char *path, const LEX_CSTRING *wild) { MY_DIR *dirp; @@ -4537,7 +4538,7 @@ int schema_tables_add(THD *thd, Dynamic_array *files, static int make_table_name_list(THD *thd, Dynamic_array *table_names, LEX *lex, LOOKUP_FIELD_VALUES *lookup_field_vals, - LEX_CSTRING *db_name) + const LEX_CSTRING *db_name) { char path[FN_REFLEN + 1]; build_table_filename(path, sizeof(path) - 1, db_name->str, "", "", 0); @@ -4583,10 +4584,12 @@ make_table_name_list(THD *thd, Dynamic_array *table_names, return (schema_tables_add(thd, table_names, lookup_field_vals->table_value.str)); - if (check_db_name((LEX_STRING*)db_name)) + DBNameBuffer dbbuf(*db_name, lower_case_table_names); + const Lex_ident_db dbnorm= dbbuf.to_lex_ident_db(); + if (!dbnorm.str) return 0; // Impossible TABLE_SCHEMA name - find_files_result res= find_files(thd, table_names, db_name, path, + find_files_result res= find_files(thd, table_names, &dbnorm, path, &lookup_field_vals->table_value); if (res != FIND_FILES_OK) { diff --git a/storage/maria/ha_s3.cc b/storage/maria/ha_s3.cc index 19e32ce33fb9a..1baf8c5386996 100644 --- a/storage/maria/ha_s3.cc +++ b/storage/maria/ha_s3.cc @@ -827,7 +827,7 @@ static int s3_discover_table_existence(handlerton *hton, const char *db, */ static int s3_discover_table_names(handlerton *hton __attribute__((unused)), - LEX_CSTRING *db, + const LEX_CSTRING *db, MY_DIR *dir __attribute__((unused)), handlerton::discovered_list *result) { diff --git a/storage/perfschema/pfs_engine_table.cc b/storage/perfschema/pfs_engine_table.cc index 76095b5311b8a..e1356f837baea 100644 --- a/storage/perfschema/pfs_engine_table.cc +++ b/storage/perfschema/pfs_engine_table.cc @@ -1960,7 +1960,7 @@ bool pfs_show_status(handlerton *hton, THD *thd, } int pfs_discover_table_names(handlerton *hton __attribute__((unused)), - LEX_CSTRING *db, + const LEX_CSTRING *db, MY_DIR *dir __attribute__((unused)), handlerton::discovered_list *result) { diff --git a/storage/perfschema/pfs_engine_table.h b/storage/perfschema/pfs_engine_table.h index 02ef9b07010d2..1ef1e0282dee8 100644 --- a/storage/perfschema/pfs_engine_table.h +++ b/storage/perfschema/pfs_engine_table.h @@ -619,7 +619,7 @@ struct PFS_triple_index bool pfs_show_status(handlerton *hton, THD *thd, stat_print_fn *print, enum ha_stat_type stat); -int pfs_discover_table_names(handlerton *hton, LEX_CSTRING *db, +int pfs_discover_table_names(handlerton *hton, const LEX_CSTRING *db, MY_DIR *dir, handlerton::discovered_list *result);