Test outside of loop
authorKarl O. Pinc <kop@karlpinc.com>
Sat, 5 Oct 2024 01:03:14 +0000 (20:03 -0500)
committerKarl O. Pinc <kop@karlpinc.com>
Sat, 5 Oct 2024 01:03:14 +0000 (20:03 -0500)
src/pgwui_sql/views/sql.py

index 2c6b6654266edd36058884a50c3982fb5a4a883b..52e531cc1b0ed8ed54398c1ed74f1ee68b97755d 100644 (file)
@@ -337,24 +337,23 @@ class SQLResultsHandler(pgwui_core.core.SessionDBHandler):
         csv_writer = self.write_sql()
 
         nextset = True
-        download_as = self.uf['download_as']
-        stmt_no = 1
-        while nextset is True:
-            if download_as == MANY_FILES_VALUE:
+        if self.uf['download_as'] == MANY_FILES_VALUE:
+            stmt_no = 1
+            while nextset is True:
                 with zipfile.Path(
                         self.zip_fd,
                         at=self.zip_at_pathname(f'stmt{stmt_no}.txt')
                 ).open(mode='w', newline='') as fd:
                     self.write_resultset(
                         cur, self.make_csv_writer(fd), null_rep)
+                nextset = cur.nextset()
                 stmt_no += 1
-            else:
+            self.zip_fd.close()
+        else:
+            while nextset is True:
                 self.write_resultset(cur, csv_writer, null_rep)
+                nextset = cur.nextset()
 
-            nextset = cur.nextset()
-
-        if download_as == MANY_FILES_VALUE:
-            self.zip_fd.close()
         self.tfile.seek(0)
 
     def make_sql_results(self, cur):