diff options
-rw-r--r-- | sql/item_func.cc | 6 | ||||
-rw-r--r-- | sql/lex_string.h | 14 | ||||
-rw-r--r-- | sql/sql_alter.cc | 14 | ||||
-rw-r--r-- | sql/sql_lex.cc | 4 | ||||
-rw-r--r-- | sql/sql_trigger.cc | 2 | ||||
-rw-r--r-- | sql/sql_yacc.yy | 8 | ||||
-rw-r--r-- | sql/sql_yacc_ora.yy | 8 |
7 files changed, 31 insertions, 25 deletions
diff --git a/sql/item_func.cc b/sql/item_func.cc index 59cf5b53154..46b2d301e4e 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -62,9 +62,9 @@ bool check_reserved_words(const LEX_CSTRING *name) { - if (!my_strcasecmp(system_charset_info, name->str, "GLOBAL") || - !my_strcasecmp(system_charset_info, name->str, "LOCAL") || - !my_strcasecmp(system_charset_info, name->str, "SESSION")) + if (lex_string_eq(name, STRING_WITH_LEN("GLOBAL")) || + lex_string_eq(name, STRING_WITH_LEN("LOCAL")) || + lex_string_eq(name, STRING_WITH_LEN("SESSION"))) return TRUE; return FALSE; } diff --git a/sql/lex_string.h b/sql/lex_string.h index 25f2c83a372..a5209165be0 100644 --- a/sql/lex_string.h +++ b/sql/lex_string.h @@ -21,6 +21,7 @@ typedef struct st_mysql_const_lex_string LEX_CSTRING; /* Functions to compare if two lex strings are equal */ + static inline bool lex_string_cmp(CHARSET_INFO *charset, const LEX_CSTRING *a, const LEX_CSTRING *b) { @@ -30,6 +31,7 @@ static inline bool lex_string_cmp(CHARSET_INFO *charset, const LEX_CSTRING *a, /* Compare to LEX_CSTRING's and return 0 if equal */ + static inline bool cmp(const LEX_CSTRING *a, const LEX_CSTRING *b) { return (a->length != b->length || @@ -40,6 +42,7 @@ static inline bool cmp(const LEX_CSTRING *a, const LEX_CSTRING *b) Compare if two LEX_CSTRING are equal. Assumption is that character set is ASCII (like for plugin names) */ + static inline bool lex_string_eq(const LEX_CSTRING *a, const LEX_CSTRING *b) { if (a->length != b->length) @@ -48,12 +51,15 @@ static inline bool lex_string_eq(const LEX_CSTRING *a, const LEX_CSTRING *b) } /* - Compare if two LEX_CSTRING are equal in system character set - (field names, user variables, etc - but *not* table names) + To be used when calling lex_string_eq with STRING_WITH_LEN() as second + argument */ -static inline bool lex_string_syseq(const LEX_CSTRING *a, const LEX_CSTRING *b) + +static inline bool lex_string_eq(const LEX_CSTRING *a, const char *b, size_t b_length) { - return lex_string_cmp(system_charset_info, a, b) == 0; + if (a->length != b_length) + return 0; /* Different */ + return strcasecmp(a->str, b) == 0; } #endif /* LEX_STRING_INCLUDED */ diff --git a/sql/sql_alter.cc b/sql/sql_alter.cc index 77e0c9d5298..a58ecdcc314 100644 --- a/sql/sql_alter.cc +++ b/sql/sql_alter.cc @@ -54,11 +54,11 @@ Alter_info::Alter_info(const Alter_info &rhs, MEM_ROOT *mem_root) bool Alter_info::set_requested_algorithm(const LEX_CSTRING *str) { // To avoid adding new keywords to the grammar, we match strings here. - if (!my_strcasecmp(system_charset_info, str->str, "INPLACE")) + if (lex_string_eq(str, STRING_WITH_LEN("INPLACE"))) requested_algorithm= ALTER_TABLE_ALGORITHM_INPLACE; - else if (!my_strcasecmp(system_charset_info, str->str, "COPY")) + else if (lex_string_eq(str, STRING_WITH_LEN("COPY"))) requested_algorithm= ALTER_TABLE_ALGORITHM_COPY; - else if (!my_strcasecmp(system_charset_info, str->str, "DEFAULT")) + else if (lex_string_eq(str, STRING_WITH_LEN("DEFAULT"))) requested_algorithm= ALTER_TABLE_ALGORITHM_DEFAULT; else return true; @@ -69,13 +69,13 @@ bool Alter_info::set_requested_algorithm(const LEX_CSTRING *str) bool Alter_info::set_requested_lock(const LEX_CSTRING *str) { // To avoid adding new keywords to the grammar, we match strings here. - if (!my_strcasecmp(system_charset_info, str->str, "NONE")) + if (lex_string_eq(str, STRING_WITH_LEN("NONE"))) requested_lock= ALTER_TABLE_LOCK_NONE; - else if (!my_strcasecmp(system_charset_info, str->str, "SHARED")) + else if (lex_string_eq(str, STRING_WITH_LEN("SHARED"))) requested_lock= ALTER_TABLE_LOCK_SHARED; - else if (!my_strcasecmp(system_charset_info, str->str, "EXCLUSIVE")) + else if (lex_string_eq(str, STRING_WITH_LEN("EXCLUSIVE"))) requested_lock= ALTER_TABLE_LOCK_EXCLUSIVE; - else if (!my_strcasecmp(system_charset_info, str->str, "DEFAULT")) + else if (lex_string_eq(str, STRING_WITH_LEN("DEFAULT"))) requested_lock= ALTER_TABLE_LOCK_DEFAULT; else return true; diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index 968c3767780..2c8c4f4bec0 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -7038,9 +7038,9 @@ Item *LEX::create_item_ident_sp(THD *thd, Lex_ident_sys_st *name, if (thd->variables.sql_mode & MODE_ORACLE) { - if (!my_strcasecmp(system_charset_info, name->str, "SQLCODE")) + if (lex_string_eq(name, STRING_WITH_LEN("SQLCODE"))) return new (thd->mem_root) Item_func_sqlcode(thd); - if (!my_strcasecmp(system_charset_info, name->str, "SQLERRM")) + if (lex_string_eq(name, STRING_WITH_LEN("SQLERRM"))) return new (thd->mem_root) Item_func_sqlerrm(thd); } return create_item_ident_nosp(thd, name); diff --git a/sql/sql_trigger.cc b/sql/sql_trigger.cc index 5b218a1e36a..9f913e45744 100644 --- a/sql/sql_trigger.cc +++ b/sql/sql_trigger.cc @@ -431,7 +431,7 @@ bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create) /* We don't allow creating triggers on tables in the 'mysql' schema */ - if (create && !my_strcasecmp(system_charset_info, "mysql", tables->db.str)) + if (create && lex_string_eq(&tables->db, STRING_WITH_LEN("mysql"))) { my_error(ER_NO_TRIGGERS_ON_SYSTEM_SCHEMA, MYF(0)); DBUG_RETURN(TRUE); diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 1ff86c777b5..8789b218a8d 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -14106,9 +14106,9 @@ opt_format_json: /* empty */ {} | FORMAT_SYM '=' ident_or_text { - if (!my_strcasecmp(system_charset_info, $3.str, "JSON")) + if (lex_string_eq(&$3, STRING_WITH_LEN("JSON"))) Lex->explain_json= true; - else if (!my_strcasecmp(system_charset_info, $3.str, "TRADITIONAL")) + else if (lex_string_eq(&$3, STRING_WITH_LEN("TRADITIONAL"))) DBUG_ASSERT(Lex->explain_json==false); else my_yyabort_error((ER_UNKNOWN_EXPLAIN_FORMAT, MYF(0), "EXPLAIN", @@ -17466,9 +17466,9 @@ opt_format_xid: /* empty */ { $$= false; } | FORMAT_SYM '=' ident_or_text { - if (!my_strcasecmp(system_charset_info, $3.str, "SQL")) + if (lex_string_eq(&$3, STRING_WITH_LEN("SQL"))) $$= true; - else if (!my_strcasecmp(system_charset_info, $3.str, "RAW")) + else if (lex_string_eq(&$3, STRING_WITH_LEN("RAW"))) $$= false; else { diff --git a/sql/sql_yacc_ora.yy b/sql/sql_yacc_ora.yy index dc0878d7ee7..e84bf4fe5a2 100644 --- a/sql/sql_yacc_ora.yy +++ b/sql/sql_yacc_ora.yy @@ -13848,9 +13848,9 @@ opt_format_json: /* empty */ {} | FORMAT_SYM '=' ident_or_text { - if (!my_strcasecmp(system_charset_info, $3.str, "JSON")) + if (lex_string_eq(&$3, STRING_WITH_LEN("JSON"))) Lex->explain_json= true; - else if (!my_strcasecmp(system_charset_info, $3.str, "TRADITIONAL")) + else if (lex_string_eq(&$3, STRING_WITH_LEN("TRADITIONAL"))) DBUG_ASSERT(Lex->explain_json==false); else my_yyabort_error((ER_UNKNOWN_EXPLAIN_FORMAT, MYF(0), "EXPLAIN", @@ -17332,9 +17332,9 @@ opt_format_xid: /* empty */ { $$= false; } | FORMAT_SYM '=' ident_or_text { - if (!my_strcasecmp(system_charset_info, $3.str, "SQL")) + if (lex_string_eq(&$3, STRING_WITH_LEN("SQL"))) $$= true; - else if (!my_strcasecmp(system_charset_info, $3.str, "RAW")) + else if (lex_string_eq(&$3, STRING_WITH_LEN("RAW"))) $$= false; else { |