2009-12-04 03:41:31 +00:00
|
|
|
<?php
|
2009-12-19 18:24:00 +00:00
|
|
|
/**
|
2012-12-22 22:48:15 +00:00
|
|
|
* SQL Dump element. Dumps out SQL log information
|
2009-12-19 18:24:00 +00:00
|
|
|
*
|
2010-10-03 16:38:58 +00:00
|
|
|
* PHP 5
|
2009-12-19 18:24:00 +00:00
|
|
|
*
|
|
|
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
2013-02-08 11:59:49 +00:00
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2009-12-19 18:24:00 +00:00
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
2013-02-08 12:22:51 +00:00
|
|
|
* For full copyright and license information, please see the LICENSE.txt
|
2009-12-19 18:24:00 +00:00
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2013-02-08 11:59:49 +00:00
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2009-12-19 18:24:00 +00:00
|
|
|
* @link http://cakephp.org CakePHP(tm) Project
|
2011-10-15 18:17:44 +00:00
|
|
|
* @package Cake.View.Elements
|
2009-12-19 18:24:00 +00:00
|
|
|
* @since CakePHP(tm) v 1.3
|
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
|
|
|
*/
|
|
|
|
if (!class_exists('ConnectionManager') || Configure::read('debug') < 2) {
|
2009-12-04 03:41:31 +00:00
|
|
|
return false;
|
|
|
|
}
|
2010-08-27 01:24:09 +00:00
|
|
|
$noLogs = !isset($logs);
|
|
|
|
if ($noLogs):
|
2010-08-11 03:09:27 +00:00
|
|
|
$sources = ConnectionManager::sourceList();
|
|
|
|
|
2009-12-04 04:29:28 +00:00
|
|
|
$logs = array();
|
|
|
|
foreach ($sources as $source):
|
2011-04-29 15:49:33 +00:00
|
|
|
$db = ConnectionManager::getDataSource($source);
|
2011-02-25 01:51:43 +00:00
|
|
|
if (!method_exists($db, 'getLog')):
|
2009-12-04 04:29:28 +00:00
|
|
|
continue;
|
|
|
|
endif;
|
|
|
|
$logs[$source] = $db->getLog();
|
|
|
|
endforeach;
|
2010-08-27 01:24:09 +00:00
|
|
|
endif;
|
2009-12-04 04:29:28 +00:00
|
|
|
|
2010-08-27 01:24:09 +00:00
|
|
|
if ($noLogs || isset($_forced_from_dbo_)):
|
2010-08-11 03:09:27 +00:00
|
|
|
foreach ($logs as $source => $logInfo):
|
|
|
|
$text = $logInfo['count'] > 1 ? 'queries' : 'query';
|
|
|
|
printf(
|
2012-02-10 01:00:25 +00:00
|
|
|
'<table class="cake-sql-log" id="cakeSqlLog_%s" summary="Cake SQL Log" cellspacing="0">',
|
2010-08-11 03:09:27 +00:00
|
|
|
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) :
|
2011-09-03 16:47:00 +00:00
|
|
|
$i += array('error' => '');
|
2012-02-10 01:00:25 +00:00
|
|
|
if (!empty($i['params']) && is_array($i['params'])) {
|
2012-02-04 02:21:06 +00:00
|
|
|
$bindParam = $bindType = null;
|
2012-02-10 01:00:25 +00:00
|
|
|
if (preg_match('/.+ :.+/', $i['query'])) {
|
2012-02-04 02:21:06 +00:00
|
|
|
$bindType = true;
|
|
|
|
}
|
2012-02-10 01:00:25 +00:00
|
|
|
foreach ($i['params'] as $bindKey => $bindVal) {
|
|
|
|
if ($bindType === true) {
|
2012-02-04 02:21:06 +00:00
|
|
|
$bindParam .= h($bindKey) ." => " . h($bindVal) . ", ";
|
|
|
|
} else {
|
|
|
|
$bindParam .= h($bindVal) . ", ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$i['query'] .= " , params[ " . rtrim($bindParam, ', ') . " ]";
|
|
|
|
}
|
2010-08-11 03:09:27 +00:00
|
|
|
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>
|
2011-10-28 05:01:17 +00:00
|
|
|
<?php
|
2010-08-27 01:24:09 +00:00
|
|
|
endforeach;
|
|
|
|
else:
|
|
|
|
echo '<p>Encountered unexpected $logs cannot generate SQL log</p>';
|
2010-08-11 03:09:27 +00:00
|
|
|
endif;
|