Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

1.3 fix cache regex #492

Merged
merged 1 commit into from

2 participants

@dkullmann

...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

@dkullmann dkullmann 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>
47a8525
@markstory markstory merged commit 9efeea5 into cakephp:1.3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 18, 2012
  1. @dkullmann

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

    dkullmann authored
    …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>
This page is out of date. Refresh to see the latest.
View
2  cake/libs/model/datasources/dbo_source.php
@@ -420,7 +420,7 @@ function fetchAll($sql, $cache = true, $modelName = null) {
}
if ($cache) {
- if (strpos(trim(strtolower($sql)), 'select') !== false) {
+ if (preg_match('/^\s*select/i', $sql)) {
$this->_queryCache[$sql] = $out;
}
}
View
19 cake/tests/cases/libs/model/datasources/dbo_source.test.php
@@ -4251,6 +4251,25 @@ function testFetchAllBooleanReturns() {
}
/**
+ * test that query propery caches/doesn't cache selects
+ *
+ * @return void
+ * @author David Kullmann
+ */
+ function testFetchAllCaching() {
+ $query = "SELECT NOW() as TIME";
+ $result = $this->db->fetchAll($query);
+
+ $this->assertTrue(is_array($this->db->_queryCache[$query]));
+ $this->assertEqual($this->db->_queryCache[$query][0][0]['TIME'], $result[0][0]['TIME']);
+
+ $query = "DROP TABLE IF EXISTS select_test";
+ $result = $this->db->fetchAll($query);
+
+ $this->assertTrue(!isset($this->db->_queryCache[$query]));
+ }
+
+/**
* test ShowQuery generation of regular and error messages
*
* @return void
Something went wrong with that request. Please try again.