Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
1.42.0 (2025/12/20)
Upcoming (TBD)
==============

Features
--------
* Update query processing functions to allow automatic show_warnings to work for more code paths like DDL

Bug Fixes
--------
* Update the prompt display logic to handle an edge case where a socket is used without
Expand Down
8 changes: 5 additions & 3 deletions mycli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1273,7 +1273,7 @@ def format_output(
if title: # Only print the title if it's not None.
output = itertools.chain(output, [title])

if cur:
if headers or (cur and title):
column_types = None
if isinstance(cur, Cursor):

Expand All @@ -1283,7 +1283,7 @@ def get_col_type(col) -> type:

column_types = [get_col_type(tup) for tup in cur.description]

if max_width is not None:
if max_width is not None and isinstance(cur, Cursor):
cur = list(cur)

formatted = use_formatter.format_output(
Expand Down Expand Up @@ -1377,7 +1377,9 @@ def get_last_query(self) -> str | None:
is_flag=True,
help="Automatically switch to vertical output mode if the result is wider than the terminal width.",
)
@click.option("--show-warnings/--no-show-warnings", is_flag=True, help="Automatically show warnings after executing a SQL statement.")
@click.option(
"--show-warnings/--no-show-warnings", "show_warnings", is_flag=True, help="Automatically show warnings after executing a SQL statement."
)
@click.option("-t", "--table", is_flag=True, help="Display batch output in table format.")
@click.option("--csv", is_flag=True, help="Display batch output in CSV format.")
@click.option("--warn/--no-warn", default=None, help="Warn before running a destructive query.")
Expand Down
2 changes: 1 addition & 1 deletion mycli/sqlexecute.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ def get_result(self, cursor: Cursor) -> tuple:
plural = '' if cursor.warning_count == 1 else 's'
status = f'{status}, {cursor.warning_count} warning{plural}'

return (title, cursor if cursor.description else None, headers, status)
return (title, cursor, headers, status)

def tables(self) -> Generator[tuple[str], None, None]:
"""Yields table names"""
Expand Down
11 changes: 11 additions & 0 deletions test/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,17 @@ def test_disable_show_warnings(executor):
assert result[0]["status"] == "Show warnings disabled."


@dbtest
def test_output_ddl_with_warning_and_show_warnings_enabled(executor):
runner = CliRunner()
db = "mycli_test_db"
table = "table_that_definitely_does_not_exist_1234"
sql = f"DROP TABLE IF EXISTS {db}.{table}"
result = runner.invoke(cli, args=CLI_ARGS + ["--show-warnings", "--no-warn"], input=sql)
expected = "Level\tCode\tMessage\nNote\t1051\tUnknown table 'mycli_test_db.table_that_definitely_does_not_exist_1234'\n"
assert expected in result.output


@dbtest
def test_output_with_warning_and_show_warnings_enabled(executor):
runner = CliRunner()
Expand Down