Skip to content

Find SQL console clause keywords only outside literals - #59

Merged
oblomov-dev merged 1 commit into
mainfrom
claude/sql-keywords-outside-literals
Nov 13, 2026
Merged

oblomov-dev merged 1 commit into
mainfrom
claude/sql-keywords-outside-literals

Conversation

@oblomov-dev

Copy link
Copy Markdown
Member

What and why

After #58 the parser kept string literals byte-exact, but it still searched for the clause keywords (SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY, UNION SELECT, UP TO n ROWS, INTO/APPENDING) in the raw query text. Because of that, a literal such as ' from ' or 'x ORDER BY y' split the query at the wrong place, and 'up to 5 rows into x' was cut out of a WHERE literal.

  • A new private mask_literals( ) method builds on split_literals( ). It returns the same text with every literal, delimiters included, replaced by underscores. The copy has the same length as the original, so an offset found in the copy also points to the right place in the original.
  • parse( ) (UNION SELECT) and parse_segment( ) (all other keywords) now search the masked copy and cut the original text at the offsets they find.
  • UP TO … ROWS and INTO … are removed from both copies with replace( off len ), so the two copies stay aligned. Offset access is used only on local strings; no offset access is used on method arguments.

Tests

Five new tests in ltcl_parser put keywords inside literals in WHERE, the select list (CASE … THEN 'from x' …), HAVING, ORDER BY, UNION SELECT and UP TO/INTO. All five failed on the old code and all pass now (25 passed, 0 failed).

Checks run

  • npm run check (Standard ABAP, ABAP Cloud, abap2UI5-linter, rename): 0 issues
  • npm run unit: 25/25 passed
  • npm run auto_downport in a scratch copy: the 7.02 lint finds 0 issues

Generated by Claude Code

The parser searched SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY,
UNION SELECT, UP TO n ROWS and INTO/APPENDING in the raw query text, so
a literal such as ' from ' or 'x ORDER BY y' split the query at the
wrong place, and 'up to 5 rows into x' was cut out of a WHERE literal.

Every keyword search now runs in a copy whose literals are blanked out
by underscores (mask_literals, same length as the original), and the
original is cut at the offsets found there. UP TO and INTO are removed
from both copies with replace( off len ), so the offsets stay aligned.

Unit tests cover keywords inside literals in WHERE, the select list,
HAVING, ORDER BY, UNION SELECT and UP TO/INTO; all five failed before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014YZFmF4CrXfWRsmrwPJTRL
@oblomov-dev
oblomov-dev merged commit a2c42a5 into main Nov 13, 2026
9 checks passed
@oblomov-dev
oblomov-dev deleted the claude/sql-keywords-outside-literals branch November 13, 2026 10:18
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.

2 participants