Skip to content

Commit

Permalink
fix count statement when displaylimit=None (#815)
Browse files Browse the repository at this point in the history
  • Loading branch information
bbeat2782 authored Aug 18, 2023
1 parent 0ee02e8 commit 5210516
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* [Fix] `--persist/--persist-replace` perform `ROLLBACK` automatically when needed
* [Fix] `ResultSet` footer (when `displaylimit` truncates results and when showing how to convert to a data frame) now appears in the `ResultSet` plain text representation (#682)
* [Fix] Improve error when calling `%sqlcmd` (#761)
* [Fix] Fix count statement's result not displayed when `displaylimit=None` (#801)
* [API Change] When loading connections from a `.ini` file via `%sql --section section_name`, the section name is set as the connection alias
* [API Change] Starting connections from a `.ini` file via `%sql [section_name]` has been deprecated
* [Doc] Fixes documentation inaccuracy that said `:variable` was deprecated (we brought it back in `0.9.0`)
Expand Down
4 changes: 3 additions & 1 deletion src/sql/run/resultset.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ def _extend_results(self, elements):
"""Store the DB fetched results into the internal list of results"""
to_add = self._config.displaylimit - len(self._results)
self._results.extend(elements)
self._pretty_table.add_rows(elements[:to_add])
self._pretty_table.add_rows(
elements if self._config.displaylimit == 0 else elements[:to_add]
)

def mark_fetching_as_done(self):
self._mark_fetching_as_done = True
Expand Down
22 changes: 22 additions & 0 deletions src/tests/test_magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,28 @@ def test_displaylimit_with_conditional_clause(
assert f"Truncated to {DISPLAYLIMIT_LINK} of 10" in out._repr_html_()


@pytest.mark.parametrize(
"config_value",
[
(1),
(0),
(None),
],
)
def test_displaylimit_with_count_statement(ip, load_penguin, config_value):
ip.run_cell(f"%config SqlMagic.displaylimit = {config_value}")
result = ip.run_line_magic("sql", "select count(*) from penguins.csv")

assert isinstance(result, ResultSet)
assert str(result) == (
"+--------------+\n"
"| count_star() |\n"
"+--------------+\n"
"| 344 |\n"
"+--------------+"
)


def test_column_local_vars(ip):
ip.run_line_magic("config", "SqlMagic.column_local_vars = True")
result = runsql(ip, "SELECT * FROM author;")
Expand Down

0 comments on commit 5210516

Please sign in to comment.