2021-04-26 20:07:00 +02:00
|
|
|
#coding:utf-8
|
|
|
|
|
2022-02-04 19:05:19 +01:00
|
|
|
"""
|
|
|
|
ID: dml.merge-02
|
|
|
|
FBTEST: functional.dml.merge.02
|
|
|
|
TITLE: MERGE statement can have only one RETURNING which must be after all WHEN sub-statements
|
|
|
|
DESCRIPTION:
|
|
|
|
"""
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-02-04 19:05:19 +01:00
|
|
|
import pytest
|
|
|
|
from firebird.qa import *
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-02-04 19:05:19 +01:00
|
|
|
db = db_factory()
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-02-04 19:05:19 +01:00
|
|
|
test_script = """
|
2021-04-26 20:07:00 +02:00
|
|
|
set list on;
|
|
|
|
|
|
|
|
recreate table ta(id int primary key, x int, y int);
|
|
|
|
recreate table tb(id int primary key, x int, y int);
|
|
|
|
commit;
|
2022-02-04 19:05:19 +01:00
|
|
|
|
2021-12-22 20:25:10 +01:00
|
|
|
insert into ta(id, x, y) values(1, 10, 100);
|
|
|
|
insert into tb(id, x, y) values(1, 10, 100);
|
|
|
|
commit;
|
2021-04-26 20:07:00 +02:00
|
|
|
|
|
|
|
-- [ 1 ] must PASS:
|
|
|
|
merge into tb t
|
|
|
|
using ta s on s.id = t.id
|
2021-12-22 20:25:10 +01:00
|
|
|
when NOT matched then insert values(-s.id, -s.x, -s.y) ------------------------- (a)
|
|
|
|
when matched then
|
|
|
|
delete
|
|
|
|
returning old.id as deleted_id, old.x as deleted_x, old.y as deleted_y ----- (b)
|
2021-04-26 20:07:00 +02:00
|
|
|
;
|
|
|
|
rollback;
|
|
|
|
|
|
|
|
-- [ 2 ] must FAIL with
|
|
|
|
-- Statement failed, SQLSTATE = 42000 / ... / -Token unknown / -when
|
|
|
|
|
|
|
|
merge into tb t
|
|
|
|
using ta s on s.id = t.id
|
2021-12-22 20:25:10 +01:00
|
|
|
when matched then delete returning old.id, old.x, old.y ----------------------- (b)
|
|
|
|
when NOT matched then insert values(-s.id, -s.x, -s.y) ------------------------ (a)
|
2021-04-26 20:07:00 +02:00
|
|
|
;
|
2021-12-22 20:25:10 +01:00
|
|
|
"""
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-02-04 19:05:19 +01:00
|
|
|
act = isql_act('db', test_script, substitutions=[('-Token unknown .*', ''), ('[ \t]+', ' ')])
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-02-04 19:05:19 +01:00
|
|
|
expected_stdout = """
|
2021-12-22 20:25:10 +01:00
|
|
|
DELETED_ID 1
|
|
|
|
DELETED_X 10
|
|
|
|
DELETED_Y 100
|
|
|
|
"""
|
2022-02-04 19:05:19 +01:00
|
|
|
|
|
|
|
expected_stderr = """
|
2021-04-26 20:07:00 +02:00
|
|
|
Statement failed, SQLSTATE = 42000
|
|
|
|
Dynamic SQL Error
|
|
|
|
-SQL error code = -104
|
|
|
|
-Token unknown - line 4, column 5
|
|
|
|
-when
|
2021-12-22 20:25:10 +01:00
|
|
|
"""
|
2021-04-26 20:07:00 +02:00
|
|
|
|
|
|
|
@pytest.mark.version('>=3.0')
|
2022-02-04 19:05:19 +01:00
|
|
|
def test_1(act: Action):
|
|
|
|
act.expected_stdout = expected_stdout
|
|
|
|
act.expected_stderr = expected_stderr
|
|
|
|
act.execute()
|
|
|
|
assert (act.clean_stderr == act.clean_expected_stderr and
|
|
|
|
act.clean_stdout == act.clean_expected_stdout)
|