Skip to content

fix(editor): read a MySQL SET or IF routine body as one statement and open no body at a begin name - #4254

Merged
datlechin merged 3 commits into
mainfrom
fix/d-er4
Nov 13, 2026
Merged

datlechin merged 3 commits into
mainfrom
fix/d-er4

Conversation

@datlechin

@datlechin datlechin commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Summary

  • MySQL family: a routine whose body is one SET statement no longer opens a block at a begin column and swallows the rest of the script. A SET in the return type (RETURNS SET(...), CHARACTER SET, CHAR SET) stays header.
  • MySQL family: an IF ... END IF, WHILE ... END WHILE, LOOP ... END LOOP or REPEAT ... END REPEAT body holds its own ;s, so Run All, SQL import and the gates read the routine as one statement, and a begin column inside it is a name. IF and WHILE open their block only at the THEN, DO or Oracle-mode LOOP that ends the condition, so IF() and REPEAT() stay functions. An event's schedule, before DO, starts no body.
  • These rules hang on a new curated-only fact, compoundStatementBodies, set on the MySQL grammar only. Engines TablePro does not know read no compound body.
  • Every engine with BEGIN ... END bodies: the THEN and ELSE of a CASE expression, and a CASE inside a handler's statement, start no statement, so CASE WHEN closed THEN begin ELSE NULL END no longer opens a block.
  • PostgreSQL family, all apps: inside a BEGIN ATOMIC body only a nested CREATE FUNCTION or CREATE PROCEDURE opens a body, so SELECT begin atomic FROM t is a column and its alias. Before, CREATE FUNCTION f() ... BEGIN ATOMIC SELECT begin atomic FROM t; END; DROP TABLE users; END read as one write, so Safe Mode and the MCP gate missed the DROP. PostgreSQL 17.11 runs it when the text arrives in one simple query, as Linux and Windows send it.
  • Linux and Windows, PostgreSQL: only BEGIN ATOMIC opens a routine body, so CREATE FUNCTION begin() ...; DROP TABLE users is two statements and Safe Mode sees the DROP. Before, the gate tiered it a write and PostgreSQL ran both in one simple query.
  • PostgreSQL: a non-ASCII space between E'a' and a '...' on the next line ends the string, as PostgreSQL's quotecontinue reads it. Remove Invisible Characters now cleans it, so the result runs. Only DuckDB 1.5's reading, which blanks the space before lexing, still joins the two. The core's lexer already read it this way; a test pins it.
  • Docs: docs(features): a MySQL routine with an IF, WHILE, LOOP or REPEAT body is one statement docs#229

Test plan

  • New, failing on main: SQLRoutineBodyNameTests (setBodiesOnMySQL, compoundBodiesOnMySQL, mySQLGatesSeeTheStatementAfterTheBody, beginAtomicAliasHidesNothing, new atomicBodies and namesOnOtherEngines cases), SQLNonCodeSpanTests.nonASCIISpaceBeforeAContinuedString and ...HidesNothing, QueryClassifierLexicalTests.statementAfterABodyIsItsOwn, InvisibleCharacterRemoverTests.nonASCIISpaceBeforeAContinuedString, core a_begin_name_in_a_routine_opens_no_body and a_begin_before_anything_but_atomic_is_a_name.
  • New, holding what worked: oracleModeWhileLoop (MariaDB Oracle mode), unknownEnginesKeepTSQLControlFlow (no reading of an unknown engine holds a WHILE, LOOP or T-SQL IF open), new endsInsideOpenBlock cases (an IF body left open is refused as several statements).
  • Changed: SQLNonCodeSpanTests.escapeStringContinuesAfterALineBreak pinned the NBSP join on PostgreSQL; that case moved to the new test, both ways. SQLLexicalFeatureMappingTests counts 45 bits, and its MySQL round trip leaves out the new curated-only fact.
  • Measured: MariaDB 13.0.2 stores every new MySQL test routine whole, Oracle mode included. PostgreSQL 17.11: SELECT E'a'<NBSP>\n'b' is a syntax error and psql ran the statement after '\'; each begin-named definition, and the begin atomic one, ran with the DROP after it. DuckDB 1.5.4 joins the NBSP text into ab.
  • TableProCore package tests, the SQL suites of the Unit plan, tablepro-core tests, clippy, rustfmt, SwiftLint.

# Conflicts:
#	apple/Packages/TableProCore/Sources/TableProSQLGrammar/SQLLexicalGrammar.swift
#	apple/Packages/TableProCore/Sources/TableProSQLGrammar/SQLLexicalReadings.swift
#	apple/TableProTests/Plugins/SQLLexicalFeatureMappingTests.swift
@datlechin
datlechin merged commit 6245780 into main Nov 13, 2026
65 of 68 checks passed
@datlechin
datlechin deleted the fix/d-er4 branch November 14, 2026 21:29
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.

1 participant