1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-30 16:24:05 +03:00

MDEV-20735 Allow non-reserved keywords as user defined type names

This commit is contained in:
Alexander Barkov
2019-10-03 16:03:32 +04:00
parent d168601e83
commit c2d8db66be
8 changed files with 237 additions and 28 deletions

View File

@ -1809,5 +1809,36 @@ ERROR HY000: Unknown data type: 'DUAL'
SELECT CAST(1 AS DUAL);
ERROR HY000: Unknown data type: 'DUAL'
#
# MDEV-20735 Allow non-reserved keywords as user defined type names
#
CREATE TABLE t1 (a ASCII);
ERROR HY000: Unknown data type: 'ASCII'
SELECT CAST(1 AS ASCII);
ERROR HY000: Unknown data type: 'ASCII'
CREATE TABLE t1 (a LANGUAGE);
ERROR HY000: Unknown data type: 'LANGUAGE'
SELECT CAST(1 AS LANGUAGE);
ERROR HY000: Unknown data type: 'LANGUAGE'
CREATE TABLE t1 (a CLOSE);
ERROR HY000: Unknown data type: 'CLOSE'
SELECT CAST(1 AS CLOSE);
ERROR HY000: Unknown data type: 'CLOSE'
CREATE TABLE t1 (a NAMES);
ERROR HY000: Unknown data type: 'NAMES'
SELECT CAST(1 AS NAMES);
ERROR HY000: Unknown data type: 'NAMES'
CREATE TABLE t1 (a END);
ERROR HY000: Unknown data type: 'END'
SELECT CAST(1 AS END);
ERROR HY000: Unknown data type: 'END'
CREATE TABLE t1 (a GLOBAL);
ERROR HY000: Unknown data type: 'GLOBAL'
SELECT CAST(1 AS GLOBAL);
ERROR HY000: Unknown data type: 'GLOBAL'
CREATE TABLE t1 (a ACTION);
ERROR HY000: Unknown data type: 'ACTION'
SELECT CAST(1 AS ACTION);
ERROR HY000: Unknown data type: 'ACTION'
#
# End of 10.5 tests
#

View File

@ -1581,6 +1581,46 @@ CREATE TABLE t1 (a DUAL);
--error ER_UNKNOWN_DATA_TYPE
SELECT CAST(1 AS DUAL);
--echo #
--echo # MDEV-20735 Allow non-reserved keywords as user defined type names
--echo #
--error ER_UNKNOWN_DATA_TYPE
CREATE TABLE t1 (a ASCII);
--error ER_UNKNOWN_DATA_TYPE
SELECT CAST(1 AS ASCII);
--error ER_UNKNOWN_DATA_TYPE
CREATE TABLE t1 (a LANGUAGE);
--error ER_UNKNOWN_DATA_TYPE
SELECT CAST(1 AS LANGUAGE);
--error ER_UNKNOWN_DATA_TYPE
CREATE TABLE t1 (a CLOSE);
--error ER_UNKNOWN_DATA_TYPE
SELECT CAST(1 AS CLOSE);
--error ER_UNKNOWN_DATA_TYPE
CREATE TABLE t1 (a NAMES);
--error ER_UNKNOWN_DATA_TYPE
SELECT CAST(1 AS NAMES);
--error ER_UNKNOWN_DATA_TYPE
CREATE TABLE t1 (a END);
--error ER_UNKNOWN_DATA_TYPE
SELECT CAST(1 AS END);
--error ER_UNKNOWN_DATA_TYPE
CREATE TABLE t1 (a GLOBAL);
--error ER_UNKNOWN_DATA_TYPE
SELECT CAST(1 AS GLOBAL);
--error ER_UNKNOWN_DATA_TYPE
CREATE TABLE t1 (a ACTION);
--error ER_UNKNOWN_DATA_TYPE
SELECT CAST(1 AS ACTION);
--echo #
--echo # End of 10.5 tests
--echo #

View File

