Skip to content

Commit

Permalink
DibiTranslator: empty arrays DO NOT generate NULL (BC break!) & added…
Browse files Browse the repository at this point in the history
… array modifier %in
  • Loading branch information
dg authored and Majkl578 committed Jan 23, 2010
1 parent 0fcca77 commit e42df47
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion dibi/libs/DibiFluent.php
Expand Up @@ -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',
Expand Down
9 changes: 5 additions & 4 deletions dibi/libs/DibiTranslator.php
Expand Up @@ -218,7 +218,7 @@ public function formatValue($value, $modifier)

} 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 {
Expand Down Expand Up @@ -248,12 +248,13 @@ public function formatValue($value, $modifier)
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, ...)
Expand Down Expand Up @@ -287,7 +288,7 @@ public function formatValue($value, $modifier)
}
}
foreach ($vx as $k => $v) {
$vx[$k] = '(' . ($v ? implode(', ', $v) : 'NULL') . ')';
$vx[$k] = '(' . implode(', ', $v) . ')';
}
return '(' . implode(', ', $kx) . ') VALUES ' . implode(', ', $vx);

Expand All @@ -313,7 +314,7 @@ public function formatValue($value, $modifier)
foreach ($value as $v) {
$vx[] = $this->formatValue($v, $modifier);
}
return $vx ? implode(', ', $vx) : 'NULL';
return implode(', ', $vx);
}
}

Expand Down

0 comments on commit e42df47

Please sign in to comment.