feat: implement multi-line EXIT(query) support - #636
feat: implement multi-line EXIT(query) support#636David Levy (dlevy-msft-sql) wants to merge 7 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request implements multi-line EXIT(query) support in interactive mode for go-sqlcmd. When an EXIT command with parentheses is entered and the parentheses are unbalanced, the shell now prompts for continuation lines until the parentheses balance, matching the behavior of ODBC sqlcmd.
Changes:
- Added
isExitParenBalanced()function to check if parentheses in EXIT command arguments are balanced - Added
readExitContinuation()function to prompt for and read continuation lines in interactive mode - Updated
exitCommand()to call continuation logic when parentheses are unbalanced - Added comprehensive test suite for
isExitParenBalanced() - Removed the README limitation note about EXIT(query) not supporting multi-line
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| pkg/sqlcmd/commands.go | Implements core multi-line EXIT(query) functionality with parentheses balancing check and continuation prompt logic |
| pkg/sqlcmd/commands_test.go | Adds test cases for the new isExitParenBalanced() function covering various edge cases |
| README.md | Removes the documented limitation about EXIT(query) not supporting multi-line queries |
a4dd987 to
b38d203
Compare
In interactive mode, EXIT(query) can now span multiple lines when parentheses are unbalanced. Handles SQL strings, comments, and bracket identifiers correctly. Includes protection against infinite loops (max 1000 continuation lines) and user-friendly error messages for EOF/incomplete commands.
d3961ef to
bc4b6b6
Compare
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
The PR claims to fix #520 (-Q multi-line input with :EXIT on a later line) but the current implementation/tests only cover interactive continuation and likely do not address command detection in multi-line -Q queries.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
Suppressed comments (1)
pkg/sqlcmd/commands.go:214
- The comment describing SQL Server quote escaping uses a smart quote character (”); it looks like it should describe doubled single quotes ('') for escaping in string literals. This is misleading/typo-prone when someone later maintains the parser.
// isExitParenBalanced checks if the parentheses in an EXIT command argument are balanced.
// It tracks quotes to avoid counting parens inside string literals.
// It handles SQL Server's quote escaping: ” inside single-quoted strings, "" inside double-quoted strings, and ]] inside bracket identifiers.
// It also ignores parentheses inside SQL comments (-- single-line and /* multi-line */).
- Files reviewed: 3/3 changed files
- Comments generated: 1
- Review effort level: Lite
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🔵 Needs a closer look
The new paren-balancing helper can incorrectly report balanced parentheses when depth goes negative mid-scan and later returns to zero, which can break continuation detection and validation.
Review details
Suppressed comments (3)
Previously missed (2) — in code that hasn't changed since the last review.
pkg/sqlcmd/commands.go:270
- isExitParenBalanced() only checks that final depth is 0, but it can incorrectly return true if the scan ever goes negative and later returns to 0 (e.g. "())("). Treating any intermediate negative depth as unbalanced avoids accepting invalid/mismatched parentheses ordering.
pkg/sqlcmd/commands_test.go:489 - The test table for isExitParenBalanced() doesn’t include a case where depth goes negative mid-scan but ends at 0 (e.g. "())("). Adding this would prevent regressions for the intermediate-negative-depth bug.
pkg/sqlcmd/commands.go:213
- The comment describing SQL Server quote escaping contains an incorrect curly quote character (”); this should describe the actual escape sequence for single quotes (''), otherwise the documentation is misleading for future maintenance.
// It handles SQL Server's quote escaping: ” inside single-quoted strings, "" inside double-quoted strings, and ]] inside bracket identifiers.
- Files reviewed: 3/3 changed files
- Comments generated: 0 new
- Review effort level: Lite
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
isExitParenBalanced can incorrectly treat improperly nested parentheses as “balanced” when depth goes negative mid-scan, which can prematurely stop continuation prompting and attempt executing invalid queries.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
Suppressed comments (1)
pkg/sqlcmd/commands.go:214
- The comment describing SQL Server quote escaping uses a curly quote character and describes the wrong escape sequence for single-quoted strings. SQL Server escapes single quotes as two single quotes: ''. This comment should be corrected to avoid misleading future changes.
// isExitParenBalanced checks if the parentheses in an EXIT command argument are balanced.
// It tracks quotes to avoid counting parens inside string literals.
// It handles SQL Server's quote escaping: ” inside single-quoted strings, "" inside double-quoted strings, and ]] inside bracket identifiers.
// It also ignores parentheses inside SQL comments (-- single-line and /* multi-line */).
- Files reviewed: 7/7 changed files
- Comments generated: 2
- Review effort level: Lite
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
Interactive EXIT(query) continuation can get stuck prompting indefinitely for inputs with an unmatched closing parenthesis because “needs more lines” and “invalid prefix” are not distinguished.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
- Files reviewed: 7/7 changed files
- Comments generated: 1
- Review effort level: Lite
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟢 Approval recommended
The functional changes are well-covered by targeted tests for both interactive continuation and -Q parsing, with only minor documentation nits noted.
Review details
- Files reviewed: 7/7 changed files
- Comments generated: 1
- Review effort level: Lite
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟢 Approval recommended
The parsing changes are well-scoped and are backed by targeted regression and integration tests covering the reported failure mode and the new interactive continuation behavior.
Review details
- Files reviewed: 7/7 changed files
- Comments generated: 0 new
- Review effort level: Lite
In interactive mode, EXIT(query) can now span multiple lines when parentheses are unbalanced. The shell prompts for continuation lines until parentheses balance, matching ODBC sqlcmd behavior. Adds isExitParenBalanced() function, readExitContinuation() for prompting, updates exitCommand(), adds tests, and removes README limitation note.
Fixes #520.