mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
Merge pull request #2067 from chillu/pulls/sqlquery-zero-limit
BUG Accept $limit=0 in SQLQuery->setLimit()
This commit is contained in:
commit
c14b7997d6
@ -450,6 +450,7 @@ class SQLQuery {
|
||||
* Internally, limit will always be stored as a map containing the keys 'start' and 'limit'
|
||||
*
|
||||
* @param int|string|array $limit If passed as a string or array, assumes SQL escaped data.
|
||||
* Only applies for positive values, or if an $offset is set as well.
|
||||
* @param int $offset
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
@ -461,7 +462,7 @@ class SQLQuery {
|
||||
throw new InvalidArgumentException("SQLQuery::setLimit() only takes positive values");
|
||||
}
|
||||
|
||||
if($limit && is_numeric($limit)) {
|
||||
if(is_numeric($limit) && ($limit || $offset)) {
|
||||
$this->limit = array(
|
||||
'start' => $offset,
|
||||
'limit' => $limit,
|
||||
|
@ -138,6 +138,39 @@ class SQLQueryTest extends SapphireTest {
|
||||
$query->sql());
|
||||
}
|
||||
|
||||
public function testNullLimit() {
|
||||
$query = new SQLQuery();
|
||||
$query->setFrom("MyTable");
|
||||
$query->setLimit(null);
|
||||
|
||||
$this->assertEquals(
|
||||
'SELECT * FROM MyTable',
|
||||
$query->sql()
|
||||
);
|
||||
}
|
||||
|
||||
public function testZeroLimit() {
|
||||
$query = new SQLQuery();
|
||||
$query->setFrom("MyTable");
|
||||
$query->setLimit(0);
|
||||
|
||||
$this->assertEquals(
|
||||
'SELECT * FROM MyTable',
|
||||
$query->sql()
|
||||
);
|
||||
}
|
||||
|
||||
public function testZeroLimitWithOffset() {
|
||||
$query = new SQLQuery();
|
||||
$query->setFrom("MyTable");
|
||||
$query->setLimit(0, 99);
|
||||
|
||||
$this->assertEquals(
|
||||
'SELECT * FROM MyTable LIMIT 0 OFFSET 99',
|
||||
$query->sql()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException InvalidArgumentException
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user