mirror of
https://github.com/friendica/friendica
synced 2024-12-23 12:40:17 +00:00
Ensure IN() Conditions Never Mix Data Types
This commit is contained in:
parent
47ab72352e
commit
150989ba99
1 changed files with 13 additions and 21 deletions
|
@ -1299,37 +1299,29 @@ class dba {
|
||||||
$condition_string .= " AND ";
|
$condition_string .= " AND ";
|
||||||
}
|
}
|
||||||
if (is_array($value)) {
|
if (is_array($value)) {
|
||||||
// Check if there are integer values in the parameters
|
/**
|
||||||
|
* Workaround for MySQL Bug #64791.
|
||||||
|
* Never mix data types inside any IN() condition.
|
||||||
|
* In case of mixed types, cast all as string.
|
||||||
|
* Logic needs to be consistent with dba::p() data types.
|
||||||
|
*/
|
||||||
$is_int = false;
|
$is_int = false;
|
||||||
$is_float = false;
|
|
||||||
$is_alpha = false;
|
$is_alpha = false;
|
||||||
foreach ($value as $single_value) {
|
foreach ($value as $single_value) {
|
||||||
if (is_int($single_value)) {
|
if (is_int($single_value)) {
|
||||||
$is_int = true;
|
$is_int = true;
|
||||||
}
|
} else {
|
||||||
|
|
||||||
// To prevent to round floats we look for them
|
|
||||||
if (round($single_value) != (float)$single_value) {
|
|
||||||
$is_float = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Is any non numeric value present?
|
|
||||||
if (!is_numeric($single_value)) {
|
|
||||||
$is_alpha = true;
|
$is_alpha = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cast them all in an unique method
|
if ($is_int && $is_alpha) {
|
||||||
if ($is_int) {
|
foreach ($value as &$ref) {
|
||||||
$casted = [];
|
if (is_int($ref)) {
|
||||||
foreach ($value as $single_value) {
|
$ref = (string)$ref;
|
||||||
if (!$is_alpha && !$is_float) {
|
|
||||||
$casted[] = (int)$single_value;
|
|
||||||
} else {
|
|
||||||
$casted[] = (string)$single_value;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$value = $casted;
|
unset($ref); //Prevent accidental re-use.
|
||||||
}
|
}
|
||||||
|
|
||||||
$new_values = array_merge($new_values, array_values($value));
|
$new_values = array_merge($new_values, array_values($value));
|
||||||
|
|
Loading…
Reference in a new issue