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 @@ -8,6 +8,7 @@ Bug Fixes
* Bracket IPv6 hosts in the DSN shown and saved by `\dsn`, so a saved alias for `::1` can be used to connect again.
* Support `DELIMITER` in batch input (`mycli < file.sql`, `--batch`), so dumps with triggers or routines restore.
* Read `--batch` files and read and write `--checkpoint` files as UTF-8, fixing `--resume` and non-ASCII batch files on Windows.
* Terminate `use`, `source`, `\u` and `\.` at newline in batch input, as the vendor client does.


v2.30.4 (2026/11/12)
Expand Down
8 changes: 8 additions & 0 deletions mycli/packages/utils/batch_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
MAX_MULTILINE_BATCH_STATEMENT = 5000

DELIMITER_RE = re.compile(r'^\s*delimiter\s+(\S+)\s*$', re.IGNORECASE)
# Client commands the vendor client ends at the newline, without a delimiter
LINE_COMMAND_RE = re.compile(r'^\s*(/?use|/?source|[/\\]u|[/\\]\.)\s+\S', re.IGNORECASE)


def _has_tokens(text: str) -> bool:
Expand All @@ -32,6 +34,12 @@ def statements_from_filehandle(file_h: IO) -> Generator[tuple[str, int], None, N
statements = ''
line_counter = 0
continue
if LINE_COMMAND_RE.match(batch_text) and not _has_tokens(statements) and not batch_text.rstrip().endswith(delimiter):
yield (batch_text.strip(), batch_counter)
batch_counter += 1
statements = ''
line_counter = 0
continue
statements += batch_text
if delimiter != ';':
statement = statements.rstrip()
Expand Down
20 changes: 20 additions & 0 deletions mycli_test/pytests/test_batch_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,23 @@ def test_statements_from_filehandle_handles_delimiter_blocks() -> None:
('CREATE PROCEDURE p1()\nBEGIN\n SELECT 1;\nEND', 0),
('CALL p1();', 1),
]


def test_statements_from_filehandle_ends_use_at_newline() -> None:
statements = collect_statements('select 1;\nuse mysql\nselect database();\n')

assert statements == [
('select 1;', 0),
('use mysql', 1),
('select database();', 2),
]


def test_statements_from_filehandle_ends_slash_use_at_newline() -> None:
statements = collect_statements('select 1;\n/use mysql\nselect database();\n')

assert statements == [
('select 1;', 0),
('/use mysql', 1),
('select database();', 2),
]
Loading