Browse Source

Update limit() for Sqlite.

It should behave as the parent class does.
mark_story 13 years ago
parent
commit
00569ea405

+ 2 - 6
lib/Cake/Model/Datasource/Database/Sqlite.php

@@ -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;
 		}

+ 24 - 0
lib/Cake/Test/Case/Model/Datasource/Database/SqliteTest.php

@@ -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);
+	}
+
 }