Skip to content

Commit

Permalink
SqlPreprocessor::formatValue() rejects array unless they are explicit…
Browse files Browse the repository at this point in the history
…ly allowed (possible BC break)
  • Loading branch information
dg committed Mar 27, 2020
1 parent 6c2a0a5 commit 0a203f0
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Database/SqlPreprocessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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';
Expand Down

0 comments on commit 0a203f0

Please sign in to comment.