]> git.nbdom.net Git - nb.git/commitdiff
rename db.stdin db.exec
authorNico Boisselier <nico@dhcp-192-168-4-150.semantico.net>
Thu, 27 Oct 2016 14:27:50 +0000 (15:27 +0100)
committerNico Boisselier <nico@dhcp-192-168-4-150.semantico.net>
Thu, 27 Oct 2016 14:27:50 +0000 (15:27 +0100)
lib/php/db.php
lib/php/db/table.php

index 4b0bdcb36b308a2d661ebdd780da8166cce66d47..209fad278fbb5a9414d7884d54b6f76777c50334 100644 (file)
@@ -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,
index 9457b55111c19bcf12c4cf6fdf39737a45696d8b..fd8741bb414a3f3d6abb0444c825527a5e268932 100644 (file)
@@ -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]);
     }