]> git.nbdom.net Git - nb.git/commitdiff
putr back create table
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 6 Apr 2016 15:49:08 +0000 (17:49 +0200)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 6 Apr 2016 15:49:08 +0000 (17:49 +0200)
lib/php/db.php
lib/php/db/table.php

index cf32676caef5526279dd746bc3465470a489b9ad..ec39dfc6689e7465934e97499519f5026a4b1ab6 100644 (file)
@@ -703,6 +703,9 @@ EOF;
   public function fields($st) {
     # See: http://php.net/manual/en/pdostatement.getcolumnmeta.php
     $fields = array();
+    #debug($st->columnCount());
+    #debug($st->getColumnMeta(0));
+
     for ($i = 0; $i < $st->columnCount(); $i++) {
       $col = $st->getColumnMeta($i);
 
index c81045927797a82e512bafc9ea8973a9db109c5d..b5ef096b68c9d8164e99350be309c7742eb7d0fa 100644 (file)
@@ -82,11 +82,11 @@ Class Table extends nb {
     foreach ($opt as $k => $v) { $this->$k = $v; }
 
     // Name, could be a select
-    if (0 and stripos($this->name,'SELECT ')===0) {
+    if (DB_TABLE_QUERY_NAME and stripos($this->name,'SELECT ')===0) {
       #$temp = '_'.substr(md5($this->name),0,6);
       $temp = DB_TABLE_QUERY_NAME;
       #bye("CREATE TEMPORARY VIEW $temp AS $this->name");
-      $this->db()->conn->query("CREATE TEMPORARY TABLE $temp AS $this->name");
+      $this->db()->conn->query("CREATE TEMPORARY VIEW $temp AS $this->name");
       $this->name = $temp;
 
     } elseif (preg_match('/\b(\.import|LOAD DATA|COPY|INSERT|REPLACE|DELETE|TRUNCATE|CREATE|DROP|ALERT)\b/',$this->name)) {
@@ -162,6 +162,7 @@ Class Table extends nb {
       $this->fields = array();
       $conf = str_replace('<NAME>',$this->name,$this->db()->type('table.fields',true));
       if (is_scalar($conf)) $conf = array('sql'=>$conf);
+      #debug($conf);
       $rows = $this->db()->conn->query($conf['sql']);
       $rows->setFetchMode(PDO::FETCH_ASSOC);
 
@@ -586,9 +587,11 @@ Class Table extends nb {
     $st->execute();
 
     # Fields
-    $fields = array();
-    foreach ($this->db()->fields($st) as $f) { $fields[$f->name] = $f; }
-    $this->fields = $fields;
+    if (!DB_TABLE_QUERY_NAME) {
+      $fields = array();
+      foreach ($this->db()->fields($st) as $f) { $fields[$f->name] = $f; }
+      $this->fields = $fields;
+    }
     #debug($fields);
     #bye($this->name);
     if (!$this->p('action')) echo $this->html_menu();