Skip to content

Commit 2bb333a

Browse files
authored
Merge pull request #228 from matthieu-rolland/improve-sql
Cast criterion category/product IDs to integers before insert
2 parents c498099 + 24a14dd commit 2bb333a

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

src/Repository/ProductCommentCriterionRepository.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,13 @@ public function update(ProductCommentCriterion $criterion): int
154154
private function updateCategories($criterion): int
155155
{
156156
$res = 0;
157-
$criterionId = $criterion->getId();
157+
$criterionId = (int) $criterion->getId();
158158
foreach ($criterion->getCategories() as $id_category) {
159159
$res += $this->connection->executeUpdate(
160160
'INSERT INTO `' .
161161
_DB_PREFIX_ . 'product_comment_criterion_category` (`id_product_comment_criterion`, `id_category`)
162-
VALUES(' . $criterionId . ',' . $id_category . ')'
162+
VALUES(?, ?)',
163+
[$criterionId, (int) $id_category]
163164
);
164165
}
165166

@@ -169,12 +170,13 @@ private function updateCategories($criterion): int
169170
private function updateProducts($criterion): int
170171
{
171172
$res = 0;
172-
$criterionId = $criterion->getId();
173+
$criterionId = (int) $criterion->getId();
173174
foreach ($criterion->getProducts() as $id_product) {
174175
$res += $this->connection->executeUpdate(
175176
'INSERT INTO `' .
176177
_DB_PREFIX_ . 'product_comment_criterion_product` (`id_product_comment_criterion`, `id_product`)
177-
VALUES(' . $criterionId . ',' . $id_product . ')'
178+
VALUES(?, ?)',
179+
[$criterionId, (int) $id_product]
178180
);
179181
}
180182

0 commit comments

Comments
 (0)