6
0
mirror of https://github.com/FirebirdSQL/firebird-qa.git synced 2025-01-22 21:43:06 +01:00
firebird-qa/tests/bugs/core_2005_test.py

104 lines
2.9 KiB
Python
Raw Normal View History

2021-04-26 20:07:00 +02:00
#coding:utf-8
2022-01-21 18:49:26 +01:00
"""
ID: issue-2442
ISSUE: 2442
TITLE: Support SQL 2008 syntax for MERGE statement with DELETE extension
DESCRIPTION:
JIRA: CORE-2005
FBTEST: bugs.core_2005
2022-01-21 18:49:26 +01:00
"""
2021-04-26 20:07:00 +02:00
2022-01-21 18:49:26 +01:00
import pytest
from firebird.qa import *
2021-04-26 20:07:00 +02:00
2022-01-21 18:49:26 +01:00
db = db_factory()
2021-04-26 20:07:00 +02:00
2022-01-21 18:49:26 +01:00
test_script = """
2021-04-26 20:07:00 +02:00
recreate table src(id int primary key, x int, y int, z computed by(x+y));
recreate table tgt(id int primary key, x int, y int, z computed by(x+y));
commit;
2022-01-21 18:49:26 +01:00
2021-04-26 20:07:00 +02:00
insert into src values(1, 5, 2);
insert into src values(3, 4, 3);
insert into src values(5, 3, 4);
insert into src values(6, 2, 5);
insert into src values(7, 1, 1);
insert into src values(8, 0, 0);
insert into src values(9, 1, 2);
commit;
2022-01-21 18:49:26 +01:00
2021-04-26 20:07:00 +02:00
insert into tgt values(2, 2, 5);
insert into tgt values(3, 3, 5);
insert into tgt values(4, 1, 7);
insert into tgt values(5, 6, 3);
commit;
2022-01-21 18:49:26 +01:00
2021-04-26 20:07:00 +02:00
set transaction snapshot no wait;
2022-01-21 18:49:26 +01:00
2021-04-26 20:07:00 +02:00
set term ^;
execute block as
begin
in autonomous transaction do
merge into tgt t
using src s
on s.id = t.id
when not matched and s.z >= 7 then
insert values(id, x, y)
when matched and t.z > s.z then
delete
when matched then
update set x = s.x, y = s.y
;
2022-01-21 18:49:26 +01:00
2021-04-26 20:07:00 +02:00
merge into src t
using tgt s
on s.id = t.id
when matched and t.z <= s.z then
update set x = s.x, y = s.y
when not matched and s.z >= 7 then
insert values(id, x, y)
when matched then
delete
;
end
^
set term ;^
commit;
2022-01-21 18:49:26 +01:00
2021-04-26 20:07:00 +02:00
select * from src;
select * from tgt;
2021-12-22 20:23:11 +01:00
"""
2021-04-26 20:07:00 +02:00
2022-01-21 18:49:26 +01:00
act = isql_act('db', test_script, substitutions=[('=.*', '')])
2021-04-26 20:07:00 +02:00
2022-01-21 18:49:26 +01:00
expected_stdout = """
2021-04-26 20:07:00 +02:00
ID X Y Z
============ ============ ============ =====================
1 5 2 7
3 3 5 8
5 6 3 9
6 2 5 7
7 1 1 2
8 0 0 0
9 1 2 3
2 2 5 7
4 1 7 8
ID X Y Z
============ ============ ============ =====================
2 2 5 7
4 1 7 8
1 5 2 7
6 2 5 7
2021-12-22 20:23:11 +01:00
"""
2021-04-26 20:07:00 +02:00
@pytest.mark.version('>=3.0')
2022-01-21 18:49:26 +01:00
def test_1(act: Action):
act.expected_stdout = expected_stdout
act.execute()
assert act.clean_stdout == act.clean_expected_stdout
2021-04-26 20:07:00 +02:00