From 1aa88757fa3f8882ebf39d04d80847f9c1b197d9 Mon Sep 17 00:00:00 2001 From: Scott Nemes Date: Tue, 23 Dec 2025 18:30:33 -0800 Subject: [PATCH 1/3] Updated query handling to allow show_warnings to work for additional code paths. --- mycli/main.py | 4 ++-- mycli/sqlexecute.py | 2 +- test/test_main.py | 11 +++++++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/mycli/main.py b/mycli/main.py index 6f9965b5..c5d4db8e 100755 --- a/mycli/main.py +++ b/mycli/main.py @@ -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): @@ -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( diff --git a/mycli/sqlexecute.py b/mycli/sqlexecute.py index 49c41e8a..d7445abb 100644 --- a/mycli/sqlexecute.py +++ b/mycli/sqlexecute.py @@ -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""" diff --git a/test/test_main.py b/test/test_main.py index 34cbde66..3d6baaec 100644 --- a/test/test_main.py +++ b/test/test_main.py @@ -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() From 6caee6113ad2e3756b1e41e7d8e6d7b947c2634e Mon Sep 17 00:00:00 2001 From: Scott Nemes Date: Tue, 23 Dec 2025 18:50:00 -0800 Subject: [PATCH 2/3] Updated changelog --- changelog.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index f2132346..04387011 100644 --- a/changelog.md +++ b/changelog.md @@ -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 From 4c3868b73dbb99aac3e66b56a72e94afa16138de Mon Sep 17 00:00:00 2001 From: Scott Nemes Date: Tue, 23 Dec 2025 22:30:28 -0800 Subject: [PATCH 3/3] Fixed show-warnings param to work correctly --- mycli/main.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mycli/main.py b/mycli/main.py index c5d4db8e..86dcc5c4 100755 --- a/mycli/main.py +++ b/mycli/main.py @@ -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.")