Fixing issues with DboSource::execute() where queries would not be run if stats = false in the options. Tests added.

This commit is contained in:
mark_story 2009-09-30 00:37:06 -04:00
parent 778a6b9303
commit 6dbba17d1b
2 changed files with 23 additions and 2 deletions

View file

@ -184,9 +184,9 @@ class DboSource extends DataSource {
$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 file

@ -3799,6 +3799,27 @@ class DboSourceTest extends CakeTestCase {
$this->testDb->error = $oldError;
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
*