Skip to content
Open
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
8 changes: 8 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
Upcoming (TBD)
==============

Bug Fixes
---------
* Improve query cancellation on control-c.


1.61.0 (2026/03/07)
==============

Expand Down
13 changes: 6 additions & 7 deletions mycli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1212,14 +1212,13 @@ def one_iteration(text: str | None = None) -> None:
except KeyboardInterrupt:
# get last connection id
connection_id_to_kill = sqlexecute.connection_id or 0
# some mysql compatible databases may not implemente connection_id()
# some mysql-compatible databases may not implement connection_id()
if connection_id_to_kill > 0:
logger.debug("connection id to kill: %r", connection_id_to_kill)
# Restart connection to the database
sqlexecute.connect()
try:
for _preamble, _cur, _headers, status in sqlexecute.run(f"kill {connection_id_to_kill}"):
status_str = str(status).lower()
sqlexecute.connect()
for kill_result in sqlexecute.run(f"kill {connection_id_to_kill}"):
status_str = str(kill_result.status_plain).lower()
if status_str.find("ok") > -1:
logger.debug("cancelled query, connection id: %r, sql: %r", connection_id_to_kill, text)
self.echo(f"Cancelled query id: {connection_id_to_kill}", err=True, fg="blue")
Expand All @@ -1230,8 +1229,8 @@ def one_iteration(text: str | None = None) -> None:
text,
)
self.echo(f"Failed to confirm query cancellation, id: {connection_id_to_kill}", err=True, fg="red")
except Exception as e:
self.echo(f"Encountered error while cancelling query: {e}", err=True, fg="red")
except Exception as e2:
self.echo(f"Encountered error while cancelling query: {e2}", err=True, fg="red")
else:
logger.debug("Did not get a connection id, skip cancelling query")
self.echo("Did not get a connection id, skip cancelling query", err=True, fg="red")
Expand Down
2 changes: 1 addition & 1 deletion mycli/packages/special/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def execute(cur: Cursor, sql: str) -> list[SQLResult]:
command, verbosity, arg = parse_special_command(sql)

if (command not in COMMANDS) and (command.lower() not in COMMANDS):
raise CommandNotFound()
raise CommandNotFound(f'Command not found: {command}')

try:
special_cmd = COMMANDS[command]
Expand Down