mirror of
https://github.com/dg/dibi.git
synced 2025-08-05 13:47:33 +02:00
DibiResult: added simple dump in CLI mode
This commit is contained in:
@@ -636,37 +636,68 @@ class DibiResult extends DibiObject implements IDataSource
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Displays complete result set as HTML table for debug purposes.
|
* Displays complete result set as HTML or text table for debug purposes.
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
final public function dump()
|
final public function dump()
|
||||||
{
|
{
|
||||||
$i = 0;
|
$i = 0;
|
||||||
$this->seek(0);
|
$this->seek(0);
|
||||||
while ($row = $this->fetch()) {
|
if (PHP_SAPI === 'cli') {
|
||||||
if ($i === 0) {
|
$hasColors = (substr(getenv('TERM'), 0, 5) === 'xterm');
|
||||||
echo "\n<table class=\"dump\">\n<thead>\n\t<tr>\n\t\t<th>#row</th>\n";
|
$maxLen = 0;
|
||||||
|
while ($row = $this->fetch()) {
|
||||||
foreach ($row as $col => $foo) {
|
if ($i === 0) {
|
||||||
echo "\t\t<th>" . htmlSpecialChars($col) . "</th>\n";
|
foreach ($row as $col => $foo) {
|
||||||
|
$len = mb_strlen($col);
|
||||||
|
if ($len > $maxLen) $maxLen = $len;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
echo "\t</tr>\n</thead>\n<tbody>\n";
|
if ($hasColors) {
|
||||||
|
echo "\033[1;37m#row: $i\033[0m\n";
|
||||||
|
} else {
|
||||||
|
echo "#row: $i\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($row as $col => $val) {
|
||||||
|
$spaces = $maxLen - mb_strlen($col) + 2;
|
||||||
|
echo "$col" . str_repeat(" ", $spaces) . "$val\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "\n";
|
||||||
|
$i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
echo "\t<tr>\n\t\t<th>", $i, "</th>\n";
|
if ($i === 0) echo "empty result set\n";
|
||||||
foreach ($row as $col) {
|
echo "\n";
|
||||||
//if (is_object($col)) $col = $col->__toString();
|
|
||||||
echo "\t\t<td>", htmlSpecialChars($col), "</td>\n";
|
|
||||||
}
|
|
||||||
echo "\t</tr>\n";
|
|
||||||
$i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($i === 0) {
|
|
||||||
echo '<p><em>empty result set</em></p>';
|
|
||||||
} else {
|
} else {
|
||||||
echo "</tbody>\n</table>\n";
|
while ($row = $this->fetch()) {
|
||||||
|
if ($i === 0) {
|
||||||
|
echo "\n<table class=\"dump\">\n<thead>\n\t<tr>\n\t\t<th>#row</th>\n";
|
||||||
|
|
||||||
|
foreach ($row as $col => $foo) {
|
||||||
|
echo "\t\t<th>" . htmlSpecialChars($col) . "</th>\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "\t</tr>\n</thead>\n<tbody>\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "\t<tr>\n\t\t<th>", $i, "</th>\n";
|
||||||
|
foreach ($row as $col) {
|
||||||
|
//if (is_object($col)) $col = $col->__toString();
|
||||||
|
echo "\t\t<td>", htmlSpecialChars($col), "</td>\n";
|
||||||
|
}
|
||||||
|
echo "\t</tr>\n";
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($i === 0) {
|
||||||
|
echo '<p><em>empty result set</em></p>';
|
||||||
|
} else {
|
||||||
|
echo "</tbody>\n</table>\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user