From 432996b88b8e3f791fc3882c13738cbebafe8553 Mon Sep 17 00:00:00 2001 From: Nico Boisselier Date: Thu, 27 Oct 2016 15:27:50 +0100 Subject: [PATCH] rename db.stdin db.exec --- lib/php/db.php | 22 +++++++++++++++++----- lib/php/db/table.php | 4 ++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/lib/php/db.php b/lib/php/db.php index 4b0bdcb3..209fad27 100644 --- a/lib/php/db.php +++ b/lib/php/db.php @@ -511,15 +511,27 @@ class Db extends nb { $this->out($available,['action','description']); $return = true; - } elseif ($action == 'db.stdin') { + } elseif ($action == 'db.exec') { $count = 0; - while ($line = fgets(STDIN)) { - $line = preg_replace('/^\s*(.*?)\s*;?\s*$/','$1',$line); - if (!$line or strpos($line,'--') === 0) continue; + $sql = ''; + + while (($line = fgets(STDIN)) !== false) { + if (feof(STDIN)) break; + + if (strpos($line,'--') === 0) continue; + + $line = preg_replace('/[\r\n]+$/','',$line); + $sql .= $line; + + if (!preg_match('/;$/',$sql)) continue; + #$line = preg_replace('/^\s*(.*?)\s*;?\s*$/','$1',$line); + #if (!$line or strpos($line,'--') === 0) continue; + $count++; #echo "$count> $line\n"; - $this->conn->exec($line); + $this->conn->exec($sql); + $sql = ''; } $return = $this->out([ 'count' => $count, diff --git a/lib/php/db/table.php b/lib/php/db/table.php index 9457b551..fd8741bb 100644 --- a/lib/php/db/table.php +++ b/lib/php/db/table.php @@ -1732,6 +1732,10 @@ Class Table extends nb { 'sql', ] as $k) { if (!self::p($k) or !empty($this->status[$k])) continue; + + # No count for view + if ($k == 'count' and $this->type != 'table') continue; + $this->status[$k] = $this->$k(); if (is_array($this->status[$k])) $this->status[$k] = count($this->status[$k]); } -- 2.47.3