编辑器更新,此版本还有bug,暂不要更新使用

内核更新
This commit is contained in:
2016-10-12 15:35:02 +08:00
parent 8d1600a2eb
commit e70d287e89
103 changed files with 31476 additions and 175 deletions

View File

@@ -180,12 +180,17 @@ abstract class Builder
protected function parseTable($tables, $options = [])
{
$item = [];
foreach ((array) $tables as $table) {
$table = $this->parseSqlTable($table);
if (isset($options['alias'][$table])) {
$item[] = $this->parseKey($table) . ' ' . $this->parseKey($options['alias'][$table]);
foreach ((array) $tables as $key => $table) {
if (!is_numeric($key)) {
$key = $this->parseSqlTable($key);
$item[] = $this->parseKey($key) . ' ' . $this->parseKey($table);
} else {
$item[] = $this->parseKey($table);
$table = $this->parseSqlTable($table);
if (isset($options['alias'][$table])) {
$item[] = $this->parseKey($table) . ' ' . $this->parseKey($options['alias'][$table]);
} else {
$item[] = $this->parseKey($table);
}
}
}
return implode(',', $item);
@@ -437,8 +442,12 @@ abstract class Builder
list($table, $type, $on) = $item;
$condition = [];
foreach ((array) $on as $val) {
list($val1, $val2) = explode('=', $val, 2);
$condition[] = $this->parseKey($val1, $options) . '=' . $this->parseKey($val2, $options);
if (strpos($val, '=')) {
list($val1, $val2) = explode('=', $val, 2);
$condition[] = $this->parseKey($val1, $options) . '=' . $this->parseKey($val2, $options);
} else {
$condition[] = $val;
}
}
$table = $this->parseTable($table, $options);

View File

@@ -377,7 +377,7 @@ class Query
*/
public function value($field, $default = null)
{
$result = null;
$result = false;
if (!empty($this->options['cache'])) {
// 判断查询缓存
$cache = $this->options['cache'];
@@ -387,7 +387,7 @@ class Query
$key = is_string($cache['key']) ? $cache['key'] : md5($field . serialize($this->options));
$result = Cache::get($key);
}
if (!$result) {
if (false === $result) {
if (isset($this->options['field'])) {
unset($this->options['field']);
}
@@ -409,7 +409,7 @@ class Query
// 清空查询条件
$this->options = [];
}
return !is_null($result) ? $result : $default;
return false !== $result ? $result : $default;
}
/**
@@ -431,7 +431,7 @@ class Query
$guid = is_string($cache['key']) ? $cache['key'] : md5($field . serialize($this->options));
$result = Cache::get($guid);
}
if (!$result) {
if (false === $result) {
if (isset($this->options['field'])) {
unset($this->options['field']);
}
@@ -663,37 +663,21 @@ class Query
}
}
} else {
$prefix = $this->prefix;
// 传入的表名为数组
if (is_array($join)) {
if (0 !== $key = key($join)) {
// 设置了键名则键名为表名,键值作为表的别名
$table = $key;
$alias = array_shift($join);
$this->alias([$table => $alias]);
$table = [$key => array_shift($join)];
$this->alias($table);
} else {
$table = array_shift($join);
}
if (count($join)) {
// 有设置第二个元素则把第二元素作为表前缀
$table = (string) current($join) . $table;
} elseif (false === strpos($table, '.')) {
// 加上默认的表前缀
$table = $prefix . $table;
}
} else {
$join = trim($join);
if (0 === strpos($join, '__')) {
$table = $this->parseSqlTable($join);
} elseif (false === strpos($join, '(') && false === strpos($join, '.') && !empty($prefix) && 0 !== strpos($join, $prefix)) {
// 传入的表名中不带有'('并且不以默认的表前缀开头时加上默认的表前缀
$table = $prefix . $join;
} else {
$table = $join;
}
if (strpos($table, ' ')) {
$table = trim($join);
if (strpos($table, ' ') && !strpos($table, ')')) {
list($table, $alias) = explode(' ', $table);
$this->alias([$table => $alias]);
$table = [$table => $alias];
$this->alias($table);
}
}
$this->options['join'][] = [$table, strtoupper($type), $condition];
@@ -1044,7 +1028,8 @@ class Query
}
} elseif (strpos($table, ' ')) {
list($table, $alias) = explode(' ', $table);
$this->alias([$table => $alias]);
$table = [$table => $alias];
$this->alias($table);
}
} else {
$tables = $table;
@@ -1054,7 +1039,7 @@ class Query
$table[] = $val;
} else {
$this->alias([$key => $val]);
$table[] = $key;
$table[$key] = $val;
}
}
}
@@ -1187,7 +1172,11 @@ class Query
$this->options['alias'][$key] = $val;
}
} else {
$table = isset($this->options['table']) ? $this->options['table'] : $this->getTable();
if (isset($this->options['table'])) {
$table = is_array($this->options['table']) ? key($this->options['table']) : $this->options['table'];
} else {
$table = $this->getTable();
}
$this->options['alias'][$table] = $alias;
}
@@ -1365,7 +1354,7 @@ class Query
/**
* 获取数据表信息
* @access public
* @param string $tableName 数据表名 留空自动获取
* @param mixed $tableName 数据表名 留空自动获取
* @param string $fetch 获取信息类型 包括 fields type bind pk
* @return mixed
*/
@@ -1575,7 +1564,7 @@ class Query
$name = Loader::parseName(basename(str_replace('\\', '/', $currentModel)));
$table = $this->getTable();
$alias = isset($info['alias'][$name]) ? $info['alias'][$name] : $name;
$this->table($table)->alias($alias);
$this->table([$table => $alias]);
if (isset($this->options['field'])) {
$field = $this->options['field'];
unset($this->options['field']);
@@ -1587,7 +1576,7 @@ class Query
// 预载入封装
$joinTable = $model->getTable();
$joinName = Loader::parseName(basename(str_replace('\\', '/', $info['model'])));
$joinAlias = isset($info['alias'][$joinName]) ? $info['alias'][$joinName] : $joinName;
$joinAlias = isset($info['alias'][$joinName]) ? $info['alias'][$joinName] : $relation;
$this->via($joinAlias);
if (Relation::HAS_ONE == $info['type']) {
@@ -1670,8 +1659,9 @@ class Query
{
$pk = $this->getPk($options);
// 获取当前数据表
if (!empty($options['alias'][$options['table']])) {
$alias = $options['alias'][$options['table']];
$table = is_array($options['table']) ? key($options['table']) : $options['table'];
if (!empty($options['alias'][$table])) {
$alias = $options['alias'][$table];
}
if (is_string($pk)) {
$key = isset($alias) ? $alias . '.' . $pk : $pk;
@@ -1983,7 +1973,7 @@ class Query
// 判断查询缓存
$cache = $options['cache'];
if (true === $cache['key'] && !is_null($data) && !is_array($data)) {
$key = 'think:' . $options['table'] . '|' . $data;
$key = 'think:' . (is_array($options['table']) ? key($options['table']) : $options['table']) . '|' . $data;
} else {
$key = is_string($cache['key']) ? $cache['key'] : md5(serialize($options));
}
@@ -2053,7 +2043,8 @@ class Query
if (!empty($this->model)) {
throw new ModelNotFoundException('model data Not Found:' . $this->model, $this->model, $options);
} else {
throw new DataNotFoundException('table data not Found:' . $options['table'], $options['table'], $options);
$table = is_array($options['table']) ? key($options['table']) : $options['table'];
throw new DataNotFoundException('table data not Found:' . $table, $table, $options);
}
}
@@ -2095,8 +2086,13 @@ class Query
*/
public function chunk($count, $callback, $column = null)
{
$options = $this->getOptions();
$column = $column ?: $this->getPk(isset($options['table']) ? $options['table'] : '');
$options = $this->getOptions();
if (isset($options['table'])) {
$table = is_array($options['table']) ? key($options['table']) : $options['table'];
} else {
$table = '';
}
$column = $column ?: $this->getPk($table);
$bind = $this->bind;
$resultSet = $this->limit($count)->order($column, 'asc')->select();

View File

@@ -27,22 +27,23 @@ class Sqlsrv extends Builder
* order分析
* @access protected
* @param mixed $order
* @param array $options
* @return string
*/
protected function parseOrder($order)
protected function parseOrder($order, $options = [])
{
if (is_array($order)) {
$array = [];
foreach ($order as $key => $val) {
if (is_numeric($key)) {
if (false === strpos($val, '(')) {
$array[] = $this->parseKey($val);
$array[] = $this->parseKey($val, $options);
} elseif ('[rand]' == $val) {
$array[] = $this->parseRand();
}
} else {
$sort = in_array(strtolower(trim($val)), ['asc', 'desc']) ? ' ' . $val : '';
$array[] = $this->parseKey($key) . ' ' . $sort;
$array[] = $this->parseKey($key, $options) . ' ' . $sort;
}
}
$order = implode(',', $array);