summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <sanja@askmonty.org>2013-03-06 21:10:58 +0200
committerunknown <sanja@askmonty.org>2013-03-06 21:10:58 +0200
commit108a0a1823db2036000b309e7d6bd3216742c4de (patch)
tree2fee2f63610f270bf064e29152724cb8c697446f
parent4ad2fd7cdf1b95b73081f9fe61eae590504e455e (diff)
downloadmariadb-git-108a0a1823db2036000b309e7d6bd3216742c4de.tar.gz
MDEV-4241 fix.
Field_enum incorrectly inherited decimals() from Field_string. Field_enum should be always integer in numeric context.
-rw-r--r--mysql-test/r/type_enum.result15
-rw-r--r--mysql-test/t/type_enum.test15
-rw-r--r--sql/field.h1
-rw-r--r--strings/decimal.c4
4 files changed, 34 insertions, 1 deletions
diff --git a/mysql-test/r/type_enum.result b/mysql-test/r/type_enum.result
index 813f912c5af..390f969f313 100644
--- a/mysql-test/r/type_enum.result
+++ b/mysql-test/r/type_enum.result
@@ -1854,3 +1854,18 @@ a
DROP TABLE t1;
End of 5.1 tests
+#
+# MDEV-4241: Assertion failure: scale >= 0 && precision > 0 &&
+# scale <= precision in decimal_bin_size
+#
+CREATE TABLE t1 (
+f1 enum('1','2','3','4','5')
+) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (1),(2);
+SELECT AVG(f1) FROM t1;
+Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
+def AVG(f1) 246 7 6 Y 128 4 63
+AVG(f1)
+1.5000
+drop table t1;
+End of 5.3 tests
diff --git a/mysql-test/t/type_enum.test b/mysql-test/t/type_enum.test
index 2043342e2c8..5b0b70631a5 100644
--- a/mysql-test/t/type_enum.test
+++ b/mysql-test/t/type_enum.test
@@ -221,3 +221,18 @@ SELECT a FROM t1 WHERE a=0;
DROP TABLE t1;
--echo End of 5.1 tests
+
+--echo #
+--echo # MDEV-4241: Assertion failure: scale >= 0 && precision > 0 &&
+--echo # scale <= precision in decimal_bin_size
+--echo #
+CREATE TABLE t1 (
+ f1 enum('1','2','3','4','5')
+) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (1),(2);
+--enable_metadata
+SELECT AVG(f1) FROM t1;
+--disable_metadata
+drop table t1;
+
+--echo End of 5.3 tests
diff --git a/sql/field.h b/sql/field.h
index 115a9519b7b..665b784d820 100644
--- a/sql/field.h
+++ b/sql/field.h
@@ -1982,6 +1982,7 @@ public:
bool has_charset(void) const { return TRUE; }
/* enum and set are sorted as integers */
CHARSET_INFO *sort_charset(void) const { return &my_charset_bin; }
+ uint decimals() const { return 0; }
private:
int do_save_field_metadata(uchar *first_byte);
uint is_equal(Create_field *new_field);
diff --git a/strings/decimal.c b/strings/decimal.c
index e4925ff5f7c..3aced9b2572 100644
--- a/strings/decimal.c
+++ b/strings/decimal.c
@@ -1465,7 +1465,9 @@ int decimal_bin_size(int precision, int scale)
intg0=intg/DIG_PER_DEC1, frac0=scale/DIG_PER_DEC1,
intg0x=intg-intg0*DIG_PER_DEC1, frac0x=scale-frac0*DIG_PER_DEC1;
- DBUG_ASSERT(scale >= 0 && precision > 0 && scale <= precision);
+ DBUG_ASSERT(scale >= 0);
+ DBUG_ASSERT(precision > 0);
+ DBUG_ASSERT(scale <= precision);
return intg0*sizeof(dec1)+dig2bytes[intg0x]+
frac0*sizeof(dec1)+dig2bytes[frac0x];
}