Skip to content

fix: find DELETE target tables, UPSERT SET sources and CLONE sources - #2977

Open
tanjiroK-coder wants to merge 1 commit into
JSQLParser:masterfrom
tanjiroK-coder:fix/tables-finder-delete-targets-upsert-set-clone
Open

tanjiroK-coder wants to merge 1 commit into
JSQLParser:masterfrom
tanjiroK-coder:fix/tables-finder-delete-targets-upsert-set-clone

Conversation

@tanjiroK-coder

Copy link
Copy Markdown
Contributor

TablesNamesFinder skips three slots in which a statement names a table, so a table allowlist built on findTables lets such statements through.

  1. visit(Delete) visits the table after FROM but never Delete.getTables(), the list in front of FROM in T-SQL and MySQL. For DELETE secrets FROM t WHERE t.id = 1 findTables returns only t, although rows of secrets are deleted. StatementVisitorAdapter.visit(Delete) and DeleteValidator already walk that list. The new visitDeleteTargets visits each entry as a DML target unless it names the alias of the FROM table, a join or a USING item, because DELETE s FROM secrets s JOIN t ... refers to an item that is already visited (like Update.isTargetTableAlias).
  2. visit(Upsert) skips Upsert.getUpdateSets(), so UPSERT INTO t SET a = (SELECT max(pw) FROM secrets) reports only t, while the ON DUPLICATE KEY UPDATE sets were walked through the duplicate action. UpsertValidator had the same asymmetry and now validates both update-set lists.
  3. TableDefinitionTraversal.visit(CreateTable) accepts the LIKE and PARTITION OF tables but not getCloneTable(), so CREATE [SNAPSHOT] TABLE copy CLONE secrets reports only copy in the finder, StatementVisitorAdapter and CreateTableValidator.

Tests cover the T-SQL and MySQL delete shapes, alias entries that must not become tables, both UPSERT SET forms, CLONE with and without FOR SYSTEM_TIME, and a function in an UPSERT SET assignment that the validator must reject. ./gradlew check (16850 tests) and mvn verify pass.

TablesNamesFinder.visit(Delete) never visited Delete.getTables(), the table list in front of FROM in T-SQL and MySQL, so DELETE secrets FROM t reported only t. visit(Upsert) skipped Upsert.getUpdateSets(), and TableDefinitionTraversal.visit(CreateTable) did not accept getCloneTable(), so UPSERT INTO t SET a = (SELECT ... FROM secrets) and CREATE TABLE copy CLONE secrets hid secrets from the finder, the adapter and the validators. UpsertValidator now validates the SET assignments too.

This branch has not been deployed

No deployments
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