mirror of
https://github.com/FirebirdSQL/firebird-qa.git
synced 2025-01-23 05:53:06 +01:00
121 lines
3.5 KiB
Python
121 lines
3.5 KiB
Python
|
#coding:utf-8
|
||
|
#
|
||
|
# id: bugs.core_5449
|
||
|
# title: Support DEFAULT context value in INSERT, UPDATE, MERGE and UPDATE OR INSERT statements
|
||
|
# decription:
|
||
|
# Checked on WI-T4.0.0.531.
|
||
|
#
|
||
|
# tracker_id: CORE-5449
|
||
|
# min_versions: ['4.0']
|
||
|
# versions: 4.0
|
||
|
# qmid: None
|
||
|
|
||
|
import pytest
|
||
|
from firebird.qa import db_factory, isql_act, Action
|
||
|
|
||
|
# version: 4.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 test1(
|
||
|
id int generated by default as identity constraint test1_pk primary key using index test1_pk
|
||
|
,x int default 123
|
||
|
,y int
|
||
|
,z computed by(x + coalesce(y, id) )
|
||
|
);
|
||
|
|
||
|
insert into test1(id, x, y, z) values( default, default, 222, default )
|
||
|
returning 'AFFECTED BY "INSERT"' msg, id, x, y, z
|
||
|
;
|
||
|
|
||
|
update or insert into test1(id, x, y, z) values(-1, default, default, default )
|
||
|
matching(id)
|
||
|
returning 'AFFECTED BY "UPDATE OR INSERT"' msg, id, x, y, z
|
||
|
;
|
||
|
|
||
|
|
||
|
update test1 set y = z, z = default
|
||
|
where y is null
|
||
|
order by id
|
||
|
rows 1
|
||
|
returning
|
||
|
'AFFECTED BY "UPDATE"' msg,
|
||
|
id,
|
||
|
old.y as y_before_update,
|
||
|
old.z as z_before_update,
|
||
|
new.y as y_after_update,
|
||
|
new.z as z_after_update
|
||
|
;
|
||
|
|
||
|
|
||
|
merge into test1 t using(select id,x,y from test1 union all select 2*id, 3*x,4*y from test1) s
|
||
|
on s.id = t.id -- and
|
||
|
when matched then update set t.y = s.x, t.x=s.y, t.z = default
|
||
|
when NOT matched then insert(x,y,z) values(default, default, default)
|
||
|
;
|
||
|
|
||
|
select 'AFFECTED BY "MERGE"' msg, t.* from test1 t order by id;
|
||
|
"""
|
||
|
|
||
|
act_1 = isql_act('db_1', test_script_1, substitutions=substitutions_1)
|
||
|
|
||
|
expected_stdout_1 = """
|
||
|
MSG AFFECTED BY "INSERT"
|
||
|
ID 1
|
||
|
X 123
|
||
|
Y 222
|
||
|
Z 345
|
||
|
|
||
|
MSG AFFECTED BY "UPDATE OR INSERT"
|
||
|
ID -1
|
||
|
X 123
|
||
|
Y <null>
|
||
|
Z 122
|
||
|
|
||
|
MSG AFFECTED BY "UPDATE"
|
||
|
ID -1
|
||
|
Y_BEFORE_UPDATE <null>
|
||
|
Z_BEFORE_UPDATE 122
|
||
|
Y_AFTER_UPDATE 122
|
||
|
Z_AFTER_UPDATE 245
|
||
|
|
||
|
MSG AFFECTED BY "MERGE"
|
||
|
ID -1
|
||
|
X 122
|
||
|
Y 123
|
||
|
Z 245
|
||
|
|
||
|
MSG AFFECTED BY "MERGE"
|
||
|
ID 1
|
||
|
X 222
|
||
|
Y 123
|
||
|
Z 345
|
||
|
|
||
|
MSG AFFECTED BY "MERGE"
|
||
|
ID 2
|
||
|
X 123
|
||
|
Y <null>
|
||
|
Z 125
|
||
|
|
||
|
MSG AFFECTED BY "MERGE"
|
||
|
ID 3
|
||
|
X 123
|
||
|
Y <null>
|
||
|
Z 126
|
||
|
"""
|
||
|
|
||
|
@pytest.mark.version('>=4.0')
|
||
|
def test_core_5449_1(act_1: Action):
|
||
|
act_1.expected_stdout = expected_stdout_1
|
||
|
act_1.execute()
|
||
|
assert act_1.clean_expected_stdout == act_1.clean_stdout
|
||
|
|