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
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Upcoming (TBD)
Bug Fixes
--------
* Read and write the default `myclirc` as UTF-8, fixing a startup crash on non-UTF-8 locales such as Japanese Windows.
* Keep checking later statements for the destructive warning after a single-table `UPDATE ... WHERE`.


v2.30.1 (2026/10/24)
Expand Down
1 change: 1 addition & 0 deletions mycli/AUTHORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ Contributors:
* Liu Zhenlong
* Chris Burr
* Wei-Lun Li
* Shaurya Kesarwani


Created by:
Expand Down
5 changes: 2 additions & 3 deletions mycli/packages/utils/sql_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,8 @@ def is_destructive(keywords: list[str], queries: str) -> bool:
# subtle: if "UPDATE" is one of our keywords AND "query" starts with "UPDATE"
if query_starts_with(query, keywords) and query_starts_with(query, ["update"]):
if query_has_where_clause(query) and query_is_single_table_update(query):
return False
else:
return True
continue
return True
if query_starts_with(query, keywords):
return True

Expand Down
10 changes: 10 additions & 0 deletions mycli_test/pytests/test_sql_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,16 @@ def test_is_destructive_update_with_where_clause_and_comment():
assert is_destructive(["update"], sql) is False


def test_is_destructive_checks_queries_after_safe_update():
sql = "UPDATE test SET x = 1 WHERE id = 1;\ndrop database foo;"
assert is_destructive(["update", "drop"], sql) is True


def test_is_destructive_checks_updates_after_safe_update():
sql = "UPDATE test SET x = 1 WHERE id = 1;\nUPDATE test SET x = 2;"
assert is_destructive(["update"], sql) is True


def test_is_destructive_update_multiple_tables_with_where_clause():
sql = "use test;\nshow databases;\nUPDATE test, foo SET x = 1 WHERE id = 1;"
assert is_destructive(["update"], sql) is True
Expand Down
Loading