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

144 lines
2.9 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
"""
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
expected_stderr = """
2021-04-26 20:07:00 +02:00
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
2022-01-25 22:55:48 +01:00
2021-04-26 20:07:00 +02:00
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
2021-12-22 20:23:11 +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
act.expected_stderr = expected_stderr
act.execute()
assert (act.clean_stderr == act.clean_expected_stderr and
act.clean_stdout == act.clean_expected_stdout)