This function helps us to convert result set into dict Args: conn: Connection object result: 2d array result set Returns: Converted dict data
(conn, result)
| 2027 | |
| 2028 | |
| 2029 | def convert_data_to_dict(conn, result): |
| 2030 | """ |
| 2031 | This function helps us to convert result set into dict |
| 2032 | |
| 2033 | Args: |
| 2034 | conn: Connection object |
| 2035 | result: 2d array result set |
| 2036 | |
| 2037 | Returns: |
| 2038 | Converted dict data |
| 2039 | """ |
| 2040 | columns = [] |
| 2041 | col_info = conn.get_column_info() |
| 2042 | # Check column info is available or not |
| 2043 | if col_info is not None and len(col_info) > 0: |
| 2044 | for col in col_info: |
| 2045 | items = list(col.items()) |
| 2046 | column = dict() |
| 2047 | column['name'] = items[0][1] |
| 2048 | column['type_code'] = items[1][1] |
| 2049 | columns.append(column) |
| 2050 | |
| 2051 | # We need to convert result from 2D array to dict. |
| 2052 | # This Conversion is not an overhead as most of the time |
| 2053 | # result will be smaller. |
| 2054 | _tmp_result = [] |
| 2055 | for row in result: |
| 2056 | temp = dict() |
| 2057 | count = 0 |
| 2058 | for item in row: |
| 2059 | temp[columns[count]['name']] = item |
| 2060 | count += 1 |
| 2061 | _tmp_result.append(temp) |
| 2062 | # Replace 2d array with dict result |
| 2063 | result = _tmp_result |
| 2064 | |
| 2065 | return columns, result |
| 2066 | |
| 2067 | |
| 2068 | def get_additional_msgs(conn, statusmsg): |
no test coverage detected