From 0a203f0de998824c0d0d8ac4433da80d8132b5d9 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Thu, 19 Mar 2020 19:13:04 +0100 Subject: [PATCH] SqlPreprocessor::formatValue() rejects array unless they are explicitly allowed (possible BC break) --- src/Database/SqlPreprocessor.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Database/SqlPreprocessor.php b/src/Database/SqlPreprocessor.php index 149fad67f..dcaad0ca1 100644 --- a/src/Database/SqlPreprocessor.php +++ b/src/Database/SqlPreprocessor.php @@ -194,7 +194,7 @@ private function formatValue($value, string $mode = null): string $value = iterator_to_array($value); } - if (is_array($value)) { + if ($mode && is_array($value)) { $vx = $kx = []; if ($mode === self::MODE_AUTO) { $mode = $this->arrayMode; @@ -229,7 +229,7 @@ private function formatValue($value, string $mode = null): string } elseif (!$mode || $mode === self::MODE_SET) { foreach ($value as $k => $v) { if (is_int($k)) { // value, value, ... OR (1, 2), (3, 4) - $vx[] = is_array($v) ? '(' . $this->formatValue($v) . ')' : $this->formatValue($v); + $vx[] = is_array($v) ? '(' . $this->formatValue($v, self::MODE_LIST) . ')' : $this->formatValue($v); } elseif (substr($k, -1) === '=') { // key+=value, key-=value, ... $k2 = $this->delimite(substr($k, 0, -2)); $vx[] = $k2 . '=' . $k2 . ' ' . substr($k, -2, 1) . ' ' . $this->formatValue($v); @@ -255,7 +255,7 @@ private function formatValue($value, string $mode = null): string $k = $this->delimite($k); if (is_array($v)) { if ($v) { - $vx[] = $k . ' ' . ($operator ? $operator . ' ' : '') . 'IN (' . $this->formatValue(array_values($v)) . ')'; + $vx[] = $k . ' ' . ($operator ? $operator . ' ' : '') . 'IN (' . $this->formatValue(array_values($v), self::MODE_LIST) . ')'; } elseif ($operator === 'NOT') { } else { $vx[] = '1=0';