Skip to content

fix: handle SQL tool statements without result sets - #598

Merged
buzzia2001 merged 2 commits into
codefori:mainfrom
Balrocj:fix/copilot-sql-tool-ddl-result
Nov 26, 2026
Merged

buzzia2001 merged 2 commits into
codefori:mainfrom
Balrocj:fix/copilot-sql-tool-ddl-result

Conversation

@Balrocj

@Balrocj Balrocj commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes the Copilot SQL runner tool when executing successful SQL statements that do not return a result set, such as CREATE TABLE, DROP TABLE, or CREATE ALIAS.

Previously, JobManager.runSQL() could return undefined. The tool passed JSON.stringify(undefined) into LanguageModelTextPart, which also evaluates to undefined and caused VS Code to throw an error when reading .length.

The tool now always returns a consistent JSON payload:

  • Statements without a result set: {"success":true,"hasResultSet":false,"rows":[]}
  • Statements with a result set: {"success":true,"hasResultSet":true,"rows":[...]}

Tests

  • Added regression tests for statements with and without result sets.
  • Manually verified successful CREATE TABLE and DROP TABLE statements through Copilot Chat.
  • npm test passes: 186 tests.
  • npm run typings passes.

Fixes #562

@buzzia2001

Copy link
Copy Markdown
Member

@Balrocj coul dyou please upload vsix?

@Balrocj

Balrocj commented Nov 8, 2026

Copy link
Copy Markdown
Contributor Author

@buzzia2001 I built the VSIX from this branch and attached it here for testing.

It includes the fix for SQL statements that complete successfully without returning a result set.

GitHub does not allow .vsix attachments, so the package is attached as a .zip.

vscode-db2i-2.1.1-dev.0.zip

@buzzia2001 buzzia2001 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hey,
some suggestions for you:

  • src/aiProviders/copilot/sqlTool.ts:34 — hasResultSet is guessed from result === undefined. JobManager.runSQLVerbose() already returns has_results and update_count (used the same way in src/views/results/index.ts), so you could report the real flag and also give the model the affected-row count for INSERT/UPDATE/DELETE, which today just come back as rows: []:
    const result = await JobManager.runSQLVerbose(trimmed);
    // { success: true, hasResultSet: result.has_results, updateCount: result.update_count, rows: result.data ?? [] }
  • src/aiProviders/copilot/sqlTool.ts:10 — success is always true (failures throw before we get here), so it carries no information. Either drop it or catch the error and return success: false with the message. Also, result: unknown could be typed as unknown[] | undefined.

Add them and I'll merge!

@buzzia2001
buzzia2001 merged commit 85d6c20 into codefori:main Nov 26, 2026
1 check passed
@Balrocj

Balrocj commented Nov 28, 2026

Copy link
Copy Markdown
Contributor Author

@buzzia2001 thanks for the feedback and for merging the PR!

I noticed that an additional commit was added before the merge. I assume the suggested changes have already been addressed.

Please let me know if there is anything else you'd like me to follow up on.

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.

Vs Code db2i SQLRunnerTool issue on alias creation

2 participants