Skip to content

feat: implement multi-line EXIT(query) support - #636

Open
David Levy (dlevy-msft-sql) wants to merge 7 commits into
microsoft:mainfrom
dlevy-msft-sql:exit-multiline
Open

feat: implement multi-line EXIT(query) support#636
David Levy (dlevy-msft-sql) wants to merge 7 commits into
microsoft:mainfrom
dlevy-msft-sql:exit-multiline

Conversation

@dlevy-msft-sql

@dlevy-msft-sql David Levy (dlevy-msft-sql) commented Jan 25, 2026

Copy link
Copy Markdown
Contributor

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Comment thread pkg/sqlcmd/commands_test.go
Comment thread pkg/sqlcmd/commands.go Outdated
Comment thread pkg/sqlcmd/commands.go
Comment thread pkg/sqlcmd/commands.go Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Comment thread pkg/sqlcmd/commands_test.go

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

Comment thread pkg/sqlcmd/commands_test.go Outdated
Comment thread pkg/sqlcmd/commands_test.go Outdated
Comment thread pkg/sqlcmd/commands.go Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Comment thread pkg/sqlcmd/commands.go Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comment thread pkg/sqlcmd/commands_test.go
Comment thread pkg/sqlcmd/commands_test.go

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Comment thread pkg/sqlcmd/commands_test.go
@dlevy-msft-sql David Levy (dlevy-msft-sql) changed the title Implement multi-line EXIT(query) support feat: implement multi-line EXIT(query) support Feb 5, 2026
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.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings September 4, 2026 21:08

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 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

Comment thread pkg/sqlcmd/commands_test.go
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings September 4, 2026 21:15

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 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>
Copilot AI review requested due to automatic review settings September 4, 2026 21:41

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 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

Comment thread pkg/sqlcmd/commands.go
Comment thread pkg/sqlcmd/commands_test.go
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings September 4, 2026 21:54

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 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

Comment thread pkg/sqlcmd/commands.go
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings September 4, 2026 22:03

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 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

Comment thread pkg/sqlcmd/commands.go Outdated
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings September 4, 2026 22:11

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 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

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

Labels

Size: S Small issue (less than one week effort) sqlcmd switch switch in existing sqlcmd

Projects

None yet

Development

Successfully merging this pull request may close these issues.

EXIT command not parsed in powershell using -Q

2 participants