Skip to content

Commit

Permalink
Only add 'day' once with SqlServer DATEDIFF
Browse files Browse the repository at this point in the history
If a single instance of a DATEDIFF Expression was used more than once, 'day' would be added multiple times (Once be usage). This threw an SQLServer error.
  • Loading branch information
Walther Lalk committed Aug 8, 2014
1 parent 9cf4604 commit 21828e1
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/Database/Dialect/SqlserverDialectTrait.php
Expand Up @@ -155,7 +155,18 @@ protected function _transformFunctionExpression(FunctionExpression $expression)
$expression->name('')->type(' +');
break;
case 'DATEDIFF':
$expression->add(['day' => 'literal'], [], true);
$hasDay = false;
$visitor = function($value) use (&$hasDay){
if ($value === 'day') {
$hasDay = true;
}
return $value;
};
$expression->iterateParts($visitor);

if (!$hasDay) {
$expression->add(['day' => 'literal'], [], true);
}
break;
case 'CURRENT_DATE':
$time = new FunctionExpression('GETUTCDATE');
Expand Down

0 comments on commit 21828e1

Please sign in to comment.