From d6826d62ed99665ffa1df89c9ff1aeec8759f657 Mon Sep 17 00:00:00 2001 From: Martin Hradil Date: Tue, 26 Aug 2014 23:29:17 +0000 Subject: [PATCH] DibiTranslator: respect %if blocks for %lmt and %ofs as well [Closes #145][Closes #87] --- dibi/libs/DibiTranslator.php | 18 ++++++++++++------ tests/dibi/DibiTranslator.conditions.phpt | 12 ++++++++++++ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/dibi/libs/DibiTranslator.php b/dibi/libs/DibiTranslator.php index 77c1ddf..235a9ec 100644 --- a/dibi/libs/DibiTranslator.php +++ b/dibi/libs/DibiTranslator.php @@ -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 diff --git a/tests/dibi/DibiTranslator.conditions.phpt b/tests/dibi/DibiTranslator.conditions.phpt index 364a07c..8024f70 100644 --- a/tests/dibi/DibiTranslator.conditions.phpt +++ b/tests/dibi/DibiTranslator.conditions.phpt @@ -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' +));