Skip to content
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 #936

Merged
merged 1 commit into from Jun 4, 2020

Conversation

tmotyl
Copy link
Contributor

@tmotyl tmotyl commented Apr 24, 2020

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:

->where('attr_table.store_id IN (?)', $storeIds, Zend_Db::INT_TYPE);

and

->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)

Passing Zend_Db::INT_TYPE to where condition will prevent mysql performance
issues which might occur when mixed types are passed in "in()" condition.
related: #381

Also fixes type hints along the way.

Related PR on Magento2 side magento/magento2#27980

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)

Passing Zend_Db::INT_TYPE to where condition will prevent mysql performance
issues which might occur when mixed types are passed in "in()" condition.

Also fixes type hints along the way.
@sreichel sreichel self-requested a review May 19, 2020 06:49
@tmotyl
Copy link
Contributor Author

tmotyl commented Jun 4, 2020

FYI, it successfully went through the review in Magento 2.
I'm running this on prod since few weeks.

@colinmollenhour colinmollenhour merged commit 6531710 into OpenMage:1.9.4.x Jun 4, 2020
@sreichel sreichel added this to the Release 19.4.4 milestone Jun 26, 2020
edannenberg pushed a commit to edannenberg/magento-lts that referenced this pull request Aug 20, 2020
Fixes SQL query quoting/casting when type is passed to where function

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)

Passing Zend_Db::INT_TYPE to where condition will prevent mysql performance
issues which might occur when mixed types are passed in "in()" condition.

Also fixes type hints along the way.
edannenberg pushed a commit to edannenberg/magento-lts that referenced this pull request Aug 24, 2020
Fixes SQL query quoting/casting when type is passed to where function

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)

Passing Zend_Db::INT_TYPE to where condition will prevent mysql performance
issues which might occur when mixed types are passed in "in()" condition.

Also fixes type hints along the way.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants