1
0
mirror of https://github.com/dg/dibi.git synced 2025-02-23 10:26:21 +01:00

DibiTranslator: respect %if blocks for %lmt and %ofs as well [Closes #145][Closes #87]

This commit is contained in:
Martin Hradil 2014-08-26 23:29:17 +00:00 committed by David Grudl
parent 9189d56c05
commit d6826d62ed
2 changed files with 24 additions and 6 deletions

View File

@ -542,17 +542,23 @@ final class DibiTranslator extends DibiObject
return '';
} elseif ($mod === 'lmt') { // apply limit
if ($this->args[$cursor] !== NULL) {
$this->limit = (int) $this->args[$cursor];
$arg = $this->args[$cursor++];
if ($arg === NULL) {
} elseif ($this->comment) {
return "(limit $arg)";
} else {
$this->limit = (int) $arg;
}
$cursor++;
return '';
} elseif ($mod === 'ofs') { // apply offset
if ($this->args[$cursor] !== NULL) {
$this->offset = (int) $this->args[$cursor];
$arg = $this->args[$cursor++];
if ($arg === NULL) {
} elseif ($this->comment) {
return "(offset $arg)";
} else {
$this->offset = (int) $arg;
}
$cursor++;
return '';
} else { // default processing

View File

@ -74,3 +74,15 @@ WHERE
%if', FALSE, 'AND [admin]=1 %end
%else 1 LIMIT 10 %end'
));
// limit & offset
Assert::same(
'SELECT * FROM foo /* (limit 3) (offset 5) */',
$conn->translate(
'SELECT * FROM foo',
'%if', FALSE,
'%lmt', 3,
'%ofs', 5,
'%end'
));