Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Alter Table Action for Enable/Disable trigger all syntax #3547

Open
wants to merge 3 commits into
base: BABEL_5_X_DEV
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions contrib/babelfishpg_tsql/src/backend_parser/gram-tsql-rule.y
Original file line number Diff line number Diff line change
Expand Up @@ -521,11 +521,11 @@ tsql_enable_disable_trigger:

if ($1)
{
n1->subtype = AT_EnableTrigAll;
n1->subtype = AT_EnableTrigUser;
}
else
{
n1->subtype = AT_DisableTrigAll;
n1->subtype = AT_DisableTrigUser;
}

n2->relation = $5;
Expand Down
4 changes: 4 additions & 0 deletions contrib/babelfishpg_tsql/src/tsqlIface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1811,6 +1811,10 @@ class tsqlBuilder : public tsqlCommonMutator

rewritten_query_fragment.emplace(std::make_pair(ctx->start->getStartIndex(), std::make_pair(::getFullText(ctx), str)));
}
else if(ctx->TRIGGER() && ctx->ALL())
{
rewritten_query_fragment.emplace(std::make_pair(ctx->ALL()->getSymbol()->getStartIndex(),std::make_pair(::getFullText(ctx->ALL()), "USER")));
}
}

void exitEnable_trigger(TSqlParser::Enable_triggerContext *ctx) override
Expand Down
181 changes: 181 additions & 0 deletions test/JDBC/expected/BABEL-5645.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
-- setup
CREATE TABLE parent(a int primary key);
GO
CREATE TABLE child(b int, foreign key (b) references parent(a) ON UPDATE CASCADE);
GO
CREATE TRIGGER trig1 on child AFTER UPDATE AS BEGIN SELECT 1 END
GO
INSERT INTO parent values(1)
INSERT INTO child values(1)
GO
~~ROW COUNT: 1~~

~~ROW COUNT: 1~~


-- check metadata
select name,is_disabled from sys.triggers
GO
~~START~~
varchar#!#bit
trig1#!#0
~~END~~


-- check if trigger enabled, as well as fkey action works
UPDATE parent set a=2 where a=1
GO
~~START~~
int
1
~~END~~

~~ROW COUNT: 1~~

SELECT * from parent;select * from child;
GO
~~START~~
int
2
~~END~~

~~START~~
int
2
~~END~~


ALTER TABLE child disable trigger all
GO

-- check metadata
select name,is_disabled from sys.triggers
GO
~~START~~
varchar#!#bit
trig1#!#1
~~END~~


-- check if only trigger disabled and not fkey action
UPDATE parent set a=3 where a=2
GO
~~ROW COUNT: 1~~

SELECT * from parent;select * from child;
GO
~~START~~
int
3
~~END~~

~~START~~
int
3
~~END~~



ALTER TABLE child enable trigger all
GO

-- check metadata
select name,is_disabled from sys.triggers
GO
~~START~~
varchar#!#bit
trig1#!#0
~~END~~


-- check if trigger renabled
UPDATE parent set a=4 where a=3
GO
~~START~~
int
1
~~END~~

~~ROW COUNT: 1~~

SELECT * from parent;select * from child;
GO
~~START~~
int
4
~~END~~

~~START~~
int
4
~~END~~


DISABLE trigger all on child;
GO

-- check metadata
select name,is_disabled from sys.triggers
GO
~~START~~
varchar#!#bit
trig1#!#1
~~END~~


-- check if only trigger disabled and not fkey action
UPDATE parent set a=5 where a=4
GO
~~ROW COUNT: 1~~

SELECT * from parent;select * from child;
GO
~~START~~
int
5
~~END~~

~~START~~
int
5
~~END~~


ENABLE trigger all on child;
GO

-- check metadata
select name,is_disabled from sys.triggers
GO
~~START~~
varchar#!#bit
trig1#!#0
~~END~~


-- check if trigger renabled
UPDATE parent set a=6 where a=5
GO
~~START~~
int
1
~~END~~

~~ROW COUNT: 1~~

SELECT * from parent;select * from child;
GO
~~START~~
int
6
~~END~~

~~START~~
int
6
~~END~~


-- cleanup
DROP TABLE child;DROP TABLE parent;
GO
77 changes: 77 additions & 0 deletions test/JDBC/input/BABEL-5645.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
-- setup
CREATE TABLE parent(a int primary key);
GO
CREATE TABLE child(b int, foreign key (b) references parent(a) ON UPDATE CASCADE);
GO
CREATE TRIGGER trig1 on child AFTER UPDATE AS BEGIN SELECT 1 END
GO
INSERT INTO parent values(1)
INSERT INTO child values(1)
GO

-- check metadata
select name,is_disabled from sys.triggers
GO

-- check if trigger enabled, as well as fkey action works
UPDATE parent set a=2 where a=1
GO
SELECT * from parent;select * from child;
GO

ALTER TABLE child disable trigger all
GO

-- check metadata
select name,is_disabled from sys.triggers
GO

-- check if only trigger disabled and not fkey action
UPDATE parent set a=3 where a=2
GO
SELECT * from parent;select * from child;
GO


ALTER TABLE child enable trigger all
GO

-- check metadata
select name,is_disabled from sys.triggers
GO

-- check if trigger renabled
UPDATE parent set a=4 where a=3
GO
SELECT * from parent;select * from child;
GO

DISABLE trigger all on child;
GO

-- check metadata
select name,is_disabled from sys.triggers
GO

-- check if only trigger disabled and not fkey action
UPDATE parent set a=5 where a=4
GO
SELECT * from parent;select * from child;
GO

ENABLE trigger all on child;
GO

-- check metadata
select name,is_disabled from sys.triggers
GO

-- check if trigger renabled
UPDATE parent set a=6 where a=5
GO
SELECT * from parent;select * from child;
GO

-- cleanup
DROP TABLE child;DROP TABLE parent;
GO
Loading