Skip to content

Comments

MSSQL: support EXEC (@sql) dynamic SQL execution#2234

Open
yoabot-droid wants to merge 1 commit intoapache:mainfrom
yoabot-droid:mssql-exec-dynamic-sql
Open

MSSQL: support EXEC (@sql) dynamic SQL execution#2234
yoabot-droid wants to merge 1 commit intoapache:mainfrom
yoabot-droid:mssql-exec-dynamic-sql

Conversation

@yoabot-droid
Copy link

Problem

EXEC (@sql) — the T-SQL form for executing a dynamically-built SQL string — was failing to parse. parse_execute() was consuming a second parameter list after already parsing the parenthesised name expression, causing parse failures on any token that immediately followed.

Fix

Track whether the name expression was itself wrapped in parens. When it is (EXEC (@sql)), skip the parameter-list scan so no extra tokens are consumed.

Test

Adds test_exec_dynamic_sql covering:

  • EXEC (@sql) standalone
  • EXEC (@sql) followed by another statement on the next line

parse_execute() was consuming a second parameter list after already
parsing the parenthesised name expression, causing parse failures on
any token that immediately followed EXEC (@SQL).

Fixed by tracking whether the name was itself wrapped in parens; when it
is, skip the parameter-list scan and leave no tokens consumed for the
caller to mis-interpret.

Adds test_exec_dynamic_sql covering both the standalone form and the
case where a subsequent statement follows on the next line.
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