Skip to content

Commit 6a6c4c3

Browse files
committed
hackishly added support for full attribute access
1 parent be3145f commit 6a6c4c3

3 files changed

Lines changed: 25 additions & 5 deletions

File tree

‎plsql/client.py‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,23 @@ def resolve_subprogram(attributes, parameters, plsql):
157157
raise ValueError('Attribute access is too deep, maximum of 3 allowed! (schema, package, subprogram)')
158158

159159
if attribute_len == 3:
160-
# schema, package, subprogram = attributes
161-
raise NotImplementedError('Can not access with full path!')
160+
schema, package, subprogram = attributes
161+
subprogram_sql = f'''
162+
SELECT owner, object_id, subprogram_id
163+
FROM all_procedures
164+
WHERE owner = UPPER(:owner)
165+
AND object_name = UPPER(:name)
166+
AND procedure_name = UPPER(:procedure_name)
167+
AND object_type IN ('FUNCTION', 'PROCEDURE', 'PACKAGE')
168+
'''
169+
170+
binds = {'owner': schema, 'name': package, 'procedure_name': subprogram}
171+
matching_subprograms = list(plsql.query(subprogram_sql, binds).all)
172+
if len(matching_subprograms) > 1:
173+
raise NotImplementedError('Can not resolve to single subprogram!')
174+
175+
if not matching_subprograms:
176+
raise AttributeError('No such subprogram exists!')
162177
elif attribute_len == 2:
163178
# todo: at some point use to refine search due to possibility of overloaded subprograms in package
164179
_ = parameters

‎tests/test_package_type.py‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ def test_rec_type(plsql):
2424

2525
def test_rec_table(plsql):
2626
record = {
27-
f'int_{i}': i
28-
for i
29-
in range(1, 5)
27+
'int_1': 1,
28+
'int_2': 2,
29+
'int_3': 3,
30+
'int_4': 4
3031
}
3132

3233
table = [record] * 5

‎tests/test_packages.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@ def test_basic_package_access(plsql):
44

55
def test_basic_function(plsql):
66
assert plsql.test_package.simple_function(p_int=10) == 100
7+
8+
9+
def test_package_under_schema(plsql):
10+
assert plsql.test_user.test_package.simple_function(p_int=10) == 100

0 commit comments

Comments
 (0)