Skip to content

Fix SET TERM handling in SQL execution#45

Draft
Copilot wants to merge 4 commits intomasterfrom
copilot/fix-dynamic-sql-error
Draft

Fix SET TERM handling in SQL execution#45
Copilot wants to merge 4 commits intomasterfrom
copilot/fix-dynamic-sql-error

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 20, 2026

SQL scripts containing SET TERM were failing with "Token unknown" errors. The code was splitting statements on ; delimiters, which breaks when SET TERM changes the terminator to ^ or other characters for trigger/procedure definitions.

Changes

Detection and routing

  • Detect SET TERM pattern (/\bSET\s+TERM\s+/i) before splitting
  • Route entire script to isql CLI tool instead of fbird_query() when detected
  • Skip semicolon-based splitting to preserve custom terminators

Example failure case:

SET TERM ^ ;
CREATE OR ALTER TRIGGER XXX_YYY0 FOR AAAAAAAA
ACTIVE BEFORE DELETE POSITION 0
AS
BEGIN
  -- trigger body
END;^
SET TERM ; ^

Previously: Split on ; → invalid fragments → SQL error
Now: Pass complete script to isql → executes correctly

Cleanup

  • Initialize $isql_flag = false explicitly for consistent boolean logic
  • Fix deprecated curly brace string offset syntax ($cmd{n}$cmd[n]) for PHP 7.4+
Original prompt

This section details on the original issue you should resolve

<issue_title>Dynamic SQL Error SQL error code = -104 Token unknown - line 1, column 1 ^ </issue_title>
<issue_description>Hi,

I have problem with:

SET TERM ^ ;
CREATE OR ALTER trigger XXX_YYY0 for AAAAAAAA
active before delete position 0
AS
begin
  --something
end;^
SET TERM ; ^

Thanks!</issue_description>

<agent_instructions>seems to be a generic execute sql issue </agent_instructions>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits January 20, 2026 15:01
Co-authored-by: mariuz <18359+mariuz@users.noreply.github.com>
Co-authored-by: mariuz <18359+mariuz@users.noreply.github.com>
Co-authored-by: mariuz <18359+mariuz@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix dynamic SQL error for trigger creation Fix SET TERM handling in SQL execution Jan 20, 2026
Copilot AI requested a review from mariuz January 20, 2026 15:12
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.

Dynamic SQL Error SQL error code = -104 Token unknown - line 1, column 1 ^

2 participants