@ -620,5 +620,40 @@ ERROR HY000: Unknown data type: 'DUAL'
SELECT CAST(1 AS DUAL);
ERROR HY000: Unknown data type: 'DUAL'
#
# MDEV-20735 Allow non-reserved keywords as user defined type names
#
CREATE TABLE t1 (a ASCII);
ERROR HY000: Unknown data type: 'ASCII'
SELECT CAST(1 AS ASCII);
ERROR HY000: Unknown data type: 'ASCII'
CREATE TABLE t1 (a LANGUAGE);
ERROR HY000: Unknown data type: 'LANGUAGE'
SELECT CAST(1 AS LANGUAGE);
ERROR HY000: Unknown data type: 'LANGUAGE'
CREATE TABLE t1 (a CLOSE);
ERROR HY000: Unknown data type: 'CLOSE'
SELECT CAST(1 AS CLOSE);
ERROR HY000: Unknown data type: 'CLOSE'
CREATE TABLE t1 (a NAMES);
ERROR HY000: Unknown data type: 'NAMES'
SELECT CAST(1 AS NAMES);
ERROR HY000: Unknown data type: 'NAMES'
CREATE TABLE t1 (a END);
ERROR HY000: Unknown data type: 'END'
SELECT CAST(1 AS END);
ERROR HY000: Unknown data type: 'END'
CREATE TABLE t1 (a GLOBAL);
ERROR HY000: Unknown data type: 'GLOBAL'
SELECT CAST(1 AS GLOBAL);
ERROR HY000: Unknown data type: 'GLOBAL'
CREATE TABLE t1 (a ACTION);
ERROR HY000: Unknown data type: 'ACTION'
SELECT CAST(1 AS ACTION);
ERROR HY000: Unknown data type: 'ACTION'
CREATE TABLE t1 (a BEGIN);
ERROR HY000: Unknown data type: 'BEGIN'
SELECT CAST(1 AS BEGIN);
ERROR HY000: Unknown data type: 'BEGIN'
#
# End of 10.5 tests
#

View File

@ -427,6 +427,51 @@ CREATE TABLE t1 (a DUAL);
--error ER_UNKNOWN_DATA_TYPE
SELECT CAST(1 AS DUAL);
--echo #
--echo # MDEV-20735 Allow non-reserved keywords as user defined type names
--echo #
--error ER_UNKNOWN_DATA_TYPE
CREATE TABLE t1 (a ASCII);
--error ER_UNKNOWN_DATA_TYPE
SELECT CAST(1 AS ASCII);
--error ER_UNKNOWN_DATA_TYPE
CREATE TABLE t1 (a LANGUAGE);
--error ER_UNKNOWN_DATA_TYPE
SELECT CAST(1 AS LANGUAGE);
--error ER_UNKNOWN_DATA_TYPE
CREATE TABLE t1 (a CLOSE);
--error ER_UNKNOWN_DATA_TYPE
SELECT CAST(1 AS CLOSE);
--error ER_UNKNOWN_DATA_TYPE
CREATE TABLE t1 (a NAMES);
--error ER_UNKNOWN_DATA_TYPE
SELECT CAST(1 AS NAMES);
--error ER_UNKNOWN_DATA_TYPE
CREATE TABLE t1 (a END);
--error ER_UNKNOWN_DATA_TYPE
SELECT CAST(1 AS END);
--error ER_UNKNOWN_DATA_TYPE
CREATE TABLE t1 (a GLOBAL);
--error ER_UNKNOWN_DATA_TYPE
SELECT CAST(1 AS GLOBAL);
--error ER_UNKNOWN_DATA_TYPE
CREATE TABLE t1 (a ACTION);
--error ER_UNKNOWN_DATA_TYPE
SELECT CAST(1 AS ACTION);
--error ER_UNKNOWN_DATA_TYPE
CREATE TABLE t1 (a BEGIN);
--error ER_UNKNOWN_DATA_TYPE
SELECT CAST(1 AS BEGIN);
--echo #
--echo # End of 10.5 tests
--echo #

View File

