1
1
Fork 0

Add support for empty values array in Database\DBA

This commit is contained in:
Hypolite Petovan 2019-12-24 16:21:00 -05:00
parent 2056e6a5c4
commit 9c9e07dbab

View file

@ -543,33 +543,38 @@ class DBA extends BaseObject
$condition_string .= " AND "; $condition_string .= " AND ";
} }
if (is_array($value)) { if (is_array($value)) {
/* Workaround for MySQL Bug #64791. if (count($value)) {
* Never mix data types inside any IN() condition. /* Workaround for MySQL Bug #64791.
* In case of mixed types, cast all as string. * Never mix data types inside any IN() condition.
* Logic needs to be consistent with DBA::p() data types. * In case of mixed types, cast all as string.
*/ * Logic needs to be consistent with DBA::p() data types.
$is_int = false; */
$is_alpha = false; $is_int = false;
foreach ($value as $single_value) { $is_alpha = false;
if (is_int($single_value)) { foreach ($value as $single_value) {
$is_int = true; if (is_int($single_value)) {
} else { $is_int = true;
$is_alpha = true; } else {
} $is_alpha = true;
}
if ($is_int && $is_alpha) {
foreach ($value as &$ref) {
if (is_int($ref)) {
$ref = (string)$ref;
} }
} }
unset($ref); //Prevent accidental re-use.
}
$new_values = array_merge($new_values, array_values($value)); if ($is_int && $is_alpha) {
$placeholders = substr(str_repeat("?, ", count($value)), 0, -2); foreach ($value as &$ref) {
$condition_string .= self::quoteIdentifier($field) . " IN (" . $placeholders . ")"; if (is_int($ref)) {
$ref = (string)$ref;
}
}
unset($ref); //Prevent accidental re-use.
}
$new_values = array_merge($new_values, array_values($value));
$placeholders = substr(str_repeat("?, ", count($value)), 0, -2);
$condition_string .= self::quoteIdentifier($field) . " IN (" . $placeholders . ")";
} else {
// Empty value array isn't supported by IN and is logically equivalent to no match
$condition_string .= "FALSE";
}
} elseif (is_null($value)) { } elseif (is_null($value)) {
$condition_string .= self::quoteIdentifier($field) . " IS NULL"; $condition_string .= self::quoteIdentifier($field) . " IS NULL";
} else { } else {