Skip to content

fix(cli): concatenateQueries comment issues - #2414

Merged
Ford544 merged 3 commits into
mainfrom
concatenate-queries-fix
Nov 2, 2026
Merged

Ford544 merged 3 commits into
mainfrom
concatenate-queries-fix

Conversation

@Ford544

@Ford544 Ford544 commented Oct 30, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes two errors with the way concatenateQueries terminates sql statements with semicolons:

  • treating -- in a string as comment
  • ignoring # comments
  • multi-line trailing comments
  • trailing block comments containing --

@Ford544
Ford544 requested a review from a team as a code owner October 30, 2026 16:31
@Ford544
Ford544 requested review from apilaskowski, mbiernacik and rafal-hawrylak and removed request for a team October 30, 2026 16:31
} else if (char === "/" && next === "*") {
const end = statement.indexOf("*/", i + 2);
i = end === -1 ? statement.length : end + 2;
} else if (char === "'" || char === '"' || char === "`") {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

In GoogleSQL raw strings (r'...' or r"..."), a trailing backslash before the closing quote (like r'foo') does not escape the quote, so statement[i] === "\" will skip the closing quote. Worth only treating \ as an escape when the string is not preceded by r or R?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good point - I made this fix in #2408, but it makes more sense to put it here

Comment thread cli/api/dbadapters/tasks.ts Outdated
return codeEnd;
}

function formatStatement(statement: string, isLast: boolean, modifier?: (mod: string) => string) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

isLast is based on processed.length - 1, so if the last statement is comment-only (like ["SELECT 1", "-- comment"]), SELECT 1 gets isLast = false and has a semicolon added even though it is the last statement with code. Should isLast be computed from the last statement where codeEndIndex(statement) > 0?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done

@mbiernacik mbiernacik left a comment

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.

nit: The PR description lists two fixes (-- inside strings and # comments). The change also fixes multi-line trailing comments and trailing block comments containing --. It might be worth mentioning those too and linking #2413, since that PR depends on this fix.

@Ford544
Ford544 merged commit d6a2e52 into main Nov 2, 2026
15 checks passed
@Ford544
Ford544 deleted the concatenate-queries-fix branch November 2, 2026 13:41
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.

3 participants

⌂ 换网址