sql: fix empty/comment-only query handling in interactive shell#11303
Open
vishnujayvel wants to merge 5 commits into
Open
sql: fix empty/comment-only query handling in interactive shell#11303vishnujayvel wants to merge 5 commits into
vishnujayvel wants to merge 5 commits into
Conversation
In the interactive SQL shell, a bare empty query (e.g. just ";") was silently producing "Empty set, 1 warning" instead of a clear client error, and a comment-only query (e.g. "-- foo;") behaved the same way instead of being skipped silently like it is in batch mode. Branch on sqlparser.ErrEmpty in the shell's Uninterpreted callback: a truly empty statement now prints a MySQL-style "No query specified" error, while a comment-only statement is skipped silently, mirroring how execBatchMode already treats ErrEmpty as a no-op. Fixes dolthub#10864 Fixes dolthub#10863 Reported by angelamayxie
…-query-warning-10864
…into fix/empty-query-warning-10864
…into fix/empty-query-warning-10864
…-query-warning-10864
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
In the interactive
dolt sqlshell, two related edge cases around empty/comment-only statements produced confusing output instead of clear, MySQL-consistent behavior:;) silently printedEmpty set, 1 warningwith a warning body ofquery was empty after trimming comments, instead of a clear client-side error.-- foo ;) behaved the same way — a spurious "empty" warning — instead of being silently skipped the waydolt sql < file.sql(batch mode) already treats it.This PR makes the shell branch on
sqlparser.ErrEmptyexplicitly inexecShell'sUninterpretedcallback (go/cmd/dolt/commands/sql.go):;is stripped) now prints a MySQL-styleNo query specifiederror, matching how the realmysqlCLI responds to a bare;.ErrEmptybecause it's all comment) is now skipped silently — no output, no warning — which mirrors the existing behavior ofexecBatchMode, whereerr == sqlparser.ErrEmptyis already a silentcontinue.Why
Batch mode (
execBatchMode, sql.go) andprocessQuery(used by scripting/non-interactive paths) both already treatsqlparser.ErrEmptyas "silently skip." The interactive shell was the only place papering over this with a fakeEmpty set, 1 warningresult, which is misleading — there's no result set, and the "warning" concept here doesn't correspond to anything the query actually did. This change brings the shell in line with the rest of the codebase's handling of empty statements while adding a genuinely useful error for the truly-empty case (bare;), since that's a real MySQL client-side error dolt users would expect to see.Closes #10864
Closes #10863
Thanks to angelamayxie for the original reports.
Test plan
go build ./cmd/dolt/...— passesgo vet ./cmd/dolt/...— passesgofmt -l go/cmd/dolt/commands/sql.go— cleanintegration-tests/bats/sql-shell.bats:sql-shell: bare empty query gives MySQL-style error, not a warning(uses newsql-shell-empty-query.expect)sql-shell: comment-only query is skipped silently, no warning(uses newsql-shell-comment-only-query.expect)doltbinary and pass:sql-shell.batssuite regression run was kicked off locally to check for unrelated breakage; not gating this PR description on it since the two new/targeted cases already passed cleanly and no other test in the file touches this code path.