Skip to content

Commit

Permalink
Switched doctrine parameters to strings; Closes #447
Browse files Browse the repository at this point in the history
  • Loading branch information
juniwalk committed Mar 13, 2017
1 parent 3466a99 commit cd793e9
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions src/DataSource/DoctrineDataSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function getQuery()
*/
private function checkAliases($column)
{
if (Strings::contains($column, ".")) {
if (Strings::contains($column, '.')) {
return $column;
}

Expand Down Expand Up @@ -132,7 +132,7 @@ public function filterOne(array $condition)
foreach ($condition as $column => $value) {
$c = $this->checkAliases($column);

$this->data_source->andWhere("$c = ?$p")
$this->data_source->andWhere("$c = :$p")
->setParameter($p, $value);
}

Expand All @@ -153,9 +153,7 @@ public function applyFilterDate(Filter\FilterDate $filter)
$date = DateTimeHelper::tryConvertToDateTime($value, [$filter->getPhpFormat()]);
$c = $this->checkAliases($column);

$this->data_source
->andWhere("$c >= ?$p1")
->andWhere("$c <= ?$p2")
$this->data_source->andWhere("$c >= :$p1 AND $c <= :$p2")
->setParameter($p1, $date->format('Y-m-d 00:00:00'))
->setParameter($p2, $date->format('Y-m-d 23:59:59'));
}
Expand All @@ -180,7 +178,7 @@ public function applyFilterDateRange(Filter\FilterDateRange $filter)

$p = $this->getPlaceholder();

$this->data_source->andWhere("$c >= ?$p")->setParameter($p, $date_from->format('Y-m-d H:i:s'));
$this->data_source->andWhere("$c >= :$p")->setParameter($p, $date_from->format('Y-m-d H:i:s'));
}

if ($value_to) {
Expand All @@ -189,7 +187,7 @@ public function applyFilterDateRange(Filter\FilterDateRange $filter)

$p = $this->getPlaceholder();

$this->data_source->andWhere("$c <= ?$p")->setParameter($p, $date_to->format('Y-m-d H:i:s'));
$this->data_source->andWhere("$c <= :$p")->setParameter($p, $date_to->format('Y-m-d H:i:s'));
}
}

Expand All @@ -208,12 +206,12 @@ public function applyFilterRange(Filter\FilterRange $filter)

if ($value_from) {
$p = $this->getPlaceholder();
$this->data_source->andWhere("$c >= ?$p")->setParameter($p, $value_from);
$this->data_source->andWhere("$c >= :$p")->setParameter($p, $value_from);
}

if ($value_to) {
$p = $this->getPlaceholder();
$this->data_source->andWhere("$c <= ?$p")->setParameter($p, $value_to);
$this->data_source->andWhere("$c <= :$p")->setParameter($p, $value_to);
}
}

Expand All @@ -230,7 +228,7 @@ public function applyFilterText(Filter\FilterText $filter)
foreach ($condition as $column => $value) {
$c = $this->checkAliases($column);

if($filter->isExactSearch()){
if ($filter->isExactSearch()) {
$exprs[] = $this->data_source->expr()->eq($c, $this->data_source->expr()->literal($value));
continue;
}
Expand Down Expand Up @@ -262,7 +260,7 @@ public function applyFilterMultiSelect(Filter\FilterMultiSelect $filter)
$p = $this->getPlaceholder();

$values = $filter->getCondition()[$filter->getColumn()];
$expr = $this->data_source->expr()->in($c, '?'.$p);
$expr = $this->data_source->expr()->in($c, ':'.$p);

$this->data_source->andWhere($expr)->setParameter($p, $values);
}
Expand All @@ -279,7 +277,7 @@ public function applyFilterSelect(Filter\FilterSelect $filter)
foreach ($filter->getCondition() as $column => $value) {
$c = $this->checkAliases($column);

$this->data_source->andWhere("$c = ?$p")
$this->data_source->andWhere("$c = :$p")
->setParameter($p, $value);
}
}
Expand Down Expand Up @@ -341,7 +339,7 @@ public function sort(Sorting $sorting)
*/
public function getPlaceholder()
{
return $this->placeholder++;
return 'param'.($this->placeholder++);
}

}

0 comments on commit cd793e9

Please sign in to comment.