From 8f8a2dd4508b881c95deec4c0b017d1a83cd2ae3 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Fri, 29 Jul 2016 11:43:48 +0100 Subject: [PATCH] db.dmp tables sort TODO --- lib/php/db.php | 14 ++++++++++++++ lib/php/db/table.php | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/php/db.php b/lib/php/db.php index df01896a..be8b33ab 100644 --- a/lib/php/db.php +++ b/lib/php/db.php @@ -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; diff --git a/lib/php/db/table.php b/lib/php/db/table.php index 2164017e..785b9e41 100644 --- a/lib/php/db/table.php +++ b/lib/php/db/table.php @@ -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)) { -- 2.47.3