|
| 1 | +#coding:utf-8 |
| 2 | + |
| 3 | +""" |
| 4 | +ID: n/a |
| 5 | +ISSUE: https://github.com/FirebirdSQL/firebird/issues/8618 |
| 6 | +TITLE: Extra quotes in plan when using UNLIST function |
| 7 | +DESCRIPTION: |
| 8 | +NOTES: |
| 9 | + [17.07.2025] pzotov |
| 10 | + Confirmed problem on 6.0.0.845. |
| 11 | + Checked on 6.0.0.1020 |
| 12 | +""" |
| 13 | + |
| 14 | +import pytest |
| 15 | +from firebird.qa import * |
| 16 | +from firebird.driver import DatabaseError |
| 17 | + |
| 18 | +db = db_factory() |
| 19 | + |
| 20 | +act = python_act('db') |
| 21 | + |
| 22 | +#----------------------------------------------------------- |
| 23 | + |
| 24 | +def replace_leading(source, char="."): |
| 25 | + stripped = source.lstrip() |
| 26 | + return char * (len(source) - len(stripped)) + stripped |
| 27 | + |
| 28 | +#----------------------------------------------------------- |
| 29 | + |
| 30 | +@pytest.mark.version('>=6') |
| 31 | +def test_1(act: Action, capsys): |
| 32 | + |
| 33 | + qry_list = ( |
| 34 | + "select count(*) from unlist('1,2,3') as system(n)" |
| 35 | + ,"select count(*) from unlist('1,2,3') as public(n)" |
| 36 | + ,'''select count(*) as """" from unlist('1,2,3') as """"(n)''' |
| 37 | + ) |
| 38 | + |
| 39 | + with act.db.connect() as con: |
| 40 | + cur = con.cursor() |
| 41 | + for test_sql in qry_list: |
| 42 | + ps, rs = None, None |
| 43 | + try: |
| 44 | + cur = con.cursor() |
| 45 | + ps = cur.prepare(test_sql) |
| 46 | + print(test_sql) |
| 47 | + # Print explained plan with padding eash line by dots in order to see indentations: |
| 48 | + print( '\n'.join([replace_leading(s) for s in ps.detailed_plan.split('\n')]) ) |
| 49 | + |
| 50 | + # ::: NB ::: 'ps' returns data, i.e. this is SELECTABLE expression. |
| 51 | + # We have to store result of cur.execute(<psInstance>) in order to |
| 52 | + # close it explicitly. |
| 53 | + # Otherwise AV can occur during Python garbage collection and this |
| 54 | + # causes pytest to hang on its final point. |
| 55 | + # Explained by hvlad, email 26.10.24 17:42 |
| 56 | + rs = cur.execute(ps) |
| 57 | + cur_cols = cur.description |
| 58 | + for r in rs: |
| 59 | + for i in range(0,len(cur_cols)): |
| 60 | + print( cur_cols[i][0], ':', r[i] ) |
| 61 | + |
| 62 | + except DatabaseError as e: |
| 63 | + print(e.__str__()) |
| 64 | + print(e.gds_codes) |
| 65 | + finally: |
| 66 | + if rs: |
| 67 | + rs.close() # <<< EXPLICITLY CLOSING CURSOR RESULTS |
| 68 | + if ps: |
| 69 | + ps.free() |
| 70 | + |
| 71 | + act.expected_stdout = f''' |
| 72 | + {qry_list[0]} |
| 73 | + Select Expression |
| 74 | + ....-> Aggregate |
| 75 | + ........-> Function "UNLIST" as "SYSTEM" Scan |
| 76 | + COUNT : 3 |
| 77 | +
|
| 78 | + {qry_list[1]} |
| 79 | + Select Expression |
| 80 | + ....-> Aggregate |
| 81 | + ........-> Function "UNLIST" as "PUBLIC" Scan |
| 82 | + COUNT : 3 |
| 83 | +
|
| 84 | + {qry_list[2]} |
| 85 | + Select Expression |
| 86 | + ....-> Aggregate |
| 87 | + ........-> Function "UNLIST" as """" Scan |
| 88 | + " : 3 |
| 89 | + ''' |
| 90 | + act.stdout = capsys.readouterr().out |
| 91 | + assert act.clean_stdout == act.clean_expected_stdout |
0 commit comments