summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Barkov <bar@mariadb.com>2020-11-17 16:59:38 +0200
committerMonty <monty@mariadb.org>2021-01-28 11:50:54 +0200
commitf79bc15b64ca3d153fba911b18b6f1da8fdaa735 (patch)
tree0169a7fbc244a283f855866774e11942f952e1b4
parent5430e126973a267597d49e15f5c96e7b94a207c9 (diff)
downloadmariadb-git-f79bc15b64ca3d153fba911b18b6f1da8fdaa735.tar.gz
MDEV-19682 sql_mode="oracle" does not support sysdate
-rw-r--r--mysql-test/main/parser.result51
-rw-r--r--mysql-test/main/parser.test65
-rw-r--r--mysql-test/suite/compat/oracle/r/parser.result62
-rw-r--r--mysql-test/suite/compat/oracle/t/parser.test72
-rw-r--r--sql/lex.h2
-rw-r--r--sql/sql_lex.cc20
-rw-r--r--sql/sql_lex.h1
-rw-r--r--sql/sql_yacc.yy35
8 files changed, 284 insertions, 24 deletions
diff --git a/mysql-test/main/parser.result b/mysql-test/main/parser.result
index 86df20da9d8..e56367fdbab 100644
--- a/mysql-test/main/parser.result
+++ b/mysql-test/main/parser.result
@@ -109,7 +109,7 @@ ERROR 42000: You have an error in your SQL syntax; check the manual that corresp
create table SUM (a int);
drop table SUM;
create table SYSDATE(a int);
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'SYSDATE(a int)' at line 1
+DROP TABLE SYSDATE;
create table SYSDATE (a int);
drop table SYSDATE;
create table SYSTEM_USER(a int);
@@ -246,9 +246,9 @@ ERROR 42000: You have an error in your SQL syntax; check the manual that corresp
create table SUM (a int);
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'SUM (a int)' at line 1
create table SYSDATE(a int);
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'SYSDATE(a int)' at line 1
+DROP TABLE SYSDATE;
create table SYSDATE (a int);
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'SYSDATE (a int)' at line 1
+DROP TABLE SYSDATE;
create table SYSTEM_USER(a int);
drop table SYSTEM_USER;
create table SYSTEM_USER (a int);
@@ -2096,3 +2096,48 @@ ERROR HY000: Unknown data type: 'ACTION'
#
# End of 10.5 tests
#
+#
+# Start of 10.6 tests
+#
+#
+# MDEV-19682 sql_mode="oracle" does not support sysdate
+#
+SELECT sysdate LIKE '____-__-__ __:__:__';
+ERROR 42S22: Unknown column 'sysdate' in 'field list'
+SELECT sysdate = sysdate();
+ERROR 42S22: Unknown column 'sysdate' in 'field list'
+SELECT sysdate = sysdate(0);
+ERROR 42S22: Unknown column 'sysdate' in 'field list'
+CREATE DATABASE sysdate;
+DROP DATABASE sysdate;
+CREATE TABLE sysdate (a INT);
+DROP TABLE sysdate;
+CREATE TABLE t1 (sysdate INT);
+DROP TABLE t1;
+CREATE FUNCTION sysdate() RETURNS INT
+BEGIN
+RETURN 1;
+END;
+$$
+Warnings:
+Note 1585 This function 'sysdate' has the same name as a native function
+DROP FUNCTION sysdate;
+BEGIN NOT ATOMIC
+DECLARE sysdate INT DEFAULT 10;
+SELECT sysdate;
+END;
+$$
+sysdate
+10
+BEGIN NOT ATOMIC
+DECLARE a INT DEFAULT 0;
+sysdate:
+WHILE a DO
+SELECT 1;
+LEAVE sysdate;
+END WHILE ;
+END;
+$$
+#
+# End of 10.6 tests
+#
diff --git a/mysql-test/main/parser.test b/mysql-test/main/parser.test
index 49f43600795..fdd782df9b4 100644
--- a/mysql-test/main/parser.test
+++ b/mysql-test/main/parser.test
@@ -158,8 +158,8 @@ create table SUM(a int);
create table SUM (a int);
drop table SUM;
---error ER_PARSE_ERROR
create table SYSDATE(a int);
+DROP TABLE SYSDATE;
create table SYSDATE (a int);
drop table SYSDATE;
@@ -332,10 +332,10 @@ create table SUM(a int);
--error ER_PARSE_ERROR
create table SUM (a int);
---error ER_PARSE_ERROR
create table SYSDATE(a int);
---error ER_PARSE_ERROR
+DROP TABLE SYSDATE;
create table SYSDATE (a int);
+DROP TABLE SYSDATE;
create table SYSTEM_USER(a int);
drop table SYSTEM_USER;
@@ -1868,3 +1868,62 @@ SELECT CAST(1 AS ACTION);
--echo #
--echo # End of 10.5 tests
--echo #
+
+
+--echo #
+--echo # Start of 10.6 tests
+--echo #
+
+--echo #
+--echo # MDEV-19682 sql_mode="oracle" does not support sysdate
+--echo #
+
+--error ER_BAD_FIELD_ERROR
+SELECT sysdate LIKE '____-__-__ __:__:__';
+--error ER_BAD_FIELD_ERROR
+SELECT sysdate = sysdate();
+--error ER_BAD_FIELD_ERROR
+SELECT sysdate = sysdate(0);
+
+CREATE DATABASE sysdate;
+DROP DATABASE sysdate;
+
+CREATE TABLE sysdate (a INT);
+DROP TABLE sysdate;
+
+CREATE TABLE t1 (sysdate INT);
+DROP TABLE t1;
+
+DELIMITER $$;
+CREATE FUNCTION sysdate() RETURNS INT
+BEGIN
+ RETURN 1;
+END;
+$$
+DELIMITER ;$$
+DROP FUNCTION sysdate;
+
+DELIMITER $$;
+BEGIN NOT ATOMIC
+ DECLARE sysdate INT DEFAULT 10;
+ SELECT sysdate;
+END;
+$$
+DELIMITER ;$$
+
+DELIMITER $$;
+BEGIN NOT ATOMIC
+ DECLARE a INT DEFAULT 0;
+sysdate:
+ WHILE a DO
+ SELECT 1;
+ LEAVE sysdate;
+ END WHILE ;
+END;
+$$
+DELIMITER ;$$
+
+
+--echo #
+--echo # End of 10.6 tests
+--echo #
diff --git a/mysql-test/suite/compat/oracle/r/parser.result b/mysql-test/suite/compat/oracle/r/parser.result
index 3f02382b6e4..32ea444ea25 100644
--- a/mysql-test/suite/compat/oracle/r/parser.result
+++ b/mysql-test/suite/compat/oracle/r/parser.result
@@ -806,3 +806,65 @@ ERROR HY000: Unknown data type: 'BEGIN'
#
# End of 10.5 tests
#
+#
+# Start of 10.6 tests
+#
+#
+# MDEV-19682 sql_mode="oracle" does not support sysdate
+#
+SELECT sysdate LIKE '____-__-__ __:__:__';
+sysdate LIKE '____-__-__ __:__:__'
+1
+SELECT sysdate = sysdate();
+sysdate = sysdate()
+1
+SELECT sysdate = sysdate(0);
+sysdate = sysdate(0)
+1
+CREATE DATABASE sysdate;
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'sysdate' at line 1
+CREATE TABLE sysdate (a INT);
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'sysdate (a INT)' at line 1
+CREATE TABLE t1 (sysdate INT);
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'sysdate INT)' at line 1
+CREATE TABLE t1 (a sysdate);
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'sysdate)' at line 1
+CREATE FUNCTION sysdate RETURN INT AS
+BEGIN
+RETURN 1;
+END;
+$$
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'sysdate RETURN INT AS
+BEGIN
+RETURN 1;
+END' at line 1
+CREATE FUNCTION sysdate() RETURN INT AS
+BEGIN
+RETURN 1;
+END;
+$$
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'sysdate() RETURN INT AS
+BEGIN
+RETURN 1;
+END' at line 1
+DECLARE
+sysdate INT := 10;
+BEGIN
+NULL;
+END;
+$$
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'sysdate INT := 10;
+BEGIN
+NULL;
+END' at line 2
+BEGIN
+<<sysdate>>
+NULL;
+END;
+$$
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'sysdate>>
+NULL;
+END' at line 2
+#
+# End of 10.6 tests
+#
diff --git a/mysql-test/suite/compat/oracle/t/parser.test b/mysql-test/suite/compat/oracle/t/parser.test
index d5d3b39f0b9..c2019f258ce 100644
--- a/mysql-test/suite/compat/oracle/t/parser.test
+++ b/mysql-test/suite/compat/oracle/t/parser.test
@@ -653,3 +653,75 @@ SELECT CAST(1 AS BEGIN);
--echo #
--echo # End of 10.5 tests
--echo #
+
+
+--echo #
+--echo # Start of 10.6 tests
+--echo #
+
+--echo #
+--echo # MDEV-19682 sql_mode="oracle" does not support sysdate
+--echo #
+
+# SYSDATE is not deterministic. Let's use LIKE and equality.
+# The main point here is only to check that SYSDATE
+# gets parsed without parentheses. The actial value is not important.
+SELECT sysdate LIKE '____-__-__ __:__:__';
+SELECT sysdate = sysdate();
+SELECT sysdate = sysdate(0);
+
+--error ER_PARSE_ERROR
+CREATE DATABASE sysdate;
+
+--error ER_PARSE_ERROR
+CREATE TABLE sysdate (a INT);
+
+--error ER_PARSE_ERROR
+CREATE TABLE t1 (sysdate INT);
+
+--error ER_PARSE_ERROR
+CREATE TABLE t1 (a sysdate);
+
+DELIMITER $$;
+--error ER_PARSE_ERROR
+CREATE FUNCTION sysdate RETURN INT AS
+BEGIN
+ RETURN 1;
+END;
+$$
+DELIMITER ;$$
+
+DELIMITER $$;
+--error ER_PARSE_ERROR
+CREATE FUNCTION sysdate() RETURN INT AS
+BEGIN
+ RETURN 1;
+END;
+$$
+DELIMITER ;$$
+
+
+DELIMITER $$;
+--error ER_PARSE_ERROR
+DECLARE
+ sysdate INT := 10;
+BEGIN
+ NULL;
+END;
+$$
+DELIMITER ;$$
+
+
+DELIMITER $$;
+--error ER_PARSE_ERROR
+BEGIN
+<<sysdate>>
+ NULL;
+END;
+$$
+DELIMITER ;$$
+
+
+--echo #
+--echo # End of 10.6 tests
+--echo #
diff --git a/sql/lex.h b/sql/lex.h
index 542356c0e43..e54335783b8 100644
--- a/sql/lex.h
+++ b/sql/lex.h
@@ -640,6 +640,7 @@ static SYMBOL symbols[] = {
{ "SUSPEND", SYM(SUSPEND_SYM)},
{ "SWAPS", SYM(SWAPS_SYM)},
{ "SWITCHES", SYM(SWITCHES_SYM)},
+ { "SYSDATE", SYM(SYSDATE)},
{ "SYSTEM", SYM(SYSTEM)},
{ "SYSTEM_TIME", SYM(SYSTEM_TIME_SYM)},
{ "TABLE", SYM(TABLE_SYM)},
@@ -779,7 +780,6 @@ static SYMBOL sql_functions[] = {
{ "SUBSTR", SYM(SUBSTRING)},
{ "SUBSTRING", SYM(SUBSTRING)},
{ "SUM", SYM(SUM_SYM)},
- { "SYSDATE", SYM(SYSDATE)},
{ "SYSTEM_USER", SYM(USER_SYM)},
{ "TRIM", SYM(TRIM)},
{ "TRIM_ORACLE", SYM(TRIM_ORACLE)},
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index a567194fd49..05e41f334c2 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -9232,6 +9232,26 @@ Item *LEX::make_item_func_substr(THD *thd, Item *a, Item *b)
}
+Item *LEX::make_item_func_sysdate(THD *thd, uint fsp)
+{
+ /*
+ Unlike other time-related functions, SYSDATE() is
+ replication-unsafe because it is not affected by the
+ TIMESTAMP variable. It is unsafe even if
+ sysdate_is_now=1, because the slave may have
+ sysdate_is_now=0.
+ */
+ set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_SYSTEM_FUNCTION);
+ Item *item= global_system_variables.sysdate_is_now == 0 ?
+ (Item *) new (thd->mem_root) Item_func_sysdate_local(thd, fsp) :
+ (Item *) new (thd->mem_root) Item_func_now_local(thd, fsp);
+ if (unlikely(item == NULL))
+ return NULL;
+ safe_to_cache_query=0;
+ return item;
+}
+
+
Item *LEX::make_item_func_replace(THD *thd,
Item *org,
Item *find,
diff --git a/sql/sql_lex.h b/sql/sql_lex.h
index 4c904a4f15d..2083ce3f76b 100644
--- a/sql/sql_lex.h
+++ b/sql/sql_lex.h
@@ -4076,6 +4076,7 @@ public:
Item *make_item_func_replace(THD *thd, Item *org, Item *find, Item *replace);
Item *make_item_func_substr(THD *thd, Item *a, Item *b, Item *c);
Item *make_item_func_substr(THD *thd, Item *a, Item *b);
+ Item *make_item_func_sysdate(THD *thd, uint fsp);
Item *make_item_func_call_generic(THD *thd, Lex_ident_cli_st *db,
Lex_ident_cli_st *name, List<Item> *args);
Item *make_item_func_call_native_or_parse_error(THD *thd,
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index b5d61021101..dfcb43062fd 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -10292,23 +10292,22 @@ function_call_nonkeyword:
if (unlikely(!($$= Lex->make_item_func_substr(thd, $3, $5))))
MYSQL_YYABORT;
}
- | SYSDATE opt_time_precision
+/* Start SQL_MODE_ORACLE_SPECIFIC
+ | SYSDATE
{
- /*
- Unlike other time-related functions, SYSDATE() is
- replication-unsafe because it is not affected by the
- TIMESTAMP variable. It is unsafe even if
- sysdate_is_now=1, because the slave may have
- sysdate_is_now=0.
- */
- Lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_SYSTEM_FUNCTION);
- if (global_system_variables.sysdate_is_now == 0)
- $$= new (thd->mem_root) Item_func_sysdate_local(thd, $2);
- else
- $$= new (thd->mem_root) Item_func_now_local(thd, $2);
- if (unlikely($$ == NULL))
- MYSQL_YYABORT;
- Lex->safe_to_cache_query=0;
+ if (unlikely(!($$= Lex->make_item_func_sysdate(thd, 0))))
+ MYSQL_YYABORT;
+ }
+End SQL_MODE_ORACLE_SPECIFIC */
+ | SYSDATE '(' ')'
+ {
+ if (unlikely(!($$= Lex->make_item_func_sysdate(thd, 0))))
+ MYSQL_YYABORT;
+ }
+ | SYSDATE '(' real_ulong_num ')'
+ {
+ if (unlikely(!($$= Lex->make_item_func_sysdate(thd, (uint) $3))))
+ MYSQL_YYABORT;
}
| TIMESTAMP_ADD '(' interval_time_stamp ',' expr ',' expr ')'
{
@@ -15813,6 +15812,9 @@ keyword_sp_var_and_label:
| SUSPEND_SYM
| SWAPS_SYM
| SWITCHES_SYM
+/* Start SQL_MODE_DEFAULT_SPECIFIC */
+ | SYSDATE
+/* End SQL_MODE_DEFAULT_SPECIFIC */
| SYSTEM
| SYSTEM_TIME_SYM
| TABLE_NAME_SYM
@@ -16061,7 +16063,6 @@ reserved_keyword_udt_not_param_type:
| STRAIGHT_JOIN
| SUBSTRING
| SUM_SYM
- | SYSDATE
| TABLE_REF_PRIORITY
| TABLE_SYM
| TERMINATED