Skip to content

Commit

Permalink
allow OFFSET even when LIMIT not specified. fixes #88.
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul M. Jones committed May 19, 2016
1 parent ddf3d54 commit 9f025db
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
5 changes: 5 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@
<directory>./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
</phpunit>
27 changes: 16 additions & 11 deletions src/AbstractQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -468,24 +468,29 @@ protected function buildOrderBy()
*
* Builds the `LIMIT ... OFFSET` clause of the statement.
*
* Note that this will allow OFFSET values with a LIMIT.
*
* @return string
*
*/
protected function buildLimit()
{
$has_limit = $this instanceof LimitInterface;
$has_offset = $this instanceof LimitOffsetInterface;
$clause = '';
$limit = $this instanceof LimitInterface && $this->limit;
$offset = $this instanceof LimitOffsetInterface && $this->offset;

if ($has_offset && $this->limit) {
$clause = PHP_EOL . "LIMIT {$this->limit}";
if ($this->offset) {
$clause .= " OFFSET {$this->offset}";
}
return $clause;
} elseif ($has_limit && $this->limit) {
return PHP_EOL . "LIMIT {$this->limit}";
if ($limit) {
$clause .= "LIMIT {$this->limit}";
}

if ($offset) {
$clause .= " OFFSET {$this->offset}";
}

if ($clause) {
$clause = PHP_EOL . trim($clause);
}

return ''; // not applicable
return $clause;
}
}

0 comments on commit 9f025db

Please sign in to comment.