Skip to content

Commit 55d8932

Browse files
committed
some refactorings
1 parent 157837d commit 55d8932

1 file changed

Lines changed: 35 additions & 17 deletions

File tree

‎python_plsql/client.py‎

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ class ObjectTypes(IntEnum):
3636
type = 13
3737

3838

39+
class Direction(IntEnum):
40+
in_ = 0
41+
out = 1
42+
in_out = 2
43+
44+
3945
class NotFound(AttributeError):
4046
pass
4147

@@ -97,7 +103,7 @@ def _dbms_describe_describe_procedure(
97103
argument_name.aslist(),
98104
datatype.aslist(),
99105
map(bool, default_value.aslist()),
100-
in_out.aslist(),
106+
map(Direction, in_out.aslist()),
101107
length.aslist(),
102108
precision.aslist(),
103109
scale.aslist(),
@@ -450,6 +456,27 @@ def find_match(
450456
return matches[0]
451457

452458

459+
def wrap_positional(match, plsql, resolved, cursor, positional):
460+
wrapped_positional = []
461+
for value, argument in zip(positional, match.arguments):
462+
_, converter = cursor_var(plsql, cursor, resolved, argument)
463+
464+
wrapped_positional.append(converter.to_oracle(value))
465+
466+
return wrapped_positional
467+
468+
469+
def wrap_named(match, plsql, resolved, cursor, named):
470+
wrapped_named = {}
471+
for key, value in named.items():
472+
argument = match.argument(key)
473+
if argument:
474+
_, converter = cursor_var(plsql, cursor, resolved, argument)
475+
wrapped_named[key] = converter.to_oracle(value)
476+
477+
return wrapped_named
478+
479+
453480
def translate_arguments(match_filter):
454481
def decorator(func):
455482
@wraps(func)
@@ -458,22 +485,13 @@ def wrapper(self: Subprogram, *positional, **named):
458485

459486
with self._plsql._connection.cursor() as cursor:
460487

461-
wrapped_positional = []
462-
for value, argument in zip(positional, match.arguments):
463-
_, converter = cursor_var(
464-
self._plsql, cursor, self.resolved, argument
465-
)
466-
467-
wrapped_positional.append(converter.to_oracle(value))
468-
469-
wrapped_named = {}
470-
for key, value in named.items():
471-
argument = match.argument(key)
472-
if argument:
473-
_, converter = cursor_var(
474-
self._plsql, cursor, self.resolved, argument
475-
)
476-
wrapped_named[key] = converter.to_oracle(value)
488+
wrapped_positional = wrap_positional(
489+
match, self._plsql, self.resolved, cursor, positional
490+
)
491+
492+
wrapped_named = wrap_named(
493+
match, self._plsql, self.resolved, cursor, named
494+
)
477495

478496
result = func(self, match, cursor, wrapped_positional, wrapped_named)
479497

0 commit comments

Comments
 (0)