From 4d5f3378fdd9ea2f421144aa71cb1b4c03e42ec8 Mon Sep 17 00:00:00 2001 From: "Karl O. Pinc" Date: Fri, 4 Oct 2024 19:59:00 -0500 Subject: [PATCH] Fix so single-file downloads work --- src/pgwui_sql/views/sql.py | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/pgwui_sql/views/sql.py b/src/pgwui_sql/views/sql.py index c000e7f..2c6b665 100644 --- a/src/pgwui_sql/views/sql.py +++ b/src/pgwui_sql/views/sql.py @@ -302,23 +302,22 @@ class SQLResultsHandler(pgwui_core.core.SessionDBHandler): return csv.writer(fd, dialect=csv.excel_tab) def write_sql(self): - if self.uf['include_sql']: - if self.uf['download_as'] == MANY_FILES_VALUE: - with zipfile.Path( - self.zip_fd, - at=self.zip_at_pathname('statements.txt') - ).open(mode='wb') as fd: - fd.write(self.uf['sql'].encode()) - return None - else: - writer = self.make_csv_writer() + if self.uf['download_as'] == MANY_FILES_VALUE: + with zipfile.Path( + self.zip_fd, + at=self.zip_at_pathname('statements.txt') + ).open(mode='wb') as fd: + fd.write(self.uf['sql'].encode()) + else: + writer = self.make_csv_writer() + if self.uf['include_sql']: # Strip trailing whitespace from sql because otherwise, # after import to a spreadsheet with cells a single row tall, # only the empty line after the last EOL is shown and the # first cell of the sheet looks empty instead of looking like # it contains the sql. writer.writerow((self.uf['sql'].rstrip(),)) - return writer + return writer def write_resultset(self, cur, writer, null_rep): # Rather than report the statusmessage first, which requires @@ -335,7 +334,7 @@ class SQLResultsHandler(pgwui_core.core.SessionDBHandler): # Optimized to minimize RAM usage null_rep = self.uf['null_rep'] self.open_tfile() - writer = self.write_sql() + csv_writer = self.write_sql() nextset = True download_as = self.uf['download_as'] @@ -350,7 +349,7 @@ class SQLResultsHandler(pgwui_core.core.SessionDBHandler): cur, self.make_csv_writer(fd), null_rep) stmt_no += 1 else: - self.write_resultset(cur, writer, null_rep) + self.write_resultset(cur, csv_writer, null_rep) nextset = cur.nextset() -- 2.34.1