fi
#[ "$1" = "TEST" ] &&
dest=$(url2nc "$dest")
- #dest="$dest 22"
local ok
case "$_git_conn_check" in
*/
public function table($name,$params=[]) {
#if (!array_key_exists($name,$this->tables)) {
+ if (!$name) bye('empty name');
if (empty($this->tables[$name])) {
$this->tables[$name] = new Table($name,['db'=>$this]+$params);
} elseif ($params) {
foreach ($this->conn->query($sql,PDO::FETCH_ASSOC) as $row) {
#debug($row);
$name = current($row);
- $t = $this->table($name,$row+['status'=>$row]);
+ $this->table($name,$row+['status'=>$row]); # add to this->tables too !
}
}
* @param [FILES] $files Files to load
* @return ARRAY the new/existing value of $this->db
*/
- public static function conf_dbs($files=[],&$first=false) {
+ public static function conf_load($files=[],&$first=false) {
if (empty($files)) return [];
# Load all files into a $h if #files is not a hash
}
unset($yaml,$CONF);
+ if (!$h) return false;
# Emulate hash pointer _import
foreach ($h as $db=>$o) {
$id = self::p('db');
# Load databases
- $conf = self::is_hash($conf) ? $conf : self::conf_dbs($conf);
+ $conf = self::is_hash($conf) ? $conf : self::conf_load($conf);
# Check db=pdo
if ($id and preg_match('/^(\w+):(.*)/',$id,$m)) {
Db::pdef('format',out::client_type());
if(defined('DB_NO_INIT') and DB_NO_INIT) return true;
-#bye(Db::conf_dbs(array( Db::ROOT_DIR.'/etc/dbs.yaml','/etc/dbs.yaml' )));
-#$conf = Db::conf_dbs(array( Db::ROOT_DIR.'/etc/dbs.yaml','/etc/dbs.yaml' )); Db::init($conf);
+#bye(Db::conf_load(array( Db::ROOT_DIR.'/etc/dbs.yaml','/etc/dbs.yaml' )));
+#$conf = Db::conf_load(array( Db::ROOT_DIR.'/etc/dbs.yaml','/etc/dbs.yaml' )); Db::init($conf);
Db::init([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;
<?php
require_once(dirname(__FILE__).'/../config.php');
require_once(dirname(__FILE__).'/../page.php');
+#$o = new out();
+#bye($o->type);
+
$Page = new Page([
#'title' => 'Test',
'content_type' => ((Page::php_cli() and !Page::p('web') )? 'text/plain' : 'text/html'),
#
# Default params
#
-Db::pinit();
+argv2request();
# Set format from client Accept if != html
#bye(out::client_type());
#
# Confs
#
-$Confs = Db::conf_dbs(array( Db::ROOT_DIR.'/etc/dbs.yaml',Db::ROOT_DIR.'/etc/dbs.php','/etc/dbs.yaml' ));
+$Confs = Db::conf_load(array( Db::ROOT_DIR.'/etc/dbs.yaml',Db::ROOT_DIR.'/etc/dbs.php','/etc/dbs.yaml' ));
#
# Parse stdin
#
$Db = null;
$Table = null;
-#bye(Db::conf_search_db($Conf['ui']));
+$no_reset_params = [
+ 'db',
+ 'table',
+ 'format',
+];
#bye($Confs['ui']);
while($line = fgets(STDIN)){
+ $line = trim($line);
+
+ # Ignore comment
+ if (preg_match('/^\s*#/',$line)) continue;
+
+ # Exit command
+ if ($line == 'quit' or $line == 'q') break;
# Set params
- #if (preg_match('/^\s*([^=]+)\s*=\s*(.*?)\s*$/',$line,$args)) {
- #echo "IGNORE: $line";
- while ($line and preg_match('/^\s*([^=]+)\s*=\s*(.*?)\s*$/',$line,$args)) {
+ while ($line and (0
+ #or preg_match('/^([\w\.]+)=("[^"]+"|\S+)/',$line,$args)
+ or preg_match("/^([\w\.]+)='([^']+)'/",$line,$args)
+ or preg_match('/^([\w\.]+)="([^"]+)"/',$line,$args)
+ or preg_match('/^([\w\.]+)=(\S+)/',$line,$args)
+ )) {
+ # (?:(?:[^()]++|"(?R)")*)
+ $line = mb_substr($line,mb_strlen($args[0])+1);
+ #debug($args);
array_shift($args);
- #var_dump($args);
- Db::pset($args[0],$args[1]);
- $line = mb_substr($line,mb_strlen($line)-1);
+ list ($k,$v) = $args;
- }
+ Db::pset($k,$v);
+ Db::pinit();
- Db::pinit();
- if (!Db::p('action')) continue;
- if (true and !db_shell_init($Confs)) {
- echo "ERR: $line\n";
- continue;
- }
+ switch ($k) {
- #Db::bye(Db::p());
- #var_dump(Db::p());
- #echo ">>".$Db->p('action')."\n";
+ case 'action':
- $r = $Db->action($Db->p('action'),$Table);
- #foreach ($args
+ if ($v == 'reset') {
+ $keep = [];
+ foreach (Db::p() as $k => $v) { if (in_array($k,$no_reset_params)) $keep[$k] = $v; }
+ $_REQUEST = [];
+ foreach ($keep as $k => $v) { Db::pset($k,$v); }
+ $keep = [];
+ break;
+ }
+ $Db->action($Db->p('action'),$Table);
+ break;
-}
+ case 'db':
+#bye($Confs[$v]);
+ $Db = new Db($Confs[$v]+['conf'=>$Confs]);
+ $Db->connect();
+ break;
-function db_shell_init($confs) {
- global $Db, $Table;
+ case 'table':
+ $Table = new Table($v);
+ break;
- static $p_db = null;
- if (Db::p('db') and (
- $p_db === null or $p_db !== Db::p('db')
- )) {
- #if (!empty(
- unset($Table);
- unset($DB);
- return Db::init($confs);
- if (!($conf = Db::conf_search_db($confs))) return;
-#unset($conf['dbs']); unset($conf['conf']); bye($conf);
- #bye($conf);
- $Db = new Db($conf);
- $p_db = Db::p('db');
- }
- #$r = $Db->action($Db->p('action'),$Table);
- #bye(var_dump(Db::p(),true));
+ case 'format':
+ break;
- static $p_table = null;
- if ($p_table === null) $p_table = Db::p('table');
+ default:
+ echo "ERR: $k=$v\n";
+ Db::pset($k,null);
+ break;
- bye([$p_db,$p_table]);
+ }
+
+ }
}
+
?>
}
require_once(realpath(dirname(__FILE__).'/functions.php'));
#$nb = new NB(); debug($nb->test());
+#if (!defined('NB_PARAMS')) define('NB_PARAMS',$_REQUEST);
if (class_exists('NB')) return;
class NB {
* Function: argv2request
* Set $_REQUEST from argv
*/
- public static function argv2request() {
+ public static function argv2request($args=null) {
- global $argv;
+ if (isset($args)) {
+ $argv = $args;
+ $args = [];
+ } else {
+ global $argv;
+ }
$new_argv = array();
if (empty($GLOBALS['_human_len'])) {
$GLOBALS['_human_len'] = [];
if (empty($o['_human'])) $o['_human'] = [];
+ $o['tmpfile'] = tmpfile();
+
+ # switch for later use of out_csv()
$o['sep.human'] = $o['sep'];
$o['sep'] = "\t";
+
+ # no echo with out_csv()
$o['return'] = true;
- $o['tmpfile'] = tmpfile();
}
$line = out_csv($row,$o);
$sep_line = '';
if (out::p('sep_line') !== '0') {
+
foreach ($len as $i) {
- $sep_line .= '+'.str_repeat('-',$i+2);
+ $sep_line .= '+'.str_repeat('-',$i+strlen($o['sep.human'])-1);
}
$sep_line .= '+'."\n";
}