* @return boolean Was the command executed successfully?
*/
public static function rollback() {
+ $ret = false;
+
switch (self::$driver) {
case 'pdo':
if (!self::$db->inTransaction()) {
$commands = [];
// Create a key for the loop prevention
- $key = $table . ':' . implode(':', array_keys($conditions)) . ':' . implode(':', $conditions);
+ $key = $table . ':' . json_encode($conditions);
// We quit when this key already exists in the callstack.
if (isset($callstack[$key])) {
$rel_def = array_values(self::$relation[$table])[0];
// Create a key for preventing double queries
- $qkey = $field . '-' . $table . ':' . implode(':', array_keys($conditions)) . ':' . implode(':', $conditions);
+ $qkey = $field . '-' . $table . ':' . json_encode($conditions);
// When the search field is the relation field, we don't need to fetch the rows
// This is useful when the leading record is already deleted in the frontend but the rest is done in the backend
// Split the SQL queries in chunks of 100 values
// We do the $i stuff here to make the code better readable
- $i = $counter[$key_table][$key_condition];
+ $i = isset($counter[$key_table][$key_condition]) ? $counter[$key_table][$key_condition] : 0;
if (isset($compacted[$key_table][$key_condition][$i]) && count($compacted[$key_table][$key_condition][$i]) > 100) {
++$i;
}
$condition_string .= " AND ";
}
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_float = false;
$is_alpha = false;
foreach ($value as $single_value) {
if (is_int($single_value)) {
$is_int = true;
- }
-
- // 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)) {
+ } else {
$is_alpha = true;
}
}
-
- // Cast them all in an unique method
- if ($is_int) {
- $casted = [];
- foreach ($value as $single_value) {
- if (!$is_alpha && !$is_float) {
- $casted[] = (int)$single_value;
- } else {
- $casted[] = (string)$single_value;
+
+ if ($is_int && $is_alpha) {
+ foreach ($value as &$ref) {
+ if (is_int($ref)) {
+ $ref = (string)$ref;
}
}
- $value = $casted;
+ unset($ref); //Prevent accidental re-use.
}
$new_values = array_merge($new_values, array_values($value));