@@ -274,7 +274,7 @@ def to_python(value):
274274 if isinstance (value , oracle .Object ):
275275 if value .type .attributes :
276276 return record_out_converter (value )
277- if is_list_type (value .type ):
277+ elif is_list (value .type ):
278278 return list_out_converter (value )
279279 return dict_out_coverter (value )
280280 return value
@@ -330,34 +330,35 @@ def type_name(plsql: Database, resolved: ResolvedName, plsql_type: Argument):
330330 return "." .join (argument_type_name )
331331
332332
333- def in_converter (object_type ):
333+ def convert (object_type , value ):
334+ if object_type :
335+ return make_in_converter (object_type )(value )
336+ return value
337+
338+
339+ def make_in_converter (object_type ):
334340 def _in_converter (value ):
335341 var = object_type .newobject ()
336342
337- for attribute , val in zip (object_type .attributes , value ):
338- # todo: self made change to ObjectAttr.c (cx_Oracle should implement this)
339- if attribute .type :
340- val = in_converter (attribute .type )(val )
341- setattr (var , attribute .name , val )
342-
343343 if object_type .iscollection :
344- if is_list_type (object_type ):
344+ if is_list (object_type ):
345345 for val in value :
346- if object_type .elementType :
347- val = in_converter (object_type .elementType )(val )
348- var .append (val )
346+ var .append (convert (object_type .elementType , val ))
349347 else :
350348 for key , val in value .items ():
351- if object_type .elementType :
352- val = in_converter (object_type .elementType )(val )
353- var .setelement (key , val )
349+ var .setelement (key , convert (object_type .elementType , val ))
350+ else :
351+ for attribute , val in zip (object_type .attributes , value ):
352+ # todo: self made change to ObjectAttr.c (cx_Oracle should implement this)
353+ # type is not accessible by default..
354+ setattr (var , attribute .name , convert (attribute .type , val ))
354355
355356 return var
356357
357358 return _in_converter
358359
359360
360- def is_list_type (object_type : oracle .ObjectType ) -> bool :
361+ def is_list (object_type : oracle .ObjectType ) -> bool :
361362 # todo: should ask cx_Oracle if there is a better way
362363 obj = object_type .newobject ()
363364 try :
@@ -368,6 +369,32 @@ def is_list_type(object_type: oracle.ObjectType) -> bool:
368369 return False
369370
370371
372+ class SimpleVar :
373+ def __init__ (self , cursor , object_type ):
374+ self .cursor , self .object_type = cursor , object_type
375+
376+ def to_oracle (self , value ):
377+ var = self .cursor .var (self .object_type )
378+ var .setvalue (0 , value )
379+ return var
380+
381+ @staticmethod
382+ def from_oracle (var ):
383+ return var
384+
385+
386+ class UserVar :
387+ def __init__ (self , in_converter ):
388+ self .in_converter = in_converter
389+
390+ def to_oracle (self , value ):
391+ return self .in_converter (value )
392+
393+ @staticmethod
394+ def from_oracle (value ):
395+ return to_python (value )
396+
397+
371398def cursor_var (
372399 plsql : Database , cursor : oracle .Cursor , resolved : ResolvedName , plsql_type : Argument
373400):
@@ -387,23 +414,22 @@ def cursor_var(
387414 }
388415
389416 try :
390- return cursor . var ( plsql_types [plsql_type .datatype ])
417+ object_type = plsql_types [plsql_type .datatype ]
391418 except KeyError :
392- out_converters = {
393- 122 : list_out_converter , # nested table
394- 123 : list_out_converter , # varray
395- 250 : record_out_converter , # plsql record
396- 251 : dict_out_coverter , # plsql table
397- }
419+ # nested table # varray # plsql record # plsql table
420+ if plsql_type .datatype not in {122 , 123 , 250 , 251 }:
421+ raise
398422
399423 object_type = plsql ._connection .gettype (
400424 type_name (plsql = plsql , resolved = resolved , plsql_type = plsql_type )
401425 )
402- return cursor .var (
426+
427+ return (
403428 object_type ,
404- outconverter = out_converters [plsql_type .datatype ],
405- inconverter = in_converter (object_type ),
429+ UserVar (make_in_converter (object_type )),
406430 )
431+ else :
432+ return object_type , SimpleVar (cursor , object_type )
407433
408434
409435def find_match (
@@ -434,17 +460,20 @@ def wrapper(self: Subprogram, *positional, **named):
434460
435461 wrapped_positional = []
436462 for value , argument in zip (positional , match .arguments ):
437- pos = cursor_var (self ._plsql , cursor , self .resolved , argument )
438- pos .setvalue (0 , value )
439- wrapped_positional .append (pos )
463+ _ , converter = cursor_var (
464+ self ._plsql , cursor , self .resolved , argument
465+ )
466+
467+ wrapped_positional .append (converter .to_oracle (value ))
440468
441469 wrapped_named = {}
442470 for key , value in named .items ():
443471 argument = match .argument (key )
444472 if argument :
445- nam = cursor_var (self ._plsql , cursor , self .resolved , argument )
446- nam .setvalue (0 , value )
447- wrapped_named [key ] = nam
473+ _ , converter = cursor_var (
474+ self ._plsql , cursor , self .resolved , argument
475+ )
476+ wrapped_named [key ] = converter .to_oracle (value )
448477
449478 result = func (self , match , cursor , wrapped_positional , wrapped_named )
450479
@@ -468,18 +497,16 @@ def __init__(
468497
469498 @translate_arguments (match_filter = lambda x : x .is_function )
470499 def _call_function (self , match : Overload , cursor , positional , named ):
471- return cursor .callfunc (
472- self .resolved .name ,
473- cursor_var (
474- plsql = self ._plsql ,
475- cursor = cursor ,
476- resolved = self .resolved ,
477- plsql_type = match .return_type ,
478- ),
479- positional ,
480- named ,
500+ object_type , converter = cursor_var (
501+ plsql = self ._plsql ,
502+ cursor = cursor ,
503+ resolved = self .resolved ,
504+ plsql_type = match .return_type ,
481505 )
482506
507+ result = cursor .callfunc (self .resolved .name , object_type , positional , named )
508+ return converter .from_oracle (result )
509+
483510 @translate_arguments (match_filter = lambda x : not x .is_function )
484511 def _call_procedure (self , match : Overload , cursor , positional , named ):
485512 _ = match
0 commit comments