MDEV-5975 Prepared statements with DATE literals do not honor NO_ZERO_IN_DATE

This commit is contained in:
Alexander Barkov 2014-04-22 11:23:35 +04:00
parent 046ae9f5c6
commit ed93e55bac
3 changed files with 48 additions and 0 deletions

View file

@ -613,3 +613,31 @@ t1 CREATE TABLE `t1` (
`TIMESTAMP'2001-01-00 00:00:00'` datetime DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE t1;
#
# MDEV-5975 Prepared statements with DATE literals do not honor NO_ZERO_IN_DATE
#
SET sql_mode=DEFAULT;
PREPARE stmt FROM "SELECT (SELECT DATE'2001-00-00') AS c";
EXECUTE stmt;
c
2001-00-00
SET sql_mode='no_zero_in_date';
EXECUTE stmt;
c
NULL
Warnings:
Warning 1292 Incorrect datetime value: '2001-00-00'
DEALLOCATE PREPARE stmt;
SET sql_mode=DEFAULT;
PREPARE stmt FROM "SELECT (SELECT TIMESTAMP'2001-00-00 10:20:30') AS c";
EXECUTE stmt;
c
2001-00-00 10:20:30
SET sql_mode='no_zero_in_date';
EXECUTE stmt;
c
NULL
Warnings:
Warning 1292 Incorrect datetime value: '2001-00-00 10:20:30'
DEALLOCATE PREPARE stmt;
SET sql_mode=DEFAULT;

View file

@ -326,3 +326,21 @@ CREATE TABLE t1 AS SELECT
TIMESTAMP'2001-01-00 00:00:00';
SHOW CREATE TABLE t1;
DROP TABLE t1;
--echo #
--echo # MDEV-5975 Prepared statements with DATE literals do not honor NO_ZERO_IN_DATE
--echo #
SET sql_mode=DEFAULT;
PREPARE stmt FROM "SELECT (SELECT DATE'2001-00-00') AS c";
EXECUTE stmt;
SET sql_mode='no_zero_in_date';
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET sql_mode=DEFAULT;
PREPARE stmt FROM "SELECT (SELECT TIMESTAMP'2001-00-00 10:20:30') AS c";
EXECUTE stmt;
SET sql_mode='no_zero_in_date';
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET sql_mode=DEFAULT;

View file

@ -6509,6 +6509,7 @@ void Item_date_literal::print(String *str, enum_query_type query_type)
bool Item_date_literal::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date)
{
DBUG_ASSERT(fixed);
fuzzy_date |= sql_mode_for_dates(current_thd);
*ltime= cached_time;
return (null_value= check_date_with_warn(ltime, fuzzy_date,
MYSQL_TIMESTAMP_ERROR));
@ -6528,6 +6529,7 @@ void Item_datetime_literal::print(String *str, enum_query_type query_type)
bool Item_datetime_literal::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date)
{
DBUG_ASSERT(fixed);
fuzzy_date |= sql_mode_for_dates(current_thd);
*ltime= cached_time;
return (null_value= check_date_with_warn(ltime, fuzzy_date,
MYSQL_TIMESTAMP_ERROR));