@ -11648,10 +11648,7 @@ set @x = 2;
insert into t values (1);
set @x = 3;
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 'handler for sqlstate '2300' set @x2 = 1;
set @x = 1;
insert into t values (1);
s' at line 3
ERROR HY000: Unknown data type: 'handler'
DROP PROCEDURE IF EXISTS handler1;
Warnings:
Note 1305 PROCEDURE db_storedproc.handler1 does not exist
@ -11664,10 +11661,7 @@ set @x = 2;
insert into t values (1);
set @x = 3;
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 'handler for sqlstate '2300' set @x2 = 1;
set @x = 1;
insert into t values (1);
s' at line 3
ERROR HY000: Unknown data type: 'handler'
DROP PROCEDURE IF EXISTS handler1;
Warnings:
Note 1305 PROCEDURE db_storedproc.handler1 does not exist
@ -11680,10 +11674,7 @@ set @x = 2;
insert into t values (1);
set @x = 3;
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 'handler for sqlstate '2300' set @x2 = 1;
set @x = 1;
insert into t values (1);
s' at line 3
ERROR HY000: Unknown data type: 'handler'
DROP PROCEDURE IF EXISTS sp1;
Warnings:
Note 1305 PROCEDURE db_storedproc.sp1 does not exist
@ -12934,8 +12925,7 @@ CREATE PROCEDURE sp1( )
BEGIN
declare option handler for sqlstate '02000' set @var2 = 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 'handler for sqlstate '02000' set @var2 = 1;
END' at line 3
ERROR HY000: Unknown data type: 'handler'
DROP PROCEDURE IF EXISTS sp1;
Warnings:
Note 1305 PROCEDURE db_storedproc.sp1 does not exist
@ -13015,8 +13005,7 @@ CREATE PROCEDURE sp1( )
BEGIN
declare privileges handler for sqlstate '02000' set @var2 = 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 'handler for sqlstate '02000' set @var2 = 1;
END' at line 3
ERROR HY000: Unknown data type: 'handler'
DROP PROCEDURE IF EXISTS sp1;
Warnings:
Note 1305 PROCEDURE db_storedproc.sp1 does not exist
@ -13069,8 +13058,7 @@ CREATE PROCEDURE sp1( )
BEGIN
declare read_only handler for sqlstate '02000' set @var2 = 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 'handler for sqlstate '02000' set @var2 = 1;
END' at line 3
ERROR HY000: Unknown data type: 'handler'
DROP PROCEDURE IF EXISTS sp1;
Warnings:
Note 1305 PROCEDURE db_storedproc.sp1 does not exist

View File

@ -13752,7 +13752,7 @@ delimiter ;//
DROP PROCEDURE IF EXISTS handler1;
delimiter //;
--error ER_PARSE_ERROR
--error ER_UNKNOWN_DATA_TYPE
CREATE PROCEDURE handler1()
BEGIN
declare continueinv handler for sqlstate '2300' set @x2 = 1;
@ -13776,7 +13776,7 @@ delimiter ;//
DROP PROCEDURE IF EXISTS handler1;
delimiter //;
--error ER_PARSE_ERROR
--error ER_UNKNOWN_DATA_TYPE
CREATE PROCEDURE handler1()
BEGIN
declare undoinv handler for sqlstate '2300' set @x2 = 1;
@ -13800,7 +13800,7 @@ delimiter ;//
DROP PROCEDURE IF EXISTS handler1;
delimiter //;
--error ER_PARSE_ERROR
--error ER_UNKNOWN_DATA_TYPE
CREATE PROCEDURE handler1 ()
BEGIN
declare exitinv handler for sqlstate '2300' set @x2 = 1;
@ -15210,7 +15210,7 @@ delimiter ;//
DROP PROCEDURE IF EXISTS sp1;
delimiter //;
--error ER_PARSE_ERROR
--error ER_UNKNOWN_DATA_TYPE
CREATE PROCEDURE sp1( )
BEGIN
declare option handler for sqlstate '02000' set @var2 = 1;
@ -15300,7 +15300,7 @@ delimiter ;//
DROP PROCEDURE IF EXISTS sp1;
delimiter //;
--error ER_PARSE_ERROR
--error ER_UNKNOWN_DATA_TYPE
CREATE PROCEDURE sp1( )
BEGIN
declare privileges handler for sqlstate '02000' set @var2 = 1;
@ -15360,7 +15360,7 @@ delimiter ;//
DROP PROCEDURE IF EXISTS sp1;
delimiter //;
--error ER_PARSE_ERROR
--error ER_UNKNOWN_DATA_TYPE
CREATE PROCEDURE sp1( )
BEGIN
declare read_only handler for sqlstate '02000' set @var2 = 1;

View File

@ -1797,6 +1797,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize);
%type <kwd>
keyword_data_type
keyword_cast_type
keyword_ident
keyword_label
keyword_set_special_case
@ -1812,6 +1813,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize);
keyword_verb_clause
charset
reserved_keyword_udt
non_reserved_keyword_udt
%type <table>
table_ident table_ident_nodb references xid
@ -6864,6 +6866,11 @@ field_type:
if (Lex->set_field_type_udt(&$$, $1, $2))
MYSQL_YYABORT;
}
| non_reserved_keyword_udt float_options srid_option
{
if (Lex->set_field_type_udt(&$$, $1, $2))
MYSQL_YYABORT;
}
;
field_type_numeric:
@ -11915,6 +11922,11 @@ cast_type:
if (Lex->set_cast_type_udt(&$$, $1))
MYSQL_YYABORT;
}
| non_reserved_keyword_udt
{
if (Lex->set_cast_type_udt(&$$, $1))
MYSQL_YYABORT;
}
;
cast_type_numeric:
@ -15798,6 +15810,7 @@ user: user_maybe_role
/* Keywords which we allow as table aliases. */
keyword_table_alias:
keyword_data_type
| keyword_cast_type
| keyword_set_special_case
| keyword_sp_block_section
| keyword_sp_head
@ -15805,11 +15818,13 @@ keyword_table_alias:
| keyword_sp_var_not_label
| keyword_sysvar_type
| keyword_verb_clause
| EXCEPTION_ORACLE_SYM
;
/* Keyword that we allow for identifiers (except SP labels) */
keyword_ident:
keyword_data_type
| keyword_cast_type
| keyword_set_special_case
| keyword_sp_block_section
| keyword_sp_head
@ -15818,6 +15833,7 @@ keyword_ident:
| keyword_sysvar_type
| keyword_verb_clause
| WINDOW_SYM
| EXCEPTION_ORACLE_SYM
;
/*
@ -15829,10 +15845,12 @@ keyword_label:
| keyword_set_special_case
| keyword_sp_var_and_label
| keyword_sysvar_type
| EXCEPTION_ORACLE_SYM
;
keyword_sysvar_name:
keyword_data_type
| keyword_cast_type
| keyword_set_special_case
| keyword_sp_block_section
| keyword_sp_head
@ -15840,10 +15858,12 @@ keyword_sysvar_name:
| keyword_sp_var_not_label
| keyword_verb_clause
| WINDOW_SYM
| EXCEPTION_ORACLE_SYM
;
keyword_sp_decl:
keyword_data_type
| keyword_cast_type
| keyword_set_special_case
| keyword_sp_block_section
| keyword_sp_head
@ -15856,6 +15876,7 @@ keyword_sp_decl:
keyword_set_usual_case:
keyword_data_type
| keyword_cast_type
| keyword_sp_block_section
| keyword_sp_head
| keyword_sp_var_and_label
@ -15863,6 +15884,17 @@ keyword_set_usual_case:
| keyword_sysvar_type
| keyword_verb_clause
| WINDOW_SYM
| EXCEPTION_ORACLE_SYM
;
non_reserved_keyword_udt:
keyword_sp_var_not_label
| keyword_sp_head
| keyword_verb_clause
| keyword_set_special_case
| keyword_sp_block_section
| keyword_sysvar_type
| keyword_sp_var_and_label
;
/*
@ -15914,7 +15946,6 @@ keyword_sp_var_not_label:
| RESTORE_SYM
| SECURITY_SYM
| SERVER_SYM
| SIGNED_SYM
| SOCKET_SYM
| SLAVE
| SLAVES
@ -16009,7 +16040,6 @@ keyword_set_special_case:
*/
keyword_sp_block_section:
BEGIN_MARIADB_SYM
| EXCEPTION_ORACLE_SYM
| END
;
@ -16054,6 +16084,11 @@ keyword_data_type:
;
keyword_cast_type:
SIGNED_SYM
;
/*
These keywords are fine for both SP variable names and SP labels.
*/

View File

