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_5674_test.py

182 lines
4.4 KiB
Python
Raw Normal View History

2021-04-26 20:07:00 +02:00
#coding:utf-8
2022-01-25 22:55:48 +01:00
"""
ID: issue-5940
ISSUE: 5940
TITLE: Allow unused Common Table Expressions
DESCRIPTION:
JIRA: CORE-5674
FBTEST: bugs.core_5674
NOTES:
[19.07.2023] pzotov
Adjusted expected error text for FB 4.x and 5.x: it now contains not only errors but also warnings about non-used CTEs.
[12.08.2023] pzotov
Adjusted expected error text for FB 3.0.12: now it is the same as for FB 4.x+
Change caused by commit "Print warnings occurred during commit", date: 07-jul-2023, started on builds 4.0.3.2958 and 5.0.0.1101.
Discussed with Vlad, 10-jul-2023.
2022-01-25 22:55:48 +01:00
"""
2021-04-26 20:07:00 +02:00
2022-01-25 22:55:48 +01:00
import pytest
from firebird.qa import *
2021-04-26 20:07:00 +02:00
2022-01-25 22:55:48 +01:00
db = db_factory()
2021-04-26 20:07:00 +02:00
2022-01-25 22:55:48 +01:00
test_script = """
2021-04-26 20:07:00 +02:00
set list on;
-- Should PASS but two warnings will be issued:
-- SQL warning code = -104
-- -CTE "X" is not used in query
-- -CTE "Y" is not used in query
with
x as(
select 1 i from rdb$database
)
,y as(
select i from x
)
,z as (
select 2 z from rdb$database
)
select z y, z*2 x from z
2022-01-25 22:55:48 +01:00
;
2021-04-26 20:07:00 +02:00
-- Should PASS but one warning will be issued:
-- SQL warning code = -104
-- -CTE "B" is not used in query
with
a as(
select 0 a from rdb$database
)
,b as(
select 1 x from c rows 1
)
,c as(
select 2 x from d rows 1
)
,d as(
select 3 x from e rows 1
)
,e as(
select a x from a rows 1
)
select * from e
-- union all select * from b
;
-- Should FAIL with:
-- Statement failed, SQLSTATE = 42S02
-- Dynamic SQL Error
-- -SQL error code = -204
-- -Table unknown
-- -FOO
with recursive
a as(
select 0 a from rdb$database
union all
select a+1 from a where a.a < 1
)
,b as(
select 1 a from foo rows 1
)
,c as(
select 2 b from bar rows 1
)
select * from a;
-- Should FAIL with:
-- Statement failed, SQLSTATE = 42000
-- Dynamic SQL Error
-- -SQL error code = -104
-- -CTE 'C' has cyclic dependencies
with recursive
a as(
select 0 a from rdb$database
union all
select a+1 from a where a.a < 1
)
,b as(
select 1 a from c rows 1
)
,c as(
select 2 b from b rows 1
)
select * from a;
2021-12-22 20:23:11 +01:00
"""
2021-04-26 20:07:00 +02:00
2022-01-25 22:55:48 +01:00
act = isql_act('db', test_script,
substitutions=[('-At line[:]{0,1}[\\s]+[\\d]+,[\\s]+column[:]{0,1}[\\s]+[\\d]+',
'-At line: column:')])
2021-04-26 20:07:00 +02:00
2022-01-25 22:55:48 +01:00
expected_stdout = """
2021-04-26 20:07:00 +02:00
Y 2
X 4
X 0
2021-12-22 20:23:11 +01:00
"""
2022-01-25 22:55:48 +01:00
2021-04-26 20:07:00 +02:00
@pytest.mark.version('>=3.0.3')
2022-01-25 22:55:48 +01:00
def test_1(act: Action):
act.expected_stdout = expected_stdout
if act.is_version('<3.0.12'):
act.expected_stderr = """
SQL warning code = -104
-CTE "X" is not used in query
-CTE "Y" is not used in query
SQL warning code = -104
-CTE "B" is not used in query
-CTE "C" is not used in query
-CTE "D" is not used in query
Statement failed, SQLSTATE = 42S02
Dynamic SQL Error
-SQL error code = -204
-Table unknown
-FOO
-At line: column:
Statement failed, SQLSTATE = 42000
Dynamic SQL Error
-SQL error code = -104
-CTE 'C' has cyclic dependencies
"""
else:
act.expected_stderr = """
SQL warning code = -104
-CTE "X" is not used in query
-CTE "Y" is not used in query
SQL warning code = -104
-CTE "B" is not used in query
-CTE "C" is not used in query
-CTE "D" is not used in query
Statement failed, SQLSTATE = 42S02
Dynamic SQL Error
-SQL error code = -204
-Table unknown
-FOO
-At line 8, column 23
SQL warning code = -104
-CTE "B" is not used in query
-CTE "C" is not used in query
Statement failed, SQLSTATE = 42000
Dynamic SQL Error
-SQL error code = -104
-CTE 'C' has cyclic dependencies
SQL warning code = -104
-CTE "B" is not used in query
-CTE "C" is not used in query
"""
2022-01-25 22:55:48 +01:00
act.execute()
assert (act.clean_stderr == act.clean_expected_stderr and
act.clean_stdout == act.clean_expected_stdout)