2021-04-26 20:07:00 +02:00
|
|
|
#coding:utf-8
|
|
|
|
|
2022-01-21 18:49:26 +01:00
|
|
|
"""
|
|
|
|
ID: issue-3189
|
|
|
|
ISSUE: 3189
|
|
|
|
TITLE: Changing sort directon in delete statement cause deletion of all records in table
|
|
|
|
DESCRIPTION:
|
|
|
|
JIRA: CORE-2799
|
2022-02-02 15:46:19 +01:00
|
|
|
FBTEST: bugs.core_2799
|
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 test
|
|
|
|
(
|
|
|
|
id integer not null primary key,
|
|
|
|
kod varchar(5)
|
|
|
|
);
|
|
|
|
commit;
|
|
|
|
|
|
|
|
insert into test(id, kod) values(1, 'abc');
|
|
|
|
insert into test(id, kod) values(2, 'abc');
|
|
|
|
commit;
|
2022-01-21 18:49:26 +01:00
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
-- now we have 2 rows in table
|
|
|
|
-- and delete in ___ascending___ oreder
|
|
|
|
|
|
|
|
set count on;
|
|
|
|
--set echo on;
|
|
|
|
|
2022-01-21 18:49:26 +01:00
|
|
|
delete from test t
|
|
|
|
where exists(select * from test t2 where t2.id<>t.id and t2.kod=t.kod)
|
2021-04-26 20:07:00 +02:00
|
|
|
order by t.id asc;
|
|
|
|
-- 2.5: one row affected
|
|
|
|
-- 3.0: TWO rows must be affected.
|
|
|
|
commit;
|
2022-01-21 18:49:26 +01:00
|
|
|
|
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
select * from test;
|
|
|
|
-- 2.5: one row selected id=2 kod='abc'
|
|
|
|
-- 3.0: NO rows should be selected here.
|
2022-01-21 18:49:26 +01:00
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
set count off;
|
|
|
|
delete from test;
|
|
|
|
commit;
|
|
|
|
insert into test(id, kod) values(1, 'abc');
|
|
|
|
insert into test(id, kod) values(2, 'abc');
|
|
|
|
commit;
|
|
|
|
set count on;
|
|
|
|
|
|
|
|
-- now we have 2 rows in table
|
|
|
|
-- and delete in ___descending___ oreder
|
2022-01-21 18:49:26 +01:00
|
|
|
|
|
|
|
delete from test t
|
|
|
|
where exists(select * from test t2 where t2.id<>t.id and t2.kod=t.kod)
|
2021-04-26 20:07:00 +02:00
|
|
|
order by t.id desc;
|
|
|
|
-- 2.5: two rows affected.
|
|
|
|
-- 3.0: TWO rows must be affected.
|
|
|
|
commit;
|
|
|
|
|
|
|
|
select * from test;
|
|
|
|
-- 2.5: empty result set.
|
|
|
|
-- 3.0: NO rows should be selected here.
|
|
|
|
|
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)
|
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
|
|
|
Records affected: 2
|
|
|
|
Records affected: 0
|
|
|
|
Records affected: 2
|
|
|
|
Records affected: 0
|
2021-12-22 20:23:11 +01:00
|
|
|
"""
|
2021-04-26 20:07:00 +02:00
|
|
|
|
|
|
|
@pytest.mark.version('>=3.0')
|
2022-01-21 18:49:26 +01:00
|
|
|
def test_1(act: Action):
|
|
|
|
act.expected_stdout = expected_stdout
|
|
|
|
act.execute()
|
|
|
|
assert act.clean_stdout == act.clean_expected_stdout
|
2021-04-26 20:07:00 +02:00
|
|
|
|