-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix SQL query quoting/casting when type is passed to where function #27980
Fix SQL query quoting/casting when type is passed to where function #27980
Conversation
Hi @tmotyl. Thank you for your contribution
For more details, please, review the Magento Contributor Guide documentation. |
The test failures are unrelated to the change "MySQL server has gone away". Can somebody restart the tests? |
Related to #27129 as it also partically doing the same. |
@magento run all tests |
yes, I believe this patch is prerequisite to the other, as without it types for array are not interpreted correctly |
@magento run all tests |
hmm these test failures look unrelated to the change |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @tmotyl,
Please fix static tests. All others are passing now
@ihor-sviziev thanks for the review. The static tests are failing that the line
is too long. |
@tmotyl I think |
I can put mixed as it was before. Please make the decision, I will follow it. I do not want to spend too much time on secondary topic in this patch. |
@tmotyl ok, make sense. Could you try to import Expression and Select classes? I think it should fit the limit. If it will not fit - please use phpcs:ignore for specific lines |
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) ->where('attr_table.store_id IN (?)', $storeIds, Zend_Db::INT_TYPE); 2) ->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) Co-authored-by: Ihor Sviziev <ihor-sviziev@users.noreply.github.com>
thanks, done |
@magento run Static Tests |
✔️ QA Passed
before ✖️: after ✔️: |
Would like to add that basically the same changes were already added as part of #27129, so this PR will introduce phpdoc cleanup only. |
@magento run all tests |
@magento run all tests |
Hi @tmotyl, thank you for your contribution! |
Framework/DB/Select where function doesn't handle the "type" correctly.
Description (*)
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)
Manual testing scenarios (*)
$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 (*)
Resolved issues: