更新内核

This commit is contained in:
2016-09-18 22:48:00 +08:00
parent 8536017505
commit e818c386e2
10 changed files with 29 additions and 68 deletions

View File

@@ -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;
}

View File

@@ -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']);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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";

View File

@@ -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'