6
0
mirror of https://github.com/FirebirdSQL/firebird-qa.git synced 2025-01-22 13:33:07 +01:00
firebird-qa/tests/bugs/core_5062_test.py

73 lines
2.5 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-5349
ISSUE: 5349
TITLE: CHAR_TO_UUID on column with index throws expression evaluation not supported. Human readable UUID argument for CHAR_TO_UUID must be of exact length 36
2022-01-25 22:55:48 +01:00
DESCRIPTION:
JIRA: CORE-5062
NOTES:
[18.01.2025] pzotov
Resultset of cursor that executes using instance of selectable PreparedStatement must be stored
in some variable in order to have ability close it EXPLICITLY (before PS will be freed).
Otherwise access violation raises during Python GC and pytest hangs at final point (does not return control to OS).
This occurs at least for: Python 3.11.2 / pytest: 7.4.4 / firebird.driver: 1.10.6 / Firebird.Qa: 0.19.3
The reason of that was explained by Vlad, 26.10.24 17:42 ("oddities when use instances of selective statements").
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 *
from firebird.driver import DatabaseError
2021-04-26 20:07:00 +02:00
2022-01-25 22:55:48 +01:00
init_script = """
recreate table test_uuid(
datavalue int,
uuid char(16) character set octets,
constraint test_uuid_unq unique(uuid)
);
commit;
insert into test_uuid(datavalue, uuid) values( 1, char_to_uuid('57F2B8C7-E1D8-4B61-9086-C66D1794F2D9') );
commit;
2021-11-26 19:20:43 +01:00
"""
2021-04-26 20:07:00 +02:00
2022-01-25 22:55:48 +01:00
db = db_factory(init=init_script)
2021-04-26 20:07:00 +02:00
2022-01-25 22:55:48 +01:00
act = python_act('db')
2021-04-26 20:07:00 +02:00
2021-11-26 19:20:43 +01:00
@pytest.mark.version('>=3.0')
def test_1(act: Action, capsys):
2022-01-25 22:55:48 +01:00
with act.db.connect() as con:
ps, rs = None, None
cur = con.cursor()
try:
ps = cur.prepare("select datavalue from test_uuid where uuid = char_to_uuid(?)")
print(ps.plan)
2021-04-26 20:07:00 +02:00
# ::: NB ::: 'ps' returns data, i.e. this is SELECTABLE expression.
# We have to store result of cur.execute(<psInstance>) in order to
# close it explicitly.
# Otherwise AV can occur during Python garbage collection and this
# causes pytest to hang on its final point.
# Explained by hvlad, email 26.10.24 17:42
rs = cur.execute(ps, ['57F2B8C7-E1D8-4B61-9086-C66D1794F2D9'])
for r in rs:
print(r[0])
except DatabaseError as e:
print( e.__str__() )
print(e.gds_codes)
finally:
if rs:
rs.close() # <<< EXPLICITLY CLOSING CURSOR RESULTS
if ps:
ps.free()
expected_stdout = f"""
PLAN (TEST_UUID INDEX (TEST_UUID_UNQ))
1
"""
act.expected_stdout = expected_stdout
act.stdout = capsys.readouterr().out
assert act.clean_stdout == act.clean_expected_stdout
act.reset()