mirror of
https://github.com/FirebirdSQL/firebird-qa.git
synced 2025-01-22 21:43:06 +01:00
113 lines
3.2 KiB
Python
113 lines
3.2 KiB
Python
#coding:utf-8
|
|
|
|
"""
|
|
ID: issue-5720
|
|
ISSUE: 5720
|
|
TITLE: Support DEFAULT context value in INSERT, UPDATE, MERGE and UPDATE OR INSERT statements
|
|
DESCRIPTION:
|
|
JIRA: CORE-5449
|
|
FBTEST: bugs.core_5449
|
|
"""
|
|
|
|
import pytest
|
|
from firebird.qa import *
|
|
|
|
db = db_factory()
|
|
|
|
test_script = """
|
|
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 = isql_act('db', test_script)
|
|
|
|
expected_stdout = """
|
|
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_1(act: Action):
|
|
act.expected_stdout = expected_stdout
|
|
act.execute()
|
|
assert act.clean_stdout == act.clean_expected_stdout
|
|
|