public $extras;
public $formats = array( 'table','div','csv','xml','json','yaml' );
public $limits = array('10','20','50','100','500','1000');
- const help_criterias = '
- * or % for wildcar
- ! to negate
- ~ for regex
- combine criterias with OR/AND
- ';
function __construct($opt = '') {
# NB 28.03.16 return $this->conn->query("SELECT count(*) FROM ($sql) count",PDO::FETCH_COLUMN,0)->fetch();
# NB 28.03.16 }
- function help($tables=null) {
- if (!self::php_cli()) header('Content-type: text/plain');
-
- if ($tables === null) $tables = array_keys($this->tables());
- $tables = join('',ar_map('" ".$a."\n"',$tables));
-
- $criterias = join('',ar_map('" ".trim($a)."\n"',explode("\n",self::help_criterias)));
-
- return <<<EOF
-Criterias:
-$criterias
-Tables
-$tables
-Extras:
- - op = [OR|AND] criterias operator
- - sort = field+DESC
- - format = [xml|yaml|csv|table|row]
- - header = [1|0] Print header fields (default: 1)
-
-EOF;
- }
-
function print_header($format) {
if (empty($_SERVER['DOCUMENT_ROOT'])) return null;
return '"'.$value.'"';
}
- public function out2($rows,$head=array()) {
-
+ public function out($rows,$head=array()) {
out::rows($this->p('format',out::php_cli() ? 'csv' : 'table'),$rows,$head);
return true;
}
foreach($actions as $action) {
- if ($action == 'db.help') {
- $this->out2(array(
- array('db.help','This help'),
+ if ($action == 'db.help' or $action == 'help') {
+ $this->out(array(
+ array('[db.]help','This help'),
array('[db.]dbs','List databases'),
array('[db.]tables','List tables'),
array('[table.]update','Update a record'),
array('[table.]delete','Delete a record'),
- ),array('command','description'));
+ ),array('action','description'));
$return = true;
} elseif ($action == 'db.tables' or $action == 'tables') {
if (!empty($type) and strpos($t->type,$type) === false) continue;
$rows[] = $t->infos();
}
- $return = $this->out2($rows);
+ $return = $this->out($rows);
} elseif ($action == 'db.conf') {
- $return = $this->out2(array_values($this->conf));
+ $return = $this->out(array_values($this->conf));
} elseif ($action == 'db.dbs' or $action == 'dbs') {
- if (self::p('hash')) $return = $this->out2($this->conf);
- else $return = $this->out2($this->dbs,"name");
+ if (self::p('hash')) $return = $this->out($this->conf);
+ else $return = $this->out($this->dbs,"name");
} elseif ($r=self::class_action_out($this,$action)) {
return $r;