变更
This commit is contained in:
+1
-2
@@ -262,8 +262,7 @@ class ActiveQuery extends Component implements ISqlBuilder
|
|||||||
*/
|
*/
|
||||||
public function count(): int
|
public function count(): int
|
||||||
{
|
{
|
||||||
$builder = clone $this->builder;
|
$data = $this->execute($this->builder->count())->one();
|
||||||
$data = $this->execute($builder->count())->one();
|
|
||||||
if ($data && is_array($data)) {
|
if ($data && is_array($data)) {
|
||||||
return (int)array_shift($data);
|
return (int)array_shift($data);
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-7
@@ -205,6 +205,9 @@ class SqlBuilder extends Component
|
|||||||
*/
|
*/
|
||||||
public function one(): string
|
public function one(): string
|
||||||
{
|
{
|
||||||
|
if (count($this->query->select) < 1) {
|
||||||
|
$this->query->select = ['*'];
|
||||||
|
}
|
||||||
return $this->_selectPrefix() . $this->_prefix() . $this->builderLimit($this->query);
|
return $this->_selectPrefix() . $this->_prefix() . $this->builderLimit($this->query);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -215,6 +218,9 @@ class SqlBuilder extends Component
|
|||||||
*/
|
*/
|
||||||
public function all(): string
|
public function all(): string
|
||||||
{
|
{
|
||||||
|
if (count($this->query->select) < 1) {
|
||||||
|
$this->query->select = ['*'];
|
||||||
|
}
|
||||||
return $this->_selectPrefix() . $this->_prefix() . $this->builderLimit($this->query);
|
return $this->_selectPrefix() . $this->_prefix() . $this->builderLimit($this->query);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,8 +231,7 @@ class SqlBuilder extends Component
|
|||||||
*/
|
*/
|
||||||
public function count(): string
|
public function count(): string
|
||||||
{
|
{
|
||||||
$this->query->select('COUNT(*)');
|
return $this->_selectPrefix(['COUNT(*)']) . $this->_prefix() . $this->builderLimit($this->query);
|
||||||
return $this->_selectPrefix() . $this->_prefix() . $this->builderLimit($this->query);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -263,12 +268,9 @@ class SqlBuilder extends Component
|
|||||||
* @return string
|
* @return string
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
private function _selectPrefix(): string
|
private function _selectPrefix(array $select = ['*']): string
|
||||||
{
|
{
|
||||||
if (count($this->query->select) < 1) {
|
$select = "SELECT " . implode(',', $select) . " FROM " . $this->query->from;
|
||||||
$this->query->select = ['*'];
|
|
||||||
}
|
|
||||||
$select = "SELECT " . implode(',', $this->query->select) . " FROM " . $this->query->from;
|
|
||||||
if ($this->query->alias != "") {
|
if ($this->query->alias != "") {
|
||||||
$select .= " AS " . $this->query->alias;
|
$select .= " AS " . $this->query->alias;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user