cakephp2-php8/lib/Cake/View/Elements/sql_dump.ctp

83 lines
2.6 KiB
Text
Raw Normal View History

<?php
/**
2012-12-22 22:48:15 +00:00
* SQL Dump element. Dumps out SQL log information
*
2017-06-10 21:33:55 +00:00
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
2017-06-10 21:33:55 +00:00
* @link https://cakephp.org CakePHP(tm) Project
* @package Cake.View.Elements
* @since CakePHP(tm) v 1.3
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
if (!class_exists('ConnectionManager') || Configure::read('debug') < 2) {
return false;
}
$noLogs = !isset($sqlLogs);
if ($noLogs):
$sources = ConnectionManager::sourceList();
$sqlLogs = array();
foreach ($sources as $source):
$db = ConnectionManager::getDataSource($source);
if (!method_exists($db, 'getLog')):
continue;
endif;
$sqlLogs[$source] = $db->getLog();
endforeach;
endif;
if ($noLogs || isset($_forced_from_dbo_)):
foreach ($sqlLogs 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">',
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) :
$i += array('error' => '');
2012-02-10 01:00:25 +00:00
if (!empty($i['params']) && is_array($i['params'])) {
$bindParam = $bindType = null;
2012-02-10 01:00:25 +00:00
if (preg_match('/.+ :.+/', $i['query'])) {
$bindType = true;
}
2012-02-10 01:00:25 +00:00
foreach ($i['params'] as $bindKey => $bindVal) {
if ($bindType === true) {
$bindParam .= h($bindKey) . " => " . h($bindVal) . ", ";
} else {
$bindParam .= h($bindVal) . ", ";
}
}
$i['query'] .= " , params[ " . rtrim($bindParam, ', ') . " ]";
}
printf('<tr><td>%d</td><td>%s</td><td>%s</td><td style="text-align: right">%d</td><td style="text-align: right">%d</td><td style="text-align: right">%d</td></tr>%s',
$k + 1,
h($i['query']),
$i['error'],
$i['affected'],
$i['numRows'],
$i['took'],
"\n"
);
endforeach;
?>
</tbody></table>
<?php
endforeach;
else:
printf('<p>%s</p>', __d('cake_dev', 'Encountered unexpected %s. Cannot generate SQL log.', '$sqlLogs'));
endif;