Skip to content

Commit

Permalink
update 不对column做处理 用raw防止被格式化 导致无法运行自带方法(如:count,min,max等)
Browse files Browse the repository at this point in the history
kvnZero committed Nov 16, 2021
1 parent b1fdfe5 commit d0ca14c
Showing 3 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions app/ApiJson/Entity/ConditionEntity.php
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ class ConditionEntity

protected int $limit = 10;
protected int $offset = 0;
protected array $column = ['*'];
protected string $column = '*';
protected array $group = [];
protected array $order = [];
protected array $having = [];
@@ -60,9 +60,9 @@ public function addQueryWhere(string $key, string $sql, array $bindArgs = [])
}

/**
* @param array|string[] $column
* @param string $column
*/
public function setColumn(array $column): void
public function setColumn(string $column): void
{
$this->column = $column;
}
@@ -108,9 +108,9 @@ public function setOrder(array $order): void
}

/**
* @return array
* @return string
*/
public function getColumn(): array
public function getColumn(): string
{
return $this->column;
}
2 changes: 1 addition & 1 deletion app/ApiJson/Handle/FunctionColumnHandle.php
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ public function buildModel()
}, ARRAY_FILTER_USE_KEY) as $key => $value)
{
$value = str_replace([';',':'], [',', ' AS '], $value);
$this->condition->setColumn(explode(',', $value));
$this->condition->setColumn($value);
$this->unsetKey[] = $this->keyWord;
}
}
2 changes: 1 addition & 1 deletion app/ApiJson/Model/MysqlQuery.php
Original file line number Diff line number Diff line change
@@ -102,7 +102,7 @@ protected function buildQuery(bool $query = true)
}
if (!$query) return; //下面不再非查询操作

$this->db->select($this->conditionEntity->getColumn());
$this->db->select(Db::raw($this->conditionEntity->getColumn()));
$limit = $this->conditionEntity->getLimit();
if ($limit > 0) {
$this->db->limit($limit);

0 comments on commit d0ca14c

Please sign in to comment.