Refactor to make methods simpler
authorKarl O. Pinc <kop@karlpinc.com>
Sun, 18 Aug 2024 19:57:03 +0000 (14:57 -0500)
committerKarl O. Pinc <kop@karlpinc.com>
Sun, 18 Aug 2024 19:57:03 +0000 (14:57 -0500)
src/pgwui_sql/views/sql.py

index 6bf005cb2249a103ef39c0384c0b6a30287f2f05..2d1eda50d3ee78dad6914b3d6c5c6b16d1266c9f 100644 (file)
@@ -148,6 +148,14 @@ class SQLHandler(pgwui_core.core.SessionDBHandler):
 
         return response
 
+    def get_result_rows(self, cur, sql_results):
+        first = True
+        while (row := cur.fetchone()) is not None:
+            if first:
+                sql_results.append(SQLResult().build_new_result_row(cur, True))
+                first = False
+            sql_results.append(SQLResult().build_data_row(row))
+
     def cleanup(self):
         '''
         Execute a series of SQL statements.
@@ -162,13 +170,7 @@ class SQLHandler(pgwui_core.core.SessionDBHandler):
         while nextset is True:
             have_rows = cur.rownumber is not None
             if have_rows:
-                first = True
-                while (row := cur.fetchone()) is not None:
-                    if first:
-                        sql_results.append(SQLResult().build_new_result_row(
-                            cur, have_rows))
-                        first = False
-                    sql_results.append(SQLResult().build_data_row(row))
+                self.get_result_rows(cur, sql_results)
             else:
                 sql_results.append(SQLResult().build_new_result_row(
                     cur, have_rows))