staabm / phpstan-dba

PHPStan based SQL static analysis and type inference for the database access layer
https://staabm.github.io/archive.html#phpstan-dba
MIT License
250 stars 17 forks source link

SQL AST: parse expressions with no FROM clause #590

Closed hemberger closed 1 year ago

hemberger commented 1 year ago

Expressions without a FROM clause are valid SQL, and can be properly parsed by allowing QueryScope to take a nullable Table argument.

hemberger commented 1 year ago

Instead of allowing QueryScope to take a nullable Table, I'm now creating an empty Table to signify that there is no FROM clause. We could still go the nullable route if that is preferable, but it gets complicated by a bunch of bookkeeping variables to differentiate between $fromTable === null because we have an empty FROM clause (allowed) vs. because we have some other non-empty FROM clause that we don't support (disallowed). Another option is to make Table non-final and have a few subclasses (which is potentially one way to handle the abstraction for FROM subquery in the future).

staabm commented 1 year ago

thank you