Skip to content
Permalink
Browse files

Adding DboSource::getLog() and test case.

  • Loading branch information...
markstory committed Sep 2, 2009
1 parent 4ff668b commit c0a19ced14694830d8cf876973a8c48a0f2b6807
@@ -476,16 +476,27 @@ function hasResult() {
}
/**
* Outputs the contents of the queries log.
* Get the query log as an array.
*
* @param boolean $sorted
*/
function showLog($sorted = false) {
* @param boolean $sorted Get the queries sorted by time taken, defaults to false.
* @return array Array of queries run as an array
**/
function getLog($sorted = false) {
if ($sorted) {
$log = sortByKey($this->_queriesLog, 'took', 'desc', SORT_NUMERIC);
} else {
$log = $this->_queriesLog;
}
return $log;
}
/**
* Outputs the contents of the queries log.
*
* @param boolean $sorted Get the queries sorted by time taken, defaults to false
*/
function showLog($sorted = false) {
$log = $this->getLog($sorted);
if ($this->_queriesCnt > 1) {
$text = 'queries';
@@ -3620,11 +3620,11 @@ function testBuildColumn() {
function testHasAny() {
$this->testDb->hasAny($this->Model, array());
$expected = 'SELECT COUNT(`TestModel`.`id`) AS count FROM `test_models` AS `TestModel` WHERE 1 = 1';
$this->assertEqual($this->testDb->simulated[0], $expected);
$this->assertEqual($this->testDb->simulated[1], $expected);
$this->testDb->hasAny($this->Model, array('TestModel.name' => 'harry'));
$expected = "SELECT COUNT(`TestModel`.`id`) AS count FROM `test_models` AS `TestModel` WHERE `TestModel`.`name` = 'harry'";
$this->assertEqual($this->testDb->simulated[1], $expected);
$this->assertEqual($this->testDb->simulated[2], $expected);
}
/**
@@ -3969,6 +3969,30 @@ function testLog() {
Configure::write('debug', $oldDebug);
}
/**
* test getting the query log as an array.
*
* @return void
**/
function testGetLog() {
$this->testDb->logQuery('Query 1');
$this->testDb->logQuery('Query 2');
$oldError = $this->testDb->error;
$this->testDb->error = true;
$result = $this->testDb->logQuery('Error 1');
$this->assertFalse($result);
$this->testDb->error = $oldError;
$log = $this->testDb->getLog();
$expected = array('query' => 'Query 1', 'error' => '', 'affected' => '', 'numRows' => '', 'took' => '');
$this->assertEqual($log[0], $expected);
$expected = array('query' => 'Query 2', 'error' => '', 'affected' => '', 'numRows' => '', 'took' => '');
$this->assertEqual($log[1], $expected);
$expected = array('query' => 'Error 1', 'error' => true, 'affected' => '', 'numRows' => '', 'took' => '');
$this->assertEqual($log[2], $expected);
}
/**
* test ShowQuery generation of regular and error messages
*

0 comments on commit c0a19ce

Please sign in to comment.
You can’t perform that action at this time.