|
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 | {
|
@@ -280,13 +281,7 @@ public function resolveQueryStrings(Expr $queryExpr, Scope $scope): iterable
|
280 | 281 |
|
281 | 282 | $queryString = $this->resolveQueryExpr($queryExpr, $scope);
|
282 | 283 | if (null !== $queryString) {
|
283 |
| - $normalizedQuery = QuerySimulation::stripComments($this->normalizeQueryString($queryString)); |
284 |
| - |
285 |
| - // query simulation might lead in a invalid query, skip those |
286 |
| - $error = $this->validateQueryString($normalizedQuery); |
287 |
| - if ($error === null) { |
288 |
| - yield $normalizedQuery; |
289 |
| - } |
| 284 | + yield QuerySimulation::stripComments($this->normalizeQueryString($queryString)); |
290 | 285 | }
|
291 | 286 | }
|
292 | 287 |
|
@@ -360,6 +355,13 @@ private function resolveQueryStringExpr(Expr $queryExpr, Scope $scope, bool $res
|
360 | 355 | $leftString = $this->resolveQueryStringExpr($left, $scope);
|
361 | 356 | $rightString = $this->resolveQueryStringExpr($right, $scope);
|
362 | 357 |
|
| 358 | + // queries with a dynamic FROM are not resolvable |
| 359 | + if (QueryReflection::getRuntimeConfiguration()->isDebugEnabled()) { |
| 360 | + if (str_ends_with(rtrim($leftString), 'FROM') && is_numeric(trim($rightString, '"\''))) { |
| 361 | + throw new UnresolvableQueryDynamicFromException('Seems the query is too dynamic to be resolved by query simulation'); |
| 362 | + } |
| 363 | + } |
| 364 | + |
363 | 365 | if (null === $leftString || null === $rightString) {
|
364 | 366 | return null;
|
365 | 367 | }
|
|
0 commit comments