Update limit() for Sqlite.

It should behave as the parent class does.
This commit is contained in:
mark_story 2013-05-02 23:25:13 -04:00
parent 7b0af659a9
commit 00569ea405
2 changed files with 26 additions and 6 deletions

View file

@ -377,13 +377,9 @@ class Sqlite extends DboSource {
*/
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;
}

View file

@ -473,4 +473,28 @@ class SqliteTest extends CakeTestCase {
$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);
}
}