'delete' => 'table.delete',
];
+ const action_help = [
+ ['(db.)?help','This help'],
+ ['(db.)?ls','List databases from conf'],
+ ['(db.)?tables','List tables (name=* type=* count=1 engine=*)'],
+
+ ['(table.)?rows','Dump one table, use format='],
+ ['(table.)?fields','List fields'],
+ ['table.infos','Table infos (count(*). Type, ...)'],
+ ['table.sql','Get the sql source'],
+
+ ['(table.)?insert','Insert a record'],
+ ['(table.)?update','Update a record'],
+ ['(table.)?delete','Delete a record'],
+
+ ];
# Web
public $default_table;
public $sort;
}
public function out($rows,$head=[]) {
+
+ // Handle limit
+ if ($this->p('limit')) {
+
+ $limit = (int)$this->p('limit');
+ $i = empty($head) ? 1 : 0;
+
+ foreach ($rows as $k=>$v) {
+ if ($i>$limit) unset($rows[$k]);
+ $i++;
+ }
+
+ }
+
$this->out->rows($this->p('format',$this->out->php_cli() ? 'csv' : 'table'),$rows,$head);
return true;
}
public function action($action,$table=null) {
#debug(($this->tables));
- $available = [
- ['(db.)?help','This help'],
- ['(db.)?ls','List databases from conf'],
- ['(db.)?tables','List tables (name=* type=* count=1 engine=*)'],
-
- ['(table.)?rows','Dump one table, use format='],
- ['(table.)?fields','List fields'],
- ['table.infos','Table infos (count(*). Type, ...)'],
- ['table.sql','Get the sql source'],
-
- ['(table.)?insert','Insert a record'],
- ['(table.)?update','Update a record'],
- ['(table.)?delete','Delete a record'],
-
- ];
+ $available = self::action_help;
$actions = explode(',',$action);
$this->pdef('format',($this->php_cli() ? 'csv' : ''));
$rows = [];
$type = $this->p('type','');
$name = $this->p('name','');
$engine = $this->p('engine','');
+ $database = $this->p('database','');
#var_dump ($this->tables());
#foreach($this->tables as $t) debug($t->name.'='.$t->type);
if (!empty($type) and !$this->str_match($t->type,$type)) continue;
if (!empty($count) and !$this->str_match($t->count,$count)) continue;
if (!empty($engine) and !$this->str_match($t->engine,$engine)) continue;
+ if (!empty($database) and isset($t->database) and !$this->str_match($t->database,$database)) continue;
$row = $t->status();
if ($this->p('count')) $row['count'] = $t->status('count');