Skip to content

Commit

Permalink
SQL AST: parse expressions with no FROM clause (#590)
Browse files Browse the repository at this point in the history
  • Loading branch information
hemberger authored Mar 27, 2023
1 parent 31c4de9 commit 3c6c8e8
Show file tree
Hide file tree
Showing 4 changed files with 390 additions and 409 deletions.
6 changes: 5 additions & 1 deletion src/SqlAst/ParserInference.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use staabm\PHPStanDba\QueryReflection\QueryReflection;
use staabm\PHPStanDba\SchemaReflection\Join as SchemaJoin;
use staabm\PHPStanDba\SchemaReflection\SchemaReflection;
use staabm\PHPStanDba\SchemaReflection\Table;
use staabm\PHPStanDba\UnresolvableAstInQueryException;

final class ParserInference
Expand Down Expand Up @@ -60,7 +61,10 @@ public function narrowResultType(string $queryString, ConstantArrayType $resultT
}
$from = $command->getFrom();

if ($from instanceof TableReferenceTable) {
if (null === $from) {
// no FROM clause, use an empty Table to signify this
$fromTable = new Table('', []);
} elseif ($from instanceof TableReferenceTable) {
$fromName = $from->getTable()->getName();
$fromTable = $this->schemaReflection->getTable($fromName);
} elseif ($from instanceof Join) {
Expand Down
Loading

0 comments on commit 3c6c8e8

Please sign in to comment.