From 215ce03802d813e1adaea134845bcefbb890dadb Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Wed, 9 Mar 2016 03:08:54 +0000 Subject: [PATCH] Bed --- lib/php/db.php | 24 ++++++++++++++++-------- lib/php/db/table.php | 2 +- lib/php/functions.php | 2 +- lib/php/out.php | 16 +++++++++++----- 4 files changed, 29 insertions(+), 15 deletions(-) diff --git a/lib/php/db.php b/lib/php/db.php index 17fd8d90..ae97db0b 100644 --- a/lib/php/db.php +++ b/lib/php/db.php @@ -536,13 +536,15 @@ EOF; function out2($rows,$head=array()) { #if (is_scalar($head)) bye(var_dump($head,true)); - if (is_scalar($head)) $head = array($head); - #var_dump($head); - #return; + if ($this->p('header') === '0' ) $head = false; - #self::bye($head); - #self::bye($this->p('header')); - #self::bye($this->p('format')); + elseif (is_scalar($head)) $head = array($head); +# NB 09.03.16 elseif (count($rows)) { +# NB 09.03.16 $first = self::ar_first($row); +# NB 09.03.16 #if (self::is_hash($first)) +# NB 09.03.16 $head = array($head); +# NB 09.03.16 } + out::rows($this->p('format','csv'),$rows,$head); return true; } @@ -573,16 +575,22 @@ EOF; return true; } elseif ($action == 'db.tables' or $action == 'tables') { + foreach ($this->tables(true) as $name => $t) { $row=array('name'=>$t['name']); - if ($this->p('count')==='1') $row['count'] = $this->table($name)->count(); foreach (array( 'type', + 'count', 'engine', 'created', - ) as $f) { if (isset($t[$f])) $row[$f] = $t[$f]; } + ) as $f) { + if (isset($t[$f])) $row[$f] = $t[$f]; + if ($f=='count' and $this->p('count')==='1') $row['count'] = $this->table($name)->count(); + } $rows[] = $row; } + return $this->out2($rows); + return $this->out2($rows,array_keys($row)); return $this->out2(array_values($this->tables(true))); return $this->out2($this->tables(),array('name')); diff --git a/lib/php/db/table.php b/lib/php/db/table.php index bd7e7afc..764a77f9 100644 --- a/lib/php/db/table.php +++ b/lib/php/db/table.php @@ -650,7 +650,7 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. # # Row # - if ($out_conf and $count !== 1) out::row_end($out_conf); + if ($out_conf and $count !== 1) out::concat($out_conf); $count_fields = 0; diff --git a/lib/php/functions.php b/lib/php/functions.php index 04045f07..26576cf7 100644 --- a/lib/php/functions.php +++ b/lib/php/functions.php @@ -154,7 +154,7 @@ function rtf2html($rtf) { } function html2pdf($html) { - $cmd="iconv -f utf-8 -t iso-8859-1 -c|htmldoc --encryption --webpage --no-title --header '...' --footer '...'"; + $cmd="iconv -f utf-8 -t iso-8859-1 -c|htmldoc --encryption --webpage --no-title --header '...' --footer '...' -"; $cmd .= " -t pdf -"; return cmd2str($cmd,$html); } diff --git a/lib/php/out.php b/lib/php/out.php index 51f3afef..ad9c2073 100644 --- a/lib/php/out.php +++ b/lib/php/out.php @@ -59,10 +59,16 @@ class Out extends Nb { if (!empty($o['enclose'])) echo $o['enclose'][0]; if (!isset($o['head'])) return; +#var_dump($head); return; if ($head === false) return; - if (empty($head) and self::is_hash($data[0])) { - $head = array_keys($data[0]); + if (empty($head)) { + if (self::is_hash($data[0])) { + $head = array_keys($data[0]); + } else { + return; + } } + echo $o['head']($head,$o) . empty($o['eol']) ? '' : $o['eol']; } @@ -84,7 +90,7 @@ class Out extends Nb { return false; } - public static function row_end($o) { + public static function concat($o) { if (!empty($o['rec'])) echo $o['rec']; if (!empty($o['eol'])) echo $o['eol']; } @@ -94,6 +100,7 @@ class Out extends Nb { } public static function rows($type,&$data,$head=array()) { + #if (empty($head)) $head = array_fill(0,count($data[0]),'?'); if (!isset(self::$types[$type])) self::bye("Unknow type: `$type`"); $conf = self::$types[$type]; @@ -113,7 +120,7 @@ class Out extends Nb { self::begin($conf,$head); foreach ($data as $row) { - if ($count>0) out::row_end($conf); + if ($count>0) out::concat($conf); $count++; # Transform simple array into hash @@ -166,7 +173,6 @@ function out_tag_head(&$data,$o) { $o['tag'] = isset($o['tag_head']) ? $o['tag_head'] : $o['tag']; $row = out::ar_first($data); if (!out::is_hash($row)) $row = $data; - #if (!is_array($row)) return out_csv(array_fill(0,count($row),'?')); if (!is_array($row)) return 0; if (out::is_hash($row)) $row = array_keys($row); echo out_tag($row,$o); -- 2.47.3