Skip to content

Commit 6964f07

Browse files
committed
Merged from main
2 parents ba33233 + 3683b9f commit 6964f07

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ Upcoming (TBD)
33

44
Features
55
--------
6+
* Update query processing functions to allow automatic show_warnings to work for more code paths like DDL.
67
* Update the default SSL value to connect securely by default. Add a --no-ssl option to disable it.
78

89
Bug Fixes

mycli/main.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,7 +1273,7 @@ def format_output(
12731273
if title: # Only print the title if it's not None.
12741274
output = itertools.chain(output, [title])
12751275

1276-
if cur:
1276+
if headers or (cur and title):
12771277
column_types = None
12781278
if isinstance(cur, Cursor):
12791279

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

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

1286-
if max_width is not None:
1286+
if max_width is not None and isinstance(cur, Cursor):
12871287
cur = list(cur)
12881288

12891289
formatted = use_formatter.format_output(
@@ -1379,7 +1379,9 @@ def get_last_query(self) -> str | None:
13791379
is_flag=True,
13801380
help="Automatically switch to vertical output mode if the result is wider than the terminal width.",
13811381
)
1382-
@click.option("--show-warnings/--no-show-warnings", is_flag=True, help="Automatically show warnings after executing a SQL statement.")
1382+
@click.option(
1383+
"--show-warnings/--no-show-warnings", "show_warnings", is_flag=True, help="Automatically show warnings after executing a SQL statement."
1384+
)
13831385
@click.option("-t", "--table", is_flag=True, help="Display batch output in table format.")
13841386
@click.option("--csv", is_flag=True, help="Display batch output in CSV format.")
13851387
@click.option("--warn/--no-warn", default=None, help="Warn before running a destructive query.")

mycli/sqlexecute.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ def get_result(self, cursor: Cursor) -> tuple:
354354
plural = '' if cursor.warning_count == 1 else 's'
355355
status = f'{status}, {cursor.warning_count} warning{plural}'
356356

357-
return (title, cursor if cursor.description else None, headers, status)
357+
return (title, cursor, headers, status)
358358

359359
def tables(self) -> Generator[tuple[str], None, None]:
360360
"""Yields table names"""

test/test_main.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,17 @@ def test_disable_show_warnings(executor):
7070
assert result[0]["status"] == "Show warnings disabled."
7171

7272

73+
@dbtest
74+
def test_output_ddl_with_warning_and_show_warnings_enabled(executor):
75+
runner = CliRunner()
76+
db = "mycli_test_db"
77+
table = "table_that_definitely_does_not_exist_1234"
78+
sql = f"DROP TABLE IF EXISTS {db}.{table}"
79+
result = runner.invoke(cli, args=CLI_ARGS + ["--show-warnings", "--no-warn"], input=sql)
80+
expected = "Level\tCode\tMessage\nNote\t1051\tUnknown table 'mycli_test_db.table_that_definitely_does_not_exist_1234'\n"
81+
assert expected in result.output
82+
83+
7384
@dbtest
7485
def test_output_with_warning_and_show_warnings_enabled(executor):
7586
runner = CliRunner()

0 commit comments

Comments
 (0)