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