From 5815d5e6e68e1a7a838ea8f102c86441ac4daa76 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Fri, 15 Nov 2024 09:44:30 +0100 Subject: [PATCH 1/4] Fix types --- src/QueryReflection/ReflectionCache.php | 3 +++ src/SqlAst/ParserInference.php | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/src/QueryReflection/ReflectionCache.php b/src/QueryReflection/ReflectionCache.php index 840fedd8..204a0d82 100644 --- a/src/QueryReflection/ReflectionCache.php +++ b/src/QueryReflection/ReflectionCache.php @@ -157,6 +157,9 @@ private function readCachedRecords(bool $useReadLock): ?array // the schemaHash is only available in replay-and-record mode. if (null === $this->schemaHash) { + if (! is_string($cache['schemaHash'])) { + throw new ShouldNotHappenException(); + } $this->schemaHash = $cache['schemaHash']; } elseif ($this->schemaHash !== $cache['schemaHash']) { return null; diff --git a/src/SqlAst/ParserInference.php b/src/SqlAst/ParserInference.php index 27331657..7264283b 100644 --- a/src/SqlAst/ParserInference.php +++ b/src/SqlAst/ParserInference.php @@ -74,6 +74,10 @@ public function narrowResultType(string $queryString, ConstantArrayType $resultT $fromTable = $this->schemaReflection->getTable($fromName); } elseif ($from instanceof Join) { while (1) { + if (!$from instanceof Join || !method_exists($from, 'getCondition')) { + return $resultType; + } + if ($from->getCondition() === null) { if (QueryReflection::getRuntimeConfiguration()->isDebugEnabled()) { throw new UnresolvableAstInQueryException('Cannot narrow down types null join conditions: ' . $queryString); From cca9cf2b008a0b773451e45e94cc74f1f252817c Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Fri, 15 Nov 2024 09:48:56 +0100 Subject: [PATCH 2/4] Update ParserInference.php --- src/SqlAst/ParserInference.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/SqlAst/ParserInference.php b/src/SqlAst/ParserInference.php index 7264283b..bdb97b16 100644 --- a/src/SqlAst/ParserInference.php +++ b/src/SqlAst/ParserInference.php @@ -108,14 +108,16 @@ public function narrowResultType(string $queryString, ConstantArrayType $resultT $joinType = SchemaJoin::TYPE_INNER; } - $joinedTable = $this->schemaReflection->getTable($from->getRight()->getTable()->getName()); - - if ($joinedTable !== null) { - $joins[] = new SchemaJoin( - $joinType, - $joinedTable, - $from->getCondition() - ); + if ($from->getRight() instanceof TableReferenceTable) { + $joinedTable = $this->schemaReflection->getTable($from->getRight()->getTable()->getName()); + + if ($joinedTable !== null) { + $joins[] = new SchemaJoin( + $joinType, + $joinedTable, + $from->getCondition() + ); + } } if ($from->getLeft() instanceof TableReferenceTable) { From 1872220931d6b55f9f7c8a099846e439d3151638 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Fri, 15 Nov 2024 09:53:15 +0100 Subject: [PATCH 3/4] Update ReflectionCache.php --- src/QueryReflection/ReflectionCache.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/QueryReflection/ReflectionCache.php b/src/QueryReflection/ReflectionCache.php index 204a0d82..816013c2 100644 --- a/src/QueryReflection/ReflectionCache.php +++ b/src/QueryReflection/ReflectionCache.php @@ -157,7 +157,7 @@ private function readCachedRecords(bool $useReadLock): ?array // the schemaHash is only available in replay-and-record mode. if (null === $this->schemaHash) { - if (! is_string($cache['schemaHash'])) { + if ($cache['schemaHash'] !== null && ! is_string($cache['schemaHash'])) { throw new ShouldNotHappenException(); } $this->schemaHash = $cache['schemaHash']; From 334c6c616c41eb835d20c579d5a6b3826725249e Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Fri, 15 Nov 2024 09:53:23 +0100 Subject: [PATCH 4/4] Update ParserInference.php --- src/SqlAst/ParserInference.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SqlAst/ParserInference.php b/src/SqlAst/ParserInference.php index bdb97b16..3c5ef599 100644 --- a/src/SqlAst/ParserInference.php +++ b/src/SqlAst/ParserInference.php @@ -74,7 +74,7 @@ public function narrowResultType(string $queryString, ConstantArrayType $resultT $fromTable = $this->schemaReflection->getTable($fromName); } elseif ($from instanceof Join) { while (1) { - if (!$from instanceof Join || !method_exists($from, 'getCondition')) { + if (! $from instanceof Join || ! method_exists($from, 'getCondition')) { return $resultType; }