更新内核
This commit is contained in:
@@ -147,7 +147,7 @@ if (!function_exists('widget')) {
|
||||
/**
|
||||
* 渲染输出Widget
|
||||
* @param string $name Widget名称
|
||||
* @param array $data 传人的参数
|
||||
* @param array $data 传入的参数
|
||||
* @return mixed
|
||||
*/
|
||||
function widget($name, $data = [])
|
||||
@@ -272,8 +272,8 @@ if (!function_exists('url')) {
|
||||
/**
|
||||
* Url生成
|
||||
* @param string $url 路由地址
|
||||
* @param string|array $value 变量
|
||||
* @param bool|string $suffix 前缀
|
||||
* @param string|array $vars 变量
|
||||
* @param bool|string $suffix 生成的URL后缀
|
||||
* @param bool|string $domain 域名
|
||||
* @return string
|
||||
*/
|
||||
@@ -361,7 +361,7 @@ if (!function_exists('cache')) {
|
||||
}
|
||||
if ('' === $value) {
|
||||
// 获取缓存
|
||||
return Cache::get($name);
|
||||
return 0 === strpos($name, '?') ? Cache::has(substr($name, 1)) : Cache::get($name);
|
||||
} elseif (is_null($value)) {
|
||||
// 删除缓存
|
||||
return Cache::rm($name);
|
||||
|
||||
@@ -156,24 +156,6 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
||||
$query->name($this->name);
|
||||
}
|
||||
|
||||
if (!empty($this->field)) {
|
||||
if (true === $this->field) {
|
||||
$type = $this->db()->getTableInfo('', 'type');
|
||||
} else {
|
||||
$type = [];
|
||||
foreach ((array) $this->field as $key => $val) {
|
||||
if (is_int($key)) {
|
||||
$key = $val;
|
||||
$val = 'varchar';
|
||||
}
|
||||
$type[$key] = $val;
|
||||
}
|
||||
}
|
||||
$query->setFieldType($type);
|
||||
$this->field = array_keys($type);
|
||||
$query->allowField($this->field);
|
||||
}
|
||||
|
||||
if (!empty($this->pk)) {
|
||||
$query->pk($this->pk);
|
||||
}
|
||||
@@ -631,7 +613,6 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
||||
|
||||
// 检测字段
|
||||
if (!empty($this->field)) {
|
||||
$this->db();
|
||||
foreach ($this->data as $key => $val) {
|
||||
if (!in_array($key, $this->field)) {
|
||||
unset($this->data[$key]);
|
||||
@@ -781,9 +762,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
||||
public function allowField($field)
|
||||
{
|
||||
if (true === $field) {
|
||||
$field = $this->db()->getTableInfo('', 'type');
|
||||
$this->db()->setFieldType($field);
|
||||
$field = array_keys($field);
|
||||
$field = $this->db()->getTableInfo('', 'fields');
|
||||
}
|
||||
$this->field = $field;
|
||||
return $this;
|
||||
|
||||
@@ -300,6 +300,9 @@ abstract class Builder
|
||||
$bindType = isset($binds[$field]) ? $binds[$field] : PDO::PARAM_STR;
|
||||
if (is_scalar($value) && array_key_exists($field, $binds) && !in_array($exp, ['EXP', 'NOT NULL', 'NULL', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN']) && strpos($exp, 'TIME') === false) {
|
||||
if (strpos($value, ':') !== 0 || !$this->query->isBind(substr($value, 1))) {
|
||||
if ($this->query->isBind($bindName)) {
|
||||
$bindName .= '_' . uniqid();
|
||||
}
|
||||
$this->query->bind($bindName, $value, $bindType);
|
||||
$value = ':' . $bindName;
|
||||
}
|
||||
|
||||
@@ -43,10 +43,6 @@ class Query
|
||||
protected $name = '';
|
||||
// 当前数据表主键
|
||||
protected $pk;
|
||||
// 当前表字段类型信息
|
||||
protected $fieldType = [];
|
||||
// 当前允许的字段列表
|
||||
protected $allowField = [];
|
||||
// 当前数据表前缀
|
||||
protected $prefix = '';
|
||||
// 查询参数
|
||||
@@ -741,11 +737,11 @@ class Query
|
||||
}
|
||||
if (true === $field) {
|
||||
// 获取全部字段
|
||||
$fields = !empty($this->allowField) && ('' == $tableName || $this->getTable() == $tableName) ? $this->allowField : $this->getTableInfo($tableName ?: (isset($this->options['table']) ? $this->options['table'] : ''), 'fields');
|
||||
$fields = $this->getTableInfo($tableName ?: (isset($this->options['table']) ? $this->options['table'] : ''), 'fields');
|
||||
$field = $fields ?: ['*'];
|
||||
} elseif ($except) {
|
||||
// 字段排除
|
||||
$fields = !empty($this->allowField) && ('' == $tableName || $this->getTable() == $tableName) ? $this->allowField : $this->getTableInfo($tableName ?: (isset($this->options['table']) ? $this->options['table'] : ''), 'fields');
|
||||
$fields = $this->getTableInfo($tableName ?: (isset($this->options['table']) ? $this->options['table'] : ''), 'fields');
|
||||
$field = $fields ? array_diff($fields, $field) : $field;
|
||||
}
|
||||
if ($tableName) {
|
||||
@@ -1260,35 +1256,6 @@ 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->allowField = $field;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置字段类型
|
||||
* @access public
|
||||
* @param array $fieldType 字段类型信息
|
||||
* @return $this
|
||||
*/
|
||||
public function setFieldType($fieldType = [])
|
||||
{
|
||||
$this->fieldType = $fieldType;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定数据表主键
|
||||
* @access public
|
||||
@@ -1375,7 +1342,12 @@ class Query
|
||||
|
||||
list($guid) = explode(' ', $tableName);
|
||||
if (!isset(self::$info[$guid])) {
|
||||
$info = $this->connection->getFields($tableName);
|
||||
// 读取缓存
|
||||
if (is_file(RUNTIME_PATH . 'schema/' . $guid . '.php')) {
|
||||
$info = include RUNTIME_PATH . 'schema/' . $guid . '.php';
|
||||
} else {
|
||||
$info = $this->connection->getFields($guid);
|
||||
}
|
||||
$fields = array_keys($info);
|
||||
$bind = $type = [];
|
||||
foreach ($info as $key => $val) {
|
||||
@@ -1416,13 +1388,13 @@ class Query
|
||||
// 获取当前数据表字段信息
|
||||
public function getTableFields($options)
|
||||
{
|
||||
return !empty($this->allowField) ? $this->allowField : $this->getTableInfo($options['table'], 'fields');
|
||||
return $this->getTableInfo($options['table'], 'fields');
|
||||
}
|
||||
|
||||
// 获取当前数据表字段类型
|
||||
public function getFieldsType($options)
|
||||
{
|
||||
return !empty($this->fieldType) ? $this->fieldType : $this->getTableInfo($options['table'], 'type');
|
||||
return $this->getTableInfo($options['table'], 'type');
|
||||
}
|
||||
|
||||
// 获取当前数据表绑定信息
|
||||
@@ -1998,9 +1970,6 @@ class Query
|
||||
$model = $this->model;
|
||||
$data = new $model($data);
|
||||
$data->isUpdate(true, isset($options['where']['AND']) ? $options['where']['AND'] : null);
|
||||
if ($this->allowField) {
|
||||
$data->allowField($this->allowField);
|
||||
}
|
||||
// 关联查询
|
||||
if (!empty($options['relation'])) {
|
||||
$data->relationQuery($options['relation']);
|
||||
|
||||
@@ -86,6 +86,7 @@ class Mysql extends Connection
|
||||
*/
|
||||
public function getTables($dbName = '')
|
||||
{
|
||||
$this->initConnect(true);
|
||||
$sql = !empty($dbName) ? 'SHOW TABLES FROM ' . $dbName : 'SHOW TABLES ';
|
||||
// 调试开始
|
||||
$this->debug(true);
|
||||
|
||||
@@ -77,6 +77,7 @@ class Pgsql extends Connection
|
||||
*/
|
||||
public function getTables($dbName = '')
|
||||
{
|
||||
$this->initConnect(true);
|
||||
$sql = "select tablename as Tables_in_test from pg_tables where schemaname ='public'";
|
||||
// 调试开始
|
||||
$this->debug(true);
|
||||
|
||||
@@ -74,6 +74,7 @@ class Sqlite extends Connection
|
||||
*/
|
||||
public function getTables($dbName = '')
|
||||
{
|
||||
$this->initConnect(true);
|
||||
$sql = "SELECT name FROM sqlite_master WHERE type='table' "
|
||||
. "UNION ALL SELECT name FROM sqlite_temp_master "
|
||||
. "WHERE type='table' ORDER BY name";
|
||||
|
||||
@@ -99,6 +99,7 @@ class Sqlsrv extends Connection
|
||||
*/
|
||||
public function getTables($dbName = '')
|
||||
{
|
||||
$this->initConnect(true);
|
||||
$sql = "SELECT TABLE_NAME
|
||||
FROM INFORMATION_SCHEMA.TABLES
|
||||
WHERE TABLE_TYPE = 'BASE TABLE'
|
||||
|
||||
@@ -141,7 +141,11 @@ class Php
|
||||
*/
|
||||
public function config($name, $value = null)
|
||||
{
|
||||
|
||||
if (is_array($name)) {
|
||||
$this->config = array_merge($this->config, $name);
|
||||
} else {
|
||||
$this->config[$name] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -140,8 +140,10 @@ class Think
|
||||
{
|
||||
if (is_array($name)) {
|
||||
$this->template->config($name);
|
||||
$this->config = array_merge($this->config, $name);
|
||||
} else {
|
||||
$this->template->$name = $value;
|
||||
$this->config[$name] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user