From c3331b6febe11230455ce0da5c3bf77381f44e6d Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Wed, 20 Apr 2016 01:33:09 +0100 Subject: [PATCH] Bed --- bin/dbq | 3 ++- etc/profile.d/git.sh | 13 +++++++++++ lib/php/db.php | 52 ++++++++++++++++++++++++++++++------------- lib/php/db/index.php | 6 ++--- lib/php/db/table.php | 8 +++---- lib/php/functions.php | 2 +- lib/php/nb.php | 5 +++-- lib/php/out.php | 2 +- 8 files changed, 64 insertions(+), 27 deletions(-) diff --git a/bin/dbq b/bin/dbq index be92e302..dfccd167 100755 --- 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/:(.*)$//; ################################################################################# # diff --git a/etc/profile.d/git.sh b/etc/profile.d/git.sh index e7e36f2c..efaa18ea 100644 --- a/etc/profile.d/git.sh +++ b/etc/profile.d/git.sh @@ -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 diff --git a/lib/php/db.php b/lib/php/db.php index 8a47b3f1..7d081420 100644 --- a/lib/php/db.php +++ b/lib/php/db.php @@ -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'))) { diff --git a/lib/php/db/index.php b/lib/php/db/index.php index 2ff262f0..78f33fce 100755 --- a/lib/php/db/index.php +++ b/lib/php/db/index.php @@ -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); ?> diff --git a/lib/php/db/table.php b/lib/php/db/table.php index c7f57fec..97c646b7 100644 --- a/lib/php/db/table.php +++ b/lib/php/db/table.php @@ -1,7 +1,7 @@ '; + $r .= ''; // Order By /* diff --git a/lib/php/functions.php b/lib/php/functions.php index 80718d28..a133f77b 100644 --- a/lib/php/functions.php +++ b/lib/php/functions.php @@ -1,5 +1,5 @@ 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"; } /* diff --git a/lib/php/out.php b/lib/php/out.php index ad31cef8..e3bddbf3 100644 --- a/lib/php/out.php +++ b/lib/php/out.php @@ -57,7 +57,7 @@ Class Out extends Nb { 'table' => array( 'is_html' => true, - 'enclose' => array("".NB_EOL,"
".NB_EOL), + 'enclose' => array("".NB_EOL,"
".NB_EOL), 'tag_enclose' => 'tr class="row"', 'tag_head' => 'th', 'tag' => 'td', -- 2.47.3