diff options
-rw-r--r-- | client/mysqlbinlog.cc | 2 | ||||
-rw-r--r-- | include/my_time.h | 2 | ||||
-rw-r--r-- | mysql-test/r/type_blob.result | 148 | ||||
-rw-r--r-- | mysql-test/t/type_blob.test | 162 | ||||
-rw-r--r-- | sql-common/my_time.c | 6 | ||||
-rw-r--r-- | sql/field.cc | 16 | ||||
-rw-r--r-- | sql/init.cc | 2 | ||||
-rw-r--r-- | sql/item_create.cc | 54 | ||||
-rw-r--r-- | sql/share/errmsg.txt | 60 | ||||
-rw-r--r-- | sql/sql_yacc.yy | 56 | ||||
-rw-r--r-- | sql/tztime.cc | 4 | ||||
-rw-r--r-- | sql/unireg.h | 1 |
12 files changed, 442 insertions, 71 deletions
diff --git a/client/mysqlbinlog.cc b/client/mysqlbinlog.cc index 8de096e5ec1..9f021115d5d 100644 --- a/client/mysqlbinlog.cc +++ b/client/mysqlbinlog.cc @@ -1926,7 +1926,7 @@ int main(int argc, char** argv) DBUG_ENTER("main"); DBUG_PROCESS(argv[0]); - init_time(); // for time functions + my_init_time(); // for time functions parse_args(&argc, (char***)&argv); defaults_argv=argv; diff --git a/include/my_time.h b/include/my_time.h index af3fc103530..58995f1bf62 100644 --- a/include/my_time.h +++ b/include/my_time.h @@ -95,7 +95,7 @@ long calc_daynr(uint year,uint month,uint day); uint calc_days_in_year(uint year); uint year_2000_handling(uint year); -void init_time(void); +void my_init_time(void); /* diff --git a/mysql-test/r/type_blob.result b/mysql-test/r/type_blob.result index 7cf85b9b315..b5ad1fd31ea 100644 --- a/mysql-test/r/type_blob.result +++ b/mysql-test/r/type_blob.result @@ -821,4 +821,152 @@ LENGTH(c) CHAR_LENGTH(c) 65535 65535 65535 65535 DROP TABLE t; +drop table if exists b15776; +create table b15776 (data blob(2147483647)); +drop table b15776; +create table b15776 (data blob(-1)); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-1))' at line 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; +create table b15776 (data blob(4294967296)); +ERROR 42000: Display width out of range for column 'data' (max = 4294967295) +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; +Field Type Null Key Default Extra +a longblob YES NULL +b longblob YES NULL +c longblob YES NULL +a1 longtext YES NULL +b1 longtext YES NULL +c1 longtext YES NULL +drop table b15776; +CREATE TABLE b15776 (a blob(4294967296)); +ERROR 42000: Display width out of range for column 'a' (max = 4294967295) +CREATE TABLE b15776 (a text(4294967296)); +ERROR 42000: Display width out of range for column 'a' (max = 4294967295) +CREATE TABLE b15776 (a blob(999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999)); +ERROR 42000: Display width out of range for column 'a' (max = 4294967295) +CREATE TABLE b15776 (a text(999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999)); +ERROR 42000: Display width out of range for column 'a' (max = 4294967295) +CREATE TABLE b15776 (a int(0)); +INSERT INTO b15776 values (NULL), (1), (42), (654); +SELECT * from b15776 ORDER BY a; +a +NULL +1 +42 +654 +DROP TABLE b15776; +CREATE TABLE b15776 (a int(-1)); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-1))' at line 1 +CREATE TABLE b15776 (a int(255)); +DROP TABLE b15776; +CREATE TABLE b15776 (a int(256)); +ERROR 42000: Display width out of range for column 'a' (max = 255) +CREATE TABLE b15776 (data blob(-1)); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-1))' at line 1 +CREATE TABLE b15776 (a char(2147483647)); +ERROR 42000: Column length too big for column 'a' (max = 255); use BLOB or TEXT instead +CREATE TABLE b15776 (a char(2147483648)); +ERROR 42000: Column length too big for column 'a' (max = 255); use BLOB or TEXT instead +CREATE TABLE b15776 (a char(4294967295)); +ERROR 42000: Column length too big for column 'a' (max = 255); use BLOB or TEXT instead +CREATE TABLE b15776 (a char(4294967296)); +ERROR 42000: Display width out of range for column 'a' (max = 4294967295) +CREATE TABLE b15776 (a year(4294967295)); +INSERT INTO b15776 VALUES (42); +SELECT * FROM b15776; +a +2042 +DROP TABLE b15776; +CREATE TABLE b15776 (a year(4294967296)); +ERROR 42000: Display width out of range for column 'a' (max = 4294967295) +CREATE TABLE b15776 (a year(0)); +DROP TABLE b15776; +CREATE TABLE b15776 (a year(-2)); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-2))' at line 1 +CREATE TABLE b15776 (a timestamp(4294967294)); +Warnings: +Warning 1287 The syntax 'TIMESTAMP(4294967294)' is deprecated and will be removed in MySQL 5.2. Please use 'TIMESTAMP' instead +DROP TABLE b15776; +CREATE TABLE b15776 (a timestamp(4294967295)); +ERROR 42000: Display width out of range for column 'a' (max = 255) +CREATE TABLE b15776 (a timestamp(4294967296)); +ERROR 42000: Display width out of range for column 'a' (max = 4294967295) +CREATE TABLE b15776 (a timestamp(-2)); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-2))' at line 1 +CREATE TABLE b15776 (a int(999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999)); +ERROR 42000: Display width out of range for column 'a' (max = 4294967295) +CREATE TABLE b15776 (a char(999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999)); +ERROR 42000: Display width out of range for column 'a' (max = 4294967295) +CREATE TABLE b15776 (a year(999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999)); +ERROR 42000: Display width out of range for column 'a' (max = 4294967295) +CREATE TABLE b15776 (a timestamp(999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999)); +ERROR 42000: Display width out of range for column 'a' (max = 4294967295) +CREATE TABLE b15776 select cast(null as char(4294967295)); +show columns from b15776; +Field Type Null Key Default Extra +cast(null as char(4294967295)) char(0) YES NULL +drop table b15776; +CREATE TABLE b15776 select cast(null as nchar(4294967295)); +show columns from b15776; +Field Type Null Key Default Extra +cast(null as nchar(4294967295)) char(0) YES NULL +drop table b15776; +CREATE TABLE b15776 select cast(null as binary(4294967295)); +show columns from b15776; +Field Type Null Key Default Extra +cast(null as binary(4294967295)) binary(0) YES NULL +drop table b15776; +explain select cast(1 as char(4294967295)); +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used +explain select cast(1 as nchar(4294967295)); +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used +explain select cast(1 as binary(4294967295)); +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used +explain select cast(1 as char(4294967296)); +ERROR 42000: Display width out of range for column 'cast as char' (max = 4294967295) +explain select cast(1 as nchar(4294967296)); +ERROR 42000: Display width out of range for column 'cast as char' (max = 4294967295) +explain select cast(1 as binary(4294967296)); +ERROR 42000: Display width out of range for column 'cast as char' (max = 4294967295) +explain select cast(1 as decimal(-1)); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-1))' at line 1 +explain select cast(1 as decimal(64, 30)); +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used +explain select cast(1 as decimal(64, 999999999999999999999999999999)); +Got one of the listed errors +explain select cast(1 as decimal(4294967296)); +Got one of the listed errors +explain select cast(1 as decimal(999999999999999999999999999999999999)); +Got one of the listed errors +explain select convert(1, char(4294967295)); +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used +explain select convert(1, char(4294967296)); +ERROR 42000: Display width out of range for column 'cast as char' (max = 4294967295) +explain select convert(1, char(999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999)); +ERROR 42000: Display width out of range for column 'cast as char' (max = 4294967295) +explain select convert(1, nchar(4294967295)); +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used +explain select convert(1, nchar(4294967296)); +ERROR 42000: Display width out of range for column 'cast as char' (max = 4294967295) +explain select convert(1, nchar(999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999)); +ERROR 42000: Display width out of range for column 'cast as char' (max = 4294967295) +explain select convert(1, binary(4294967295)); +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used +explain select convert(1, binary(4294967296)); +ERROR 42000: Display width out of range for column 'cast as char' (max = 4294967295) +explain select convert(1, binary(999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999)); +ERROR 42000: Display width out of range for column 'cast as char' (max = 4294967295) End of 5.0 tests diff --git a/mysql-test/t/type_blob.test b/mysql-test/t/type_blob.test index afb70b0bd0c..fdcd85c1b4b 100644 --- a/mysql-test/t/type_blob.test +++ b/mysql-test/t/type_blob.test @@ -446,5 +446,167 @@ INSERT INTO t (c) VALUES (REPEAT('2',65536)); INSERT INTO t (c) VALUES (REPEAT('3',65535)); SELECT LENGTH(c), CHAR_LENGTH(c) FROM t; DROP TABLE t; +# 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 +--disable_warnings +drop table if exists b15776; +--enable_warnings +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 2**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 diff --git a/sql-common/my_time.c b/sql-common/my_time.c index 543a925681b..23532027883 100644 --- a/sql-common/my_time.c +++ b/sql-common/my_time.c @@ -701,9 +701,9 @@ int check_time_range(struct st_mysql_time *my_time, int *warning) Prepare offset of system time zone from UTC for my_system_gmt_sec() func. SYNOPSIS - init_time() + my_init_time() */ -void init_time(void) +void my_init_time(void) { time_t seconds; struct tm *l_time,tm_tmp; @@ -792,7 +792,7 @@ long calc_daynr(uint year,uint month,uint day) NOTES The idea is to cache the time zone offset from UTC (including daylight saving time) for the next call to make things faster. But currently we - just calculate this offset during startup (by calling init_time() + just calculate this offset during startup (by calling my_init_time() function) and use it all the time. Time value provided should be legal time value (e.g. '2003-01-01 25:00:00' is not allowed). diff --git a/sql/field.cc b/sql/field.cc index 32bf5855d8b..c8645aa5a4f 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -9449,8 +9449,20 @@ bool Create_field::init(THD *thd, char *fld_name, enum_field_types fld_type, (fld_type_modifier & NOT_NULL_FLAG) && fld_type != MYSQL_TYPE_TIMESTAMP) flags|= NO_DEFAULT_VALUE_FLAG; - if (fld_length && !(length= (uint) atoi(fld_length))) - fld_length= 0; /* purecov: inspected */ + if (fld_length != 0) + { + errno= 0; + length= strtoul(fld_length, NULL, 10); + if (errno != 0) + { + my_error(ER_TOO_BIG_DISPLAYWIDTH, MYF(0), fld_name, MAX_FIELD_BLOBLENGTH); + DBUG_RETURN(TRUE); + } + + if (length == 0) + fld_length= 0; /* purecov: inspected */ + } + sign_len= fld_type_modifier & UNSIGNED_FLAG ? 0 : 1; switch (fld_type) { diff --git a/sql/init.cc b/sql/init.cc index aee0eb7179c..afda36b6b9d 100644 --- a/sql/init.cc +++ b/sql/init.cc @@ -35,7 +35,7 @@ void unireg_init(ulong options) wild_many='%'; wild_one='_'; wild_prefix='\\'; /* Change to sql syntax */ current_pid=(ulong) getpid(); /* Save for later ref */ - init_time(); /* Init time-functions (read zone) */ + my_init_time(); /* Init time-functions (read zone) */ #ifndef EMBEDDED_LIBRARY my_abort_hook=unireg_abort; /* Abort with close of databases */ #endif diff --git a/sql/item_create.cc b/sql/item_create.cc index 49cc33b95a7..427857c58ad 100644 --- a/sql/item_create.cc +++ b/sql/item_create.cc @@ -5057,8 +5057,41 @@ create_func_cast(THD *thd, Item *a, Cast_target cast_type, break; case ITEM_CAST_DECIMAL: { - len= c_len ? atoi(c_len) : 0; - dec= c_dec ? atoi(c_dec) : 0; + if (c_len == NULL) + { + len= 0; + } + else + { + ulong decoded_size; + errno= 0; + decoded_size= strtoul(c_len, NULL, 10); + if (errno != 0) + { + my_error(ER_TOO_BIG_PRECISION, MYF(0), c_len, a->name, + DECIMAL_MAX_PRECISION); + return NULL; + } + len= decoded_size; + } + + if (c_dec == NULL) + { + dec= 0; + } + else + { + ulong decoded_size; + errno= 0; + decoded_size= strtoul(c_dec, NULL, 10); + if ((errno != 0) || (decoded_size > UINT_MAX)) + { + my_error(ER_TOO_BIG_SCALE, MYF(0), c_dec, a->name, + DECIMAL_MAX_SCALE); + return NULL; + } + dec= decoded_size; + } my_decimal_trim(&len, &dec); if (len < dec) { @@ -5083,7 +5116,22 @@ create_func_cast(THD *thd, Item *a, Cast_target cast_type, case ITEM_CAST_CHAR: { CHARSET_INFO *real_cs= (cs ? cs : thd->variables.collation_connection); - len= c_len ? atoi(c_len) : -1; + if (c_len == NULL) + { + len= LL(-1); + } + else + { + ulong decoded_size; + errno= 0; + decoded_size= strtoul(c_len, NULL, 10); + if (errno != 0) + { + my_error(ER_TOO_BIG_DISPLAYWIDTH, MYF(0), "cast as char", MAX_FIELD_BLOBLENGTH); + return NULL; + } + len= decoded_size; + } res= new (thd->mem_root) Item_char_typecast(a, len, real_cs); break; } diff --git a/sql/share/errmsg.txt b/sql/share/errmsg.txt index 894e2094968..5b9d0ce8617 100644 --- a/sql/share/errmsg.txt +++ b/sql/share/errmsg.txt @@ -1773,30 +1773,30 @@ ER_BLOB_USED_AS_KEY 42000 S1009 swe "En BLOB '%-.192s' kan inte vara nyckel med den anv�nda tabelltypen" ukr "BLOB �������� '%-.192s' �� ���� ���� ������������ � ��������Φ ����� � ����� ��Ц �����æ" ER_TOO_BIG_FIELDLENGTH 42000 S1009 - cze "P-B��li� velk� d�lka sloupce '%-.192s' (nejv�ce %d). Pou�ijte BLOB" - dan "For stor feltl�ngde for kolonne '%-.192s' (maks = %d). Brug BLOB i stedet" - nla "Te grote kolomlengte voor '%-.192s' (max = %d). Maak hiervoor gebruik van het type BLOB" - eng "Column length too big for column '%-.192s' (max = %d); use BLOB or TEXT instead" - jps "column '%-.192s' ��,�m�ۂ��� column �̑傫�����������܂�. (�ő� %d �܂�). BLOB �������Ɏg�p���Ă�������.", - est "Tulba '%-.192s' pikkus on liiga pikk (maksimaalne pikkus: %d). Kasuta BLOB v�ljat��pi" - fre "Champ '%-.192s' trop long (max = %d). Utilisez un BLOB" - ger "Feldl�nge f�r Feld '%-.192s' zu gro� (maximal %d). BLOB- oder TEXT-Spaltentyp verwenden!" - greek "���� ������ ����� ��� �� ����� '%-.192s' (max = %d). �������� ��������������� ��� ���� BLOB" - hun "A(z) '%-.192s' oszlop tul hosszu. (maximum = %d). Hasznaljon BLOB tipust inkabb." - ita "La colonna '%-.192s' e` troppo grande (max=%d). Utilizza un BLOB." - jpn "column '%-.192s' ��,���ݤ��� column ���礭����¿�����ޤ�. (���� %d �ޤ�). BLOB ���˻��Ѥ��Ƥ�������." - kor "Į�� '%-.192s'�� Į�� ���̰� �ʹ� ��ϴ� (�ִ� = %d). ��ſ� BLOB�� ����ϼ���." - nor "For stor n�kkellengde for kolonne '%-.192s' (maks = %d). Bruk BLOB istedenfor" - norwegian-ny "For stor nykkellengde for felt '%-.192s' (maks = %d). Bruk BLOB istadenfor" - pol "Zbyt du�a d�ugo?� kolumny '%-.192s' (maks. = %d). W zamian u�yj typu BLOB" - por "Comprimento da coluna '%-.192s' grande demais (max = %d); use BLOB em seu lugar" - rum "Lungimea coloanei '%-.192s' este prea lunga (maximum = %d). Foloseste BLOB mai bine" - rus "������� ������� ����� ������� '%-.192s' (�������� = %d). ����������� ��� BLOB ��� TEXT ������ ��������" - serbian "Previ�e podataka za kolonu '%-.192s' (maksimum je %d). Upotrebite BLOB polje" - slo "Pr�li� ve�k� d�ka pre pole '%-.192s' (maximum = %d). Pou�ite BLOB" - spa "Longitud de columna demasiado grande para la columna '%-.192s' (maximo = %d).Usar BLOB en su lugar" - swe "F�r stor kolumnl�ngd angiven f�r '%-.192s' (max= %d). Anv�nd en BLOB inst�llet" - ukr "������� ������� ������� '%-.192s' (max = %d). ������������ ��� BLOB" + cze "P-B��li� velk� d�lka sloupce '%-.192s' (nejv�ce %lu). Pou�ijte BLOB" + dan "For stor feltl�ngde for kolonne '%-.192s' (maks = %lu). Brug BLOB i stedet" + nla "Te grote kolomlengte voor '%-.192s' (max = %lu). Maak hiervoor gebruik van het type BLOB" + eng "Column length too big for column '%-.192s' (max = %lu); use BLOB or TEXT instead" + jps "column '%-.192s' ��,�m�ۂ��� column �̑傫�����������܂�. (�ő� %lu �܂�). BLOB �������Ɏg�p���Ă�������.", + est "Tulba '%-.192s' pikkus on liiga pikk (maksimaalne pikkus: %lu). Kasuta BLOB v�ljat��pi" + fre "Champ '%-.192s' trop long (max = %lu). Utilisez un BLOB" + ger "Feldl�nge f�r Feld '%-.192s' zu gro� (maximal %lu). BLOB- oder TEXT-Spaltentyp verwenden!" + greek "���� ������ ����� ��� �� ����� '%-.192s' (max = %lu). �������� ��������������� ��� ���� BLOB" + hun "A(z) '%-.192s' oszlop tul hosszu. (maximum = %lu). Hasznaljon BLOB tipust inkabb." + ita "La colonna '%-.192s' e` troppo grande (max=%lu). Utilizza un BLOB." + jpn "column '%-.192s' ��,���ݤ��� column ���礭����¿�����ޤ�. (���� %lu �ޤ�). BLOB ���˻��Ѥ��Ƥ�������." + kor "Į�� '%-.192s'�� Į�� ���̰� �ʹ� ��ϴ� (�ִ� = %lu). ��ſ� BLOB�� ����ϼ���." + nor "For stor n�kkellengde for kolonne '%-.192s' (maks = %lu). Bruk BLOB istedenfor" + norwegian-ny "For stor nykkellengde for felt '%-.192s' (maks = %lu). Bruk BLOB istadenfor" + pol "Zbyt du�a d�ugo?� kolumny '%-.192s' (maks. = %lu). W zamian u�yj typu BLOB" + por "Comprimento da coluna '%-.192s' grande demais (max = %lu); use BLOB em seu lugar" + rum "Lungimea coloanei '%-.192s' este prea lunga (maximum = %lu). Foloseste BLOB mai bine" + rus "������� ������� ����� ������� '%-.192s' (�������� = %lu). ����������� ��� BLOB ��� TEXT ������ ��������" + serbian "Previ�e podataka za kolonu '%-.192s' (maksimum je %lu). Upotrebite BLOB polje" + slo "Pr�li� ve�k� d�ka pre pole '%-.192s' (maximum = %lu). Pou�ite BLOB" + spa "Longitud de columna demasiado grande para la columna '%-.192s' (maximo = %lu).Usar BLOB en su lugar" + swe "F�r stor kolumnl�ngd angiven f�r '%-.192s' (max= %lu). Anv�nd en BLOB inst�llet" + ukr "������� ������� ������� '%-.192s' (max = %lu). ������������ ��� BLOB" ER_WRONG_AUTO_KEY 42000 S1009 cze "M-B��ete m�t pouze jedno AUTO pole a to mus� b�t definov�no jako kl��" dan "Der kan kun specificeres eet AUTO_INCREMENT-felt, og det skal v�re indekseret" @@ -5513,11 +5513,11 @@ ER_SP_NO_RECURSION eng "Recursive stored functions and triggers are not allowed." ger "Rekursive gespeicherte Routinen und Triggers sind nicht erlaubt" ER_TOO_BIG_SCALE 42000 S1009 - eng "Too big scale %d specified for column '%-.192s'. Maximum is %d." - ger "Zu gro�er Skalierungsfaktor %d f�r Feld '%-.192s' angegeben. Maximum ist %d" + eng "Too big scale %d specified for column '%-.192s'. Maximum is %lu." + ger "Zu gro�er Skalierungsfaktor %d f�r Feld '%-.192s' angegeben. Maximum ist %lu" ER_TOO_BIG_PRECISION 42000 S1009 - eng "Too big precision %d specified for column '%-.192s'. Maximum is %d." - ger "Zu gro�e Genauigkeit %d f�r Feld '%-.192s' angegeben. Maximum ist %d" + eng "Too big precision %d specified for column '%-.192s'. Maximum is %lu." + ger "Zu gro�e Genauigkeit %d f�r Feld '%-.192s' angegeben. Maximum ist %lu" ER_M_BIGGER_THAN_D 42000 S1009 eng "For float(M,D), double(M,D) or decimal(M,D), M must be >= D (column '%-.192s')." ger "F�r FLOAT(M,D), DOUBLE(M,D) oder DECIMAL(M,D) muss M >= D sein (Feld '%-.192s')" @@ -5555,8 +5555,8 @@ ER_WARN_CANT_DROP_DEFAULT_KEYCACHE eng "Cannot drop default keycache" ger "Der vorgabem��ige Schl�ssel-Cache kann nicht gel�scht werden" ER_TOO_BIG_DISPLAYWIDTH 42000 S1009 - eng "Display width out of range for column '%-.192s' (max = %d)" - ger "Anzeigebreite au�erhalb des zul�ssigen Bereichs f�r Spalte '%-.192s' (Maximum: %d)" + eng "Display width out of range for column '%-.192s' (max = %lu)" + ger "Anzeigebreite au�erhalb des zul�ssigen Bereichs f�r Spalte '%-.192s' (Maximum: %lu)" ER_XAER_DUPID XAE08 eng "XAER_DUPID: The XID already exists" ger "XAER_DUPID: Die XID existiert bereits" diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 896b0b26bfa..e479d5e4136 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -1282,7 +1282,8 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); single_multi table_wild_list table_wild_one opt_wild union_clause union_list precision subselect_start opt_and charset - subselect_end select_var_list select_var_list_init help opt_len + subselect_end select_var_list select_var_list_init help + field_length opt_field_length opt_extended_describe prepare prepare_src execute deallocate statement sp_suid @@ -4642,7 +4643,7 @@ field_spec: ; type: - int_type opt_len field_options { $$=$1; } + int_type opt_field_length field_options { $$=$1; } | real_type opt_precision field_options { $$=$1; } | FLOAT_SYM float_options field_options { $$=MYSQL_TYPE_FLOAT; } | BIT_SYM @@ -4650,9 +4651,8 @@ type: Lex->length= (char*) "1"; $$=MYSQL_TYPE_BIT; } - | BIT_SYM '(' NUM ')' + | BIT_SYM field_length { - Lex->length= $3.str; $$=MYSQL_TYPE_BIT; } | BOOL_SYM @@ -4665,9 +4665,8 @@ type: Lex->length=(char*) "1"; $$=MYSQL_TYPE_TINY; } - | char '(' NUM ')' opt_binary + | char field_length opt_binary { - Lex->length=$3.str; $$=MYSQL_TYPE_STRING; } | char opt_binary @@ -4675,9 +4674,8 @@ type: Lex->length=(char*) "1"; $$=MYSQL_TYPE_STRING; } - | nchar '(' NUM ')' opt_bin_mod + | nchar field_length opt_bin_mod { - Lex->length=$3.str; $$=MYSQL_TYPE_STRING; Lex->charset=national_charset_info; } @@ -4687,9 +4685,8 @@ type: $$=MYSQL_TYPE_STRING; Lex->charset=national_charset_info; } - | BINARY '(' NUM ')' + | BINARY field_length { - Lex->length=$3.str; Lex->charset=&my_charset_bin; $$=MYSQL_TYPE_STRING; } @@ -4699,30 +4696,27 @@ type: Lex->charset=&my_charset_bin; $$=MYSQL_TYPE_STRING; } - | varchar '(' NUM ')' opt_binary + | varchar field_length opt_binary { - Lex->length=$3.str; $$= MYSQL_TYPE_VARCHAR; } - | nvarchar '(' NUM ')' opt_bin_mod + | nvarchar field_length opt_bin_mod { - Lex->length=$3.str; $$= MYSQL_TYPE_VARCHAR; Lex->charset=national_charset_info; } - | VARBINARY '(' NUM ')' + | VARBINARY field_length { - Lex->length=$3.str; Lex->charset=&my_charset_bin; $$= MYSQL_TYPE_VARCHAR; } - | YEAR_SYM opt_len field_options + | YEAR_SYM opt_field_length field_options { $$=MYSQL_TYPE_YEAR; } | DATE_SYM { $$=MYSQL_TYPE_DATE; } | TIME_SYM { $$=MYSQL_TYPE_TIME; } - | TIMESTAMP opt_len + | TIMESTAMP opt_field_length { if (YYTHD->variables.sql_mode & MODE_MAXDB) $$=MYSQL_TYPE_DATETIME; @@ -4742,7 +4736,7 @@ type: Lex->charset=&my_charset_bin; $$=MYSQL_TYPE_TINY_BLOB; } - | BLOB_SYM opt_len + | BLOB_SYM opt_field_length { Lex->charset=&my_charset_bin; $$=MYSQL_TYPE_BLOB; @@ -4778,7 +4772,7 @@ type: { $$=MYSQL_TYPE_MEDIUM_BLOB; } | TINYTEXT opt_binary { $$=MYSQL_TYPE_TINY_BLOB; } - | TEXT_SYM opt_len opt_binary + | TEXT_SYM opt_field_length opt_binary { $$=MYSQL_TYPE_BLOB; } | MEDIUMTEXT opt_binary { $$=MYSQL_TYPE_MEDIUM_BLOB; } @@ -4868,8 +4862,8 @@ real_type: float_options: /* empty */ { Lex->dec=Lex->length= (char*)0; } - | '(' NUM ')' - { Lex->length=$2.str; Lex->dec= (char*)0; } + | field_length + { Lex->dec= (char*)0; } | precision {} ; @@ -4899,9 +4893,15 @@ field_option: | ZEROFILL { Lex->type|= UNSIGNED_FLAG | ZEROFILL_FLAG; } ; -opt_len: - /* empty */ { Lex->length=(char*) 0; /* use default length */ } - | '(' NUM ')' { Lex->length= $2.str; } +field_length: + '(' LONG_NUM ')' { Lex->length= $2.str; } + | '(' ULONGLONG_NUM ')' { Lex->length= $2.str; } + | '(' DECIMAL_NUM ')' { Lex->length= $2.str; } + | '(' NUM ')' { Lex->length= $2.str; }; + +opt_field_length: + /* empty */ { Lex->length=(char*) 0; /* use default length */ } + | field_length { } ; opt_precision: @@ -7464,11 +7464,11 @@ in_sum_expr: ; cast_type: - BINARY opt_len + BINARY opt_field_length { $$=ITEM_CAST_CHAR; Lex->charset= &my_charset_bin; Lex->dec= 0; } - | CHAR_SYM opt_len opt_binary + | CHAR_SYM opt_field_length opt_binary { $$=ITEM_CAST_CHAR; Lex->dec= 0; } - | NCHAR_SYM opt_len + | NCHAR_SYM opt_field_length { $$=ITEM_CAST_CHAR; Lex->charset= national_charset_info; Lex->dec=0; } | SIGNED_SYM { $$=ITEM_CAST_SIGNED_INT; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; } diff --git a/sql/tztime.cc b/sql/tztime.cc index f080c61e243..1028cfb7c1b 100644 --- a/sql/tztime.cc +++ b/sql/tztime.cc @@ -1034,7 +1034,7 @@ public: return lowest possible my_time_t in case of ambiguity or if we provide time corresponding to the time-gap. - You should call init_time() function before using this function. + You should call my_init_time() function before using this function. RETURN VALUE Corresponding my_time_t value or 0 in case of error @@ -2663,7 +2663,7 @@ main(int argc, char **argv) } printf("gmt_sec_to_TIME = localtime for time_t in [1000000000,1100000000) range\n"); - init_time(); + my_init_time(); /* Be careful here! my_system_gmt_sec doesn't fully handle unnormalized diff --git a/sql/unireg.h b/sql/unireg.h index 18c3ab16f6a..c1c0e11e113 100644 --- a/sql/unireg.h +++ b/sql/unireg.h @@ -63,6 +63,7 @@ #define MAX_MBWIDTH 3 /* Max multibyte sequence */ #define MAX_FIELD_CHARLENGTH 255 #define MAX_FIELD_VARCHARLENGTH 65535 +#define MAX_FIELD_BLOBLENGTH UINT_MAX #define CONVERT_IF_BIGGER_TO_BLOB 512 /* Used for CREATE ... SELECT */ /* Max column width +1 */ |