Skip to content

Commit d15e290

Browse files
committed
MDEV-31982 Remove check_db_name() from prepare_db_action()
- Adding a new class Lex_ident_db, to store normalized database names: lower-cased if lower-case-table-name says so, and checked to be a valid database name using Lex_ident_fs::check_db_name() - Reusing the new class in parameters to functions: prepare_db_action() mysql_create_db() mysql_alter_db() mysql_rm_db() mysql_upgrade_db() This change removed two old-style check_db_name() calls.
1 parent ebbf566 commit d15e290

File tree

6 files changed

+141
-128
lines changed

6 files changed

+141
-128
lines changed

sql/lex_ident.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,26 @@ class Lex_ident_fs: public LEX_CSTRING
4747
};
4848

4949

50+
/**
51+
A normalized database name identifier.
52+
- Converted to lower case if lower_case_table_names say so
53+
- Checked to be a valid database name
54+
*/
55+
class Lex_ident_db: public Lex_ident_fs
56+
{
57+
public:
58+
Lex_ident_db()
59+
:Lex_ident_fs(NULL, 0)
60+
{ }
61+
Lex_ident_db(const char *str, size_t length)
62+
:Lex_ident_fs(str, length)
63+
{
64+
DBUG_SLOW_ASSERT(ok_for_lower_case_names());
65+
DBUG_SLOW_ASSERT(!check_db_name());
66+
}
67+
};
68+
69+
5070
/*
5171
A helper class to store temporary database names in a buffer.
5272
After constructing it's typically should be checked using
@@ -67,6 +87,13 @@ class DBNameBuffer: public CharBuffer<SAFE_NAME_LEN + MY_CS_MBMAXLEN>
6787
{
6888
copy_casedn(&my_charset_utf8mb3_general_ci, db, casedn);
6989
}
90+
Lex_ident_db to_lex_ident_db_with_error() const
91+
{
92+
LEX_CSTRING tmp= to_lex_cstring();
93+
if (Lex_ident_fs(tmp).check_db_name_with_error())
94+
return Lex_ident_db();
95+
return Lex_ident_db(tmp.str, tmp.length);
96+
}
7097
};
7198

7299

sql/sql_class.cc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6078,6 +6078,26 @@ void THD::get_definer(LEX_USER *definer, bool role)
60786078
}
60796079

60806080

6081+
bool THD::check_slave_ignored_db_with_error(const Lex_ident_db &db) const
6082+
{
6083+
#ifdef HAVE_REPLICATION
6084+
if (slave_thread)
6085+
{
6086+
Rpl_filter *rpl_filter;
6087+
rpl_filter= system_thread_info.rpl_sql_info->rpl_filter;
6088+
if (!rpl_filter->db_ok(db.str) ||
6089+
!rpl_filter->db_ok_with_wild_table(db.str))
6090+
{
6091+
my_message(ER_SLAVE_IGNORED_TABLE,
6092+
ER_THD(this, ER_SLAVE_IGNORED_TABLE), MYF(0));
6093+
return true;
6094+
}
6095+
}
6096+
#endif
6097+
return false;
6098+
}
6099+
6100+
60816101
/**
60826102
Mark transaction to rollback and mark error as fatal to a sub-statement.
60836103

sql/sql_class.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5356,6 +5356,8 @@ class THD: public THD_count, /* this must be first */
53565356
bool is_binlog_dump_thread();
53575357
#endif
53585358

5359+
bool check_slave_ignored_db_with_error(const Lex_ident_db &db) const;
5360+
53595361
/*
53605362
Indicates if this thread is suspended due to awaiting an ACK from a
53615363
replica. True if suspended, false otherwise.

0 commit comments

Comments
 (0)