Merging from 5.3

modified:
  include/my_time.h
  libmysql/libmysql.c
  mysql-test/r/adddate_454.result
  mysql-test/r/cast.result
  mysql-test/r/date_formats.result
  mysql-test/r/func_sapdb.result
  mysql-test/r/func_time.result
  mysql-test/r/mdev316.result
  mysql-test/r/parser.result
  mysql-test/r/partition_datatype.result
  mysql-test/r/partition_pruning.result
  mysql-test/r/type_date.result
  mysql-test/r/type_datetime.result
  mysql-test/suite/vcol/r/vcol_misc.result
  mysql-test/t/cast.test
  sql-common/my_time.c
  sql/field.cc
  sql/field_conv.cc
  sql/filesort.cc
  sql/item.cc
  sql/item.h
  sql/item_cmpfunc.cc
  sql/item_func.cc
  sql/item_strfunc.cc
  sql/item_timefunc.cc
  sql/sql_time.cc
pending merges:
  Sergei Golubchik 2013-07-03 MDEV-4667 DATE('string') incompability betwe...
This commit is contained in:
Alexander Barkov 2013-07-08 16:49:42 +04:00
commit 1f3ec9800c
26 changed files with 140 additions and 122 deletions

View File

@ -65,14 +65,17 @@ typedef long my_time_t;
#endif #endif
/* Flags to str_to_datetime */ /* Flags to str_to_datetime */
#define TIME_FUZZY_DATE 1
/*
TIME_FUZZY_DATES is used for the result will only be used for comparison
purposes. Conversion is as relaxed as possible.
*/
#define TIME_FUZZY_DATES 1
#define TIME_DATETIME_ONLY 2 #define TIME_DATETIME_ONLY 2
#define TIME_TIME_ONLY 4 #define TIME_TIME_ONLY 4
/* Must be same as MODE_NO_ZERO_IN_DATE */ #define TIME_NO_ZERO_IN_DATE (1UL << 23) /* == MODE_NO_ZERO_IN_DATE */
#define TIME_NO_ZERO_IN_DATE (65536L*2*2*2*2*2*2*2) #define TIME_NO_ZERO_DATE (1UL << 24) /* == MODE_NO_ZERO_DATE */
/* Must be same as MODE_NO_ZERO_DATE */ #define TIME_INVALID_DATES (1UL << 25) /* == MODE_INVALID_DATES */
#define TIME_NO_ZERO_DATE (TIME_NO_ZERO_IN_DATE*2)
#define TIME_INVALID_DATES (TIME_NO_ZERO_DATE*2)
#define MYSQL_TIME_WARN_TRUNCATED 1 #define MYSQL_TIME_WARN_TRUNCATED 1
#define MYSQL_TIME_WARN_OUT_OF_RANGE 2 #define MYSQL_TIME_WARN_OUT_OF_RANGE 2

View File

