1、更新tp5内核
2、修复后台文档模型创建的bug
This commit is contained in:
@@ -34,7 +34,7 @@ class Query
|
||||
// 数据库Connection对象实例
|
||||
protected $connection;
|
||||
// 数据库驱动类型
|
||||
protected $driver;
|
||||
protected $builder;
|
||||
// 当前模型类名称
|
||||
protected $model;
|
||||
// 当前数据表名称(含前缀)
|
||||
@@ -59,7 +59,7 @@ class Query
|
||||
public function __construct(Connection $connection = null, $model = '')
|
||||
{
|
||||
$this->connection = $connection ?: Db::connect([], true);
|
||||
$this->driver = $this->connection->getConfig('type');
|
||||
$this->builder = $this->connection->getConfig('builder') ?: $this->connection->getConfig('type');
|
||||
$this->prefix = $this->connection->getConfig('prefix');
|
||||
$this->model = $model;
|
||||
}
|
||||
@@ -357,7 +357,7 @@ class Query
|
||||
protected function builder()
|
||||
{
|
||||
static $builder = [];
|
||||
$driver = $this->driver;
|
||||
$driver = $this->builder;
|
||||
if (!isset($builder[$driver])) {
|
||||
$class = false !== strpos($driver, '\\') ? $driver : '\\think\\db\\builder\\' . ucfirst($driver);
|
||||
$builder[$driver] = new $class($this->connection);
|
||||
@@ -720,11 +720,11 @@ class Query
|
||||
}
|
||||
if (true === $field) {
|
||||
// 获取全部字段
|
||||
$fields = $this->getTableInfo($tableName, 'fields');
|
||||
$fields = isset($this->options['allow_field']) ? $this->options['allow_field'] : $this->getTableInfo($tableName, 'fields');
|
||||
$field = $fields ?: ['*'];
|
||||
} elseif ($except) {
|
||||
// 字段排除
|
||||
$fields = $this->getTableInfo($tableName, 'fields');
|
||||
$fields = isset($this->options['allow_field']) ? $this->options['allow_field'] : $this->getTableInfo($tableName, 'fields');
|
||||
$field = $fields ? array_diff($fields, $field) : $field;
|
||||
}
|
||||
if ($tableName) {
|
||||
@@ -1235,6 +1235,47 @@ class Query
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置数据表字段
|
||||
* @access public
|
||||
* @param string|array $field 字段信息
|
||||
* @return $this
|
||||
*/
|
||||
public function allowField($field)
|
||||
{
|
||||
if (true === $field) {
|
||||
$field = $this->getTableInfo('', 'fields');
|
||||
} elseif (is_string($field)) {
|
||||
$field = explode(',', $field);
|
||||
}
|
||||
$this->options['allow_field'] = $field;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置字段类型
|
||||
* @access public
|
||||
* @param array $fieldType 字段类型信息
|
||||
* @return $this
|
||||
*/
|
||||
public function setFieldType($fieldType = [])
|
||||
{
|
||||
$this->options['field_type'] = $fieldType;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定数据表主键
|
||||
* @access public
|
||||
* @param string $pk 主键
|
||||
* @return $this
|
||||
*/
|
||||
public function pk($pk)
|
||||
{
|
||||
$this->options['pk'] = $pk;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询日期或者时间
|
||||
* @access public
|
||||
@@ -1284,18 +1325,6 @@ class Query
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置字段类型
|
||||
* @access public
|
||||
* @param array $fieldType 字段类型信息
|
||||
* @return $this
|
||||
*/
|
||||
public function setFieldType($fieldType = [])
|
||||
{
|
||||
$this->options['field_type'] = $fieldType;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据表信息
|
||||
* @access public
|
||||
@@ -1327,13 +1356,7 @@ class Query
|
||||
foreach ($info as $key => $val) {
|
||||
// 记录字段类型
|
||||
$type[$key] = $val['type'];
|
||||
if (preg_match('/(int|double|float|decimal|real|numeric|serial)/is', $val['type'])) {
|
||||
$bind[$key] = PDO::PARAM_INT;
|
||||
} elseif (preg_match('/bool/is', $val['type'])) {
|
||||
$bind[$key] = PDO::PARAM_BOOL;
|
||||
} else {
|
||||
$bind[$key] = PDO::PARAM_STR;
|
||||
}
|
||||
$bind[$key] = $this->getFieldBindType($val['type']);
|
||||
if (!empty($val['primary'])) {
|
||||
$pk[] = $key;
|
||||
}
|
||||
@@ -1352,12 +1375,60 @@ class Query
|
||||
/**
|
||||
* 获取当前数据表的主键
|
||||
* @access public
|
||||
* @param string $table 数据表名
|
||||
* @param string|array $options 数据表名或者查询参数
|
||||
* @return string|array
|
||||
*/
|
||||
public function getPk($table = '')
|
||||
public function getPk($options = '')
|
||||
{
|
||||
return $this->getTableInfo($table, 'pk');
|
||||
if (!empty($options['pk'])) {
|
||||
$pk = $options['pk'];
|
||||
} elseif (isset($this->options['pk'])) {
|
||||
$pk = $this->options['pk'];
|
||||
} else {
|
||||
$pk = $this->getTableInfo(is_array($options) ? $options['table'] : $options, 'pk');
|
||||
}
|
||||
return $pk;
|
||||
}
|
||||
|
||||
// 获取当前数据表字段信息
|
||||
public function getTableFields($options)
|
||||
{
|
||||
return !empty($options['allow_field']) ? $options['allow_field'] : $this->getTableInfo($options['table'], 'fields');
|
||||
}
|
||||
|
||||
// 获取当前数据表字段类型
|
||||
public function getFieldsType($options)
|
||||
{
|
||||
return !empty($options['field_type']) ? $options['field_type'] : $this->getTableInfo($options['table'], 'type');
|
||||
}
|
||||
|
||||
// 获取当前数据表绑定信息
|
||||
public function getFieldsBind($options)
|
||||
{
|
||||
$types = $this->getFieldsType($options);
|
||||
$bind = [];
|
||||
foreach ($types as $key => $type) {
|
||||
$bind[$key] = $this->getFieldBindType($type);
|
||||
}
|
||||
return $bind;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取字段绑定类型
|
||||
* @access public
|
||||
* @param string $type 字段类型
|
||||
* @return integer
|
||||
*/
|
||||
protected function getFieldBindType($type)
|
||||
{
|
||||
if (preg_match('/(int|double|float|decimal|real|numeric|serial)/is', $type)) {
|
||||
$bind = PDO::PARAM_INT;
|
||||
} elseif (preg_match('/bool/is', $type)) {
|
||||
$bind = PDO::PARAM_BOOL;
|
||||
} else {
|
||||
$bind = PDO::PARAM_STR;
|
||||
}
|
||||
return $bind;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1546,7 +1617,7 @@ class Query
|
||||
*/
|
||||
protected function parsePkWhere($data, &$options)
|
||||
{
|
||||
$pk = $this->getPk($options['table']);
|
||||
$pk = $this->getPk($options);
|
||||
// 获取当前数据表
|
||||
if (!empty($options['alias'])) {
|
||||
$alias = $options['alias'];
|
||||
@@ -1684,7 +1755,7 @@ class Query
|
||||
{
|
||||
$options = $this->parseExpress();
|
||||
if (empty($options['where'])) {
|
||||
$pk = $this->getPk($options['table']);
|
||||
$pk = $this->getPk($options);
|
||||
// 如果存在主键数据 则自动作为更新条件
|
||||
if (is_string($pk) && isset($data[$pk])) {
|
||||
$where[$pk] = $data[$pk];
|
||||
@@ -1951,8 +2022,8 @@ class Query
|
||||
*/
|
||||
public function chunk($count, $callback, $column = null)
|
||||
{
|
||||
$column = $column ?: $this->getPk();
|
||||
$options = $this->getOptions();
|
||||
$column = $column ?: ($options['pk'] ?: $this->getPk());
|
||||
$bind = $this->bind;
|
||||
$resultSet = $this->limit($count)->order($column, 'asc')->select();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user