Commit 12f54d7d authored by Sergei Golubchik's avatar Sergei Golubchik

@@old_mode=zero_date_time_cast

parent 68916bca
...@@ -22,6 +22,7 @@ Id User Host db Command Time State Info ...@@ -22,6 +22,7 @@ Id User Host db Command Time State Info
# #
# MDEV-5372 Make "CAST(time_expr AS DATETIME)" compatible with the SQL Standard) # MDEV-5372 Make "CAST(time_expr AS DATETIME)" compatible with the SQL Standard)
# #
set @@old_mode=zero_date_time_cast;
SELECT CAST(TIME'-10:30:30' AS DATETIME); SELECT CAST(TIME'-10:30:30' AS DATETIME);
CAST(TIME'-10:30:30' AS DATETIME) CAST(TIME'-10:30:30' AS DATETIME)
NULL NULL
......
...@@ -111,10 +111,14 @@ SELECT @@global.old_mode; ...@@ -111,10 +111,14 @@ SELECT @@global.old_mode;
@@global.old_mode @@global.old_mode
NO_PROGRESS_INFO NO_PROGRESS_INFO
SET @@global.old_mode = 4; SET @@global.old_mode = 4;
ERROR 42000: Variable 'old_mode' can't be set to the value of '4'
SELECT @@global.old_mode; SELECT @@global.old_mode;
@@global.old_mode @@global.old_mode
NO_PROGRESS_INFO ZERO_DATE_TIME_CAST
SET @@global.old_mode = 8;
ERROR 42000: Variable 'old_mode' can't be set to the value of '8'
SELECT @@global.old_mode;
@@global.old_mode
ZERO_DATE_TIME_CAST
SET @@global.old_mode = 0.4; SET @@global.old_mode = 0.4;
ERROR 42000: Incorrect argument type to variable 'old_mode' ERROR 42000: Incorrect argument type to variable 'old_mode'
'#---------------------FN_DYNVARS_152_08----------------------#' '#---------------------FN_DYNVARS_152_08----------------------#'
......
...@@ -168,10 +168,13 @@ SELECT @@global.old_mode; ...@@ -168,10 +168,13 @@ SELECT @@global.old_mode;
SET @@global.old_mode = 2; SET @@global.old_mode = 2;
SELECT @@global.old_mode; SELECT @@global.old_mode;
--Error ER_WRONG_VALUE_FOR_VAR
SET @@global.old_mode = 4; SET @@global.old_mode = 4;
SELECT @@global.old_mode; SELECT @@global.old_mode;
--Error ER_WRONG_VALUE_FOR_VAR
SET @@global.old_mode = 8;
SELECT @@global.old_mode;
# use of decimal values # use of decimal values
--Error ER_WRONG_TYPE_FOR_VAR --Error ER_WRONG_TYPE_FOR_VAR
......
...@@ -29,7 +29,7 @@ SHOW PROCESSLIST; ...@@ -29,7 +29,7 @@ SHOW PROCESSLIST;
--echo # --echo #
--echo # MDEV-5372 Make "CAST(time_expr AS DATETIME)" compatible with the SQL Standard) --echo # MDEV-5372 Make "CAST(time_expr AS DATETIME)" compatible with the SQL Standard)
--echo # --echo #
# Checking that "mysqld --old" exposes the 5.5 conversion behaviour set @@old_mode=zero_date_time_cast;
SELECT CAST(TIME'-10:30:30' AS DATETIME); SELECT CAST(TIME'-10:30:30' AS DATETIME);
SELECT CAST(TIME'10:20:30' AS DATETIME); SELECT CAST(TIME'10:20:30' AS DATETIME);
SELECT CAST(TIME'830:20:30' AS DATETIME); SELECT CAST(TIME'830:20:30' AS DATETIME);
...@@ -53,12 +53,12 @@ SELECT a, CAST(a AS DATETIME), TO_DAYS(a) FROM t1; ...@@ -53,12 +53,12 @@ SELECT a, CAST(a AS DATETIME), TO_DAYS(a) FROM t1;
DROP TABLE t1; DROP TABLE t1;
# Note, it was actually a bug that TO_DAYS('830:20:30') returned NULL # Note, it was actually a bug that TO_DAYS('830:20:30') returned NULL
# for a column, while 3 for an expression. We won't fix this, # for a column, while 3 for an expression. We won't fix this,
# it's "mysqld --old" anyway. # it's "old_mode" anyway.
SELECT TO_DAYS(TIME'-10:20:30'); SELECT TO_DAYS(TIME'-10:20:30');
SELECT TO_DAYS(TIME'10:20:30'); SELECT TO_DAYS(TIME'10:20:30');
SELECT TO_DAYS(TIME'830:20:30'); SELECT TO_DAYS(TIME'830:20:30');
# This is to cover Item_temporal_hybrid_func::fix_temporal_type in --old mode: # This is to cover Item_temporal_hybrid_func::fix_temporal_type in old_mode:
CREATE TABLE t1 (a DATETIME, b TIME); CREATE TABLE t1 (a DATETIME, b TIME);
INSERT INTO t1 VALUES (NULL, '00:20:12'); INSERT INTO t1 VALUES (NULL, '00:20:12');
INSERT INTO t1 VALUES (NULL, '-00:20:12'); INSERT INTO t1 VALUES (NULL, '-00:20:12');
......
...@@ -248,7 +248,8 @@ bool Item::get_date_with_conversion(MYSQL_TIME *ltime, ulonglong fuzzydate) ...@@ -248,7 +248,8 @@ bool Item::get_date_with_conversion(MYSQL_TIME *ltime, ulonglong fuzzydate)
and leave it to get_date() to check date. and leave it to get_date() to check date.
*/ */
ulonglong time_flag= (field_type() == MYSQL_TYPE_TIME && ulonglong time_flag= (field_type() == MYSQL_TYPE_TIME &&
!current_thd->variables.old_mode) ? TIME_TIME_ONLY : 0; !(current_thd->variables.old_behavior & OLD_MODE_ZERO_DATE_TIME_CAST)) ?
TIME_TIME_ONLY : 0;
if (get_date(ltime, fuzzydate | time_flag)) if (get_date(ltime, fuzzydate | time_flag))
return true; return true;
if (ltime->time_type == MYSQL_TIMESTAMP_TIME && if (ltime->time_type == MYSQL_TIMESTAMP_TIME &&
......
...@@ -121,8 +121,9 @@ enum enum_filetype { FILETYPE_CSV, FILETYPE_XML }; ...@@ -121,8 +121,9 @@ enum enum_filetype { FILETYPE_CSV, FILETYPE_XML };
#define MODE_PAD_CHAR_TO_FULL_LENGTH (1ULL << 31) #define MODE_PAD_CHAR_TO_FULL_LENGTH (1ULL << 31)
/* Bits for different old style modes */ /* Bits for different old style modes */
#define OLD_MODE_NO_DUP_KEY_WARNINGS_WITH_IGNORE 1 #define OLD_MODE_NO_DUP_KEY_WARNINGS_WITH_IGNORE (1 << 0)
#define OLD_MODE_NO_PROGRESS_INFO 2 #define OLD_MODE_NO_PROGRESS_INFO (1 << 1)
#define OLD_MODE_ZERO_DATE_TIME_CAST (1 << 2)
extern char internal_table_name[2]; extern char internal_table_name[2];
extern char empty_c_string[1]; extern char empty_c_string[1];
......
...@@ -1243,7 +1243,7 @@ time_to_datetime_old(THD *thd, const MYSQL_TIME *from, MYSQL_TIME *to) ...@@ -1243,7 +1243,7 @@ time_to_datetime_old(THD *thd, const MYSQL_TIME *from, MYSQL_TIME *to)
bool bool
time_to_datetime(THD *thd, const MYSQL_TIME *from, MYSQL_TIME *to) time_to_datetime(THD *thd, const MYSQL_TIME *from, MYSQL_TIME *to)
{ {
if (thd->variables.old_mode) if (thd->variables.old_behavior & OLD_MODE_ZERO_DATE_TIME_CAST)
return time_to_datetime_old(thd, from, to); return time_to_datetime_old(thd, from, to);
set_current_date(thd, to); set_current_date(thd, to);
mix_date_and_time(to, from); mix_date_and_time(to, from);
...@@ -1266,7 +1266,8 @@ time_to_datetime_with_warn(THD *thd, ...@@ -1266,7 +1266,8 @@ time_to_datetime_with_warn(THD *thd,
only in the old mode. only in the old mode.
*/ */
if (time_to_datetime(thd, from, to) || if (time_to_datetime(thd, from, to) ||
(thd->variables.old_mode && check_date(to, fuzzydate, &warn))) ((thd->variables.old_behavior && OLD_MODE_ZERO_DATE_TIME_CAST) &&
check_date(to, fuzzydate, &warn)))
{ {
ErrConvTime str(from); ErrConvTime str(from);
make_truncated_value_warning(thd, Sql_condition::WARN_LEVEL_WARN, make_truncated_value_warning(thd, Sql_condition::WARN_LEVEL_WARN,
......
...@@ -2876,7 +2876,9 @@ static Sys_var_set Sys_sql_mode( ...@@ -2876,7 +2876,9 @@ static Sys_var_set Sys_sql_mode(
static const char *old_mode_names[]= static const char *old_mode_names[]=
{ {
"NO_DUP_KEY_WARNINGS_WITH_IGNORE", "NO_PROGRESS_INFO", "NO_DUP_KEY_WARNINGS_WITH_IGNORE",
"NO_PROGRESS_INFO",
"ZERO_DATE_TIME_CAST",
0 0
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment