!3110 创建触发器语法报错信息修改

Merge pull request !3110 from 暖阳/trigger_errmsg
This commit is contained in:
opengauss-bot
2023-04-23 09:03:56 +00:00
committed by Gitee
3 changed files with 90 additions and 14 deletions

View File

@ -11653,11 +11653,15 @@ CreateTrigStmt:
{
if ($2 != false)
{
parser_yyerror("syntax error found");
ereport(errstate,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("syntax error.")));
}
if ($3 != NULL)
{
parser_yyerror("only support definer in B compatibility database and B syntax");
ereport(errstate,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("only support definer in B compatibility database and B syntax")));
}
CreateTrigStmt *n = makeNode(CreateTrigStmt);
n->definer = $3;
@ -11719,15 +11723,20 @@ CreateTrigStmt:
u_sess->parser_cxt.isCreateFuncOrProc = true;
} subprogram_body
{
if (u_sess->attr.attr_sql.sql_compatibility != B_FORMAT || $2 != false)
{
parser_yyerror("only support definer, trigger_order, subprogram_body in B compatibility database");
}
CreateTrigStmt *n = makeNode(CreateTrigStmt);
if ($2 != false)
{
parser_yyerror("syntax error found");
ereport(errstate,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("syntax error.")));
}
if (u_sess->attr.attr_sql.sql_compatibility != B_FORMAT)
{
ereport(errstate,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("Current syntax is supported only in B compatibility database")));
}
CreateTrigStmt *n = makeNode(CreateTrigStmt);
n->definer = $3;
n->if_not_exists = false;
n->schemaname = $5->schemaname;
@ -11758,15 +11767,20 @@ CreateTrigStmt:
u_sess->parser_cxt.isCreateFuncOrProc = true;
} subprogram_body
{
if (u_sess->attr.attr_sql.sql_compatibility != B_FORMAT)
{
parser_yyerror("only support definer, if not exists, trigger_order, subprogram_body in B compatibility database");
}
CreateTrigStmt *n = makeNode(CreateTrigStmt);
if ($2 != false)
{
parser_yyerror("syntax error");
ereport(errstate,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("syntax error.")));
}
if (u_sess->attr.attr_sql.sql_compatibility != B_FORMAT)
{
ereport(errstate,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("Current syntax is supported only in B compatibility database")));
}
CreateTrigStmt *n = makeNode(CreateTrigStmt);
n->definer = $3;
n->if_not_exists = true;
n->schemaname = $8->schemaname;

View File

@ -3,6 +3,28 @@
drop database if exists db_mysql;
NOTICE: database "db_mysql" does not exist, skipping
create database db_mysql dbcompatibility 'B';
drop database if exists db_td;
NOTICE: database "db_td" does not exist, skipping
create database db_td dbcompatibility='C';
\c db_td
create table animals (id int, name char(30));
create table food (id int, foodtype varchar(32), remark varchar(32), time_flag timestamp);
create trigger animal_trigger1
after insert on animals
for each row
begin
insert into food(id, foodtype, remark, time_flag) values (1,'ice cream', 'sdsdsdsd', now());
end;
/
ERROR: Current syntax is supported only in B compatibility database
create or replace trigger animal_trigger1
after insert on animals
for each row
begin
insert into food(id, foodtype, remark, time_flag) values (1,'ice cream', 'sdsdsdsd', now());
end;
/
ERROR: syntax error.
\c db_mysql
create table t (id int);
create table t1 (id int);
@ -49,6 +71,14 @@ begin
insert into food(id, foodtype, remark, time_flag) values (1,'ice cream', 'sdsdsdsd', now());
end;
/
create or replace trigger animal_trigger1
after insert on animals
for each row
begin
insert into food(id, foodtype, remark, time_flag) values (1,'ice cream', 'sdsdsdsd', now());
end;
/
ERROR: syntax error.
--different type trigger follows|precedes
create trigger animal_trigger2
before insert on animals
@ -493,6 +523,7 @@ ERROR: drop trigger without table name only support in B-format database
drop trigger if exists animal_trigger1;
ERROR: drop trigger without table name only support in B-format database
drop database db_mysql;
drop database db_td;
-- test declare condition in other compatibility
create or replace procedure test_condition_1 as
declare

View File

@ -2,6 +2,28 @@
-- test mysql compatibility trigger
drop database if exists db_mysql;
create database db_mysql dbcompatibility 'B';
drop database if exists db_td;
create database db_td dbcompatibility='C';
\c db_td
create table animals (id int, name char(30));
create table food (id int, foodtype varchar(32), remark varchar(32), time_flag timestamp);
create trigger animal_trigger1
after insert on animals
for each row
begin
insert into food(id, foodtype, remark, time_flag) values (1,'ice cream', 'sdsdsdsd', now());
end;
/
create or replace trigger animal_trigger1
after insert on animals
for each row
begin
insert into food(id, foodtype, remark, time_flag) values (1,'ice cream', 'sdsdsdsd', now());
end;
/
\c db_mysql
create table t (id int);
create table t1 (id int);
@ -49,6 +71,14 @@ begin
end;
/
create or replace trigger animal_trigger1
after insert on animals
for each row
begin
insert into food(id, foodtype, remark, time_flag) values (1,'ice cream', 'sdsdsdsd', now());
end;
/
--different type trigger follows|precedes
create trigger animal_trigger2
@ -370,6 +400,7 @@ call test_condition_1();
drop trigger animal_trigger1;
drop trigger if exists animal_trigger1;
drop database db_mysql;
drop database db_td;
-- test declare condition in other compatibility
create or replace procedure test_condition_1 as