@ -3200,7 +3200,7 @@ static void fetch_string_with_conversion(MYSQL_BIND *param, char *value,
case MYSQL_TYPE_TIME: case MYSQL_TYPE_TIME:
{ {
MYSQL_TIME *tm= (MYSQL_TIME *)buffer; MYSQL_TIME *tm= (MYSQL_TIME *)buffer;
str_to_time(value, length, tm, TIME_FUZZY_DATE, &err); str_to_time(value, length, tm, 0, &err);
*param->error= test(err); *param->error= test(err);
break; break;
} }
@ -3209,7 +3209,7 @@ static void fetch_string_with_conversion(MYSQL_BIND *param, char *value,
case MYSQL_TYPE_TIMESTAMP: case MYSQL_TYPE_TIMESTAMP:
{ {
MYSQL_TIME *tm= (MYSQL_TIME *)buffer; MYSQL_TIME *tm= (MYSQL_TIME *)buffer;
(void) str_to_datetime(value, length, tm, TIME_FUZZY_DATE, &err); (void) str_to_datetime(value, length, tm, 0, &err);
*param->error= test(err) && (param->buffer_type == MYSQL_TYPE_DATE && *param->error= test(err) && (param->buffer_type == MYSQL_TYPE_DATE &&
tm->time_type != MYSQL_TIMESTAMP_DATE); tm->time_type != MYSQL_TIMESTAMP_DATE);
break; break;
@ -3332,9 +3332,7 @@ static void fetch_long_with_conversion(MYSQL_BIND *param, MYSQL_FIELD *field,
case MYSQL_TYPE_DATETIME: case MYSQL_TYPE_DATETIME:
{ {
int error; int error;
value= number_to_datetime(value, 0, value= number_to_datetime(value, 0, (MYSQL_TIME *) buffer, 0, &error);
(MYSQL_TIME *) buffer, TIME_FUZZY_DATE,
&error);
*param->error= test(error); *param->error= test(error);
break; break;
} }

View File

@ -4,6 +4,8 @@ select * from t1;
d d
2012-00-00 2012-00-00
update t1 set d = adddate(d, interval 1 day); update t1 set d = adddate(d, interval 1 day);
Warnings:
Warning 1292 Incorrect datetime value: '2012-00-00'
select * from t1; select * from t1;
d d
NULL NULL

View File

@ -268,37 +268,37 @@ cast(010203101112.121314 as datetime)
0001-02-03 10:11:12 0001-02-03 10:11:12
select cast(120010203101112.121314 as datetime); select cast(120010203101112.121314 as datetime);
cast(120010203101112.121314 as datetime) cast(120010203101112.121314 as datetime)
0000-00-00 00:00:00 NULL
Warnings: Warnings:
Warning 1292 Incorrect datetime value: '120010203101112.121314' Warning 1292 Incorrect datetime value: '120010203101112.121314'
select cast(cast(1.1 as decimal) as datetime); select cast(cast(1.1 as decimal) as datetime);
cast(cast(1.1 as decimal) as datetime) cast(cast(1.1 as decimal) as datetime)
0000-00-00 00:00:00 NULL
Warnings: Warnings:
Warning 1292 Incorrect datetime value: '1' Warning 1292 Incorrect datetime value: '1'
select cast(cast(-1.1 as decimal) as datetime); select cast(cast(-1.1 as decimal) as datetime);
cast(cast(-1.1 as decimal) as datetime) cast(cast(-1.1 as decimal) as datetime)
0000-00-00 00:00:00 NULL
Warnings: Warnings:
Warning 1292 Incorrect datetime value: '-1' Warning 1292 Incorrect datetime value: '-1'
select cast('0' as date); select cast('0' as date);
cast('0' as date) cast('0' as date)
0000-00-00 NULL
Warnings: Warnings:
Warning 1292 Incorrect datetime value: '0' Warning 1292 Incorrect datetime value: '0'
select cast('' as date); select cast('' as date);
cast('' as date) cast('' as date)
0000-00-00 NULL
Warnings: Warnings:
Warning 1292 Incorrect datetime value: '' Warning 1292 Incorrect datetime value: ''
select cast('0' as datetime); select cast('0' as datetime);
cast('0' as datetime) cast('0' as datetime)
0000-00-00 00:00:00 NULL
Warnings: Warnings:
Warning 1292 Incorrect datetime value: '0' Warning 1292 Incorrect datetime value: '0'
select cast('' as datetime); select cast('' as datetime);
cast('' as datetime) cast('' as datetime)
0000-00-00 00:00:00 NULL
Warnings: Warnings:
Warning 1292 Incorrect datetime value: '' Warning 1292 Incorrect datetime value: ''
select cast('0' as time); select cast('0' as time);
@ -306,7 +306,7 @@ cast('0' as time)
00:00:00 00:00:00
select cast('' as time); select cast('' as time);
cast('' as time) cast('' as time)
00:00:00 NULL
Warnings: Warnings:
Warning 1292 Truncated incorrect time value: '' Warning 1292 Truncated incorrect time value: ''
select cast(NULL as DATE); select cast(NULL as DATE);
@ -323,13 +323,13 @@ cast(NULL as BINARY)
NULL NULL
select cast(cast(120010203101112.121314 as double) as datetime); select cast(cast(120010203101112.121314 as double) as datetime);
cast(cast(120010203101112.121314 as double) as datetime) cast(cast(120010203101112.121314 as double) as datetime)
0000-00-00 00:00:00 NULL
select cast(cast(1.1 as double) as datetime); select cast(cast(1.1 as double) as datetime);
cast(cast(1.1 as double) as datetime) cast(cast(1.1 as double) as datetime)
0000-00-00 00:00:01 0000-00-00 00:00:01
select cast(cast(-1.1 as double) as datetime); select cast(cast(-1.1 as double) as datetime);
cast(cast(-1.1 as double) as datetime) cast(cast(-1.1 as double) as datetime)
0000-00-00 00:00:00 NULL
explain extended select cast(10 as double(5,2)); explain extended select cast(10 as double(5,2));
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
@ -786,4 +786,10 @@ SELECT CAST(TIME('10:20:30') AS DATE) + INTERVAL 1 DAY;
CAST(TIME('10:20:30') AS DATE) + INTERVAL 1 DAY CAST(TIME('10:20:30') AS DATE) + INTERVAL 1 DAY
NULL NULL
Warnings: Warnings:
Warning 1292 Truncated incorrect date value: '0000-00-00' Warning 1292 Incorrect datetime value: '0000-00-00'
SET SQL_MODE=ALLOW_INVALID_DATES;
SELECT DATE("foo");
DATE("foo")
NULL
Warnings:
Warning 1292 Incorrect datetime value: 'foo'

View File

@ -521,7 +521,7 @@ TIME_FORMAT("25:00:00", '%l %p')
1 AM 1 AM
SELECT DATE_FORMAT('%Y-%m-%d %H:%i:%s', 1151414896); SELECT DATE_FORMAT('%Y-%m-%d %H:%i:%s', 1151414896);
DATE_FORMAT('%Y-%m-%d %H:%i:%s', 1151414896) DATE_FORMAT('%Y-%m-%d %H:%i:%s', 1151414896)
1151414896 NULL
Warnings: Warnings:
Warning 1292 Incorrect datetime value: '%Y-%m-%d %H:%i:%s' Warning 1292 Incorrect datetime value: '%Y-%m-%d %H:%i:%s'
select str_to_date('04 /30/2004', '%m /%d/%Y'); select str_to_date('04 /30/2004', '%m /%d/%Y');

View File

@ -168,7 +168,7 @@ date("1997-12-31 23:59:59.000001")
1997-12-31 1997-12-31
select date("1997-13-31 23:59:59.000001"); select date("1997-13-31 23:59:59.000001");
date("1997-13-31 23:59:59.000001") date("1997-13-31 23:59:59.000001")
0000-00-00 NULL
Warnings: Warnings:
Warning 1292 Incorrect datetime value: '1997-13-31 23:59:59.000001' Warning 1292 Incorrect datetime value: '1997-13-31 23:59:59.000001'
select time("1997-12-31 23:59:59.000001"); select time("1997-12-31 23:59:59.000001");
@ -176,7 +176,7 @@ time("1997-12-31 23:59:59.000001")
23:59:59.000001 23:59:59.000001
select time("1997-12-31 25:59:59.000001"); select time("1997-12-31 25:59:59.000001");
time("1997-12-31 25:59:59.000001") time("1997-12-31 25:59:59.000001")
00:00:00 NULL
Warnings: Warnings:
Warning 1292 Truncated incorrect time value: '1997-12-31 25:59:59.000001' Warning 1292 Truncated incorrect time value: '1997-12-31 25:59:59.000001'
select microsecond("1997-12-31 23:59:59.000001"); select microsecond("1997-12-31 23:59:59.000001");
@ -250,8 +250,6 @@ a
select microsecond(19971231235959.01) as a; select microsecond(19971231235959.01) as a;
a a
10000 10000
Warnings:
Warning 1292 Truncated incorrect time value: '19971231235959.01'
select date_add("1997-12-31",INTERVAL "10.09" SECOND_MICROSECOND) as a; select date_add("1997-12-31",INTERVAL "10.09" SECOND_MICROSECOND) as a;
a a
1997-12-31 00:00:10.090000 1997-12-31 00:00:10.090000

View File

@ -1222,14 +1222,13 @@ DROP TABLE t1,t2;
set time_zone= @@global.time_zone; set time_zone= @@global.time_zone;
select str_to_date('10:00 PM', '%h:%i %p') + INTERVAL 10 MINUTE; select str_to_date('10:00 PM', '%h:%i %p') + INTERVAL 10 MINUTE;
str_to_date('10:00 PM', '%h:%i %p') + INTERVAL 10 MINUTE str_to_date('10:00 PM', '%h:%i %p') + INTERVAL 10 MINUTE
NULL 22:10:00
Warnings:
Warning 1411 Incorrect datetime value: '10:00 PM' for function str_to_date
select str_to_date("1997-00-04 22:23:00","%Y-%m-%D") + interval 10 minute; select str_to_date("1997-00-04 22:23:00","%Y-%m-%D") + interval 10 minute;
str_to_date("1997-00-04 22:23:00","%Y-%m-%D") + interval 10 minute str_to_date("1997-00-04 22:23:00","%Y-%m-%D") + interval 10 minute
NULL NULL
Warnings: Warnings:
Warning 1411 Incorrect datetime value: '1997-00-04 22:23:00' for function str_to_date Warning 1292 Truncated incorrect date value: '1997-00-04 22:23:00'
Warning 1292 Incorrect datetime value: '1997-00-04'
create table t1 (field DATE); create table t1 (field DATE);
insert into t1 values ('2006-11-06'); insert into t1 values ('2006-11-06');
select * from t1 where field < '2006-11-06 04:08:36.0'; select * from t1 where field < '2006-11-06 04:08:36.0';
@ -1423,13 +1422,15 @@ MAKEDATE(11111111,1)
NULL NULL
SELECT WEEK(DATE_ADD(FROM_DAYS(1),INTERVAL 1 MONTH), 1); SELECT WEEK(DATE_ADD(FROM_DAYS(1),INTERVAL 1 MONTH), 1);
WEEK(DATE_ADD(FROM_DAYS(1),INTERVAL 1 MONTH), 1) WEEK(DATE_ADD(FROM_DAYS(1),INTERVAL 1 MONTH), 1)
0 NULL
Warnings:
Warning 1292 Incorrect datetime value: '0000-00-00'
# #
# Bug#12584302 AFTER FIX FOR #12403504: ASSERTION FAILED: DELSUM+(INT) Y/4-TEMP > 0, # Bug#12584302 AFTER FIX FOR #12403504: ASSERTION FAILED: DELSUM+(INT) Y/4-TEMP > 0,
# #
DO WEEK((DATE_ADD((CAST(0 AS DATE)), INTERVAL 1 YEAR_MONTH)), 5); DO WEEK((DATE_ADD((CAST(0 AS DATE)), INTERVAL 1 YEAR_MONTH)), 5);
Warnings: Warnings:
Warning 1292 Incorrect datetime value: '0' Warning 1292 Incorrect datetime value: '0000-00-00'
# #
# BUG#13458237 INCONSISTENT HANDLING OF INVALIDE DATES WITH ZERO DAY # BUG#13458237 INCONSISTENT HANDLING OF INVALIDE DATES WITH ZERO DAY
# SIMILAR TO '2009-10-00' # SIMILAR TO '2009-10-00'
@ -1713,6 +1714,7 @@ min(timestampadd(month, 1>'', from_days('%Z')))
NULL NULL
Warnings: Warnings:
Warning 1292 Truncated incorrect INTEGER value: '%Z' Warning 1292 Truncated incorrect INTEGER value: '%Z'
Warning 1292 Incorrect datetime value: '0000-00-00'
create table t1(a time); create table t1(a time);
insert into t1 values ('00:00:00'),('00:01:00'); insert into t1 values ('00:00:00'),('00:01:00');
select 1 from t1 where 1 < some (select cast(a as datetime) from t1); select 1 from t1 where 1 < some (select cast(a as datetime) from t1);
@ -1781,7 +1783,7 @@ Warnings:
Warning 1441 Datetime function: time field overflow Warning 1441 Datetime function: time field overflow
select cast('131415.123e0' as time); select cast('131415.123e0' as time);
cast('131415.123e0' as time) cast('131415.123e0' as time)
00:00:00 NULL
Warnings: Warnings:
Warning 1292 Truncated incorrect time value: '131415.123e0' Warning 1292 Truncated incorrect time value: '131415.123e0'
select cast('2010-01-02 03:04:05' as datetime) between null and '2010-01-02 03:04:04'; select cast('2010-01-02 03:04:05' as datetime) between null and '2010-01-02 03:04:04';
@ -1801,12 +1803,12 @@ unix_timestamp(null)
NULL NULL
select truncate(date('2010-40-10'), 6); select truncate(date('2010-40-10'), 6);
truncate(date('2010-40-10'), 6) truncate(date('2010-40-10'), 6)
0.000000 NULL
Warnings: Warnings:
Warning 1292 Incorrect datetime value: '2010-40-10' Warning 1292 Incorrect datetime value: '2010-40-10'
select extract(month from '2010-40-50'); select extract(month from '2010-40-50');
extract(month from '2010-40-50') extract(month from '2010-40-50')
0 NULL
Warnings: Warnings:
Warning 1292 Incorrect datetime value: '2010-40-50' Warning 1292 Incorrect datetime value: '2010-40-50'
select subtime('0000-00-10 10:10:10', '30 10:00:00'); select subtime('0000-00-10 10:10:10', '30 10:00:00');
@ -1884,6 +1886,8 @@ insert into t1 values ('0000-00-00');
select timestampadd(week, 1, f1) from t1; select timestampadd(week, 1, f1) from t1;
timestampadd(week, 1, f1) timestampadd(week, 1, f1)
NULL NULL
Warnings:
Warning 1292 Incorrect datetime value: '0000-00-00'
select timestampadd(week, 1, date("0000-00-00")); select timestampadd(week, 1, date("0000-00-00"));
timestampadd(week, 1, date("0000-00-00")) timestampadd(week, 1, date("0000-00-00"))
NULL NULL

View File

@ -16,7 +16,7 @@ cast(convert(0x0030 using ucs2) as decimal(5.2)) cast(concat(convert(0x0030 usin
0 0 0 0
select cast(convert(_ucs2 0x0030 using latin1) as date), cast(concat(convert(_ucs2 0x0030 using latin1)) as date); select cast(convert(_ucs2 0x0030 using latin1) as date), cast(concat(convert(_ucs2 0x0030 using latin1)) as date);
cast(convert(_ucs2 0x0030 using latin1) as date) cast(concat(convert(_ucs2 0x0030 using latin1)) as date) cast(convert(_ucs2 0x0030 using latin1) as date) cast(concat(convert(_ucs2 0x0030 using latin1)) as date)
0000-00-00 0000-00-00 NULL NULL
Warnings: Warnings:
Warning 1292 Incorrect datetime value: '0' Warning 1292 Incorrect datetime value: '0'
Warning 1292 Incorrect datetime value: '0' Warning 1292 Incorrect datetime value: '0'

View File

@ -555,14 +555,10 @@ ERROR 42000: Incorrect parameters in the call to native function 'atan'
DROP TABLE IF EXISTS t1; DROP TABLE IF EXISTS t1;
SELECT STR_TO_DATE('10:00 PM', '%h:%i %p') + INTERVAL 10 MINUTE; SELECT STR_TO_DATE('10:00 PM', '%h:%i %p') + INTERVAL 10 MINUTE;
STR_TO_DATE('10:00 PM', '%h:%i %p') + INTERVAL 10 MINUTE STR_TO_DATE('10:00 PM', '%h:%i %p') + INTERVAL 10 MINUTE
NULL 22:10:00
Warnings:
Warning 1411 Incorrect datetime value: '10:00 PM' for function str_to_date
SELECT STR_TO_DATE('10:00 PM', '%h:%i %p') + INTERVAL (INTERVAL(1,2,3) + 1) MINUTE; SELECT STR_TO_DATE('10:00 PM', '%h:%i %p') + INTERVAL (INTERVAL(1,2,3) + 1) MINUTE;
STR_TO_DATE('10:00 PM', '%h:%i %p') + INTERVAL (INTERVAL(1,2,3) + 1) MINUTE STR_TO_DATE('10:00 PM', '%h:%i %p') + INTERVAL (INTERVAL(1,2,3) + 1) MINUTE
NULL 22:01:00
Warnings:
Warning 1411 Incorrect datetime value: '10:00 PM' for function str_to_date
SELECT "1997-12-31 23:59:59" + INTERVAL 1 SECOND; SELECT "1997-12-31 23:59:59" + INTERVAL 1 SECOND;
"1997-12-31 23:59:59" + INTERVAL 1 SECOND "1997-12-31 23:59:59" + INTERVAL 1 SECOND
1998-01-01 00:00:00 1998-01-01 00:00:00

View File

@ -699,6 +699,7 @@ a tz
2038-01-19 03:14:06 Moscow 2038-01-19 03:14:06 Moscow
UPDATE t2 SET a = TIMESTAMPADD(SECOND, 1, a); UPDATE t2 SET a = TIMESTAMPADD(SECOND, 1, a);
Warnings: Warnings:
Warning 1292 Incorrect datetime value: '0000-00-00'
Warning 1264 Out of range value for column 'a' at row 34 Warning 1264 Out of range value for column 'a' at row 34
Warning 1264 Out of range value for column 'a' at row 35 Warning 1264 Out of range value for column 'a' at row 35
SELECT MIN(a), MAX(a) FROM t2; SELECT MIN(a), MAX(a) FROM t2;
@ -780,6 +781,10 @@ a tz
2038-01-19 03:14:07 UTC 2038-01-19 03:14:07 UTC
2011-10-30 00:00:02 Moscow 2011-10-30 00:00:02 Moscow
UPDATE t2 SET a = TIMESTAMPADD(SECOND, -1, a); UPDATE t2 SET a = TIMESTAMPADD(SECOND, -1, a);
Warnings:
Warning 1292 Incorrect datetime value: '0000-00-00'
Warning 1292 Incorrect datetime value: '0000-00-00'
Warning 1292 Incorrect datetime value: '0000-00-00'
SELECT MIN(a), MAX(a) FROM t2; SELECT MIN(a), MAX(a) FROM t2;
MIN(a) MAX(a) MIN(a) MAX(a)
1970-01-01 00:00:01 2038-01-19 03:14:06 1970-01-01 00:00:01 2038-01-19 03:14:06
@ -1174,6 +1179,7 @@ a tz
2038-01-19 06:14:06 Moscow 2038-01-19 06:14:06 Moscow
UPDATE t2 SET a = TIMESTAMPADD(SECOND, 1, a); UPDATE t2 SET a = TIMESTAMPADD(SECOND, 1, a);
Warnings: Warnings:
Warning 1292 Incorrect datetime value: '0000-00-00'
Warning 1299 Invalid TIMESTAMP value in column 'a' at row 8 Warning 1299 Invalid TIMESTAMP value in column 'a' at row 8
Warning 1299 Invalid TIMESTAMP value in column 'a' at row 9 Warning 1299 Invalid TIMESTAMP value in column 'a' at row 9
Warning 1264 Out of range value for column 'a' at row 34 Warning 1264 Out of range value for column 'a' at row 34
@ -1258,6 +1264,9 @@ a tz
2011-10-30 03:00:02 Moscow 2011-10-30 03:00:02 Moscow
UPDATE t2 SET a = TIMESTAMPADD(SECOND, -1, a); UPDATE t2 SET a = TIMESTAMPADD(SECOND, -1, a);
Warnings: Warnings:
Warning 1292 Incorrect datetime value: '0000-00-00'
Warning 1292 Incorrect datetime value: '0000-00-00'
Warning 1292 Incorrect datetime value: '0000-00-00'
Warning 1299 Invalid TIMESTAMP value in column 'a' at row 18 Warning 1299 Invalid TIMESTAMP value in column 'a' at row 18
Warning 1299 Invalid TIMESTAMP value in column 'a' at row 19 Warning 1299 Invalid TIMESTAMP value in column 'a' at row 19
SELECT MIN(a), MAX(a) FROM t2; SELECT MIN(a), MAX(a) FROM t2;

View File

@ -2235,10 +2235,9 @@ INSERT INTO t1 VALUES (1, '2009-01-01'), (2, NULL);
# test with an invalid date, which lead to item->null_value is set. # test with an invalid date, which lead to item->null_value is set.
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < CAST('2009-04-99' AS DATETIME); EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < CAST('2009-04-99' AS DATETIME);
id select_type table partitions type possible_keys key key_len ref rows Extra id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE t1 p20090401 ALL NULL NULL NULL NULL 2 Using where 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
Warnings: Warnings:
Warning 1292 Incorrect datetime value: '2009-04-99' Warning 1292 Incorrect datetime value: '2009-04-99'
Warning 1292 Incorrect datetime value: '2009-04-99'
DROP TABLE t1; DROP TABLE t1;
CREATE TABLE t1 CREATE TABLE t1
(a INT NOT NULL AUTO_INCREMENT, (a INT NOT NULL AUTO_INCREMENT,

View File

@ -136,7 +136,7 @@ select @d:=1311;
1311 1311
select year(@d), month(@d), day(@d), cast(@d as date); select year(@d), month(@d), day(@d), cast(@d as date);
year(@d) month(@d) day(@d) cast(@d as date) year(@d) month(@d) day(@d) cast(@d as date)
0 0 0 0000-00-00 NULL NULL NULL NULL
Warnings: Warnings:
Warning 1292 Incorrect datetime value: '1311' Warning 1292 Incorrect datetime value: '1311'
Warning 1292 Incorrect datetime value: '1311' Warning 1292 Incorrect datetime value: '1311'

View File

@ -657,8 +657,8 @@ create table t1 (d date, t time) engine=myisam;
insert into t1 values ('2000-12-03','22:55:23'),('2008-05-03','10:19:31'); insert into t1 values ('2000-12-03','22:55:23'),('2008-05-03','10:19:31');
select case when d = '2012-12-12' then d else t end as cond, group_concat( d ) from t1 group by cond; select case when d = '2012-12-12' then d else t end as cond, group_concat( d ) from t1 group by cond;
cond group_concat( d ) cond group_concat( d )
0000-00-00 00:00:00 2000-12-03 NULL 2000-12-03
0000-00-00 00:00:00 2008-05-03 NULL 2008-05-03
Warnings: Warnings:
Warning 1292 Incorrect datetime value: '22:55:23' Warning 1292 Incorrect datetime value: '22:55:23'
Warning 1292 Incorrect datetime value: '10:19:31' Warning 1292 Incorrect datetime value: '10:19:31'

View File

@ -187,7 +187,11 @@ ts TIMESTAMP,
tsv TIMESTAMP AS (ADDDATE(ts, INTERVAL 1 DAY)) VIRTUAL tsv TIMESTAMP AS (ADDDATE(ts, INTERVAL 1 DAY)) VIRTUAL
) ENGINE=MyISAM; ) ENGINE=MyISAM;
INSERT INTO t1 (tsv) VALUES (DEFAULT); INSERT INTO t1 (tsv) VALUES (DEFAULT);
Warnings:
Warning 1292 Incorrect datetime value: '0000-00-00'
INSERT DELAYED INTO t1 (tsv) VALUES (DEFAULT); INSERT DELAYED INTO t1 (tsv) VALUES (DEFAULT);
Warnings:
Warning 1292 Incorrect datetime value: '0000-00-00'
FLUSH TABLES; FLUSH TABLES;
SELECT COUNT(*) FROM t1; SELECT COUNT(*) FROM t1;
COUNT(*) COUNT(*)

View File

@ -450,3 +450,6 @@ drop table t1;
# #
SELECT CAST(TIME('10:20:30') AS DATE) + INTERVAL 1 DAY; SELECT CAST(TIME('10:20:30') AS DATE) + INTERVAL 1 DAY;
SET SQL_MODE=ALLOW_INVALID_DATES;
SELECT DATE("foo");

View File

@ -82,7 +82,7 @@ my_bool check_date(const MYSQL_TIME *ltime, my_bool not_zero_date,
{ {
if (not_zero_date) if (not_zero_date)
{ {
if ((((flags & TIME_NO_ZERO_IN_DATE) || !(flags & TIME_FUZZY_DATE)) && if (((flags & TIME_NO_ZERO_IN_DATE) &&
(ltime->month == 0 || ltime->day == 0)) || ltime->neg || (ltime->month == 0 || ltime->day == 0)) || ltime->neg ||
(!(flags & TIME_INVALID_DATES) && (!(flags & TIME_INVALID_DATES) &&
ltime->month && ltime->day > days_in_month[ltime->month-1] && ltime->month && ltime->day > days_in_month[ltime->month-1] &&
@ -114,7 +114,7 @@ my_bool check_date(const MYSQL_TIME *ltime, my_bool not_zero_date,
length Length of string length Length of string
l_time Date is stored here l_time Date is stored here
flags Bitmap of following items flags Bitmap of following items
TIME_FUZZY_DATE Set if we should allow partial dates TIME_FUZZY_DATE
TIME_DATETIME_ONLY Set if we only allow full datetimes. TIME_DATETIME_ONLY Set if we only allow full datetimes.
TIME_NO_ZERO_IN_DATE Don't allow partial dates TIME_NO_ZERO_IN_DATE Don't allow partial dates
TIME_NO_ZERO_DATE Don't allow 0000-00-00 date TIME_NO_ZERO_DATE Don't allow 0000-00-00 date
@ -1242,12 +1242,7 @@ longlong number_to_datetime(longlong nr, ulong sec_part, MYSQL_TIME *time_res,
nr= (nr+19000000L)*1000000L; /* YYMMDD, year: 1970-1999 */ nr= (nr+19000000L)*1000000L; /* YYMMDD, year: 1970-1999 */
goto ok; goto ok;
} }
/* if (nr < 10000101L)
Though officially we support DATE values from 1000-01-01 only, one can
easily insert a value like 1-1-1. So, for consistency reasons such dates
are allowed when TIME_FUZZY_DATE is set.
*/
if (nr < 10000101L && !(flags & TIME_FUZZY_DATE))
goto err; goto err;
if (nr <= 99991231L) if (nr <= 99991231L)
{ {
@ -1326,7 +1321,7 @@ int number_to_time(my_bool neg, longlong nr, ulong sec_part,
if (nr > 9999999 && neg == 0) if (nr > 9999999 && neg == 0)
{ {
if (number_to_datetime(nr, sec_part, ltime, if (number_to_datetime(nr, sec_part, ltime,
TIME_FUZZY_DATE | TIME_INVALID_DATES, was_cut) < 0) TIME_INVALID_DATES, was_cut) < 0)
return -1; return -1;
ltime->year= ltime->month= ltime->day= 0; ltime->year= ltime->month= ltime->day= 0;

View File

@ -5012,10 +5012,9 @@ int Field_temporal::store(const char *from,uint len,CHARSET_INFO *cs)
ErrConvString str(from, len, cs); ErrConvString str(from, len, cs);
func_res= str_to_datetime(cs, from, len, &ltime, func_res= str_to_datetime(cs, from, len, &ltime,
(TIME_FUZZY_DATE |
(thd->variables.sql_mode & (thd->variables.sql_mode &
(MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE | (MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE |
MODE_INVALID_DATES))), MODE_INVALID_DATES)),
&error); &error);
return store_TIME_with_warning(&ltime, &str, error, func_res > MYSQL_TIMESTAMP_ERROR); return store_TIME_with_warning(&ltime, &str, error, func_res > MYSQL_TIMESTAMP_ERROR);
} }
@ -5029,11 +5028,10 @@ int Field_temporal::store(double nr)
ErrConvDouble str(nr); ErrConvDouble str(nr);
longlong tmp= double_to_datetime(nr, &ltime, longlong tmp= double_to_datetime(nr, &ltime,
(TIME_FUZZY_DATE | (thd->variables.sql_mode &
(thd->variables.sql_mode &
(MODE_NO_ZERO_IN_DATE | (MODE_NO_ZERO_IN_DATE |
MODE_NO_ZERO_DATE | MODE_NO_ZERO_DATE |
MODE_INVALID_DATES))), &error); MODE_INVALID_DATES)), &error);
return store_TIME_with_warning(&ltime, &str, error, tmp != -1); return store_TIME_with_warning(&ltime, &str, error, tmp != -1);
} }
@ -5046,11 +5044,10 @@ int Field_temporal::store(longlong nr, bool unsigned_val)
THD *thd= table->in_use; THD *thd= table->in_use;
ErrConvInteger str(nr); ErrConvInteger str(nr);
tmp= number_to_datetime(nr, 0, &ltime, (TIME_FUZZY_DATE | tmp= number_to_datetime(nr, 0, &ltime, (thd->variables.sql_mode &
(thd->variables.sql_mode &
(MODE_NO_ZERO_IN_DATE | (MODE_NO_ZERO_IN_DATE |
MODE_NO_ZERO_DATE | MODE_NO_ZERO_DATE |
MODE_INVALID_DATES))), &error); MODE_INVALID_DATES)), &error);
return store_TIME_with_warning(&ltime, &str, error, tmp != -1); return store_TIME_with_warning(&ltime, &str, error, tmp != -1);
} }
@ -5066,17 +5063,16 @@ int Field_temporal::store_time_dec(MYSQL_TIME *ltime, uint dec)
structure always fit into DATETIME range. structure always fit into DATETIME range.
*/ */
have_smth_to_conv= !check_date(&l_time, pack_time(&l_time) != 0, have_smth_to_conv= !check_date(&l_time, pack_time(&l_time) != 0,
(TIME_FUZZY_DATE | (current_thd->variables.sql_mode &
(current_thd->variables.sql_mode &
(MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE | (MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE |
MODE_INVALID_DATES))), &error); MODE_INVALID_DATES)), &error);
return store_TIME_with_warning(&l_time, &str, error, have_smth_to_conv); return store_TIME_with_warning(&l_time, &str, error, have_smth_to_conv);
} }
my_decimal *Field_temporal::val_decimal(my_decimal *d) my_decimal *Field_temporal::val_decimal(my_decimal *d)
{ {
MYSQL_TIME ltime; MYSQL_TIME ltime;
if (get_date(&ltime, TIME_FUZZY_DATE)) if (get_date(&ltime, 0))
{ {
bzero(&ltime, sizeof(ltime)); bzero(&ltime, sizeof(ltime));
ltime.time_type= mysql_type_to_time_type(type()); ltime.time_type= mysql_type_to_time_type(type());
@ -5215,7 +5211,8 @@ String *Field_time::val_str(String *val_buffer,
bool Field_time::get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) bool Field_time::get_date(MYSQL_TIME *ltime, ulonglong fuzzydate)
{ {
THD *thd= table->in_use; THD *thd= table->in_use;
if (!(fuzzydate & (TIME_FUZZY_DATE|TIME_TIME_ONLY))) if (!(fuzzydate & TIME_TIME_ONLY) &&
(fuzzydate & TIME_NO_ZERO_IN_DATE))
{ {
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN, push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
ER_WARN_DATA_OUT_OF_RANGE, ER_WARN_DATA_OUT_OF_RANGE,
@ -5345,7 +5342,7 @@ bool Field_time_hires::get_date(MYSQL_TIME *ltime, ulonglong fuzzydate)
ltime->time_type= MYSQL_TIMESTAMP_TIME; ltime->time_type= MYSQL_TIMESTAMP_TIME;
ltime->hour+= (ltime->month*32+ltime->day)*24; ltime->hour+= (ltime->month*32+ltime->day)*24;
ltime->month= ltime->day= 0; ltime->month= ltime->day= 0;
return fuzzydate & (TIME_FUZZY_DATE | TIME_TIME_ONLY) ? 0 : 1; return !(fuzzydate & TIME_TIME_ONLY) && (fuzzydate & TIME_NO_ZERO_IN_DATE);
} }
@ -5736,7 +5733,7 @@ void Field_datetime::store_TIME(MYSQL_TIME *ltime)
bool Field_datetime::send_binary(Protocol *protocol) bool Field_datetime::send_binary(Protocol *protocol)
{ {
MYSQL_TIME tm; MYSQL_TIME tm;
Field_datetime::get_date(&tm, TIME_FUZZY_DATE); Field_datetime::get_date(&tm, 0);
return protocol->store(&tm, 0); return protocol->store(&tm, 0);
} }
@ -5820,7 +5817,7 @@ bool Field_datetime::get_date(MYSQL_TIME *ltime, ulonglong fuzzydate)
if (!tmp) if (!tmp)
return fuzzydate & TIME_NO_ZERO_DATE; return fuzzydate & TIME_NO_ZERO_DATE;
if (!ltime->month || !ltime->day) if (!ltime->month || !ltime->day)
return !(fuzzydate & TIME_FUZZY_DATE); return fuzzydate & TIME_NO_ZERO_IN_DATE;
return 0; return 0;
} }
@ -5873,11 +5870,10 @@ int Field_datetime_hires::store_decimal(const my_decimal *d)
error= 2; error= 2;
} }
else else
tmp= number_to_datetime(nr, sec_part, &ltime, (TIME_FUZZY_DATE | tmp= number_to_datetime(nr, sec_part, &ltime, (thd->variables.sql_mode &
(thd->variables.sql_mode &
(MODE_NO_ZERO_IN_DATE | (MODE_NO_ZERO_IN_DATE |
MODE_NO_ZERO_DATE | MODE_NO_ZERO_DATE |
MODE_INVALID_DATES))), &error); MODE_INVALID_DATES)), &error);
return store_TIME_with_warning(&ltime, &str, error, tmp != -1); return store_TIME_with_warning(&ltime, &str, error, tmp != -1);
} }
@ -5885,7 +5881,7 @@ int Field_datetime_hires::store_decimal(const my_decimal *d)
bool Field_datetime_hires::send_binary(Protocol *protocol) bool Field_datetime_hires::send_binary(Protocol *protocol)
{ {
MYSQL_TIME ltime; MYSQL_TIME ltime;
Field_datetime_hires::get_date(&ltime, TIME_FUZZY_DATE); Field_datetime_hires::get_date(&ltime, 0);
return protocol->store(&ltime, dec); return protocol->store(&ltime, dec);
} }
@ -5893,14 +5889,14 @@ bool Field_datetime_hires::send_binary(Protocol *protocol)
double Field_datetime_hires::val_real(void) double Field_datetime_hires::val_real(void)
{ {
MYSQL_TIME ltime; MYSQL_TIME ltime;
Field_datetime_hires::get_date(&ltime, TIME_FUZZY_DATE); Field_datetime_hires::get_date(&ltime, 0);
return TIME_to_double(&ltime); return TIME_to_double(&ltime);
} }
longlong Field_datetime_hires::val_int(void) longlong Field_datetime_hires::val_int(void)
{ {
MYSQL_TIME ltime; MYSQL_TIME ltime;
Field_datetime_hires::get_date(&ltime, TIME_FUZZY_DATE); Field_datetime_hires::get_date(&ltime, 0);
return TIME_to_ulonglong_datetime(&ltime); return TIME_to_ulonglong_datetime(&ltime);
} }
@ -5909,7 +5905,7 @@ String *Field_datetime_hires::val_str(String *str,
String *unused __attribute__((unused))) String *unused __attribute__((unused)))
{ {
MYSQL_TIME ltime; MYSQL_TIME ltime;
Field_datetime_hires::get_date(&ltime, TIME_FUZZY_DATE); Field_datetime_hires::get_date(&ltime, 0);
str->alloc(field_length+1); str->alloc(field_length+1);
str->length(field_length); str->length(field_length);
my_datetime_to_str(&ltime, (char*) str->ptr(), dec); my_datetime_to_str(&ltime, (char*) str->ptr(), dec);
@ -5924,7 +5920,7 @@ bool Field_datetime_hires::get_date(MYSQL_TIME *ltime, ulonglong fuzzydate)
if (!packed) if (!packed)
return fuzzydate & TIME_NO_ZERO_DATE; return fuzzydate & TIME_NO_ZERO_DATE;
if (!ltime->month || !ltime->day) if (!ltime->month || !ltime->day)
return !(fuzzydate & TIME_FUZZY_DATE); return fuzzydate & TIME_NO_ZERO_IN_DATE;
return 0; return 0;
} }

View File

@ -419,7 +419,7 @@ static void do_field_decimal(Copy_field *copy)
static void do_field_temporal(Copy_field *copy) static void do_field_temporal(Copy_field *copy)
{ {
MYSQL_TIME ltime; MYSQL_TIME ltime;
copy->from_field->get_date(&ltime, TIME_FUZZY_DATE); copy->from_field->get_date(&ltime, 0);
copy->to_field->store_time_dec(&ltime, copy->from_field->decimals()); copy->to_field->store_time_dec(&ltime, copy->from_field->decimals());
} }
@ -890,7 +890,7 @@ int field_conv(Field *to,Field *from)
if (from->cmp_type() == TIME_RESULT) if (from->cmp_type() == TIME_RESULT)
{ {
MYSQL_TIME ltime; MYSQL_TIME ltime;
if (from->get_date(&ltime, TIME_FUZZY_DATE)) if (from->get_date(&ltime, 0))
return to->reset(); return to->reset();
else else
return to->store_time_dec(&ltime, from->decimals()); return to->store_time_dec(&ltime, from->decimals());

View File

@ -874,7 +874,7 @@ static void make_sortkey(register SORTPARAM *param,
else else
{ {
MYSQL_TIME buf; MYSQL_TIME buf;
if (item->get_date_result(&buf, TIME_FUZZY_DATE | TIME_INVALID_DATES)) if (item->get_date_result(&buf, TIME_INVALID_DATES))
{ {
DBUG_ASSERT(maybe_null); DBUG_ASSERT(maybe_null);
DBUG_ASSERT(item->null_value); DBUG_ASSERT(item->null_value);

View File

@ -297,7 +297,7 @@ String *Item::val_string_from_decimal(String *str)
String *Item::val_string_from_date(String *str) String *Item::val_string_from_date(String *str)
{ {
MYSQL_TIME ltime; MYSQL_TIME ltime;
if (get_date(&ltime, TIME_FUZZY_DATE) || if (get_date(&ltime, 0) ||
str->alloc(MAX_DATE_STRING_REP_LENGTH)) str->alloc(MAX_DATE_STRING_REP_LENGTH))
{ {
null_value= 1; null_value= 1;
@ -354,7 +354,7 @@ my_decimal *Item::val_decimal_from_date(my_decimal *decimal_value)
{ {
DBUG_ASSERT(fixed == 1); DBUG_ASSERT(fixed == 1);
MYSQL_TIME ltime; MYSQL_TIME ltime;
if (get_date(&ltime, TIME_FUZZY_DATE)) if (get_date(&ltime, 0))
{ {
my_decimal_set_zero(decimal_value); my_decimal_set_zero(decimal_value);
null_value= 1; // set NULL, stop processing null_value= 1; // set NULL, stop processing
@ -413,10 +413,9 @@ int Item::save_time_in_field(Field *field)
int Item::save_date_in_field(Field *field) int Item::save_date_in_field(Field *field)
{ {
MYSQL_TIME ltime; MYSQL_TIME ltime;
if (get_date(&ltime, TIME_FUZZY_DATE | if (get_date(&ltime, (current_thd->variables.sql_mode &
(current_thd->variables.sql_mode & (MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE |
(MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE | MODE_INVALID_DATES))))
MODE_INVALID_DATES))))
return set_field_to_null_with_conversions(field, 0); return set_field_to_null_with_conversions(field, 0);
field->set_notnull(); field->set_notnull();
return field->store_time_dec(&ltime, decimals); return field->store_time_dec(&ltime, decimals);
@ -1280,7 +1279,7 @@ err:
if allowed, otherwise - null. if allowed, otherwise - null.
*/ */
bzero((char*) ltime,sizeof(*ltime)); bzero((char*) ltime,sizeof(*ltime));
return null_value|= (fuzzydate & (TIME_NO_ZERO_DATE|TIME_NO_ZERO_IN_DATE)); return null_value|= !(fuzzydate & TIME_FUZZY_DATES);
} }
bool Item::get_seconds(ulonglong *sec, ulong *sec_part) bool Item::get_seconds(ulonglong *sec, ulong *sec_part)
@ -6385,7 +6384,7 @@ bool Item::send(Protocol *protocol, String *buffer)
case MYSQL_TYPE_TIMESTAMP: case MYSQL_TYPE_TIMESTAMP:
{ {
MYSQL_TIME tm; MYSQL_TIME tm;
get_date(&tm, TIME_FUZZY_DATE | sql_mode_for_dates()); get_date(&tm, sql_mode_for_dates());
if (!null_value) if (!null_value)
{ {
if (f_type == MYSQL_TYPE_DATE) if (f_type == MYSQL_TYPE_DATE)
@ -8610,8 +8609,8 @@ int stored_field_cmp_to_item(THD *thd, Field *field, Item *item)
} }
else else
{ {
field->get_date(&field_time, TIME_FUZZY_DATE | TIME_INVALID_DATES); field->get_date(&field_time, TIME_INVALID_DATES);
item->get_date(&item_time, TIME_FUZZY_DATE | TIME_INVALID_DATES); item->get_date(&item_time, TIME_INVALID_DATES);
} }
return my_time_compare(&field_time, &item_time); return my_time_compare(&field_time, &item_time);
} }
@ -8793,7 +8792,7 @@ bool Item_cache_temporal::cache_value()
value_cached= true; value_cached= true;
MYSQL_TIME ltime; MYSQL_TIME ltime;
if (example->get_date_result(&ltime, TIME_FUZZY_DATE)) if (example->get_date_result(&ltime, 0))
value=0; value=0;
else else
value= pack_time(&ltime); value= pack_time(&ltime);

View File

@ -1047,7 +1047,7 @@ public:
Item **ref, bool skip_registered); Item **ref, bool skip_registered);
virtual bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate); virtual bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate);
bool get_time(MYSQL_TIME *ltime) bool get_time(MYSQL_TIME *ltime)
{ return get_date(ltime, TIME_TIME_ONLY | TIME_FUZZY_DATE); } { return get_date(ltime, TIME_TIME_ONLY); }
bool get_seconds(ulonglong *sec, ulong *sec_part); bool get_seconds(ulonglong *sec, ulong *sec_part);
virtual bool get_date_result(MYSQL_TIME *ltime, ulonglong fuzzydate) virtual bool get_date_result(MYSQL_TIME *ltime, ulonglong fuzzydate)
{ return get_date(ltime,fuzzydate); } { return get_date(ltime,fuzzydate); }

View File

@ -723,7 +723,7 @@ bool get_mysql_time_from_str(THD *thd, String *str, timestamp_type warn_type,
bool value; bool value;
int error; int error;
enum_mysql_timestamp_type timestamp_type; enum_mysql_timestamp_type timestamp_type;
int flags= TIME_FUZZY_DATE | MODE_INVALID_DATES; int flags= TIME_FUZZY_DATES | MODE_INVALID_DATES;
ErrConvString err(str); ErrConvString err(str);
if (warn_type == MYSQL_TIMESTAMP_TIME) if (warn_type == MYSQL_TIMESTAMP_TIME)
@ -896,7 +896,7 @@ get_datetime_value(THD *thd, Item ***item_arg, Item **cache_arg,
else else
{ {
MYSQL_TIME ltime; MYSQL_TIME ltime;
uint fuzzydate= TIME_FUZZY_DATE | TIME_INVALID_DATES; uint fuzzydate= TIME_FUZZY_DATES | TIME_INVALID_DATES;
if (f_type == MYSQL_TYPE_TIME) if (f_type == MYSQL_TYPE_TIME)
fuzzydate|= TIME_TIME_ONLY; fuzzydate|= TIME_TIME_ONLY;
if (item->get_date(&ltime, fuzzydate)) if (item->get_date(&ltime, fuzzydate))

View File

@ -2849,7 +2849,7 @@ double Item_func_min_max::val_real()
if (compare_as_dates) if (compare_as_dates)
{ {
MYSQL_TIME ltime; MYSQL_TIME ltime;
if (get_date(&ltime, TIME_FUZZY_DATE)) if (get_date(&ltime, 0))
return 0; return 0;
return TIME_to_double(&ltime); return TIME_to_double(&ltime);
@ -2878,7 +2878,7 @@ longlong Item_func_min_max::val_int()
if (compare_as_dates) if (compare_as_dates)
{ {
MYSQL_TIME ltime; MYSQL_TIME ltime;
if (get_date(&ltime, TIME_FUZZY_DATE)) if (get_date(&ltime, 0))
return 0; return 0;
return TIME_to_ulonglong(&ltime); return TIME_to_ulonglong(&ltime);
@ -2908,7 +2908,7 @@ my_decimal *Item_func_min_max::val_decimal(my_decimal *dec)
if (compare_as_dates) if (compare_as_dates)
{ {
MYSQL_TIME ltime; MYSQL_TIME ltime;
if (get_date(&ltime, TIME_FUZZY_DATE)) if (get_date(&ltime, 0))
return 0; return 0;
return date2my_decimal(&ltime, dec); return date2my_decimal(&ltime, dec);

View File

@ -3873,10 +3873,10 @@ void Item_func_dyncol_create::prepare_arguments()
} }
break; break;
case DYN_COL_DATETIME: case DYN_COL_DATETIME:
args[valpos]->get_date(&vals[i].x.time_value, TIME_FUZZY_DATE); args[valpos]->get_date(&vals[i].x.time_value, 0);
break; break;
case DYN_COL_DATE: case DYN_COL_DATE:
args[valpos]->get_date(&vals[i].x.time_value, TIME_FUZZY_DATE); args[valpos]->get_date(&vals[i].x.time_value, 0);
break; break;
case DYN_COL_TIME: case DYN_COL_TIME:
args[valpos]->get_time(&vals[i].x.time_value); args[valpos]->get_time(&vals[i].x.time_value);

View File

@ -780,7 +780,7 @@ longlong Item_func_to_seconds::val_int_endpoint(bool left_endp,
longlong seconds; longlong seconds;
longlong days; longlong days;
int dummy; /* unused */ int dummy; /* unused */
if (get_arg0_date(&ltime, TIME_FUZZY_DATE)) if (get_arg0_date(&ltime, TIME_FUZZY_DATES))
{ {
/* got NULL, leave the incl_endp intact */ /* got NULL, leave the incl_endp intact */
return LONGLONG_MIN; return LONGLONG_MIN;
@ -858,7 +858,7 @@ longlong Item_func_to_days::val_int_endpoint(bool left_endp, bool *incl_endp)
MYSQL_TIME ltime; MYSQL_TIME ltime;
longlong res; longlong res;
int dummy; /* unused */ int dummy; /* unused */
if (get_arg0_date(&ltime, TIME_FUZZY_DATE)) if (get_arg0_date(&ltime, 0))
{ {
/* got NULL, leave the incl_endp intact */ /* got NULL, leave the incl_endp intact */
return LONGLONG_MIN; return LONGLONG_MIN;
@ -922,14 +922,14 @@ longlong Item_func_dayofmonth::val_int()
{ {
DBUG_ASSERT(fixed == 1); DBUG_ASSERT(fixed == 1);
MYSQL_TIME ltime; MYSQL_TIME ltime;
return get_arg0_date(&ltime, TIME_FUZZY_DATE) ? 0 : (longlong) ltime.day; return get_arg0_date(&ltime, 0) ? 0 : (longlong) ltime.day;
} }
longlong Item_func_month::val_int() longlong Item_func_month::val_int()
{ {
DBUG_ASSERT(fixed == 1); DBUG_ASSERT(fixed == 1);
MYSQL_TIME ltime; MYSQL_TIME ltime;
return get_arg0_date(&ltime, TIME_FUZZY_DATE) ? 0 : (longlong) ltime.month; return get_arg0_date(&ltime, 0) ? 0 : (longlong) ltime.month;
} }
@ -953,7 +953,7 @@ String* Item_func_monthname::val_str(String* str)
uint err; uint err;
MYSQL_TIME ltime; MYSQL_TIME ltime;
if ((null_value= (get_arg0_date(&ltime, TIME_FUZZY_DATE) || !ltime.month))) if ((null_value= (get_arg0_date(&ltime, 0) || !ltime.month)))
return (String *) 0; return (String *) 0;
month_name= locale->month_names->type_names[ltime.month - 1]; month_name= locale->month_names->type_names[ltime.month - 1];
@ -971,7 +971,7 @@ longlong Item_func_quarter::val_int()
{ {
DBUG_ASSERT(fixed == 1); DBUG_ASSERT(fixed == 1);
MYSQL_TIME ltime; MYSQL_TIME ltime;
if (get_arg0_date(&ltime, TIME_FUZZY_DATE)) if (get_arg0_date(&ltime, 0))
return 0; return 0;
return (longlong) ((ltime.month+2)/3); return (longlong) ((ltime.month+2)/3);
} }
@ -1045,7 +1045,7 @@ longlong Item_func_week::val_int()
DBUG_ASSERT(fixed == 1); DBUG_ASSERT(fixed == 1);
uint year; uint year;
MYSQL_TIME ltime; MYSQL_TIME ltime;
if (get_arg0_date(&ltime, TIME_NO_ZERO_DATE)) if (get_arg0_date(&ltime, TIME_NO_ZERO_DATE | TIME_NO_ZERO_IN_DATE))
return 0; return 0;
return (longlong) calc_week(&ltime, return (longlong) calc_week(&ltime,
week_mode((uint) args[1]->val_int()), week_mode((uint) args[1]->val_int()),
@ -1058,7 +1058,7 @@ longlong Item_func_yearweek::val_int()
DBUG_ASSERT(fixed == 1); DBUG_ASSERT(fixed == 1);
uint year,week; uint year,week;
MYSQL_TIME ltime; MYSQL_TIME ltime;
if (get_arg0_date(&ltime, TIME_NO_ZERO_DATE)) if (get_arg0_date(&ltime, TIME_NO_ZERO_DATE | TIME_NO_ZERO_IN_DATE))
return 0; return 0;
week= calc_week(&ltime, week= calc_week(&ltime,
(week_mode((uint) args[1]->val_int()) | WEEK_YEAR), (week_mode((uint) args[1]->val_int()) | WEEK_YEAR),
@ -1072,7 +1072,7 @@ longlong Item_func_weekday::val_int()
DBUG_ASSERT(fixed == 1); DBUG_ASSERT(fixed == 1);
MYSQL_TIME ltime; MYSQL_TIME ltime;
if (get_arg0_date(&ltime, TIME_NO_ZERO_DATE)) if (get_arg0_date(&ltime, TIME_NO_ZERO_DATE | TIME_NO_ZERO_IN_DATE))
return 0; return 0;
return (longlong) calc_weekday(calc_daynr(ltime.year, ltime.month, return (longlong) calc_weekday(calc_daynr(ltime.year, ltime.month,
@ -1114,7 +1114,7 @@ longlong Item_func_year::val_int()
{ {
DBUG_ASSERT(fixed == 1); DBUG_ASSERT(fixed == 1);
MYSQL_TIME ltime; MYSQL_TIME ltime;
return get_arg0_date(&ltime, TIME_FUZZY_DATE) ? 0 : (longlong) ltime.year; return get_arg0_date(&ltime, 0) ? 0 : (longlong) ltime.year;
} }
@ -1146,7 +1146,7 @@ longlong Item_func_year::val_int_endpoint(bool left_endp, bool *incl_endp)
{ {
DBUG_ASSERT(fixed == 1); DBUG_ASSERT(fixed == 1);
MYSQL_TIME ltime; MYSQL_TIME ltime;
if (get_arg0_date(&ltime, TIME_FUZZY_DATE)) if (get_arg0_date(&ltime, 0))
{ {
/* got NULL, leave the incl_endp intact */ /* got NULL, leave the incl_endp intact */
return LONGLONG_MIN; return LONGLONG_MIN;
@ -1467,7 +1467,7 @@ longlong Item_temporal_func::val_int()
{ {
DBUG_ASSERT(fixed == 1); DBUG_ASSERT(fixed == 1);
MYSQL_TIME ltime; MYSQL_TIME ltime;
if (get_date(&ltime, TIME_FUZZY_DATE | sql_mode)) if (get_date(&ltime, sql_mode))
return 0; return 0;
longlong v= TIME_to_ulonglong(&ltime); longlong v= TIME_to_ulonglong(&ltime);
return ltime.neg ? -v : v; return ltime.neg ? -v : v;
@ -1478,7 +1478,7 @@ double Item_temporal_func::val_real()
{ {
DBUG_ASSERT(fixed == 1); DBUG_ASSERT(fixed == 1);
MYSQL_TIME ltime; MYSQL_TIME ltime;
if (get_date(&ltime, TIME_FUZZY_DATE | sql_mode)) if (get_date(&ltime, sql_mode))
return 0; return 0;
return TIME_to_double(&ltime); return TIME_to_double(&ltime);
} }
@ -1858,7 +1858,7 @@ String *Item_func_date_format::val_str(String *str)
int is_time_flag = is_time_format ? TIME_TIME_ONLY : 0; int is_time_flag = is_time_format ? TIME_TIME_ONLY : 0;
DBUG_ASSERT(fixed == 1); DBUG_ASSERT(fixed == 1);
if (get_arg0_date(&l_time, TIME_FUZZY_DATE | is_time_flag)) if (get_arg0_date(&l_time, is_time_flag))
return 0; return 0;
if (!(format = args[1]->val_str(str)) || !format->length()) if (!(format = args[1]->val_str(str)) || !format->length())
@ -2032,10 +2032,15 @@ bool Item_date_add_interval::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date)
{ {
INTERVAL interval; INTERVAL interval;
if (args[0]->get_date(ltime, TIME_NO_ZERO_DATE | TIME_FUZZY_DATE | TIME_NO_ZERO_IN_DATE) || if (args[0]->get_date(ltime, 0) ||
get_interval_value(args[1], int_type, &interval)) get_interval_value(args[1], int_type, &interval))
return (null_value=1); return (null_value=1);
if (ltime->time_type != MYSQL_TIMESTAMP_TIME &&
check_date_with_warn(ltime, TIME_NO_ZERO_DATE | TIME_NO_ZERO_IN_DATE,
MYSQL_TIMESTAMP_ERROR))
return (null_value=1);
if (date_sub_interval) if (date_sub_interval)
interval.neg = !interval.neg; interval.neg = !interval.neg;
@ -2128,7 +2133,7 @@ longlong Item_extract::val_int()
long neg; long neg;
int is_time_flag = date_value ? 0 : TIME_TIME_ONLY; int is_time_flag = date_value ? 0 : TIME_TIME_ONLY;
if (get_arg0_date(&ltime, TIME_FUZZY_DATE | is_time_flag)) if (get_arg0_date(&ltime, is_time_flag))
return 0; return 0;
neg= ltime.neg ? -1 : 1; neg= ltime.neg ? -1 : 1;
@ -2553,7 +2558,7 @@ bool Item_func_add_time::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date)
if (is_date) // TIMESTAMP function if (is_date) // TIMESTAMP function
{ {
if (get_arg0_date(&l_time1, TIME_FUZZY_DATE) || if (get_arg0_date(&l_time1, 0) ||
args[1]->get_time(&l_time2) || args[1]->get_time(&l_time2) ||
l_time1.time_type == MYSQL_TIMESTAMP_TIME || l_time1.time_type == MYSQL_TIMESTAMP_TIME ||
l_time2.time_type != MYSQL_TIMESTAMP_TIME) l_time2.time_type != MYSQL_TIMESTAMP_TIME)

View File

@ -332,7 +332,7 @@ str_to_datetime_with_warn(CHARSET_INFO *cs,
@param nr integer part of the number to convert @param nr integer part of the number to convert
@param sec_part microsecond part of the number @param sec_part microsecond part of the number
@param ltime converted value will be written here @param ltime converted value will be written here
@param fuzzydate conversion flags (TIME_FUZZY_DATE, etc) @param fuzzydate conversion flags (TIME_INVALID_DATE, etc)
@param str original number, as an ErrConv. For the warning @param str original number, as an ErrConv. For the warning
@param field_name field name or NULL if not a field. For the warning @param field_name field name or NULL if not a field. For the warning
@ -349,6 +349,7 @@ static bool number_to_time_with_warn(bool neg, ulonglong nr, ulong sec_part,
if (fuzzydate & TIME_TIME_ONLY) if (fuzzydate & TIME_TIME_ONLY)
{ {
fuzzydate= TIME_TIME_ONLY; // clear other flags
f_type= MYSQL_TYPE_TIME; f_type= MYSQL_TYPE_TIME;
res= number_to_time(neg, nr, sec_part, ltime, &was_cut); res= number_to_time(neg, nr, sec_part, ltime, &was_cut);
} }
@ -358,7 +359,7 @@ static bool number_to_time_with_warn(bool neg, ulonglong nr, ulong sec_part,
res= neg ? -1 : number_to_datetime(nr, sec_part, ltime, fuzzydate, &was_cut); res= neg ? -1 : number_to_datetime(nr, sec_part, ltime, fuzzydate, &was_cut);
} }
if (res < 0 || (was_cut && !(fuzzydate & TIME_FUZZY_DATE))) if (res < 0 || (was_cut && (fuzzydate & TIME_NO_ZERO_IN_DATE)))
{ {
make_truncated_value_warning(current_thd, make_truncated_value_warning(current_thd,
MYSQL_ERROR::WARN_LEVEL_WARN, str, MYSQL_ERROR::WARN_LEVEL_WARN, str,