|
@@ -94,7 +94,7 @@ class Model
|
|
|
$file .= $this->partition['table'] . '.php';
|
|
|
}
|
|
|
if (isset($this->partition['field']) && $this->partition['field']) {
|
|
|
- if (strstr($this->partition['field']['value'], 'date(')) {
|
|
|
+ if (is_string($this->partition['field']['value']) && strstr($this->partition['field']['value'], 'date(')) {
|
|
|
$this->partition['field']['type'] = 'time';
|
|
|
$e = '$v=' . $this->partition['field']['value'] . ';';
|
|
|
eval($e);
|
|
@@ -122,6 +122,10 @@ class Model
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ public function optimize()
|
|
|
+ {
|
|
|
+ return $this->store->optimize($this->config['table']);
|
|
|
+ }
|
|
|
public function load($param, $set = array(), $lock = false)
|
|
|
{
|
|
|
return $this->store->load($this->config['table'], $param, $set, $this->config['struct'], $lock);
|
|
@@ -133,7 +137,11 @@ class Model
|
|
|
}
|
|
|
if (empty($set['order'])) {
|
|
|
if (isset($this->config['order'])) {
|
|
|
- $set['order'] = $this->config['order'] . ',id desc';
|
|
|
+ if (strstr($this->config['order'], 'id asc')) {
|
|
|
+ $set['order'] = $this->config['order'];
|
|
|
+ } else {
|
|
|
+ $set['order'] = $this->config['order'] . ',id desc';
|
|
|
+ }
|
|
|
} else {
|
|
|
$set['order'] = 'id desc';
|
|
|
}
|
|
@@ -162,6 +170,10 @@ class Model
|
|
|
if (isset($this->partition['where']) && $this->partition['where']) {
|
|
|
$param = array_merge($this->partition['where'], $param);
|
|
|
}
|
|
|
+ if (isset($this->config['count']) && $this->config['count'] = 2) {
|
|
|
+ $data = $this->store->explain($this->config['table'], $param, $this->config['struct']);
|
|
|
+ return $data['rows'] ?? 0;
|
|
|
+ }
|
|
|
return $this->store->count($this->config['table'], $param, $this->config['struct']);
|
|
|
}
|
|
|
public function kv($param, $set = array())
|
|
@@ -240,7 +252,11 @@ class Model
|
|
|
$temp = explode('limit', $sql);
|
|
|
$sql = $temp[0];
|
|
|
}
|
|
|
- $sql .= ' limit ' . Paginator::init($page['num'], $page['page'] ?? 1, function()use($sql, $bind){return $this->queryCount($sql, $bind);});
|
|
|
+ $limit = Paginator::init($page['num'], $page['page'] ?? 1, function()use($sql, $bind){return $this->queryCount($sql, $bind);});
|
|
|
+ if (is_array($limit)) {
|
|
|
+ $limit = implode(',', $limit);
|
|
|
+ }
|
|
|
+ $sql .= ' limit ' . $limit;
|
|
|
}
|
|
|
$result = $this->store->query($sql, $bind);
|
|
|
if (isset($page['num']) && empty($page['page'])) {
|