Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Extracting sql dump generation into a view element.

Changing the behavior of DboSource::getLog().
Adding sql dump element to layout.
  • Loading branch information...
commit cbb29dcc5d5599d41084ed3001e69d5169007f56 1 parent 3eaff3e
@markstory markstory authored
View
4 cake/libs/model/datasources/dbo_source.php
@@ -500,7 +500,7 @@ function getLog($sorted = false) {
} else {
$log = $this->_queriesLog;
}
- return $log;
+ return array('log' => $log, 'count' => $this->_queriesCnt, 'time' => $this->_queriesTime);
}
/**
@@ -509,6 +509,8 @@ function getLog($sorted = false) {
* @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
31 cake/libs/view/elements/sql_dump.ctp
@@ -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
1  cake/libs/view/layouts/default.ctp
@@ -55,5 +55,6 @@
</div>
</div>
<?php echo $cakeDebug; ?>
+ <?php echo $this->element('sql_dump'); ?>
</body>
</html>
Please sign in to comment.
Something went wrong with that request. Please try again.