@ -1266,6 +1266,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize);
%type <kwd>
keyword_data_type
keyword_cast_type
keyword_ident
keyword_label
keyword_set_special_case
@ -1282,6 +1283,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize);
keyword_directly_assignable
charset
reserved_keyword_udt
non_reserved_keyword_udt
%type <table>
table_ident table_ident_nodb references xid
@ -6863,6 +6865,11 @@ field_type:
if (Lex->set_field_type_udt(&$$, $1, $2))
MYSQL_YYABORT;
}
| non_reserved_keyword_udt float_options srid_option
{
if (Lex->set_field_type_udt(&$$, $1, $2))
MYSQL_YYABORT;
}
;
@ -12014,6 +12021,11 @@ cast_type:
if (Lex->set_cast_type_udt(&$$, $1))
MYSQL_YYABORT;
}
| non_reserved_keyword_udt
{
if (Lex->set_cast_type_udt(&$$, $1))
MYSQL_YYABORT;
}
;
cast_type_numeric:
@ -15950,6 +15962,7 @@ user: user_maybe_role
/* Keywords which we allow as table aliases. */
keyword_table_alias:
keyword_data_type
| keyword_cast_type
| keyword_set_special_case
| keyword_sp_block_section
| keyword_sp_head
@ -15958,11 +15971,13 @@ keyword_table_alias:
| keyword_sysvar_type
| keyword_verb_clause
| FUNCTION_SYM
| EXCEPTION_ORACLE_SYM
;
/* Keyword that we allow for identifiers (except SP labels) */
keyword_ident:
keyword_data_type
| keyword_cast_type
| keyword_set_special_case
| keyword_sp_block_section
| keyword_sp_head
@ -15972,6 +15987,7 @@ keyword_ident:
| keyword_verb_clause
| FUNCTION_SYM
| WINDOW_SYM
| EXCEPTION_ORACLE_SYM
;
/*
@ -15985,10 +16001,12 @@ keyword_label:
| keyword_sysvar_type
| FUNCTION_SYM
| COMPRESSED_SYM
| EXCEPTION_ORACLE_SYM
;
keyword_sysvar_name:
keyword_data_type
| keyword_cast_type
| keyword_set_special_case
| keyword_sp_block_section
| keyword_sp_head
@ -15997,6 +16015,7 @@ keyword_sysvar_name:
| keyword_verb_clause
| FUNCTION_SYM
| WINDOW_SYM
| EXCEPTION_ORACLE_SYM
;
keyword_sp_decl:
@ -16011,6 +16030,7 @@ keyword_sp_decl:
keyword_set_usual_case:
keyword_data_type
| keyword_cast_type
| keyword_sp_block_section
| keyword_sp_head
| keyword_sp_var_and_label
@ -16019,10 +16039,12 @@ keyword_set_usual_case:
| keyword_verb_clause
| FUNCTION_SYM
| WINDOW_SYM
| EXCEPTION_ORACLE_SYM
;
keyword_directly_assignable:
keyword_data_type
| keyword_cast_type
| keyword_set_special_case
| keyword_sp_var_and_label
| keyword_sp_var_not_label
@ -16031,6 +16053,16 @@ keyword_directly_assignable:
| WINDOW_SYM
;
non_reserved_keyword_udt:
keyword_sp_var_not_label
| keyword_sp_head
| keyword_verb_clause
| keyword_set_special_case
| keyword_sp_block_section
| keyword_sysvar_type
| keyword_sp_var_and_label
;
/*
Keywords that we allow in Oracle-style direct assignments:
xxx := 10;
@ -16080,7 +16112,6 @@ keyword_sp_var_not_label:
| RESTORE_SYM
| SECURITY_SYM
| SERVER_SYM
| SIGNED_SYM
| SOCKET_SYM
| SLAVE
| SLAVES
@ -16175,7 +16206,6 @@ keyword_set_special_case:
*/
keyword_sp_block_section:
BEGIN_ORACLE_SYM
| EXCEPTION_ORACLE_SYM
| END
;
@ -16220,6 +16250,11 @@ keyword_data_type:
;
keyword_cast_type:
SIGNED_SYM
;
/*
These keywords are fine for both SP variable names and SP labels.
*/