Skip to content

Commit 3c6c8e8

Browse files
authored
SQL AST: parse expressions with no FROM clause (#590)
1 parent 31c4de9 commit 3c6c8e8

File tree

4 files changed

+390
-409
lines changed

4 files changed

+390
-409
lines changed

src/SqlAst/ParserInference.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use staabm\PHPStanDba\QueryReflection\QueryReflection;
2525
use staabm\PHPStanDba\SchemaReflection\Join as SchemaJoin;
2626
use staabm\PHPStanDba\SchemaReflection\SchemaReflection;
27+
use staabm\PHPStanDba\SchemaReflection\Table;
2728
use staabm\PHPStanDba\UnresolvableAstInQueryException;
2829

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

63-
if ($from instanceof TableReferenceTable) {
64+
if (null === $from) {
65+
// no FROM clause, use an empty Table to signify this
66+
$fromTable = new Table('', []);
67+
} elseif ($from instanceof TableReferenceTable) {
6468
$fromName = $from->getTable()->getName();
6569
$fromTable = $this->schemaReflection->getTable($fromName);
6670
} elseif ($from instanceof Join) {

0 commit comments

Comments
 (0)