Commit 068450a3 authored by Alexander Barkov's avatar Alexander Barkov

MDEV-15689 Fix Item_func_set_collation to pass the collation using CHARSET_INFO instead of Item

Main changes:

- Changing the constructor to accept a CHARSET_INFO pointer, instead of an Item pointer
- Updating the bison grammar accordingly

Additional cleanups:

- Simplifying Item_func_set_collation::eq() by reusing Item_func::eq()
- Removing unused binary_keyword
parent 0f26f71b
......@@ -3437,27 +3437,13 @@ String *Item_func_set_collation::val_str(String *str)
void Item_func_set_collation::fix_length_and_dec()
{
CHARSET_INFO *set_collation;
const char *colname;
String tmp, *str= args[1]->val_str(&tmp);
colname= str->c_ptr();
if (colname == binary_keyword)
set_collation= get_charset_by_csname(args[0]->collation.collation->csname,
MY_CS_BINSORT,MYF(0));
else
{
if (!(set_collation= mysqld_collation_get_by_name(colname)))
return;
}
if (!set_collation ||
!my_charset_same(args[0]->collation.collation,set_collation))
if (!my_charset_same(args[0]->collation.collation, m_set_collation))
{
my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0),
colname, args[0]->collation.collation->csname);
m_set_collation->name, args[0]->collation.collation->csname);
return;
}
collation.set(set_collation, DERIVATION_EXPLICIT,
collation.set(m_set_collation, DERIVATION_EXPLICIT,
args[0]->collation.repertoire);
max_length= args[0]->max_length;
}
......@@ -3465,22 +3451,8 @@ void Item_func_set_collation::fix_length_and_dec()
bool Item_func_set_collation::eq(const Item *item, bool binary_cmp) const
{
/* Assume we don't have rtti */
if (this == item)
return 1;
if (item->type() != FUNC_ITEM)
return 0;
Item_func *item_func=(Item_func*) item;
if (arg_count != item_func->argument_count() ||
functype() != item_func->functype())
return 0;
Item_func_set_collation *item_func_sc=(Item_func_set_collation*) item;
if (collation.collation != item_func_sc->collation.collation)
return 0;
for (uint i=0; i < arg_count ; i++)
if (!args[i]->eq(item_func_sc->args[i], binary_cmp))
return 0;
return 1;
return Item_func::eq(item, binary_cmp) &&
collation.collation == item->collation.collation;
}
......@@ -3488,9 +3460,7 @@ void Item_func_set_collation::print(String *str, enum_query_type query_type)
{
args[0]->print_parenthesised(str, query_type, precedence());
str->append(STRING_WITH_LEN(" collate "));
DBUG_ASSERT(args[1]->basic_const_item() &&
args[1]->type() == Item::STRING_ITEM);
((Item_string *)args[1])->print_value(str);
str->append(m_set_collation->name);
}
String *Item_func_charset::val_str(String *str)
......
......@@ -1355,9 +1355,10 @@ class Item_func_conv_charset :public Item_str_func
class Item_func_set_collation :public Item_str_func
{
CHARSET_INFO *m_set_collation;
public:
Item_func_set_collation(THD *thd, Item *a, Item *b):
Item_str_func(thd, a, b) {}
Item_func_set_collation(THD *thd, Item *a, CHARSET_INFO *set_collation):
Item_str_func(thd, a), m_set_collation(set_collation) {}
String *val_str(String *);
void fix_length_and_dec();
bool eq(const Item *item, bool binary_cmp) const;
......
......@@ -302,7 +302,7 @@ static TYPELIB tc_heuristic_recover_typelib=
tc_heuristic_recover_names, NULL
};
const char *first_keyword= "first", *binary_keyword= "BINARY";
const char *first_keyword= "first";
const char *my_localhost= "localhost", *delayed_user= "DELAYED";
const char *quoted_string= "%`s";
......
......@@ -267,7 +267,7 @@ extern time_t server_start_time, flush_status_time;
extern char *opt_mysql_tmpdir, mysql_charsets_dir[];
extern size_t mysql_unpacked_real_data_home_len;
extern MYSQL_PLUGIN_IMPORT MY_TMPDIR mysql_tmpdir_list;
extern const char *first_keyword, *delayed_user, *binary_keyword;
extern const char *first_keyword, *delayed_user;
extern MYSQL_PLUGIN_IMPORT const char *my_localhost;
extern MYSQL_PLUGIN_IMPORT const char **errmesg; /* Error messages */
extern const char *myisam_recover_options_str;
......
......@@ -10064,15 +10064,9 @@ column_default_non_parenthesized_expr:
simple_expr:
column_default_non_parenthesized_expr
| simple_expr COLLATE_SYM ident_or_text %prec NEG
| simple_expr COLLATE_SYM collation_name %prec NEG
{
Item *i1= new (thd->mem_root) Item_string(thd, $3.str,
$3.length,
thd->charset());
if (i1 == NULL)
MYSQL_YYABORT;
$$= new (thd->mem_root) Item_func_set_collation(thd, $1, i1);
if ($$ == NULL)
if (!($$= new (thd->mem_root) Item_func_set_collation(thd, $1, $3)))
MYSQL_YYABORT;
}
| '(' parenthesized_expr ')' { $$= $2; }
......
......@@ -9862,15 +9862,9 @@ column_default_non_parenthesized_expr:
simple_expr:
column_default_non_parenthesized_expr
| explicit_cursor_attr
| simple_expr COLLATE_SYM ident_or_text %prec NEG
| simple_expr COLLATE_SYM collation_name %prec NEG
{
Item *i1= new (thd->mem_root) Item_string(thd, $3.str,
$3.length,
thd->charset());
if (i1 == NULL)
MYSQL_YYABORT;
$$= new (thd->mem_root) Item_func_set_collation(thd, $1, i1);
if ($$ == NULL)
if (!($$= new (thd->mem_root) Item_func_set_collation(thd, $1, $3)))
MYSQL_YYABORT;
}
| '(' parenthesized_expr ')' { $$= $2; }
......
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