Skip to content

Commit ef7c41b

Browse files
committed
nested types are still broken, but having a nested of records (which have columns that are nested tables works)
1 parent 33a6055 commit ef7c41b

4 files changed

Lines changed: 99 additions & 10 deletions

File tree

‎python_plsql/client.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,9 @@ def plsql_record(attributes) -> Any:
276276
# noinspection PyTypeChecker
277277
def to_python(value):
278278
if isinstance(value, oracle.Object):
279-
return record_converter(value)
279+
if value.type.attributes:
280+
return record_converter(value)
281+
return list_converter(value)
280282
return value
281283

282284

‎tests/func/test_return_values.py‎

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import pytest
22
import datetime
33

4+
RECORD = (42, 84, 126)
5+
NESTED = [i * 2 for i in range(1, 11)]
6+
PLSQL_TABLE = {i: i for i in range(1, 11)}
7+
48

59
@pytest.mark.parametrize(
610
"func, expected",
@@ -15,25 +19,39 @@
1519
("ret_long_raw", b"42"),
1620
("ret_char", "42"),
1721
("ret_bool", True),
18-
("ret_record", (42, 84, 126)),
19-
("ret_record_of_records", (42, (42, 84, 126), (42, 84, 126))),
20-
("ret_nested", [i * 2 for i in range(1, 11)]),
21-
("ret_nested_of_records", [(42, 84, 126) for i in range(1, 11)]),
22-
("ret_plsql_table", {i: i for i in range(1, 11)}),
23-
("ret_plsql_table_of_records", {i: (42, 84, 126) for i in range(1, 11)}),
22+
("ret_record", RECORD),
23+
("ret_record_of_records", (42, RECORD, RECORD)),
24+
("ret_record_of_nested", (42, NESTED, NESTED),),
25+
pytest.param(
26+
"ret_record_of_plsql_table",
27+
(42, PLSQL_TABLE, PLSQL_TABLE),
28+
marks=pytest.mark.xfail(
29+
reason="No current way to tell between NESTED and PLSQL tables for multi-layered types"
30+
),
31+
),
32+
("ret_nested", NESTED),
33+
("ret_nested_of_records", [RECORD] * 10),
34+
("ret_nested_of_record_of_nested", [(42, NESTED, NESTED)] * 10),
35+
("ret_plsql_table", PLSQL_TABLE),
36+
("ret_plsql_table_of_records", {i: RECORD for i in range(1, 11)}),
37+
pytest.param(
38+
"ret_plsql_table_of_nested",
39+
{i: NESTED for i in range(1, 11)},
40+
marks=pytest.mark.skip(reason="Memory access violation"),
41+
),
2442
pytest.param(
2543
"ret_nested_of_nested",
26-
[[i * 2 for i in range(1, 11)] for i in range(1, 11)],
44+
[NESTED] * 10,
2745
marks=pytest.mark.skip(reason="Memory access violation"),
2846
),
2947
pytest.param(
3048
"ret_nested_of_plsql_table",
31-
[{i: i for i in range(1, 11)} for i in range(1, 11)],
49+
[PLSQL_TABLE] * 10,
3250
marks=pytest.mark.skip(reason="Memory access violation"),
3351
),
3452
pytest.param(
3553
"ret_plsql_table_of_plsql_table",
36-
{i: {j: j for j in range(1, 11)} for i in range(1, 11)},
54+
{i: PLSQL_TABLE for i in range(1, 11)},
3755
marks=pytest.mark.skip(reason="Memory access violation"),
3856
),
3957
],

‎tests/sql/package/test_return-b.sql‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,17 @@ CREATE OR REPLACE PACKAGE BODY test_return AS
126126
RETURN vt_nested_of_plsql_table;
127127
END ret_nested_of_plsql_table;
128128

129+
FUNCTION ret_nested_of_record_of_nested
130+
RETURN tt_nested_of_record_of_nested IS
131+
vt_nested_of_record_of_nested tt_nested_of_record_of_nested := tt_nested_of_record_of_nested();
132+
BEGIN
133+
FOR v_i IN 1 .. 10 LOOP
134+
vt_nested_of_record_of_nested.extend;
135+
vt_nested_of_record_of_nested(v_i) := ret_record_of_nested;
136+
END LOOP;
137+
return vt_nested_of_record_of_nested;
138+
END ret_nested_of_record_of_nested;
139+
129140
-- 123 VARRAY -- list
130141
--FUNCTION ret_binary_integer
131142
--RETURN BINARY_INTEGER;
@@ -171,6 +182,26 @@ CREATE OR REPLACE PACKAGE BODY test_return AS
171182
RETURN vr_record_of_records;
172183
END ret_record_of_records;
173184

