[Issue] Fix SQL query quoting/casting when type is passed to where function #29590
Labels
Component: DB
Fixed in 2.4.x
The issue has been fixed in 2.4-develop branch
Issue: Confirmed
Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed
Issue: Format is valid
Gate 1 Passed. Automatic verification of issue format passed
Issue: Ready for Work
Gate 4. Acknowledged. Issue is added to backlog and ready for development
Priority: P3
May be fixed according to the position in the backlog.
Progress: done
Reproduced on 2.4.x
The issue has been reproduced on latest 2.4-develop branch
Severity: S4
Affects aesthetics, professional look and feel, “quality” or “usability”.
This issue is automatically created based on existing pull request: #27980: Fix SQL query quoting/casting when type is passed to where function
Framework/DB/Select where function doesn't handle the "type" correctly.
Preconditions (*)
The $type variable can be both string or int, so before comparing it to
'TYPE_CONDITION' string it has to be casted to avoid comparing integer zero
with string (0 == 'TYPE_CONDITION') which will wrongly return true,
and remove the information about type.
Pass type provided to where function down the chain to allow automatic
casting of arrays of values e.g. to int.
This fixes following cases:
1)
$select-->where('attr_table.store_id IN (?)', $storeIds, Zend_Db::INT_TYPE);
2)
$select-->where('attr_table.store_id = ?', $storeId, Zend_Db::INT_TYPE);
In both cases now passed value is correctly casted to int
(either single value, or each value from array)
Related Pull Requests
Fixed Issues (if relevant)
Steps to reproduce:
$select->from(['catalog_product_entity'], '*')->where('entity_id in (?)', ['1', 2, 3], \Zend_Db::INT_TYPE);
$select->__toString()
Expected result (*)
SELECT
catalog_product_entity
.* FROMcatalog_product_entity
WHERE (entity_id in(1, 2, 3)
);Actual result (*)
SELECT
catalog_product_entity
.* FROMcatalog_product_entity
WHERE (entity_id in('1', 2, 3)
);Questions or comments
Contribution checklist (*)
The text was updated successfully, but these errors were encountered: