diff options
author | gluh@mysql.com/gluh.(none) <> | 2006-08-08 16:03:42 +0500 |
---|---|---|
committer | gluh@mysql.com/gluh.(none) <> | 2006-08-08 16:03:42 +0500 |
commit | 7e07425b2b10a23fc864b0e5ee11e264f19f547c (patch) | |
tree | 475ca7e04f6aa86e1aaadb5b9381c3f76cb6cf95 /sql | |
parent | 91c118e224b1ef4c741bee9a0c533e4b2c34c812 (diff) | |
download | mariadb-git-7e07425b2b10a23fc864b0e5ee11e264f19f547c.tar.gz |
Bug#16172 DECIMAL data type processed incorrectly
issue an 'overflow warning' if result value is bigger than max possible value
Diffstat (limited to 'sql')
-rw-r--r-- | sql/item_create.cc | 2 | ||||
-rw-r--r-- | sql/item_func.cc | 23 | ||||
-rw-r--r-- | sql/my_decimal.h | 8 |
3 files changed, 32 insertions, 1 deletions
diff --git a/sql/item_create.cc b/sql/item_create.cc index 7147142d8a7..e02ba384717 100644 --- a/sql/item_create.cc +++ b/sql/item_create.cc @@ -463,7 +463,7 @@ Item *create_func_cast(Item *a, Cast_target cast_type, int len, int dec, case ITEM_CAST_TIME: res= new Item_time_typecast(a); break; case ITEM_CAST_DATETIME: res= new Item_datetime_typecast(a); break; case ITEM_CAST_DECIMAL: - res= new Item_decimal_typecast(a, (len>0) ? len : 10, dec ? dec : 2); + res= new Item_decimal_typecast(a, (len > 0) ? len : 10, dec); break; case ITEM_CAST_CHAR: res= new Item_char_typecast(a, len, cs ? cs : diff --git a/sql/item_func.cc b/sql/item_func.cc index e901eaf8654..250dec6ae57 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -955,9 +955,32 @@ longlong Item_decimal_typecast::val_int() my_decimal *Item_decimal_typecast::val_decimal(my_decimal *dec) { my_decimal tmp_buf, *tmp= args[0]->val_decimal(&tmp_buf); + bool sign; if ((null_value= args[0]->null_value)) return NULL; my_decimal_round(E_DEC_FATAL_ERROR, tmp, decimals, FALSE, dec); + sign= dec->sign(); + if (unsigned_flag) + { + if (sign) + { + my_decimal_set_zero(dec); + goto err; + } + } + if (max_length - 2 - decimals < (uint) my_decimal_intg(dec)) + { + max_my_decimal(dec, max_length - 2, decimals); + dec->sign(sign); + goto err; + } + return dec; + +err: + push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_ERROR, + ER_WARN_DATA_OUT_OF_RANGE, + ER(ER_WARN_DATA_OUT_OF_RANGE), + name, 1); return dec; } diff --git a/sql/my_decimal.h b/sql/my_decimal.h index b02abacf0a3..3ce8cfee75d 100644 --- a/sql/my_decimal.h +++ b/sql/my_decimal.h @@ -383,5 +383,13 @@ int my_decimal_cmp(const my_decimal *a, const my_decimal *b) return decimal_cmp((decimal_t*) a, (decimal_t*) b); } + +inline +int my_decimal_intg(const my_decimal *a) +{ + return decimal_intg((decimal_t*) a); +} + + #endif /*my_decimal_h*/ |