@@ -89,6 +89,8 @@ def query(
89
89
omit_trailing_semicolon = db_connection .omit_trailing_semicolon ,
90
90
)
91
91
all_rows = cur .fetchall ()
92
+ if all_rows is None :
93
+ all_rows = []
92
94
self ._commit_if_needed (db_connection , no_transaction )
93
95
col_names = [c [0 ] for c in cur .description ]
94
96
self ._log_query_results (col_names , all_rows )
@@ -144,6 +146,8 @@ def row_count(
144
146
omit_trailing_semicolon = db_connection .omit_trailing_semicolon ,
145
147
)
146
148
data = cur .fetchall ()
149
+ if data is None :
150
+ data = []
147
151
self ._commit_if_needed (db_connection , no_transaction )
148
152
col_names = [c [0 ] for c in cur .description ]
149
153
if db_connection .module_name in ["sqlite3" , "ibm_db" , "ibm_db_dbi" , "pyodbc" , "jaydebeapi" ]:
@@ -803,6 +807,10 @@ def _log_query_results(self, col_names, result_rows, log_head: Optional[int] = N
803
807
804
808
if log_head is None :
805
809
log_head = self .LOG_QUERY_RESULTS_HEAD
810
+
811
+ if result_rows is None :
812
+ result_rows = []
813
+
806
814
cell_border_and_align = "border: 1px solid rgb(160 160 160);padding: 8px 10px;text-align: center;"
807
815
table_border = "2px solid rgb(140 140 140)"
808
816
row_index_background_color = "#d6ecd4"
@@ -816,25 +824,26 @@ def _log_query_results(self, col_names, result_rows, log_head: Optional[int] = N
816
824
msg += f'<th scope="col" style="background-color: #505050; color: #fff;{ cell_border_and_align } ">{ col } </th>'
817
825
msg += "</tr>"
818
826
table_truncated = False
819
- if result_rows is not None :
820
- for i , row in enumerate (result_rows ):
821
- if log_head and i >= log_head :
822
- table_truncated = True
823
- break
824
- row_style = ""
825
- if i % 2 == 0 :
826
- row_style = ' style="background-color: var(--secondary-color, #eee)"'
827
- msg += f"<tr{ row_style } >"
828
- msg += f'<th scope="row" style="color:{ row_index_text_color } ; background-color: { row_index_background_color } ;{ cell_border_and_align } ">{ i } </th>'
829
- for cell in row :
830
- try :
831
- cell_string = str (cell )
832
- except TypeError as e :
833
- cell_string = f"Unable printing the value: { e } "
834
- msg += f'<td style="{ cell_border_and_align } ">{ cell_string } </td>'
835
- msg += "</tr>"
836
- msg += "</table>"
837
- if table_truncated :
838
- msg += f'<p style="font-weight: bold;">Log limit of { log_head } rows was reached, the table was truncated</p>'
839
- msg += "</div>"
840
- logger .info (msg , html = True )
827
+ for i , row in enumerate (result_rows ):
828
+ if log_head and i >= log_head :
829
+ table_truncated = True
830
+ break
831
+ row_style = ""
832
+ if i % 2 == 0 :
833
+ row_style = ' style="background-color: var(--secondary-color, #eee)"'
834
+ msg += f"<tr{ row_style } >"
835
+ msg += f'<th scope="row" style="color:{ row_index_text_color } ; background-color: { row_index_background_color } ;{ cell_border_and_align } ">{ i } </th>'
836
+ for cell in row :
837
+ try :
838
+ cell_string = str (cell )
839
+ except TypeError as e :
840
+ cell_string = f"Unable printing the value: { e } "
841
+ msg += f'<td style="{ cell_border_and_align } ">{ cell_string } </td>'
842
+ msg += "</tr>"
843
+ msg += "</table>"
844
+ if table_truncated :
845
+ msg += (
846
+ f'<p style="font-weight: bold;">Log limit of { log_head } rows was reached, the table was truncated</p>'
847
+ )
848
+ msg += "</div>"
849
+ logger .info (msg , html = True )
0 commit comments