Skip to content

Commit

Permalink
Update limit() for Sqlite.
Browse files Browse the repository at this point in the history
It should behave as the parent class does.
  • Loading branch information
markstory committed May 3, 2013
1 parent 7b0af65 commit 00569ea
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
8 changes: 2 additions & 6 deletions lib/Cake/Model/Datasource/Database/Sqlite.php
Expand Up @@ -377,13 +377,9 @@ public function fetchResult() {
*/
public function limit($limit, $offset = null) {
if ($limit) {
$rt = '';
if (!strpos(strtolower($limit), 'limit') || strpos(strtolower($limit), 'limit') === 0) {
$rt = ' LIMIT';
}
$rt .= ' ' . $limit;
$rt = sprintf(' LIMIT %u', $limit);
if ($offset) {
$rt .= ' OFFSET ' . $offset;
$rt .= sprintf(' OFFSET %u', $offset);
}
return $rt;
}
Expand Down
24 changes: 24 additions & 0 deletions lib/Cake/Test/Case/Model/Datasource/Database/SqliteTest.php
Expand Up @@ -473,4 +473,28 @@ public function testNestedTransaction() {
$this->assertNotEmpty($model->read(null, 1));
}

/**
* Test the limit function.
*
* @return void
*/
public function testLimit() {
$db = $this->Dbo;

$result = $db->limit('0');
$this->assertNull($result);

$result = $db->limit('10');
$this->assertEquals(' LIMIT 10', $result);

$result = $db->limit('FARTS', 'BOOGERS');
$this->assertEquals(' LIMIT 0 OFFSET 0', $result);

$result = $db->limit(20, 10);
$this->assertEquals(' LIMIT 20 OFFSET 10', $result);

$result = $db->limit(10, 300000000000000000000000000000);
$this->assertEquals(' LIMIT 10 OFFSET 0', $result);
}

}

0 comments on commit 00569ea

Please sign in to comment.