Description
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:
- Make custom select like
$select->from(['catalog_product_entity'], '*')->where('entity_id in (?)', ['1', 2, 3], \Zend_Db::INT_TYPE);
- Check sql
$select->__toString()
Expected result (*)
SELECT catalog_product_entity
.* FROM catalog_product_entity
WHERE (entity_id in (1, 2, 3)
);
Actual result (*)
SELECT catalog_product_entity
.* FROM catalog_product_entity
WHERE (entity_id in ('1', 2, 3)
);
Questions or comments
Contribution checklist (*)
- Pull request has a meaningful description of its purpose
- All commits are accompanied by meaningful commit messages
- All new or changed code is covered with unit/integration tests (if applicable)
- All automated tests passed successfully (all builds are green)