diff options
author | unknown <konstantin@mysql.com> | 2005-05-03 19:32:29 +0400 |
---|---|---|
committer | unknown <konstantin@mysql.com> | 2005-05-03 19:32:29 +0400 |
commit | 3aa89efcdd44ed3407638889ede544fc0ed3eb49 (patch) | |
tree | 9a3785c3361bd8e3d2c4f0888548924229df20ff /sql/item.cc | |
parent | 9724795fd68149c2a780de1cdcb194c8a7b17597 (diff) | |
parent | b883aebae088aa156f0ddba943fba4b4f4c17f8e (diff) | |
download | mariadb-git-3aa89efcdd44ed3407638889ede544fc0ed3eb49.tar.gz |
Manual merge of Bug#9096
Diffstat (limited to 'sql/item.cc')
-rw-r--r-- | sql/item.cc | 115 |
1 files changed, 114 insertions, 1 deletions
diff --git a/sql/item.cc b/sql/item.cc index 7264f8b2d68..495ad772ec6 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -557,6 +557,11 @@ void Item::set_name(const char *str, uint length, CHARSET_INFO *cs) bool Item::eq(const Item *item, bool binary_cmp) const { + /* + Note, that this is never TRUE if item is a Item_param: + for all basic constants we have special checks, and Item_param's + type() can be only among basic constant types. + */ return type() == item->type() && name && item->name && !my_strcasecmp(system_charset_info,name,item->name); } @@ -601,7 +606,7 @@ Item *Item_string::safe_charset_converter(CHARSET_INFO *tocs) bool Item_string::eq(const Item *item, bool binary_cmp) const { - if (type() == item->type()) + if (type() == item->type() && item->basic_const_item()) { if (binary_cmp) return !stringcmp(&str_value, &item->str_value); @@ -2194,6 +2199,72 @@ bool Item_param::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) } +bool Item_param::basic_const_item() const +{ + if (state == NO_VALUE || state == TIME_VALUE) + return FALSE; + return TRUE; +} + + +Item * +Item_param::new_item() +{ + /* see comments in the header file */ + switch (state) { + case NULL_VALUE: + return new Item_null(name); + case INT_VALUE: + return new Item_int(name, value.integer, max_length); + case REAL_VALUE: + return new Item_real(name, value.real, decimals, max_length); + case STRING_VALUE: + case LONG_DATA_VALUE: + return new Item_string(name, str_value.c_ptr_quick(), str_value.length(), + str_value.charset()); + case TIME_VALUE: + break; + case NO_VALUE: + default: + DBUG_ASSERT(0); + }; + return 0; +} + + +bool +Item_param::eq(const Item *arg, bool binary_cmp) const +{ + Item *item; + if (!basic_const_item() || !arg->basic_const_item() || arg->type() != type()) + return FALSE; + /* + We need to cast off const to call val_int(). This should be OK for + a basic constant. + */ + item= (Item*) arg; + + switch (state) { + case NULL_VALUE: + return TRUE; + case INT_VALUE: + return value.integer == item->val_int() && + unsigned_flag == item->unsigned_flag; + case REAL_VALUE: + return value.real == item->val(); + case STRING_VALUE: + case LONG_DATA_VALUE: + if (binary_cmp) + return !stringcmp(&str_value, &item->str_value); + return !sortcmp(&str_value, &item->str_value, collation.collation); + default: + break; + } + return FALSE; +} + +/* End of Item_param related */ + void Item_param::print(String *str) { if (state == NO_VALUE) @@ -3346,6 +3417,22 @@ int Item_decimal::save_in_field(Field *field, bool no_conversions) } +bool Item_int::eq(const Item *arg, bool binary_cmp) const +{ + /* No need to check for null value as basic constant can't be NULL */ + if (arg->basic_const_item() && arg->type() == type()) + { + /* + We need to cast off const to call val_int(). This should be OK for + a basic constant. + */ + Item *item= (Item*) arg; + return item->val_int() == value && item->unsigned_flag == unsigned_flag; + } + return FALSE; +} + + Item_num *Item_uint::neg() { Item_decimal *item= new Item_decimal(value, 0); @@ -3433,6 +3520,21 @@ void Item_float::print(String *str) In number context this is a longlong value. */ +bool Item_real::eq(const Item *arg, bool binary_cmp) const +{ + if (arg->basic_const_item() && arg->type() == type()) + { + /* + We need to cast off const to call val_int(). This should be OK for + a basic constant. + */ + Item *item= (Item*) arg; + return item->val() == value; + } + return FALSE; +} + + inline uint char_val(char X) { return (uint) (X >= '0' && X <= '9' ? X-'0' : @@ -3503,6 +3605,17 @@ int Item_hex_string::save_in_field(Field *field, bool no_conversions) } +bool Item_varbinary::eq(const Item *arg, bool binary_cmp) const +{ + if (arg->basic_const_item() && arg->type() == type()) + { + if (binary_cmp) + return !stringcmp(&str_value, &arg->str_value); + return !sortcmp(&str_value, &arg->str_value, collation.collation); + } + return FALSE; +} + /* bin item. In string context this is a binary string. |