mirror of
https://github.com/dg/dibi.git
synced 2025-08-05 05:37:39 +02:00
- improved %and & %or modifiers behavior
- added %sql modifier for arrays (sub-translating)
This commit is contained in:
@@ -205,18 +205,16 @@ final class DibiTranslator extends DibiObject
|
|||||||
if (empty($value)) {
|
if (empty($value)) {
|
||||||
return '1';
|
return '1';
|
||||||
|
|
||||||
} elseif (!is_string(key($value))) {
|
} else foreach ($value as $k => $v) {
|
||||||
foreach ($value as $v) {
|
if (is_string($k)) {
|
||||||
$vx[] = $this->formatValue($v, 'sql');
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
foreach ($value as $k => $v) {
|
|
||||||
$pair = explode('%', $k, 2); // split into identifier & modifier
|
$pair = explode('%', $k, 2); // split into identifier & modifier
|
||||||
$k = $this->delimite($pair[0]);
|
$k = $this->delimite($pair[0]);
|
||||||
$v = $this->formatValue($v, isset($pair[1]) ? $pair[1] : FALSE);
|
$v = $this->formatValue($v, isset($pair[1]) ? $pair[1] : FALSE);
|
||||||
$op = isset($pair[1]) && $pair[1] === 'l' ? 'IN' : ($v === 'NULL' ? 'IS' : '=');
|
$op = isset($pair[1]) && $pair[1] === 'l' ? 'IN' : ($v === 'NULL' ? 'IS' : '=');
|
||||||
$vx[] = $k . ' ' . $op . ' ' . $v;
|
$vx[] = $k . ' ' . $op . ' ' . $v;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
$vx[] = $this->formatValue($v, 'sql');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return implode($operator, $vx);
|
return implode($operator, $vx);
|
||||||
@@ -257,6 +255,11 @@ final class DibiTranslator extends DibiObject
|
|||||||
}
|
}
|
||||||
return implode(', ', $vx);
|
return implode(', ', $vx);
|
||||||
|
|
||||||
|
case 'sql':
|
||||||
|
$translator = new self($this->driver);
|
||||||
|
$translator->translate($value);
|
||||||
|
return $translator->sql;
|
||||||
|
|
||||||
default: // value, value, value - all with the same modifier
|
default: // value, value, value - all with the same modifier
|
||||||
foreach ($value as $v) {
|
foreach ($value as $v) {
|
||||||
$vx[] = $this->formatValue($v, $modifier);
|
$vx[] = $this->formatValue($v, $modifier);
|
||||||
|
Reference in New Issue
Block a user