2021-04-26 20:07:00 +02:00
|
|
|
#coding:utf-8
|
|
|
|
#
|
|
|
|
# id: functional.tabloid.pg_14421
|
|
|
|
# title: UPDATE/DETERE RETURNING should issue only one row when applying to table with self-referencing FK
|
|
|
|
# decription:
|
|
|
|
# Original issue:
|
|
|
|
# https://www.postgresql.org/message-id/cakfquwyrb5iyfqs6o9mmtbxp96l40bxpnfgosj8xm88ag%2b5_aa%40mail.gmail.com
|
|
|
|
#
|
|
|
|
# tracker_id:
|
|
|
|
# min_versions: ['3.0']
|
|
|
|
# versions: 3.0
|
|
|
|
# qmid: None
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
from firebird.qa import db_factory, isql_act, Action
|
|
|
|
|
|
|
|
# version: 3.0
|
|
|
|
# resources: None
|
|
|
|
|
|
|
|
substitutions_1 = []
|
|
|
|
|
|
|
|
init_script_1 = """"""
|
|
|
|
|
|
|
|
db_1 = db_factory(sql_dialect=3, init=init_script_1)
|
|
|
|
|
|
|
|
test_script_1 = """
|
|
|
|
set list on;
|
|
|
|
recreate table test(
|
|
|
|
id int primary key,
|
|
|
|
pid int references test(id) on delete cascade on update cascade
|
|
|
|
);
|
|
|
|
insert into test values (1, null);
|
|
|
|
insert into test values (2, 1);
|
|
|
|
insert into test values (3, 2);
|
|
|
|
insert into test values (4, 2);
|
|
|
|
insert into test values (5, 2);
|
|
|
|
insert into test values (6, 2);
|
|
|
|
insert into test values (7, 2);
|
|
|
|
commit;
|
|
|
|
|
|
|
|
delete from test
|
|
|
|
where id = 2
|
|
|
|
returning id as old_id
|
|
|
|
;
|
|
|
|
rollback;
|
|
|
|
|
|
|
|
|
|
|
|
update test set id=9 where id=2
|
|
|
|
returning old.id as old_id, new.id as new_id
|
|
|
|
;
|
|
|
|
|
|
|
|
rollback;
|
2021-12-22 20:25:10 +01:00
|
|
|
"""
|
2021-04-26 20:07:00 +02:00
|
|
|
|
|
|
|
act_1 = isql_act('db_1', test_script_1, substitutions=substitutions_1)
|
|
|
|
|
|
|
|
expected_stdout_1 = """
|
|
|
|
OLD_ID 2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
OLD_ID 2
|
|
|
|
NEW_ID 9
|
2021-12-22 20:25:10 +01:00
|
|
|
"""
|
2021-04-26 20:07:00 +02:00
|
|
|
|
|
|
|
@pytest.mark.version('>=3.0')
|
2021-04-28 12:42:11 +02:00
|
|
|
def test_1(act_1: Action):
|
2021-04-26 20:07:00 +02:00
|
|
|
act_1.expected_stdout = expected_stdout_1
|
|
|
|
act_1.execute()
|
2021-12-22 20:25:10 +01:00
|
|
|
assert act_1.clean_stdout == act_1.clean_expected_stdout
|
2021-04-26 20:07:00 +02:00
|
|
|
|