Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed composite "in" condition on QueryBuilder
- Loading branch information
1 parent
b7f728b
commit dee1f4e
Showing
5 changed files
with
162 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
/** | ||
* @link http://www.yiiframework.com/ | ||
* @copyright Copyright (c) 2008 Yii Software LLC | ||
* @license http://www.yiiframework.com/license/ | ||
*/ | ||
|
||
namespace edgardmessias\db\firebird; | ||
|
||
use yii\db\Expression; | ||
use yii\db\ExpressionBuilderInterface; | ||
use yii\db\ExpressionBuilderTrait; | ||
use yii\db\ExpressionInterface; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
class ExpressionBuilder implements ExpressionBuilderInterface | ||
{ | ||
use ExpressionBuilderTrait; | ||
|
||
|
||
/** | ||
* {@inheritdoc} | ||
* @param Expression|ExpressionInterface $expression the expression to be built | ||
*/ | ||
public function build(ExpressionInterface $expression, array &$params = []) | ||
{ | ||
$params = array_merge($params, $expression->params); | ||
$string = $expression->__toString(); | ||
|
||
static $expressionMap = [ | ||
"strftime('%Y')" => "EXTRACT(YEAR FROM TIMESTAMP 'now')" | ||
]; | ||
|
||
if (isset($expressionMap[$string])) { | ||
return $expressionMap[$string]; | ||
} | ||
|
||
return $string; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
/** | ||
* @link http://www.yiiframework.com/ | ||
* @copyright Copyright (c) 2008 Yii Software LLC | ||
* @license http://www.yiiframework.com/license/ | ||
*/ | ||
|
||
namespace edgardmessias\db\firebird\conditions; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
class InConditionBuilder extends \yii\db\conditions\InConditionBuilder | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function buildCompositeInCondition($operator, $columns, $values, &$params) | ||
{ | ||
$quotedColumns = []; | ||
foreach ($columns as $i => $column) { | ||
$quotedColumns[$i] = strpos($column, '(') === false ? $this->queryBuilder->db->quoteColumnName($column) : $column; | ||
} | ||
$vss = []; | ||
foreach ($values as $value) { | ||
$vs = []; | ||
foreach ($columns as $i => $column) { | ||
if (isset($value[$column])) { | ||
$phName = $this->queryBuilder->bindParam($value[$column], $params); | ||
$vs[] = $quotedColumns[$i] . ($operator === 'IN' ? ' = ' : ' != ') . $phName; | ||
} else { | ||
$vs[] = $quotedColumns[$i] . ($operator === 'IN' ? ' IS' : ' IS NOT') . ' NULL'; | ||
} | ||
} | ||
$vss[] = '(' . implode($operator === 'IN' ? ' AND ' : ' OR ', $vs) . ')'; | ||
} | ||
|
||
return '(' . implode($operator === 'IN' ? ' OR ' : ' AND ', $vss) . ')'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters