Skip to content

Commit bc31c0c

Browse files
committed
Improved id concatenation in the sql
1 parent 37f76dc commit bc31c0c

1 file changed

Lines changed: 24 additions & 3 deletions

File tree

src/BenGorFile/File/Infrastructure/Persistence/Sql/SqlListOfIdsSpecification.php

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ public function buildCount()
4949

5050
private function buildWhere()
5151
{
52-
$whereClause = !empty($this->ids) ? 'WHERE f.id IN (:ids) ' : '';
52+
$inString = $this->generateInString($this->ids);
53+
$whereClause = !empty($this->ids) ? 'WHERE f.id IN (' . $inString . ') ' : '';
5354

5455
return $whereClause;
5556
}
@@ -64,8 +65,8 @@ private function buildLimit()
6465
private function buildParameters()
6566
{
6667
$parameters = [];
67-
if (!empty($this->name)) {
68-
$parameters = array_merge([':ids' => implode(',', $this->ids)], $parameters);
68+
if (!empty($this->ids)) {
69+
$parameters = array_merge($this->generateInParameters($this->ids), $parameters);
6970
}
7071

7172
if ($this->limit > 0) {
@@ -74,4 +75,24 @@ private function buildParameters()
7475

7576
return $parameters;
7677
}
78+
79+
private function generateInString(array $ids)
80+
{
81+
$in = '';
82+
foreach ($ids as $i => $item) {
83+
$in .= ":id$i,";
84+
}
85+
86+
return rtrim($in, ',');
87+
}
88+
89+
private function generateInParameters(array $ids)
90+
{
91+
$productVariantIdParams = [];
92+
foreach ($ids as $i => $item) {
93+
$productVariantIdParams[":id$i"] = $item;
94+
}
95+
96+
return $productVariantIdParams;
97+
}
7798
}

0 commit comments

Comments
 (0)