-
-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
修复带 distinct 的分页查询器,记录数量返回不正确 (#571)
* 修复带 distinct 的分页查询器,记录数量返回不正确 * 修复 whereBrackets 返回非数组值时,生成的 SQL 不带括号 * 修复 * 修复
- Loading branch information
Showing
6 changed files
with
167 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Imi\Db\Query\Interfaces; | ||
|
||
interface IWrapField extends IField | ||
{ | ||
public function getSubFields(): array; | ||
|
||
public function setSubFields(array $subFields): void; | ||
|
||
public function getWrapLeft(): string; | ||
|
||
public function setWrapLeft(string $wrapLeft): void; | ||
|
||
public function getWrapRight(): string; | ||
|
||
public function setWrapRight(string $wrapRight): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Imi\Db\Query; | ||
|
||
use Imi\Db\Query\Interfaces\IQuery; | ||
use Imi\Db\Query\Interfaces\IWrapField; | ||
|
||
class WrapField extends Field implements IWrapField | ||
{ | ||
protected array $subFields = []; | ||
|
||
protected string $wrapLeft = ''; | ||
|
||
protected string $wrapRight = ''; | ||
|
||
public function __construct(string $wrapLeft, array $subFields, string $wrapRight, ?string $alias = null) | ||
{ | ||
$this->wrapLeft = $wrapLeft; | ||
$this->subFields = $subFields; | ||
$this->wrapRight = $wrapRight; | ||
$this->alias = $alias; | ||
} | ||
|
||
public function getSubFields(): array | ||
{ | ||
return $this->subFields; | ||
} | ||
|
||
public function setSubFields(array $subFields): void | ||
{ | ||
$this->subFields = $subFields; | ||
} | ||
|
||
public function getWrapLeft(): string | ||
{ | ||
return $this->wrapLeft; | ||
} | ||
|
||
public function setWrapLeft(string $wrapLeft): void | ||
{ | ||
$this->wrapLeft = $wrapLeft; | ||
} | ||
|
||
public function getWrapRight(): string | ||
{ | ||
return $this->wrapRight; | ||
} | ||
|
||
public function setWrapRight(string $wrapRight): void | ||
{ | ||
$this->wrapRight = $wrapRight; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function toString(IQuery $query): string | ||
{ | ||
if (null === $this->alias) | ||
{ | ||
$alias = ''; | ||
} | ||
else | ||
{ | ||
$alias = ' as ' . $query->fieldQuote($this->alias); | ||
} | ||
if ($this->subFields) | ||
{ | ||
$result = []; | ||
$binds = &$this->binds; | ||
foreach ($this->subFields as $k => $v) | ||
{ | ||
if (\is_int($k)) | ||
{ | ||
if ($v instanceof Field) | ||
{ | ||
$field = $v; | ||
} | ||
else | ||
{ | ||
$field = new Field(); | ||
$field->setValue($v ?? '', $query); | ||
} | ||
} | ||
else | ||
{ | ||
$field = new Field(null, null, $k, $v); | ||
} | ||
$result[] = $field->toString($query); | ||
$fieldBinds = $field->getBinds(); | ||
if ($fieldBinds) | ||
{ | ||
$binds = array_merge($binds, $fieldBinds); | ||
} | ||
} | ||
|
||
$result = implode(',', $result); | ||
} | ||
else | ||
{ | ||
$result = parent::toString($query); | ||
} | ||
|
||
return $this->wrapLeft . $result . $this->wrapRight . $alias; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters