Skip to content

Support DELIMITER in batch input - #2430

Merged
rolandwalker merged 1 commit into
dbcli:mainfrom
jayhemnani9910:batch-delimiter
Nov 13, 2026
Merged

rolandwalker merged 1 commit into
dbcli:mainfrom
jayhemnani9910:batch-delimiter

Conversation

@jayhemnani9910

Copy link
Copy Markdown
Contributor

Description

mycli < file.sql and --batch split the input on ; only, so any DELIMITER block fails. A mysqldump/mariadb-dump file with a trigger or routine stops at the first one:

$ mycli -D app_restore < dump.sql
(1065, 'Query was empty')

and the rest of the dump never runs. A script with a procedure:

DELIMITER //
CREATE PROCEDURE p1()
BEGIN
  SELECT 'in proc';
END //
DELIMITER ;
CALL p1();

fails with (1064, "... near '' at line 3").

statements_from_filehandle now treats a DELIMITER x line as a client command, the way the mysql client does: it switches the delimiter and isn't sent. While the delimiter isn't ;, lines are collected until the text ends with it, and the statement is yielded without it. Input with the default ; goes through the existing sqlglot/sqlparse path unchanged.

Tested: a new test_batch_utils.py case fails without the change. pytest mycli_test/pytests: 3354 passed with the change and 3353 on main, with the same 62 failures on both (tests that need a live server here). Against MariaDB 11: the dump above restores with its trigger (none restored on main), and the script prints in proc and runs the statements after it. ruff check, ruff format and mypy --install-types . clean.

Checklist

  • I added this contribution to the changelog.md file.
  • I added my name to the mycli/AUTHORS.txt file (or it's already there).
  • To lint and format the code, I ran
    uv run ruff check && uv run ruff format && uv run mypy --install-types .

@rolandwalker

Copy link
Copy Markdown
Contributor

Hi! Thanks! This issue is first in https://github.com/dbcli/mycli/blob/main/doc/known_bugs.md#custom-delimiters, and there are other places custom delimiters are ignored.

Unfortunately merging #2429 created a merge conflict here; can you fix it? Or should I?

statements += batch_text
if delimiter != ';':
statement = statements.rstrip()
if statement.endswith(delimiter):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A comment is probably warranted regarding the limitation that the custom delimiter may only be recognized at EOL.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a comment there in 23a3762: the custom delimiter is only recognized at the end of a line, so two statements on one line go out as one.

@jayhemnani9910

Copy link
Copy Markdown
Contributor Author

@rolandwalker rebased onto main and fixed the changelog conflict in 23a3762. Tests pass.

@rolandwalker

Copy link
Copy Markdown
Contributor

Sweet! Thanks!

@rolandwalker
rolandwalker merged commit 88b168e into dbcli:main Nov 13, 2026
13 checks passed
@rolandwalker

Copy link
Copy Markdown
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants