8000 Fix issues with HTML output · ratajs/SuperSQL@adc34fb · GitHub
[go: up one dir, main page]

Skip to content

Commit adc34fb

Browse files
committed
Fix issues with HTML output
1 parent 70a7a87 commit adc34fb

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

ssql.php

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,10 @@ public function getColumns() {
737737
};
738738
$columns[$i - 1] = new StdClass();
739739
$columns[$i - 1]->name = $meta['name'];
740-
$columns[$i - 1]->table = $meta['table'];
740+
if(isset($meta['table']))
741+
$columns[$i - 1]->table = $meta['table'];
742+
else
743+
$columns[$i - 1]->table = NULL;
741744
if(isset($meta['mysql:decl_type']))
742745
$columns[$i - 1]->type = strtoupper($meta['mysql:decl_type']);
743746
elseif(isset($meta['sqlite:decl_type'])) {
@@ -803,21 +806,28 @@ public function dump($limit = 256, bool $columntypes = true, bool $print = true)
803806
$tables = [];
804807
if($columns[0]) {
805808
foreach($columns as $k => $v) {
809+
if($v->table===NULL) {
810+
$tables = NULL;
811+
break;
812+
};
806813
if(!in_array($v->table, $tables))
807814
$tables[] = $v->table;
808815
};
809-
$h.= "<caption>";
810-
$h.= implode(", ", $tables);
811-
$h.= "</caption><tr>";
816+
if($tables!==NULL && count($tables) > 0) {
817+
$h.= "<caption>";
818+
$h.= implode(", ", $tables);
819+
$h.= "</caption>";
820+
};
821+
$h.= "<thead><tr>";
812822
};
813823
$i = 0;
814824
while($i++ < $this->columnCount) {
815825
$h.= "<th style=\"border: 1px solid black; padding: 5px; background-color: #ccf;\">";
816-
if(count($tables) > 1)
826+
if($tables!==NULL && count($tables) > 1)
817827
$h.= $columns[$i - 1]->table . ".";
818828
if($columns[$i - 1]) {
819829
$h.= $columns[$i - 1]->name;
820-
if($columntypes) {
830+
if($columntypes && $columns[$i - 1]->type!==NULL) {
821831
$h.= "<small style=\"opacity: .75\">&nbsp;&ndash;&nbsp;<em>";
822832
$h.= $columns[$i - 1]->type;
823833
$h.= "</em></small>";
@@ -836,7 +846,7 @@ public function dump($limit = 256, bool $columntypes = true, bool $print = true)
836846
$h.= $k;
837847
$h.= "</th>";
838848
};
839-
$h.= "</tr>";
849+
$h.= "</tr></thead>";
840850
};
841851
if(count($f)==0 && $this->columnCount + count($this->callbacks) > 0)
842852
$h.= "<tr><td colspan=\"" . $this->columnCount . "\" style=\"border: 1px solid black; padding: 5px;\"><em>No rows returned</em></td></tr>";
@@ -848,7 +858,7 @@ public function dump($limit = 256, bool $columntypes = true, bool $print = true)
848858
$h.= "<td style=\"border: 1px solid black; padding: 5px; text-align: center;\">" . ($val===NULL ? "<em>NULL</em>" : ($limit && (strlen($val) > $limit) ? "<em>Value longer than " . $limit . " bytes</em>" : ("<pre>" . (((!empty($columns[$i]) && $columns[$i]->type=="BLOB") || !preg_match("/^[\x{0020}-\x{007E}\x{00A0}-ſΑ-ωА-я‐- ⁰-₿℀-⋿①-⓿]*$/", $val)) ? ("<strong>HEX: </strong><em>" . bin2hex($val) . "</em>") : str_replace(["\n", "\r"], "", nl2br(htmlspecialchars($val, ENT_QUOTES, "UTF-8")))) . "</pre>"))) . "</td>";
849859
$i++;
850860
};
851-
$h.= "<tr>";
861+
$h.= "</tr>";
852862
};
853863
}
854864
else

0 commit comments

Comments
 (0)
0