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

144 lines
7.0 KiB
Python
Raw Normal View History

2021-04-26 20:07:00 +02:00
#coding:utf-8
2022-01-27 20:08:36 +01:00
"""
ID: issue-6598
ISSUE: 6598
TITLE: LEAD() and LAG() do not allow to specify 3rd argument ("DEFAULT" value when pointer is out of scope) of INT128 datatype.
2022-01-27 20:08:36 +01:00
DESCRIPTION:
JIRA: CORE-6357
FBTEST: bugs.core_6357
NOTES:
[13.12.2023] pzotov
Added 'SQLSTATE' in substitutions: runtime error must not be filtered out by '?!(...)' pattern
("negative lookahead assertion", see https://docs.python.org/3/library/re.html#regular-expression-syntax).
Added 'combine_output = True' in order to see SQLSTATE if any error occurs.
2022-01-27 20:08:36 +01:00
"""
2021-04-26 20:07:00 +02:00
2022-01-27 20:08:36 +01:00
import pytest
from firebird.qa import *
2021-04-26 20:07:00 +02:00
2022-01-27 20:08:36 +01:00
db = db_factory()
2021-04-26 20:07:00 +02:00
2022-01-27 20:08:36 +01:00
test_script = """
2021-04-26 20:07:00 +02:00
set heading off;
recreate table test1 (a smallint);
recreate table test2 (a bigint);
recreate table test3 (a int128);
recreate table test4 (a decfloat);
2022-01-27 20:08:36 +01:00
2021-04-26 20:07:00 +02:00
insert into test1 values (1);
insert into test1 values (2);
2022-01-27 20:08:36 +01:00
2021-04-26 20:07:00 +02:00
insert into test2 select * from test1;
insert into test3 select * from test1;
insert into test4 select * from test1;
2022-01-27 20:08:36 +01:00
2021-04-26 20:07:00 +02:00
set list on;
set sqlda_display on;
2022-01-27 20:08:36 +01:00
2021-04-26 20:07:00 +02:00
select a as field_a, lead(a, 1, 32767)over(order by a) lead_for_smallint from test1;
select a as field_a, lag(a, 1, -32768)over(order by a) lag_for_smallint from test1;
2022-01-27 20:08:36 +01:00
2021-04-26 20:07:00 +02:00
select a as field_a, lead(a, 1, 9223372036854775807)over(order by a) lead_for_bigint from test2;
select a as field_a, lag(a, 1, -9223372036854775808)over(order by a) lag_for_bigint from test2;
2022-01-27 20:08:36 +01:00
2021-04-26 20:07:00 +02:00
select a as field_a, lead(a, 1, 170141183460469231731687303715884105727)over(order by a) lead_for_int128 from test3;
select a as field_a, lag(a, 1, -170141183460469231731687303715884105728)over(order by a) lag_for_int128 from test3;
2022-01-27 20:08:36 +01:00
2021-04-26 20:07:00 +02:00
select a as field_a, lag(a, 1, -9.999999999999999999999999999999999e6144) over (order by a) lag_for_decfloat_1 from test4;
select a as field_a, lag(a, 1, -1.0e-6143)over(order by a) lag_for_decfloat_2 from test4;
select a as field_a, lag(a, 1, 1.0e-6143)over(order by a) lag_for_decfloat_3 from test4;
select a as field_a, lag(a, 1, 9.999999999999999999999999999999999e6144)over(order by a) lag_for_decfloat_4 from test4;
2021-12-22 20:23:11 +01:00
"""
2021-04-26 20:07:00 +02:00
act = isql_act('db', test_script, substitutions=[('^((?!SQLSTATE|sqltype|FIELD_A|LAG_FOR|LEAD_FOR).)*$', ''), ('[ \t]+', ' ')])
2021-04-26 20:07:00 +02:00
2022-01-27 20:08:36 +01:00
expected_stdout = """
2021-04-26 20:07:00 +02:00
01: sqltype: 500 SHORT Nullable scale: 0 subtype: 0 len: 2
: name: A alias: FIELD_A
02: sqltype: 500 SHORT Nullable scale: 0 subtype: 0 len: 2
: name: LEAD alias: LEAD_FOR_SMALLINT
FIELD_A 1
LEAD_FOR_SMALLINT 2
FIELD_A 2
LEAD_FOR_SMALLINT 32767
01: sqltype: 500 SHORT Nullable scale: 0 subtype: 0 len: 2
: name: A alias: FIELD_A
02: sqltype: 500 SHORT Nullable scale: 0 subtype: 0 len: 2
: name: LAG alias: LAG_FOR_SMALLINT
FIELD_A 1
LAG_FOR_SMALLINT -32768
FIELD_A 2
LAG_FOR_SMALLINT 1
01: sqltype: 580 INT64 Nullable scale: 0 subtype: 0 len: 8
: name: A alias: FIELD_A
02: sqltype: 580 INT64 Nullable scale: 0 subtype: 0 len: 8
: name: LEAD alias: LEAD_FOR_BIGINT
FIELD_A 1
LEAD_FOR_BIGINT 2
FIELD_A 2
LEAD_FOR_BIGINT 9223372036854775807
01: sqltype: 580 INT64 Nullable scale: 0 subtype: 0 len: 8
: name: A alias: FIELD_A
02: sqltype: 580 INT64 Nullable scale: 0 subtype: 0 len: 8
: name: LAG alias: LAG_FOR_BIGINT
FIELD_A 1
LAG_FOR_BIGINT -9223372036854775808
FIELD_A 2
LAG_FOR_BIGINT 1
01: sqltype: 32752 INT128 Nullable scale: 0 subtype: 0 len: 16
: name: A alias: FIELD_A
02: sqltype: 32752 INT128 Nullable scale: 0 subtype: 0 len: 16
: name: LEAD alias: LEAD_FOR_INT128
FIELD_A 1
LEAD_FOR_INT128 2
FIELD_A 2
LEAD_FOR_INT128 170141183460469231731687303715884105727
01: sqltype: 32752 INT128 Nullable scale: 0 subtype: 0 len: 16
: name: A alias: FIELD_A
02: sqltype: 32752 INT128 Nullable scale: 0 subtype: 0 len: 16
: name: LAG alias: LAG_FOR_INT128
FIELD_A 1
LAG_FOR_INT128 -170141183460469231731687303715884105728
FIELD_A 2
LAG_FOR_INT128 1
01: sqltype: 32762 DECFLOAT(34) Nullable scale: 0 subtype: 0 len: 16
: name: A alias: FIELD_A
02: sqltype: 32762 DECFLOAT(34) Nullable scale: 0 subtype: 0 len: 16
: name: LAG alias: LAG_FOR_DECFLOAT_1
FIELD_A 1
LAG_FOR_DECFLOAT_1 -9.999999999999999999999999999999999E+6144
FIELD_A 2
LAG_FOR_DECFLOAT_1 1
01: sqltype: 32762 DECFLOAT(34) Nullable scale: 0 subtype: 0 len: 16
: name: A alias: FIELD_A
02: sqltype: 32762 DECFLOAT(34) Nullable scale: 0 subtype: 0 len: 16
: name: LAG alias: LAG_FOR_DECFLOAT_2
FIELD_A 1
LAG_FOR_DECFLOAT_2 -1.0E-6143
FIELD_A 2
LAG_FOR_DECFLOAT_2 1
01: sqltype: 32762 DECFLOAT(34) Nullable scale: 0 subtype: 0 len: 16
: name: A alias: FIELD_A
02: sqltype: 32762 DECFLOAT(34) Nullable scale: 0 subtype: 0 len: 16
: name: LAG alias: LAG_FOR_DECFLOAT_3
FIELD_A 1
LAG_FOR_DECFLOAT_3 1.0E-6143
FIELD_A 2
LAG_FOR_DECFLOAT_3 1
01: sqltype: 32762 DECFLOAT(34) Nullable scale: 0 subtype: 0 len: 16
: name: A alias: FIELD_A
02: sqltype: 32762 DECFLOAT(34) Nullable scale: 0 subtype: 0 len: 16
: name: LAG alias: LAG_FOR_DECFLOAT_4
FIELD_A 1
LAG_FOR_DECFLOAT_4 9.999999999999999999999999999999999E+6144
FIELD_A 2
LAG_FOR_DECFLOAT_4 1
2021-12-22 20:23:11 +01:00
"""
2021-04-26 20:07:00 +02:00
@pytest.mark.version('>=4.0')
2022-01-27 20:08:36 +01:00
def test_1(act: Action):
act.expected_stdout = expected_stdout
act.execute(combine_output = True)
2022-01-27 20:08:36 +01:00
assert act.clean_stdout == act.clean_expected_stdout