summaryrefslogtreecommitdiff
path: root/mysql-test/t
diff options
context:
space:
mode:
authorunknown <cmiller@zippy.cornsilk.net>2007-08-31 15:24:43 -0400
committerunknown <cmiller@zippy.cornsilk.net>2007-08-31 15:24:43 -0400
commit13fea36d03529eefceadaa16b8a9d1faf3802eed (patch)
treea4312c3393e59c7c903a284b76a49c01dcd7bdc4 /mysql-test/t
parent898333f843b5c750b9863ea94d60ab81a9caca4e (diff)
downloadmariadb-git-13fea36d03529eefceadaa16b8a9d1faf3802eed.tar.gz
Bug#15776: 32-bit signed int used for length of blob
Based on contributed patch from Martin Friebe, CLA from 2007-02-24. The parser lacked support for field sizes after signed long, when it should extend to 2**32-1. Now, we correct that limitation, and also make the error handling consistent for casts. mysql-test/r/type_blob.result: Verify that blobs may be created with the size that is already documented. Additionally, test the limits of several other types. mysql-test/t/type_blob.test: Verify that blobs may be created with the size that is already documented. Additionally, test the limits of several other types. sql/field.cc: atoi() insufficient to gauge the length of some fields. Change it to strtoul(). sql/item_create.cc: atoi() insufficient to gauge the length of some fields. Change it to strtoul(). If a casted length is too long, raise an error. sql/share/errmsg.txt: Change ER_TOO_BIG_FIELDLENGTH so that it can accept sizes larger than 2**15 -- instead, 2**32. sql/sql_yacc.yy: Make lengths take, in addition to NUM, LONG_NUM, ULONGLONG_NUM, and DECIMAL_NUM. sql/unireg.h: Define new constant.
Diffstat (limited to 'mysql-test/t')
-rw-r--r--mysql-test/t/type_blob.test161
1 files changed, 161 insertions, 0 deletions
diff --git a/mysql-test/t/type_blob.test b/mysql-test/t/type_blob.test
index ba9f374a24c..097c749f977 100644
--- a/mysql-test/t/type_blob.test
+++ b/mysql-test/t/type_blob.test
@@ -436,4 +436,165 @@ set @@sql_mode='TRADITIONAL';
create table t1 (a text default '');
set @@sql_mode='';
+#
+# Bug#15776: 32-bit signed int used for length of blob
+# """LONGBLOB: A BLOB column with a maximum length of 4,294,967,295 or 4GB."""
+#
+# Conditions should be in this order:
+# A size is not in the allowed bounds.
+# If the type is char-ish AND size is within the max blob size:
+# raise ER_TOO_BIG_FIELDLENGTH (suggest using BLOB)
+# If size is too small:
+# raise ER_PARSE_ERROR
+# raise ER_TOO_BIG_DISPLAYWIDTH
+
+# BLOB and TEXT types
+create table b15776 (data blob(2147483647));
+drop table b15776;
+--error ER_PARSE_ERROR
+create table b15776 (data blob(-1));
+create table b15776 (data blob(2147483648));
+drop table b15776;
+create table b15776 (data blob(4294967294));
+drop table b15776;
+create table b15776 (data blob(4294967295));
+drop table b15776;
+--error ER_TOO_BIG_DISPLAYWIDTH
+create table b15776 (data blob(4294967296));
+
+CREATE TABLE b15776 (a blob(2147483647), b blob(2147483648), c blob(4294967295), a1 text(2147483647), b1 text(2147483648), c1 text(4294967295) );
+show columns from b15776;
+drop table b15776;
+
+--error ER_TOO_BIG_DISPLAYWIDTH
+CREATE TABLE b15776 (a blob(4294967296));
+--error ER_TOO_BIG_DISPLAYWIDTH
+CREATE TABLE b15776 (a text(4294967296));
+--error ER_TOO_BIG_DISPLAYWIDTH
+CREATE TABLE b15776 (a blob(999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999));
+--error ER_TOO_BIG_DISPLAYWIDTH
+CREATE TABLE b15776 (a text(999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999));
+
+# Int types
+# "Another extension is supported by MySQL for optionally specifying the
+# display width of integer data types in parentheses following the base keyword
+# for the type (for example, INT(4)). This optional display width is used to
+# display integer values having a width less than the width specified for the
+# column by left-padding them with spaces." ยง Numeric Types
+CREATE TABLE b15776 (a int(0)); # 0 is special case, means default size
+INSERT INTO b15776 values (NULL), (1), (42), (654);
+SELECT * from b15776 ORDER BY a;
+DROP TABLE b15776;
+--error ER_PARSE_ERROR
+CREATE TABLE b15776 (a int(-1));
+CREATE TABLE b15776 (a int(255));
+DROP TABLE b15776;
+--error ER_TOO_BIG_DISPLAYWIDTH
+CREATE TABLE b15776 (a int(256));
+--error ER_PARSE_ERROR
+CREATE TABLE b15776 (data blob(-1));
+
+# Char types
+# Recommend BLOB
+--error ER_TOO_BIG_FIELDLENGTH
+CREATE TABLE b15776 (a char(2147483647));
+--error ER_TOO_BIG_FIELDLENGTH
+CREATE TABLE b15776 (a char(2147483648));
+--error ER_TOO_BIG_FIELDLENGTH
+CREATE TABLE b15776 (a char(4294967295));
+# Even BLOB won't hold
+--error ER_TOO_BIG_DISPLAYWIDTH
+CREATE TABLE b15776 (a char(4294967296));
+
+
+# Other numeric-ish types
+## For year, widths not "2" or "4" are silently rewritten to "4". But
+## When we complain about it, we say that the max is 255. We may be
+## talking about different things. It's confusing.
+CREATE TABLE b15776 (a year(4294967295));
+INSERT INTO b15776 VALUES (42);
+SELECT * FROM b15776;
+DROP TABLE b15776;
+--error ER_TOO_BIG_DISPLAYWIDTH
+CREATE TABLE b15776 (a year(4294967296));
+CREATE TABLE b15776 (a year(0)); # 0 is special case, means default size
+DROP TABLE b15776;
+--error ER_PARSE_ERROR
+CREATE TABLE b15776 (a year(-2));
+
+## For timestamp, we silently rewrite widths to 14 or 19.
+CREATE TABLE b15776 (a timestamp(4294967294));
+DROP TABLE b15776;
+--error ER_TOO_BIG_DISPLAYWIDTH
+CREATE TABLE b15776 (a timestamp(4294967295));
+--error ER_TOO_BIG_DISPLAYWIDTH
+CREATE TABLE b15776 (a timestamp(4294967296));
+--error ER_PARSE_ERROR
+CREATE TABLE b15776 (a timestamp(-2));
+
+
+# We've already tested the case, but this should visually show that
+# widths that are too large to be interpreted cause DISPLAYWIDTH errors.
+--error ER_TOO_BIG_DISPLAYWIDTH
+CREATE TABLE b15776 (a int(999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999));
+--error ER_TOO_BIG_DISPLAYWIDTH
+CREATE TABLE b15776 (a char(999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999));
+--error ER_TOO_BIG_DISPLAYWIDTH
+CREATE TABLE b15776 (a year(999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999));
+--error ER_TOO_BIG_DISPLAYWIDTH
+CREATE TABLE b15776 (a timestamp(999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999));
+
+## Do not select, too much memory needed.
+CREATE TABLE b15776 select cast(null as char(4294967295));
+show columns from b15776;
+drop table b15776;
+CREATE TABLE b15776 select cast(null as nchar(4294967295));
+show columns from b15776;
+drop table b15776;
+CREATE TABLE b15776 select cast(null as binary(4294967295));
+show columns from b15776;
+drop table b15776;
+
+explain select cast(1 as char(4294967295));
+explain select cast(1 as nchar(4294967295));
+explain select cast(1 as binary(4294967295));
+
+--error ER_TOO_BIG_DISPLAYWIDTH
+explain select cast(1 as char(4294967296));
+--error ER_TOO_BIG_DISPLAYWIDTH
+explain select cast(1 as nchar(4294967296));
+--error ER_TOO_BIG_DISPLAYWIDTH
+explain select cast(1 as binary(4294967296));
+
+--error ER_PARSE_ERROR
+explain select cast(1 as decimal(-1));
+explain select cast(1 as decimal(64, 30));
+# It's not as important which errors are raised for these, since the
+# limit is nowhere near 3**32. We may fix these eventually to take
+# 4294967295 and still reject it because it's greater than 64 or 30,
+# but that's not a high priority and the parser needn't worry about
+# such a weird case.
+--error ER_TOO_BIG_SCALE,ER_PARSE_ERROR
+explain select cast(1 as decimal(64, 999999999999999999999999999999));
+--error ER_TOO_BIG_PRECISION,ER_PARSE_ERROR
+explain select cast(1 as decimal(4294967296));
+--error ER_TOO_BIG_PRECISION,ER_PARSE_ERROR
+explain select cast(1 as decimal(999999999999999999999999999999999999));
+
+explain select convert(1, char(4294967295));
+--error ER_TOO_BIG_DISPLAYWIDTH
+explain select convert(1, char(4294967296));
+--error ER_TOO_BIG_DISPLAYWIDTH
+explain select convert(1, char(999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999));
+explain select convert(1, nchar(4294967295));
+--error ER_TOO_BIG_DISPLAYWIDTH
+explain select convert(1, nchar(4294967296));
+--error ER_TOO_BIG_DISPLAYWIDTH
+explain select convert(1, nchar(999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999));
+explain select convert(1, binary(4294967295));
+--error ER_TOO_BIG_DISPLAYWIDTH
+explain select convert(1, binary(4294967296));
+--error ER_TOO_BIG_DISPLAYWIDTH
+explain select convert(1, binary(999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999));
+
--echo End of 5.0 tests