1+ import datetime
12from collections import namedtuple
23from operator import itemgetter
34
@@ -25,11 +26,14 @@ class Subprogram:
2526 AND subprogram_id = :subprogram_id
2627 AND object_type IN ('FUNCTION', 'PROCEDURE', 'PACKAGE')
2728'''
28-
29+ # fixme: not gonna scale with user defined types in database
2930 argument_mapping = {
3031 'VARCHAR2' : str ,
3132 'INTEGER' : int ,
32- 'NUMBER' : float
33+ 'NUMBER' : float ,
34+ 'DATE' : datetime .datetime ,
35+ 'CLOB' : oracle .CLOB ,
36+ 'BLOB' : oracle .BLOB
3337 }
3438
3539 def __init__ (self , plsql , name , owner , object_id , subprogram_id ):
@@ -72,9 +76,15 @@ def __call__(self, **kwargs):
7276 pass
7377 kwargs [name ] = parameter
7478
79+ def pythonize_value (value ):
80+ try :
81+ return value .read ()
82+ except AttributeError :
83+ return value
84+
7585 def parse_in_out (parameters ):
7686 return {
77- param_name : param_value .getvalue ()
87+ param_name : pythonize_value ( param_value .getvalue () )
7888 for param_name , param_value
7989 in parameters
8090 }
@@ -90,6 +100,8 @@ def parse_in_out(parameters):
90100 if object_type == FUNCTION :
91101 result = cursor .callfunc (self .name , self .return_type , keywordParameters = kwargs )
92102
103+ result = pythonize_value (result )
104+
93105 if in_out_parameters :
94106 return result , parse_in_out (in_out_parameters )
95107 return result
@@ -177,7 +189,6 @@ def __getattr__(self, item):
177189 return self
178190
179191 def __call__ (self , ** parameters ):
180- # todo: potential
181192 found_subprogram = resolve_subprogram (attributes = self .attributes , parameters = parameters , plsql = self .plsql )
182193 subprogram = Subprogram (self .plsql , '.' .join (self .attributes ), ** found_subprogram ._asdict ())
183194 return subprogram (** parameters )
0 commit comments