6
0
mirror of https://github.com/FirebirdSQL/firebird-qa.git synced 2025-01-22 21:43:06 +01:00
firebird-qa/tests/bugs/core_6090_test.py

79 lines
2.5 KiB
Python
Raw Normal View History

2021-04-26 20:07:00 +02:00
#coding:utf-8
2022-01-26 21:10:46 +01:00
"""
ID: issue-6340
ISSUE: 6340
TITLE: BLOB fields may be suddenly set to NULLs during UPDATE after a table format change
DESCRIPTION:
It's not easy to obtain BLOB_ID using only fdb. Rather in ISQL blob_id will be shown always (even if we do not want this :)).
This test runs ISQL with commands that were provided in the ticket and parses its result by extracting only column BLOB_ID.
Each BLOB_ID is added to set(), so eventually we can get total number of UNIQUE blob IDs that were generated during test.
This number must be equal to number of records in the table (three in this test).
Beside of this, we check that all blobs are not null, see 'null_blob_cnt' counter.
JIRA: CORE-6090
FBTEST: bugs.core_6090
2022-01-26 21:10:46 +01:00
"""
2021-04-26 20:07:00 +02:00
import pytest
2021-12-10 19:50:31 +01:00
import re
2022-01-26 21:10:46 +01:00
from firebird.qa import *
2021-04-26 20:07:00 +02:00
2022-01-26 21:10:46 +01:00
db = db_factory()
2021-04-26 20:07:00 +02:00
2022-01-26 21:10:46 +01:00
act = python_act('db')
2021-04-26 20:07:00 +02:00
2022-01-26 21:10:46 +01:00
test_script = """
2021-12-10 19:50:31 +01:00
set bail on;
set blob all;
set list on;
recreate view v as select 1 x from rdb$database;
commit;
recreate table test (n1 int, n2 int, n3 int, blob_id blob);
recreate view v as select blob_id from test;
commit;
insert into test values (0, 0, null, '0:foo');
insert into test values (1, 1, 1, '1:rio');
insert into test values (2, 2, 2, '2:bar');
commit;
select 1 as point, v.* from v;
update test set n1 = 1 where n2 >= 0; -- n1 should be set to 1 in all three rows
select 2 as point, v.* from v;
rollback;
2021-04-26 20:07:00 +02:00
2021-12-10 19:50:31 +01:00
update test set n1 = 1 where n2 >= 0 and n3 >= 0; -- n1 should be set to 1 in 2nd and 3rd rows
select 3 as point, v.* from v;
rollback;
2021-04-26 20:07:00 +02:00
2021-12-10 19:50:31 +01:00
alter table test add col5 date;
commit;
update test set n1 = 1 where n2 >= 0; -- n1 should be set to 1 in all three rows
select 4 as point, v.* from v; -- Here blob_id were changed because of other bug, see CORE-6089, but contents is correct
rollback;
update test set n1 = 1 where n2 >= 0 and n3 >= 0;
-- n1 should be set to 1 in 2nd and 3rd rows
select 5 as point, v.* from v; -- BUG: BLOB_ID in the second row was nullified!!!
quit;
"""
@pytest.mark.version('>=3.0.5')
2022-01-26 21:10:46 +01:00
def test_1(act: Action):
2021-12-10 19:50:31 +01:00
pattern = re.compile('BLOB_ID\\s+\\S+', re.IGNORECASE)
blob_id_set = set()
null_blob_cnt = 0
2022-01-26 21:10:46 +01:00
act.isql(switches=['-q'], input=test_script)
for line in act.stdout.splitlines():
2021-12-10 19:50:31 +01:00
if pattern.search(line):
blob_id_set.add(line.split()[1])
if '<null>' in line.lower():
null_blob_cnt += 1
# Check
assert len(blob_id_set) == 3
assert null_blob_cnt == 0