]> git.nbdom.net Git - nb.git/commitdiff
db.dmp tables sort TODO
authorNicolas Boisselier <nicolas.boisselier@semantico.com>
Fri, 29 Jul 2016 10:43:48 +0000 (11:43 +0100)
committerNicolas Boisselier <nicolas.boisselier@semantico.com>
Fri, 29 Jul 2016 10:43:48 +0000 (11:43 +0100)
lib/php/db.php
lib/php/db/table.php

index df01896aa8414acce71e11e3a00619e6a0499194..be8b33ab4123d990a35ca3f4884069d9103f0fb4 100644 (file)
@@ -605,11 +605,25 @@ class Db extends nb {
     # Table first
     uasort($tables,function($a,$b) use($views){
       #if ($a->type == 'table' and $b->type == 'table') return strcmp($a->name,$b->name);
+
       $embed = function($t) use($views) {
         return preg_match('/ FROM .*\b'.join('|',$views).'\b/',$t->sql()) ? 1 : 0;
       };
 
+      $cmp = function($t) use($views,$embed) {
+        #return preg_match('/ FROM .*\b'.join('|',$views).'\b/',$t->sql()) ? 1 : 0;
+      };
+
+      if ($a->type == 'table' and $b->type !='table') return -1;
+      if ($a->type != 'table' and $b->type =='table') return +1;
+      if ($a->type == 'table' and $b->type =='table') return strcmp($a->name,$b->name);
 
+      if (!$embed($a) and $embed($b)) return -1;
+      if ($embed($a) and !$embed($b)) return +1;
+      $diff = strlen($a->name) - strlen($b->name);
+      if (!$diff) return strcmp($a->name,$b->name);
+      return ($diff>0 ? +1 : -1);
+return;
       if ($a->type != 'table') return ($embed($a) ? -1 : +1);
       if ($b->type != 'table') return ($embed($b) ? -1 : +1);
       #if ($a->type == 'table') return +1;
index 2164017e3a0f439f477c9aa2201cd708bb8201ec..785b9e415dbd47378fe272df5b8692ac14a1bbc7 100644 (file)
@@ -99,7 +99,7 @@ Class Table extends nb {
     if (DB_TABLE_QUERY_NAME and stripos($this->name,'SELECT ')===0) {
       #$GLOBALS['DB_TABLE_QUERY_ID']++; $name = DB_TABLE_QUERY_NAME . $GLOBALS['DB_TABLE_QUERY_ID'];
       $this->db()->conn->query("CREATE TEMPORARY TABLE ".DB_TABLE_QUERY_NAME." AS $this->name");
-      $this->name = $name;
+      $this->name = DB_TABLE_QUERY_NAME;
 
     // Virtual Table
     } elseif (DB_TABLE_QUERY_NAME and !empty($this->sql)) {