diff --git a/src/Analyser/AnalyserState.php b/src/Analyser/AnalyserState.php index 0ca1d48..47c109d 100644 --- a/src/Analyser/AnalyserState.php +++ b/src/Analyser/AnalyserState.php @@ -1356,6 +1356,16 @@ private function resolveExprType(Expr\Expr $expr, ?AnalyserConditionTypeEnum $co new Schema\DbType\MixedType(), true, ); + case Expr\ExprTypeEnum::COLLATE: + assert($expr instanceof Expr\Collate); + $subresult = $this->resolveExprType($expr->expression, $condition); + + return new ExprTypeResult( + new Schema\DbType\VarcharType(), + $subresult->isNullable, + null, + $subresult->knowledgeBase, + ); default: $this->errors[] = new AnalyserError("Unhandled expression type: {$expr::getExprType()->value}"); diff --git a/tests/Analyser/AnalyserTest.php b/tests/Analyser/AnalyserTest.php index fa510e7..45e3053 100644 --- a/tests/Analyser/AnalyserTest.php +++ b/tests/Analyser/AnalyserTest.php @@ -501,6 +501,9 @@ private function provideValidOperatorTestData(): iterable 'BINARY 1 + 2', 'BINARY (1 + 2)', 'BINARY NULL', + '"a" COLLATE utf8mb4_unicode_ci', + 'name COLLATE utf8mb4_unicode_ci FROM analyser_test', + 'id COLLATE utf8mb4_unicode_ci FROM analyser_test', ]; foreach ($exprs as $expr) { @@ -1473,6 +1476,7 @@ public function provideValidNullabilityTestData(): iterable '~(col_vchar IS NOT NULL)', 'col_vchar AND DATE(NOW())', 'col_vchar OR DATE(NOW())', + 'col_vchar COLLATE utf8mb4_unicode_ci IS NOT NULL', ]; foreach (['+', '-', '~', 'BINARY'] as $unaryOp) { @@ -2184,6 +2188,12 @@ private function provideInvalidColumnTestData(): iterable 'error' => AnalyserErrorMessageBuilder::createUnknownColumnErrorMessage('aaa'), 'DB error code' => MariaDbErrorCodes::ER_BAD_FIELD_ERROR, ]; + + yield 'unknown column in COLLATE' => [ + 'query' => 'SELECT aaa COLLATE utf8mb4_unicode_ci FROM analyser_test', + 'error' => AnalyserErrorMessageBuilder::createUnknownColumnErrorMessage('aaa'), + 'DB error code' => MariaDbErrorCodes::ER_BAD_FIELD_ERROR, + ]; } /** @return iterable> */