From f4ae1e692f285022eaa4d978fa73452890b54efa Mon Sep 17 00:00:00 2001 From: castamir Date: Wed, 7 Oct 2015 16:38:35 +0200 Subject: [PATCH] DibiFluent::fetch(): fixed limit clause duplication [Closes #188][Closes #186][Closes #185] --- dibi/libs/DibiFluent.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/dibi/libs/DibiFluent.php b/dibi/libs/DibiFluent.php index 306dadf0..c2546930 100644 --- a/dibi/libs/DibiFluent.php +++ b/dibi/libs/DibiFluent.php @@ -316,11 +316,12 @@ class DibiFluent extends DibiObject implements IDataSource */ public function fetch() { - if ($this->command === 'SELECT') { - return $this->query($this->_export(NULL, array('%lmt', 1)))->fetch(); - } else { - return $this->query($this->_export())->fetch(); + if ($this->command === 'SELECT' && !$this->clauses['LIMIT']) { + $result = $this->query($this->limit(1)->_export())->fetch(); + $this->removeClause('LIMIT'); + return $result; } + return $this->query($this->_export())->fetch(); } @@ -330,11 +331,12 @@ class DibiFluent extends DibiObject implements IDataSource */ public function fetchSingle() { - if ($this->command === 'SELECT') { - return $this->query($this->_export(NULL, array('%lmt', 1)))->fetchSingle(); - } else { - return $this->query($this->_export())->fetchSingle(); + if ($this->command === 'SELECT' && !$this->clauses['LIMIT']) { + $result = $this->query($this->limit(1)->_export())->fetchSingle(); + $this->removeClause('LIMIT'); + return $result; } + return $this->query($this->_export())->fetchSingle(); }