Handle \c in the interactive SQL shell#11291
Open
vishnujayvel wants to merge 1 commit into
Open
Conversation
The interactive `dolt sql` shell did not recognize the MySQL client's `\c` escape, which cancels the statement currently being entered. Any line ending in `\c` was instead folded into the multi-line statement buffer like ordinary text, so the next line typed got concatenated onto it and produced a syntax error near the stray backslash instead of starting a fresh statement. `\c` is now registered alongside the existing `\g`/`\G` special terminators, so a line ending in `\c` stops statement accumulation. The shell then discards the buffered input without executing it or recording it in history, and resets to a fresh prompt, matching the `mysql` CLI's behavior. Fixes dolthub#10867
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Fixes #10867 — the interactive
dolt sqlshell doesn't handle the MySQL client's\cescape (cancel/clear the statement currently being entered). A line ending in\cwas folded into the multi-line buffer as ordinary text, so the next line concatenated onto it and produced a syntax error near the stray backslash instead of discarding the input.What changed
go/cmd/dolt/commands/sql.go— register\calongside the existing\g/\GinSpecialTerminators, and in the shell callback, when the accumulated query ends with\c, discard the buffered input (no execute, no history entry) and reset the prompt viapostCommandUpdate. This mirrors themysqlCLI's behavior.integration-tests/bats/sql-shell.bats+ a newintegration-tests/bats/sql-shell-clear-statement.expect— interactive PTY coverage: a partial statement followed by\cis cancelled, and a subsequent statement runs standalone.Verification
go build ./cmd/dolt/...andgo vetclean.\); with the patch,\cdiscards the buffer and the next statement executes on its own. Negative control on the unpatched binary confirmed the repro.Note on the in-flight shell rework (#11202)
I see #11202 is reworking the shell's input handling to a per-character
StreamScanner(fixing #10860/#10861/#10862/#10865/#10866). That PR doesn't cover\c(#10867), so this change is complementary — but it does touch the sameUninterpretedcallback, so the two will likely conflict textually. I've kept this minimal and modeled on the existing\g/\Ghandling specifically so it's easy to port: happy to rebase onto the scanner approach if #11202 lands first, or to fold\chandling into that effort — whichever you'd prefer.Fixes #10867