From fa0b146f67f4da7a3ab3ea88ad61e5b65a504fef Mon Sep 17 00:00:00 2001 From: David Grudl Date: Sat, 23 Jan 2010 05:25:17 +0100 Subject: [PATCH] DibiTranslator: empty arrays DO NOT generate NULL (BC break!) & added array modifier %in --- dibi/libs/DibiFluent.php | 2 +- dibi/libs/DibiTranslator.php | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/dibi/libs/DibiFluent.php b/dibi/libs/DibiFluent.php index bf6bbf3..dfbcdc6 100644 --- a/dibi/libs/DibiFluent.php +++ b/dibi/libs/DibiFluent.php @@ -33,7 +33,7 @@ class DibiFluent extends DibiObject implements IDataSource public static $modifiers = array( 'SELECT' => '%n', 'FROM' => '%n', - 'IN' => '%l', + 'IN' => '%in', 'VALUES' => '%l', 'SET' => '%a', 'WHERE' => '%and', diff --git a/dibi/libs/DibiTranslator.php b/dibi/libs/DibiTranslator.php index 46d092d..c3a472f 100644 --- a/dibi/libs/DibiTranslator.php +++ b/dibi/libs/DibiTranslator.php @@ -218,7 +218,7 @@ final class DibiTranslator extends DibiObject } else { $v = $this->formatValue($v, $pair[1]); - $vx[] = $k . ($pair[1] === 'l' ? 'IN ' : ($v === 'NULL' ? 'IS ' : '= ')) . $v; + $vx[] = $k . ($pair[1] === 'l' || $pair[1] === 'in' ? 'IN ' : ($v === 'NULL' ? 'IS ' : '= ')) . $v; } } else { @@ -248,12 +248,13 @@ final class DibiTranslator extends DibiObject return implode(', ', $vx); + case 'in':// replaces scalar %in modifier! case 'l': // (val, val, ...) foreach ($value as $k => $v) { $pair = explode('%', $k, 2); // split into identifier & modifier $vx[] = $this->formatValue($v, isset($pair[1]) ? $pair[1] : (is_array($v) ? 'ex' : FALSE)); } - return '(' . ($vx ? implode(', ', $vx) : 'NULL') . ')'; + return '(' . (($vx || $modifier === 'l') ? implode(', ', $vx) : 'NULL') . ')'; case 'v': // (key, key, ...) VALUES (val, val, ...) @@ -287,7 +288,7 @@ final class DibiTranslator extends DibiObject } } foreach ($vx as $k => $v) { - $vx[$k] = '(' . ($v ? implode(', ', $v) : 'NULL') . ')'; + $vx[$k] = '(' . implode(', ', $v) . ')'; } return '(' . implode(', ', $kx) . ') VALUES ' . implode(', ', $vx); @@ -313,7 +314,7 @@ final class DibiTranslator extends DibiObject foreach ($value as $v) { $vx[] = $this->formatValue($v, $modifier); } - return $vx ? implode(', ', $vx) : 'NULL'; + return implode(', ', $vx); } }