summaryrefslogtreecommitdiff
path: root/sql/item.cc
diff options
context:
space:
mode:
authorAlexander Barkov <bar@mariadb.org>2017-01-12 15:16:45 +0400
committerAlexander Barkov <bar@mariadb.org>2017-01-12 16:37:58 +0400
commitebb8c9fb26f86cff8c0d81bd2415f415cef952bb (patch)
tree412a9f09133ef8280b55f4e689637380cc8451d6 /sql/item.cc
parent2dc5d8bb7e087a340edb989c045070b808e0da57 (diff)
downloadmariadb-git-ebb8c9fb26f86cff8c0d81bd2415f415cef952bb.tar.gz
MDEV-11030 Assertion `precision > 0' failed in decimal_bin_size
Fixing Item::decimal_precision() to return at least one digit. This fixes the problem reported in MDEV. Also, fixing Item_func_signed::fix_length_and_dec() to reserve space for at least one digit (plus one character for an optional sign). This is needed to have CONVERT(expr,SIGNED) and CONVERT(expr,UNSIGNED) create correct string fields when they appear in string context, e.g.: CREATE TABLE t1 AS SELECT CONCAT(CONVERT('',SIGNED));
Diffstat (limited to 'sql/item.cc')
-rw-r--r--sql/item.cc9
1 files changed, 8 insertions, 1 deletions
diff --git a/sql/item.cc b/sql/item.cc
index 08599f1d486..015f5591c5d 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -533,7 +533,14 @@ uint Item::decimal_precision() const
unsigned_flag);
return MY_MIN(prec, DECIMAL_MAX_PRECISION);
}
- return MY_MIN(max_char_length(), DECIMAL_MAX_PRECISION);
+ uint res= max_char_length();
+ /*
+ Return at least one decimal digit, even if Item::max_char_length()
+ returned 0. This is important to avoid attempts to create fields of types
+ INT(0) or DECIMAL(0,0) when converting NULL or empty strings to INT/DECIMAL:
+ CREATE TABLE t1 AS SELECT CONVERT(NULL,SIGNED) AS a;
+ */
+ return res ? MY_MIN(res, DECIMAL_MAX_PRECISION) : 1;
}