Skip to content
This repository
Browse code

Added test for caching of SELECTS, but, not other statements which ha…

…ve the word "select" somewhere in them

Examples include:

INSERT INTO … VALUES … ('Great selection!')
DROP TABLE IF EXISTS selection_table

Signed-off-by: David Kullmann <kullmann.david@gmail.com>
  • Loading branch information...
commit 47a8525ddd5512a6e130ce3eb48a6a09fe153f49 1 parent 9558943
David Kullmann authored February 18, 2012
2  cake/libs/model/datasources/dbo_source.php
@@ -420,7 +420,7 @@ function fetchAll($sql, $cache = true, $modelName = null) {
420 420
 			}
421 421
 
422 422
 			if ($cache) {
423  
-				if (strpos(trim(strtolower($sql)), 'select') !== false) {
  423
+				if (preg_match('/^\s*select/i', $sql)) {
424 424
 					$this->_queryCache[$sql] = $out;
425 425
 				}
426 426
 			}
19  cake/tests/cases/libs/model/datasources/dbo_source.test.php
@@ -4251,6 +4251,25 @@ function testFetchAllBooleanReturns() {
4251 4251
 	}
4252 4252
 
4253 4253
 /**
  4254
+ * test that query propery caches/doesn't cache selects
  4255
+ *
  4256
+ * @return void
  4257
+ * @author David Kullmann
  4258
+ */
  4259
+	function testFetchAllCaching() {
  4260
+		$query = "SELECT NOW() as TIME";
  4261
+		$result = $this->db->fetchAll($query);
  4262
+		
  4263
+		$this->assertTrue(is_array($this->db->_queryCache[$query]));
  4264
+		$this->assertEqual($this->db->_queryCache[$query][0][0]['TIME'], $result[0][0]['TIME']);
  4265
+
  4266
+		$query = "DROP TABLE IF EXISTS select_test";
  4267
+		$result = $this->db->fetchAll($query);
  4268
+		
  4269
+		$this->assertTrue(!isset($this->db->_queryCache[$query]));
  4270
+	}
  4271
+
  4272
+/**
4254 4273
  * test ShowQuery generation of regular and error messages
4255 4274
  *
4256 4275
  * @return void

0 notes on commit 47a8525

Please sign in to comment.
Something went wrong with that request. Please try again.