Extracting sql dump generation into a view element.

Changing the behavior of DboSource::getLog().
Adding sql dump element to layout.
This commit is contained in:
Mark Story 2009-12-03 22:41:31 -05:00
parent 3eaff3e021
commit cbb29dcc5d
3 changed files with 35 additions and 1 deletions

View file

@ -500,7 +500,7 @@ class DboSource extends DataSource {
} else {
$log = $this->_queriesLog;
}
return $log;
return array('log' => $log, 'count' => $this->_queriesCnt, 'time' => $this->_queriesTime);
}
/**
@ -509,6 +509,8 @@ class DboSource extends DataSource {
* @param boolean $sorted Get the queries sorted by time taken, defaults to false
*/
function showLog($sorted = false) {
return false;
$log = $this->getLog($sorted);
if ($this->_queriesCnt > 1) {

View file

@ -0,0 +1,31 @@
<?php
if (!class_exists('ConnectionManager') || Configure::read('debug') < 2) {
return false;
}
$sources = ConnectionManager::sourceList();
foreach ($sources as $source):
$db =& ConnectionManager::getDataSource($source);
if (!$db->isInterfaceSupported('getLog')) {
continue;
}
$logInfo = $db->getLog();
$text = $logInfo['count'] > 1 ? 'queries' : 'query';
printf(
'<table class="cake-sql-log" id="cakeSqlLog_%s" summary="Cake SQL Log" cellspacing="0" border = "0">',
preg_replace('/[^A-Za-z0-9_]/', '_', uniqid(time(), true))
);
printf('<caption>(%s) %s %s took %s ms</caption>', $source, $logInfo['count'], $text, $logInfo['time']);
?>
<thead>
<tr><th>Nr</th><th>Query</th><th>Error</th><th>Affected</th><th>Num. rows</th><th>Took (ms)</th></tr>
</thead>
<tbody>
<?php
foreach ($logInfo['log'] as $k => $i) :
echo "<tr><td>" . ($k + 1) . "</td><td>" . h($i['query']) . "</td><td>{$i['error']}</td><td style = \"text-align: right\">{$i['affected']}</td><td style = \"text-align: right\">{$i['numRows']}</td><td style = \"text-align: right\">{$i['took']}</td></tr>\n";
endforeach;
?>
</tbody></table>
<?php endforeach; ?>

View file

@ -55,5 +55,6 @@
</div>
</div>
<?php echo $cakeDebug; ?>
<?php echo $this->element('sql_dump'); ?>
</body>
</html>