]> git.nbdom.net Git - nb.git/commitdiff
Fix bug
authorNicolas Boisselier <nicolas.boisselier@semantico.com>
Fri, 29 Jul 2016 14:49:54 +0000 (15:49 +0100)
committerNicolas Boisselier <nicolas.boisselier@semantico.com>
Fri, 29 Jul 2016 14:49:54 +0000 (15:49 +0100)
lib/php/db.php
lib/php/db/types/sqlite.php

index be8b33ab4123d990a35ca3f4884069d9103f0fb4..0995b908bb1a49ffb3b13aac3ea4ea9d290e7310 100644 (file)
@@ -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);
index 44a81ebd3d335b696d795caac67d65da511920d4..f44edd10d6afb79ff74169b2faaa31d215a0b32e 100644 (file)
@@ -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(\'<NAME>\')',