6
0
mirror of https://github.com/FirebirdSQL/firebird-qa.git synced 2025-01-23 14:03:06 +01:00
firebird-qa/tests/bugs/core_2274_test.py

89 lines
2.8 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-2700
ISSUE: 2700
TITLE: MERGE non-standard behaviour, accepts multiple matches
DESCRIPTION:
JIRA: CORE-2274
FBTEST: bugs.core_2274
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 t_payment_details(operation_id int primary key, person_id int, payment_sum int);
recreate table t_payment_totals(person_id int primary key, payment_sum int);
commit;
insert into t_payment_details(operation_id, person_id, payment_sum) values(0, 10, 0);
insert into t_payment_details(operation_id, person_id, payment_sum) values(1, 11, 11);
insert into t_payment_details(operation_id, person_id, payment_sum) values(2, 22, 222);
insert into t_payment_details(operation_id, person_id, payment_sum) values(3, 11, 3333);
insert into t_payment_details(operation_id, person_id, payment_sum) values(7, 17, 77777);
insert into t_payment_totals(person_id, payment_sum) values(10, 100);
insert into t_payment_totals(person_id, payment_sum) values(11, 111);
insert into t_payment_totals(person_id, payment_sum) values(22, 222);
set list on;
select 'before merge' as msg, e.* from t_payment_totals e order by person_id;
2022-01-21 18:49:26 +01:00
merge into t_payment_totals t
2021-04-26 20:07:00 +02:00
using t_payment_details s on s.person_id = t.person_id
when NOT matched then
insert(person_id, payment_sum) values( s.person_id, s.payment_sum )
when MATCHED then
update set t.payment_sum = t.payment_sum + s.payment_sum
;
select 'after merge' as msg, e.* from t_payment_totals e order by person_id;
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=[('[ \t]+', ' ')])
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
MSG before merge
PERSON_ID 10
PAYMENT_SUM 100
MSG before merge
PERSON_ID 11
PAYMENT_SUM 111
MSG before merge
PERSON_ID 22
PAYMENT_SUM 222
MSG after merge
PERSON_ID 10
PAYMENT_SUM 100
MSG after merge
PERSON_ID 11
PAYMENT_SUM 111
MSG after merge
PERSON_ID 22
PAYMENT_SUM 222
2021-12-22 20:23:11 +01:00
"""
2022-01-21 18:49:26 +01:00
expected_stderr = """
2021-04-26 20:07:00 +02:00
Statement failed, SQLSTATE = 21000
Multiple source records cannot match the same target during MERGE
2021-12-22 20:23:11 +01:00
"""
2021-04-26 20:07:00 +02:00
@pytest.mark.version('>=4.0')
2022-01-21 18:49:26 +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)
2021-04-26 20:07:00 +02:00