Skip to content

Commit

Permalink
Cleaned up the code. Identical to MySQL code. No functional change.
Browse files Browse the repository at this point in the history
  • Loading branch information
kadishmal committed Feb 13, 2012
1 parent 0e4fdbd commit 546343f
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions system/database/drivers/cubrid/cubrid_driver.php
Expand Up @@ -660,8 +660,6 @@ function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
function _update_batch($table, $values, $index, $where = NULL)
{
$ids = array();
$where = ($where != '' AND count($where) >=1) ? implode(" ", $where).' AND ' : '';

foreach ($values as $key => $val)
{
$ids[] = $val[$index];
Expand All @@ -670,30 +668,22 @@ function _update_batch($table, $values, $index, $where = NULL)
{
if ($field != $index)
{
$final[$field][] = 'WHEN '.$index.' = '.$val[$index].' THEN '.$val[$field];
$final[$field][] = 'WHEN '.$index.' = '.$val[$index].' THEN '.$val[$field];
}
}
}

$sql = "UPDATE ".$table." SET ";
$cases = '';

foreach ($final as $k => $v)
{
$cases .= $k.' = CASE '."\n";
foreach ($v as $row)
{
$cases .= $row."\n";
}

$cases .= 'ELSE '.$k.' END, ';
$cases .= $k." = CASE \n"
.implode("\n", $v)."\n"
.'ELSE '.$k.' END, ';
}

$sql .= substr($cases, 0, -2);

$sql .= ' WHERE '.$where.$index.' IN ('.implode(',', $ids).')';

return $sql;
return 'UPDATE '.$table.' SET '.substr($cases, 0, -2)
.' WHERE '.(($where != '' && count($where) > 0) ? implode(' ', $where).' AND ' : '')
.$index.' IN('.implode(',', $ids).')';
}

// --------------------------------------------------------------------
Expand Down

0 comments on commit 546343f

Please sign in to comment.