From f8e2ae5b40ae51256b9934cd3876aff8a8dcb78a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Fri, 26 Mar 2021 19:22:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Database/SqlBuilder.php | 3 +-- Database/Traits/QueryTrait.php | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Database/SqlBuilder.php b/Database/SqlBuilder.php index e1e207e0..aefb8205 100644 --- a/Database/SqlBuilder.php +++ b/Database/SqlBuilder.php @@ -294,8 +294,7 @@ class SqlBuilder extends Component public function tableName(): string { if ($this->query->from instanceof \Closure) { - call_user_func($this->query->from, $activeQuery = new Sql()); - $this->query->from = '(' . $activeQuery->getSql() . ')'; + $this->query->from = '(' . $this->query->makeClosureFunction($this->query->from) . ')'; } if ($this->query->from instanceof ActiveQuery) { $this->query->from = '(' . SqlBuilder::builder($this->query->from)->get($this->query->from) . ')'; diff --git a/Database/Traits/QueryTrait.php b/Database/Traits/QueryTrait.php index e49d7f80..f4710d01 100644 --- a/Database/Traits/QueryTrait.php +++ b/Database/Traits/QueryTrait.php @@ -813,7 +813,7 @@ trait QueryTrait public function where(callable|array|string $conditions): static { if ($conditions instanceof Closure) { - $conditions = '(' . $this->makeClosureFunction($conditions) . ')'; + $conditions = $this->makeClosureFunction($conditions); } $this->where[] = $conditions; return $this; @@ -828,7 +828,7 @@ trait QueryTrait * @throws ReflectionException * @throws Exception */ - private function makeClosureFunction(Closure|array $closure, $onlyWhere = false): string + public function makeClosureFunction(Closure|array $closure, $onlyWhere = false): string { $generate = $this->makeNewSqlGenerate(); if ($closure instanceof Closure) { @@ -839,7 +839,7 @@ trait QueryTrait if ($onlyWhere === true) { return $generate->getCondition(); } - return $generate->getSql(); + return '(' . $generate->getSql() . ')'; }