Skip to content

Commit

Permalink
fix false positive ambiguous column in ON DUPLICATE KEY with VALUE/S
Browse files Browse the repository at this point in the history
  • Loading branch information
schlndh committed Aug 25, 2023
1 parent ac8466d commit 27c1dbb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Analyser/AnalyserState.php
Original file line number Diff line number Diff line change
Expand Up @@ -1366,6 +1366,12 @@ private function resolveExprType(Expr\Expr $expr, ?AnalyserConditionTypeEnum $co
$this->hasAggregateFunctionCalls = true;
}

$bakFieldBehavior = $this->fieldBehavior;

if (in_array($normalizedFunctionName, ['VALUE', 'VALUES'], true)) {
$this->fieldBehavior = ColumnResolverFieldBehaviorEnum::ASSIGNMENT;
}

foreach ($arguments as $arg) {
$innerCondition = $innerConditions[$position] ?? null;
$position++;
Expand All @@ -1382,6 +1388,8 @@ private function resolveExprType(Expr\Expr $expr, ?AnalyserConditionTypeEnum $co
}
}

$this->fieldBehavior = $bakFieldBehavior;

if ($isAggregateFunction) {
$this->columnResolver->exitAggregateFunction();
}
Expand Down
16 changes: 16 additions & 0 deletions tests/Analyser/AnalyserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1154,6 +1154,22 @@ private function provideValidInsertTestData(): iterable
',
];

yield 'INSERT ... ON DUPLICATE KEY UPDATE - ambiguity resolved via VALUE' => [
'query' => '
INSERT INTO analyse_test_insert
SELECT * FROM analyse_test_insert
ON DUPLICATE KEY UPDATE id = VALUE(id);
',
];

yield 'INSERT ... ON DUPLICATE KEY UPDATE - ambiguity resolved via VALUES' => [
'query' => '
INSERT INTO analyse_test_insert
SELECT * FROM analyse_test_insert
ON DUPLICATE KEY UPDATE id = VALUES(id);
',
];

// TODO: DEFAULT expression
}

Expand Down

0 comments on commit 27c1dbb

Please sign in to comment.