185+
FUNCTION ret_record_of_nested
186+
RETURN tr_record_of_nested IS
187+
vr_record_of_nested tr_record_of_nested;
188+
BEGIN
189+
vr_record_of_nested.t_int_1 := 42;
190+
vr_record_of_nested.t_nes_2 := ret_nested;
191+
vr_record_of_nested.t_nes_3 := ret_nested;
192+
RETURN vr_record_of_nested;
193+
END ret_record_of_nested;
194+
195+
FUNCTION ret_record_of_plsql_table
196+
RETURN tr_record_of_plsql_table IS
197+
vr_record_of_plsql_table tr_record_of_plsql_table;
198+
BEGIN
199+
vr_record_of_plsql_table.t_int_1 := 42;
200+
vr_record_of_plsql_table.t_pls_2 := ret_plsql_table;
201+
vr_record_of_plsql_table.t_pls_3 := ret_plsql_table;
202+
RETURN vr_record_of_plsql_table;
203+
END ret_record_of_plsql_table;
204+
174205
-- 251 PL/SQL TABLE -- mapping
175206
FUNCTION ret_plsql_table
176207
RETURN tt_plsql_table IS
@@ -192,6 +223,16 @@ CREATE OR REPLACE PACKAGE BODY test_return AS
192223
RETURN vt_plsql_table_of_records;
193224
END ret_plsql_table_of_records;
194225

226+
FUNCTION ret_plsql_table_of_nested
227+
RETURN tt_plsql_table_of_nested IS
228+
vt_plsql_table_of_nested tt_plsql_table_of_nested;
229+
BEGIN
230+
FOR v_i IN 1 .. 10 LOOP
231+
vt_plsql_table_of_nested(v_i) := ret_nested;
232+
END LOOP;
233+
RETURN vt_plsql_table_of_nested;
234+
END ret_plsql_table_of_nested;
235+
195236
FUNCTION ret_plsql_table_of_plsql_table
196237
RETURN tt_plsql_table_of_plsql_table IS
197238
vt_plsql_table_of_plsql_table tt_plsql_table_of_plsql_table := tt_plsql_table_of_plsql_table();

‎tests/sql/package/test_return-h.sql‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,30 @@ CREATE OR REPLACE PACKAGE test_return AS
1414

1515
TYPE tt_nested IS TABLE OF PLS_INTEGER;
1616

17+
TYPE tr_record_of_nested IS RECORD (
18+
t_int_1 PLS_INTEGER,
19+
t_nes_2 tt_nested,
20+
t_nes_3 tt_nested
21+
);
22+
1723
TYPE tt_nested_of_records IS TABLE OF tr_record;
1824

1925
TYPE tt_nested_of_nested IS TABLE OF tt_nested;
2026

2127
TYPE tt_plsql_table IS TABLE OF PLS_INTEGER INDEX BY PLS_INTEGER;
2228

29+
TYPE tr_record_of_plsql_table IS RECORD (
30+
t_int_1 PLS_INTEGER,
31+
t_pls_2 tt_plsql_table,
32+
t_pls_3 tt_plsql_table
33+
);
34+
35+
TYPE tt_nested_of_record_of_nested IS TABLE OF tr_record_of_nested;
36+
2337
TYPE tt_plsql_table_of_plsql_table IS TABLE OF tt_plsql_table INDEX BY PLS_INTEGER;
2438

39+
TYPE tt_plsql_table_of_nested IS TABLE OF tt_nested INDEX BY PLS_INTEGER;
40+
2541
TYPE tt_plsql_table_of_records IS TABLE OF tr_record INDEX BY PLS_INTEGER;
2642

2743
TYPE tt_nested_of_plsql_table IS TABLE OF tt_plsql_table;
@@ -88,6 +104,9 @@ CREATE OR REPLACE PACKAGE test_return AS
88104
FUNCTION ret_nested_of_plsql_table
89105
RETURN tt_nested_of_plsql_table;
90106

107+
FUNCTION ret_nested_of_record_of_nested
108+
RETURN tt_nested_of_record_of_nested;
109+
91110
-- 123 VARRAY -- list
92111
--FUNCTION ret_binary_integer
93112
--RETURN BINARY_INTEGER;
@@ -119,13 +138,22 @@ CREATE OR REPLACE PACKAGE test_return AS
119138
FUNCTION ret_record_of_records
120139
RETURN tr_record_of_records;
121140

141+
FUNCTION ret_record_of_nested
142+
RETURN tr_record_of_nested;
143+
144+
FUNCTION ret_record_of_plsql_table
145+
RETURN tr_record_of_plsql_table;
146+
122147
-- 251 PL/SQL TABLE -- mapping
123148
FUNCTION ret_plsql_table
124149
RETURN tt_plsql_table;
125150

126151
FUNCTION ret_plsql_table_of_records
127152
RETURN tt_plsql_table_of_records;
128153

154+
FUNCTION ret_plsql_table_of_nested
155+
RETURN tt_plsql_table_of_nested;
156+
129157
FUNCTION ret_plsql_table_of_plsql_table
130158
RETURN tt_plsql_table_of_plsql_table;
131159

0 commit comments

Comments
 (0)