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;
}
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'));
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'];
}
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'];
}
}
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];
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
$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);