Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixing issues with DboSource::execute() where queries would not be ru…

…n if stats = false in the options. Tests added.
  • Loading branch information...
commit 6dbba17d1b3a670c8e8a35ea1e28310343bb3db5 1 parent 778a6b9
@markstory markstory authored
View
4 cake/libs/model/datasources/dbo_source.php
@@ -184,9 +184,9 @@ function execute($sql, $options = array()) {
$defaults = array('stats' => true, 'log' => $this->fullDebug);
$options = array_merge($defaults, $options);
+ $t = getMicrotime();
+ $this->_result = $this->_execute($sql);
if ($options['stats']) {
- $t = getMicrotime();
- $this->_result = $this->_execute($sql);
$this->took = round((getMicrotime() - $t) * 1000, 0);
$this->affected = $this->lastAffected();
$this->error = $this->lastError();
View
21 cake/tests/cases/libs/model/datasources/dbo_source.test.php
@@ -3800,6 +3800,27 @@ function testLog() {
Configure::write('debug', $oldDebug);
}
/**
+ * test that execute runs queries.
+ *
+ * @return void
+ **/
+ function testExecute() {
+ $query = 'SELECT * FROM ' . $this->testDb->fullTableName('articles') . ' WHERE 1 = 1';
+
+ $this->db->_result = null;
+ $this->db->took = null;
+ $this->db->affected = null;
+ $result = $this->db->execute($query, array('stats' => false));
+ $this->assertNotNull($result, 'No query performed! %s');
+ $this->assertNull($this->db->took, 'Stats were set %s');
+ $this->assertNull($this->db->affected, 'Stats were set %s');
+
+ $result = $this->db->execute($query);
+ $this->assertNotNull($result, 'No query performed! %s');
+ $this->assertNotNull($this->db->took, 'Stats were not set %s');
+ $this->assertNotNull($this->db->affected, 'Stats were not set %s');
+ }
+/**
* test ShowQuery generation of regular and error messages
*
* @return void
Please sign in to comment.
Something went wrong with that request. Please try again.