@@ -2655,13 +2655,16 @@ def __init__(self, connection: Connection, stmt: iStatement, sql: str, dialect:
26552655 self ._out_cnt : int = meta .get_count ()
26562656 self ._out_buffer : bytes = None
26572657 self ._out_desc : List [ItemMetadata ] = None
2658+ self ._names : List [str ] = None
26582659 if self ._out_cnt == 0 :
26592660 meta .release ()
26602661 self ._out_desc = []
2662+ self ._names = []
26612663 else :
26622664 self ._out_meta = meta
26632665 self ._out_buffer = create_string_buffer (meta .get_message_length ())
26642666 self ._out_desc = create_meta_descriptors (meta )
2667+ self ._names = [meta .field if meta .field == meta .alias else meta .alias for meta in self ._out_desc ]
26652668 def __enter__ (self ) -> Statement :
26662669 return self
26672670 def __exit__ (self , exc_type , exc_value , traceback ) -> None :
@@ -3888,6 +3891,21 @@ def is_bof(self) -> bool:
38883891 """
38893892 assert self ._result is not None
38903893 return self ._result .is_bof ()
3894+ def to_dict (self , row : Tuple , into : Dict = None ) -> Dict :
3895+ """Return row tuple as dictionary with field names as keys. Returns new dictionary
3896+ if `into` argument is not provided, otherwise returns `into` dictionary updated
3897+ with row data.
3898+
3899+ Arguments:
3900+ row: Row data returned by fetch_* method.
3901+ into: Dictionary that shouold be updated with row data.
3902+ """
3903+ assert len (self ._stmt ._names ) == len (row ), "Length of data must match number of fields"
3904+ if into is None :
3905+ into = dict (zip (self ._stmt ._names , row ))
3906+ else :
3907+ into .update (zip (self ._stmt ._names , row ))
3908+ return into
38913909 # Properties
38923910 @property
38933911 def connection (self ) -> Connection :
0 commit comments