2021-12-30 19:43:52 +01:00
|
|
|
#coding:utf-8
|
|
|
|
|
2022-01-27 20:08:36 +01:00
|
|
|
"""
|
|
|
|
ID: issue-6942
|
|
|
|
ISSUE: 6942
|
|
|
|
TITLE: Incorrect singleton error with MERGE and RETURNING
|
|
|
|
DESCRIPTION:
|
|
|
|
"""
|
2021-12-30 19:43:52 +01:00
|
|
|
|
2022-01-27 20:08:36 +01:00
|
|
|
import pytest
|
|
|
|
from firebird.qa import *
|
2021-12-30 19:43:52 +01:00
|
|
|
|
2022-01-27 20:08:36 +01:00
|
|
|
db = db_factory()
|
2021-12-30 19:43:52 +01:00
|
|
|
|
2022-01-27 20:08:36 +01:00
|
|
|
test_script = """
|
2021-12-30 19:43:52 +01:00
|
|
|
set list on;
|
|
|
|
recreate table test(
|
|
|
|
n1 integer,
|
|
|
|
n2 integer
|
|
|
|
);
|
|
|
|
|
|
|
|
insert into test values (1, 10);
|
|
|
|
insert into test values (2, 20);
|
|
|
|
commit;
|
|
|
|
|
|
|
|
--------------------------------------------------
|
|
|
|
|
|
|
|
merge into test
|
|
|
|
using (
|
|
|
|
select 2 x from rdb$database
|
|
|
|
union all
|
|
|
|
select 3 x from rdb$database
|
|
|
|
) t
|
|
|
|
on test.n1 = t.x
|
|
|
|
when not matched then insert values (3, 30)
|
|
|
|
returning n1, n2;
|
|
|
|
rollback;
|
|
|
|
|
|
|
|
--------------------------------------------------
|
|
|
|
|
|
|
|
set term ^;
|
|
|
|
execute block returns (
|
|
|
|
o1 integer,
|
|
|
|
o2 integer
|
|
|
|
)
|
|
|
|
as
|
|
|
|
begin
|
|
|
|
merge into test
|
|
|
|
using (
|
|
|
|
select 2 x from rdb$database
|
|
|
|
union all
|
|
|
|
select 3 x from rdb$database
|
|
|
|
) t
|
|
|
|
on test.n1 = t.x
|
|
|
|
when not matched then insert values (3, 30)
|
|
|
|
returning n1, n2 into o1, o2;
|
|
|
|
|
|
|
|
suspend;
|
|
|
|
end
|
|
|
|
^
|
|
|
|
set term ;^
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
2022-01-27 20:08:36 +01:00
|
|
|
act = isql_act('db', test_script)
|
2021-12-30 19:43:52 +01:00
|
|
|
|
2022-01-27 20:08:36 +01:00
|
|
|
expected_stdout = """
|
2021-12-30 19:43:52 +01:00
|
|
|
N1 3
|
|
|
|
N2 30
|
|
|
|
O1 3
|
|
|
|
O2 30
|
|
|
|
"""
|
|
|
|
|
|
|
|
@pytest.mark.version('>=5.0')
|
2022-01-27 20:08:36 +01:00
|
|
|
def test_1(act: Action):
|
|
|
|
act.expected_stdout = expected_stdout
|
|
|
|
act.execute()
|
|
|
|
assert act.clean_stdout == act.clean_expected_stdout
|