]> git.nbdom.net Git - nb.git/commitdiff
Bed
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 20 Apr 2016 00:33:09 +0000 (01:33 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 20 Apr 2016 00:33:09 +0000 (01:33 +0100)
bin/dbq
etc/profile.d/git.sh
lib/php/db.php
lib/php/db/index.php
lib/php/db/table.php
lib/php/functions.php
lib/php/nb.php
lib/php/out.php

diff --git a/bin/dbq b/bin/dbq
index be92e302930f38800cefcb160189389e89337a54..dfccd1679cd82d3b80f7bbc95c9a20ef74f7d6c2 100755 (executable)
--- a/bin/dbq
+++ b/bin/dbq
@@ -152,7 +152,8 @@ while (my ($k,$v) = each %PARAM) {
   $keys{$k} = $v;
 }
 
-$keys{table} = $1 if $keys{db} and $keys{db} =~ s/:(.*)$//;
+# NB 19.04.16 use Data::Dumper; die Dumper(\%keys);
+# NB 19.04.16 $keys{table} = $1 if $keys{db} and $keys{db} =~ s/:(.*)$//;
 
 #################################################################################
 #
index e7e36f2c2f4d2ba8ace9f757137965a30e1eaacf..efaa18eae949a1510d7840b41c69f26996260b49 100644 (file)
@@ -5,6 +5,19 @@ alias git_grep="git grep --color=auto"
 alias git_ls_tree="git ls-tree --full-tree -r HEAD"
 alias git_ls_files="git ls-files"
 
+git_log_files() {
+  git log --pretty=format: --name-status
+}
+
+git_history_clean() {
+ git gc --prune=now --aggressive
+}
+
+git_cache_rm() {
+  echo "See: http://dalibornasevic.com/posts/2-permanently-remove-files-and-folders-from-a-git-repository"
+  echo git filter-branch --index-filter "git rm --cached --ignore-unmatch $@" --force --prune-empty -- --all
+}
+
 gitcd() {
   shell_help_noarg "Change directory to file's dirname\nUsage: $FUNCNAME GIT_ARGUMENTS" "$@" && return 1
   local i d dir args
index 8a47b3f1102c3b10a138230cae450378410c6752..7d081420b02edfe55a02fcc8bf2011d87cbe90b1 100644 (file)
@@ -6,10 +6,10 @@
   from any database
 
 *****************************************************************************/
-require_once(dirname(__FILE__).'/nb.php');
-require_once(dirname(__FILE__).'/out.php');
-require_once(dirname(__FILE__).'/db/table.php');
-require_once(dirname(__FILE__).'/db/field.php');
+require_once(realpath(dirname(__FILE__).'/nb.php'));
+require_once(realpath(dirname(__FILE__).'/out.php'));
+require_once(realpath(dirname(__FILE__).'/db/table.php'));
+require_once(realpath(dirname(__FILE__).'/db/field.php'));
 $DB_TYPES = array(); # See db/types/*.php
 
 class Db extends nb {
@@ -69,7 +69,8 @@ class Db extends nb {
     foreach(out::$types as $t=>$v) if (!in_array($t,$this->formats)) $this->formats[] = $t;
 
     # Pdo
-    $this->connect();
+    $this->connect_init();
+    if (empty($this->conn)) $this->connect();
 
     # Tables - Add missing infos
     if (!empty($tables)) {
@@ -84,9 +85,7 @@ class Db extends nb {
     return true;
   }
 
-       function connect($pdo=null) {
-
-    if ($pdo !== null) $this->pdo = $pdo;
+       function connect_init() {
     if (empty($this->pdo) and $this->type) $this->pdo = $this->type.':';
     if (empty($this->type)) $this->type = strtolower(preg_replace('/^([^:]+):.*$/','\1',$this->pdo));
 
@@ -95,6 +94,7 @@ class Db extends nb {
     if( !$this->type ) return false;
     if ($this->type('use_path')) {
       $this->file = preg_replace('/^\w+:/','',$this->pdo);
+      if ($p = $this->p('db.host')) $this->file = $p;
       $this->host = $this->file;
 
     } else {
@@ -133,6 +133,10 @@ class Db extends nb {
     # Title
     if (empty($this->title)) $this->title = prettyText($this->name);
 
+  }
+
+       function connect() {
+
     # Pdo
     if (empty($this->pdo)) return false;
 
@@ -331,6 +335,8 @@ class Db extends nb {
     if (isset($this->tables)) return $this->tables;
     $this->tables = array();
 
+#debug((array)$this->conn->query("SELECT name,type FROM sqlite_master WHERE type IN('table','view') AND name NOT LIKE 'sqlite_%' ORDER BY name",PDO::FETCH_ASSOC));
+#debug($this->type('tables',true));
     foreach ($this->conn->query($this->type('tables',true),PDO::FETCH_ASSOC) as $row) {
       $name = current($row);
       $this->tables[$name] = $this->table($name,$row);
@@ -391,9 +397,10 @@ EOF;
     return true;
   }
 
-  public function action($table=null) {
+  public function action($action,$table=null) {
     #if ($this->p('format') == 'table') $this->pset('format','');
-    $actions = explode(',',$this->p('action'));
+# NB 20.04.16     $actions = explode(',',$this->p('action'));
+    $actions = explode(',',$action);
     $this->pdef('format',($this->php_cli() ? 'csv' : ''));
     $rows = array();
     $return = false;
@@ -526,6 +533,14 @@ EOF;
 
     # Load databases
     $dbs = self::is_hash($conf) ? $conf : $Db->conf_dbs($conf);
+
+    # Check db=pdo
+    if (preg_match('/^\w+:/',$Db->p('db'))) {
+      $dbs[$Db->p('db')] = array(
+        'pdo' => $Db->p('db'),
+      );
+    }
+
     if (!$dbs) return false;
     #if (! ($dbs = $Db->conf_dbs($conf)) ) return false;
     #bye($dbs['nb']);
@@ -536,9 +551,12 @@ EOF;
       $Db->pset('db',$Db->ar_first($dbs,true));
     }
 
+    if (!isset($dbs[$Db->p('db')])) {
+      $Db->bye("Can't find db: `".$Db->p('db')."` in `".join(",",array_keys($dbs))."`",false);
+    }
+
     # Connection
     #bye($Db->p('db'));
-    if (!isset($dbs[$Db->p('db')])) $Db->bye("Can't find db: `".$Db->p('db')."` in `".join(",",array_keys($dbs))."`",false);
     $db = array_merge($dbs[$Db->p('db')],array(
       'dbs'=>array_keys($dbs),
       'conf'=>$dbs,
@@ -631,14 +649,18 @@ EOF;
     $status = $new = array();
 
     $new = array(
-      'host' => $this->host,
-      'port' => $this->port,
+      'type' => $this->type,
       'name' => $this->name,
-      'user' => $this->user,
+      'host' => $this->host,
       #'tables' => count($this->tables()),
       #'dbs' => count($this->dbs),
       'tables' => count($this->tables()),
-    )+$new;
+    )
+    +($this->type('use_path') ? array() : array(
+      'port' => $this->port,
+      'user' => $this->user,
+    ))
+    +$new;
 
     if (($sqls=$this->type('status'))) {
 
index 2ff262f04e5bfcb4ee21ae375a56c2dc9ecec3e6..78f33fcef144381cceb26aee7e1b1e0a3eb2f4b0 100755 (executable)
@@ -6,8 +6,8 @@
 *
 * lib/php/db/index.php
 */
-require_once(dirname(__FILE__).'/../config.php');
-require_once(dirname(__FILE__).'/../db.php');
+require_once(realpath(dirname(__FILE__).'/../config.php'));
+require_once(realpath(dirname(__FILE__).'/../db.php'));
 /*
 # TODO - NB 08.04.16
 */
@@ -37,5 +37,5 @@ if(defined('DB_NO_INIT') and DB_NO_INIT) return true;
 Db::init(array( Db::ROOT_DIR.'/etc/dbs.yaml',Db::ROOT_DIR.'/etc/dbs.php','/etc/dbs.yaml' ));
 
 if(defined('DB_NO_ACTION') and DB_NO_ACTION) return true;
-return $Db->action($Table);
+return $Db->action($Db->p('action'),$Table);
 ?>
index c7f57fecd8a50d1b67f77984d54cbb1a6fa7d48c..97c646b72519dbba90548810624cc46de51477cc 100644 (file)
@@ -1,7 +1,7 @@
 <?php
-require_once(dirname(__FILE__).'/../db.php');
-require_once(dirname(__FILE__).'/../db/field.php');
-require_once(dirname(__FILE__).'/../out.php');
+require_once(realpath(dirname(__FILE__).'/../db.php'));
+require_once(realpath(dirname(__FILE__).'/../db/field.php'));
+require_once(realpath(dirname(__FILE__).'/../out.php'));
 #$a = array('a','b','c'); $b = array('c','a'); debug(array_diff($a,$b));
 
 define('TABLE_INDENT',NB_EOL ? "\t" : "");
@@ -1402,7 +1402,7 @@ Class Table extends nb {
     }
 
     // Submit
-    $r .= '<input type="submit" class="button button-small" /><input type="reset" class="button button-small" />';
+    $r .= '<input type="submit" class="button button-small" value="GO"/>';
 
     // Order By
     /*
index 80718d2859a207de1cb507b04b4889ba56ddc6fb..a133f77b0d42085d0b979bb44b0e5728e7d99d7d 100644 (file)
@@ -1,5 +1,5 @@
 <?php
-require_once(dirname(__FILE__).'/nb.php');
+require_once(realpath(dirname(__FILE__).'/nb.php'));
 if (!defined('EOL')) define('EOL',NB_EOL);
 /*
 Vim:
index 917204617c85e4480a3fe2fe3c956d9d75bda910..d2820ad8245846bed7d579400aceda6c905f9e13 100644 (file)
@@ -3,9 +3,10 @@ if (!defined('NB_ROOT')) define('NB_ROOT',realpath(dirname(__FILE__).'/../..'));
 #die($_REQUEST['prod']);
 if (!defined('NB_EOL')) define('NB_EOL',defined('NB_PROD') ? '' : "\n");
 #if (!defined('NB_EOL')) define('NB_EOL',"\n");
-require_once(dirname(__FILE__).'/functions.php');
+require_once(realpath(dirname(__FILE__).'/functions.php'));
 #print_r(self::p());
 #$nb = new NB(); debug($nb->test());
+if (class_exists('NB')) return;
 class NB {
 
   const ROOT_DIR = NB_ROOT;
@@ -326,7 +327,7 @@ class NB {
       $msg .= ( $one_line ? ($preff !=='' ? $preff : ' | ') : "\n$preff " ) . self::debug_backtrace_info($call_info);
     }
 
-               return $msg;
+               return $msg."\n";
        }
 
   /*
index ad31cef8bbf50df74d096d6b89e656c354077df5..e3bddbf3102d2c85931a77023ae9f7ed9cceeb55 100644 (file)
@@ -57,7 +57,7 @@ Class Out extends Nb {
 
       'table' => array(
         'is_html' => true,
-        'enclose' => array("<table class=\"rows\">".NB_EOL,"</table>".NB_EOL),
+        'enclose' => array("<table class=\"rows wp-list-table widefat fixed striped\">".NB_EOL,"</table>".NB_EOL),
         'tag_enclose' => 'tr class="row"',
         'tag_head' => 'th',
         'tag' => 'td',