From: Nicolas Boisselier Date: Fri, 29 Jul 2016 14:49:54 +0000 (+0100) Subject: Fix bug X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=c0217794999a04d4a2128436f29611fba7780b98;p=nb.git Fix bug --- diff --git a/lib/php/db.php b/lib/php/db.php index be8b33ab..0995b908 100644 --- a/lib/php/db.php +++ b/lib/php/db.php @@ -370,7 +370,7 @@ class Db extends nb { array('[table.]rows','Dump one table, use format='), array('[table.]fields','List fields'), - array('table.inf','Table infos (count(*). Type, ...)'), + array('table.infos','Table infos (count(*). Type, ...)'), array('table.sql','Get the sql source'), array('[table.]insert','Insert a record'), @@ -395,6 +395,7 @@ class Db extends nb { $rows[] = $t->infos(); } + usort($rows,function($a,$b) { return strcmp($a['name'],$b['name']); }); $return = $this->out($rows); } elseif ($action == 'db.conf') { @@ -603,17 +604,13 @@ class Db extends nb { } # Table first - uasort($tables,function($a,$b) use($views){ + if (0) 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); @@ -622,6 +619,7 @@ class Db extends nb { if ($embed($a) and !$embed($b)) return +1; $diff = strlen($a->name) - strlen($b->name); if (!$diff) return strcmp($a->name,$b->name); +echo(">".$a->name."\n"); return ($diff>0 ? +1 : -1); return; if ($a->type != 'table') return ($embed($a) ? -1 : +1); diff --git a/lib/php/db/types/sqlite.php b/lib/php/db/types/sqlite.php index 44a81ebd..f44edd10 100644 --- a/lib/php/db/types/sqlite.php +++ b/lib/php/db/types/sqlite.php @@ -29,6 +29,7 @@ $DB_TYPES['sqlite'] = array ( 'ip2int' => function ($value) { return ip2long($value); }, 'concat' => function ($v1,$v2) { return $v1.$v2; }, 'date_format' => function ($date,$format) { return strftime($format,$date); }, + 'cidr_range' => function ( $cidr, $chkip=null ) { return nb::cidr_range( $cidr,$chkip); }, 'regexp' => function ($pattern, $data, $delimiter = '~', $modifiers = 'isuS') { if (isset($pattern, $data) === true) { return (preg_match(sprintf('%1$s%2$s%1$s%3$s', $delimiter, $pattern, $modifiers), $data) > 0); @@ -48,7 +49,8 @@ $DB_TYPES['sqlite'] = array ( ,2), ), -'tables' => 'SELECT name,type FROM sqlite_master WHERE type IN(\'table\',\'view\') AND name NOT LIKE \'sqlite_%\' ORDER BY name', +'tables' => "SELECT name,type FROM sqlite_master WHERE type IN('table','view') AND name NOT LIKE 'sqlite_%'", +#'tables' => 'SELECT name,type FROM sqlite_master WHERE type IN(\'table\',\'view\') AND name NOT LIKE \'sqlite_%\' ORDER BY name', 'table.fields' => array ( 'sql' => 'PRAGMA table_info(\'\')',