From: Nicolas Boisselier Date: Mon, 29 Feb 2016 01:44:28 +0000 (+0000) Subject: nb::ar_map and function out() format csv X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=8883f9dfb2f325723dade4320a63a0a0a2c1eb9f;p=nb.git nb::ar_map and function out() format csv --- diff --git a/lib/php/db.php b/lib/php/db.php index 52e6467e..552caa7a 100644 --- a/lib/php/db.php +++ b/lib/php/db.php @@ -373,6 +373,18 @@ EOF; #echo $v.PHP_EOL; #bye($f); return true; if ($f == 'json') { echo json_encode($v).PHP_EOL; } + #elseif ($f == 'csv' and is_array($v)) { echo join("\n",$v)."\n"; } + #elseif ($f == 'csv') { echo join("\t",nb::ar_map('json_encode($a)',$v))."\n"; } + #elseif ($f == 'csv') { echo json_encode($v).PHP_EOL; } + elseif ($f == 'csv') { + #if (is_object($row)) echo "$row\n"; + #$isHash = array_values($v) !== $v; + foreach ($v as $row) { + if (is_scalar($row)) echo "$row\n"; + else echo join("\t",array_values($row))."\n"; + } + #echo json_encode($v).PHP_EOL; + } elseif (preg_match('/yaml|yml/',$f)) { echo $this->yaml_encode($v); } elseif (preg_match('/php|var_export/',$f)) { echo var_export($v,true); } elseif (preg_match('/var_dump/',$f)) { echo var_dump($v,true); } @@ -391,6 +403,9 @@ EOF; if ($action == 'tables') { return $this->out($this->tables()); + } elseif ($action == 'dbs') { + return $this->out($this->dbs); + } elseif ($action == 'html_menu') { $this->print_header($this->p('format','html')); echo $this->html_menu(); diff --git a/lib/php/nb.php b/lib/php/nb.php index 77292b91..ca02fba1 100644 --- a/lib/php/nb.php +++ b/lib/php/nb.php @@ -60,6 +60,14 @@ class nb { return debug($msg,$level); } + /* + * Function: ar_map + * Does what it says + */ + static function ar_map($text) { + return ar_map($text); + } + /* * Function: prettyText * Does what it says