内核更新

This commit is contained in:
2016-08-19 11:53:45 +08:00
parent 63f95a8ee9
commit 707ebdf51d
20 changed files with 505 additions and 154 deletions

View File

@@ -1768,12 +1768,18 @@ class Query
public function update(array $data)
{
$options = $this->parseExpress();
$pk = $this->getPk($options);
if (isset($options['cache']) && is_string($options['cache'])) {
$key = $options['cache'];
}
if (empty($options['where'])) {
$pk = $this->getPk($options);
// 如果存在主键数据 则自动作为更新条件
if (is_string($pk) && isset($data[$pk])) {
$where[$pk] = $data[$pk];
$key = 'think:' . $options['table'] . '|' . $data[$pk];
if (!isset($key)) {
$key = 'think:' . $options['table'] . '|' . $data[$pk];
}
unset($data[$pk]);
} elseif (is_array($pk)) {
// 增加复合主键支持
@@ -1793,6 +1799,8 @@ class Query
} else {
$options['where']['AND'] = $where;
}
} elseif (is_string($pk) && isset($options['where']['AND'][$pk]) && is_scalar($options['where']['AND'][$pk])) {
$key = 'think:' . $options['table'] . '|' . $options['where']['AND'][$pk];
}
// 生成UPDATE SQL语句
$sql = $this->builder()->update($data, $options);
@@ -2037,7 +2045,7 @@ class Query
public function chunk($count, $callback, $column = null)
{
$options = $this->getOptions();
$column = $column ?: $this->getPk();
$column = $column ?: $this->getPk(isset($options['table']) ? $options['table'] : '');
$bind = $this->bind;
$resultSet = $this->limit($count)->order($column, 'asc')->select();
@@ -2093,9 +2101,12 @@ class Query
{
// 分析查询表达式
$options = $this->parseExpress();
if (isset($options['cache']) && is_string($options['cache'])) {
$key = $options['cache'];
}
if (!is_null($data) && true !== $data) {
if (!is_array($data)) {
if (!isset($key) && !is_array($data)) {
// 缓存标识
$key = 'think:' . $options['table'] . '|' . $data;
}