|
32 | 32 | use staabm\PHPStanDba\SchemaReflection\SchemaReflection; |
33 | 33 | use staabm\PHPStanDba\SqlAst\ParserInference; |
34 | 34 | use staabm\PHPStanDba\UnresolvableQueryException; |
| 35 | +use staabm\PHPStanDba\UnresolvableQueryDynamicFromException; |
35 | 36 |
|
36 | 37 | final class QueryReflection |
37 | 38 | { |
@@ -291,13 +292,7 @@ public function resolveQueryStrings(Expr $queryExpr, Scope $scope): iterable |
291 | 292 |
|
292 | 293 | $queryString = $this->resolveQueryExpr($queryExpr, $scope); |
293 | 294 | if (null !== $queryString) { |
294 | | - $normalizedQuery = QuerySimulation::stripComments($this->normalizeQueryString($queryString)); |
295 | | - |
296 | | - // query simulation might lead in a invalid query, skip those |
297 | | - $error = $this->validateQueryString($normalizedQuery); |
298 | | - if ($error === null) { |
299 | | - yield $normalizedQuery; |
300 | | - } |
| 295 | + yield QuerySimulation::stripComments($this->normalizeQueryString($queryString)); |
301 | 296 | } |
302 | 297 | } |
303 | 298 |
|
@@ -371,6 +366,13 @@ private function resolveQueryStringExpr(Expr $queryExpr, Scope $scope, bool $res |
371 | 366 | $leftString = $this->resolveQueryStringExpr($left, $scope); |
372 | 367 | $rightString = $this->resolveQueryStringExpr($right, $scope); |
373 | 368 |
|
| 369 | + // queries with a dynamic FROM are not resolvable |
| 370 | + if (QueryReflection::getRuntimeConfiguration()->isDebugEnabled()) { |
| 371 | + if (str_ends_with(rtrim($leftString), 'FROM') && is_numeric(trim($rightString, '"\''))) { |
| 372 | + throw new UnresolvableQueryDynamicFromException('Seems the query is too dynamic to be resolved by query simulation'); |
| 373 | + } |
| 374 | + } |
| 375 | + |
374 | 376 | if (null === $leftString || null === $rightString) { |
375 | 377 | return null; |
376 | 378 | } |
|
0 commit comments