CreateSchemaObjectsSQLBuilder.php
2 years ago
DefaultSelectSQLBuilder.php
2 years ago
DropSchemaObjectsSQLBuilder.php
2 years ago
SelectSQLBuilder.php
2 years ago
index.php
2 years ago
DefaultSelectSQLBuilder.php
69 lines
| 1 | <?php |
| 2 | namespace MailPoetVendor\Doctrine\DBAL\SQL\Builder; |
| 3 | if (!defined('ABSPATH')) exit; |
| 4 | use MailPoetVendor\Doctrine\DBAL\Exception; |
| 5 | use MailPoetVendor\Doctrine\DBAL\Platforms\AbstractPlatform; |
| 6 | use MailPoetVendor\Doctrine\DBAL\Query\ForUpdate\ConflictResolutionMode; |
| 7 | use MailPoetVendor\Doctrine\DBAL\Query\SelectQuery; |
| 8 | use function count; |
| 9 | use function implode; |
| 10 | final class DefaultSelectSQLBuilder implements SelectSQLBuilder |
| 11 | { |
| 12 | private AbstractPlatform $platform; |
| 13 | private ?string $forUpdateSQL; |
| 14 | private ?string $skipLockedSQL; |
| 15 | public function __construct(AbstractPlatform $platform, ?string $forUpdateSQL, ?string $skipLockedSQL) |
| 16 | { |
| 17 | $this->platform = $platform; |
| 18 | $this->forUpdateSQL = $forUpdateSQL; |
| 19 | $this->skipLockedSQL = $skipLockedSQL; |
| 20 | } |
| 21 | public function buildSQL(SelectQuery $query) : string |
| 22 | { |
| 23 | $parts = ['SELECT']; |
| 24 | if ($query->isDistinct()) { |
| 25 | $parts[] = 'DISTINCT'; |
| 26 | } |
| 27 | $parts[] = implode(', ', $query->getColumns()); |
| 28 | $from = $query->getFrom(); |
| 29 | if (count($from) > 0) { |
| 30 | $parts[] = 'FROM ' . implode(', ', $from); |
| 31 | } |
| 32 | $where = $query->getWhere(); |
| 33 | if ($where !== null) { |
| 34 | $parts[] = 'WHERE ' . $where; |
| 35 | } |
| 36 | $groupBy = $query->getGroupBy(); |
| 37 | if (count($groupBy) > 0) { |
| 38 | $parts[] = 'GROUP BY ' . implode(', ', $groupBy); |
| 39 | } |
| 40 | $having = $query->getHaving(); |
| 41 | if ($having !== null) { |
| 42 | $parts[] = 'HAVING ' . $having; |
| 43 | } |
| 44 | $orderBy = $query->getOrderBy(); |
| 45 | if (count($orderBy) > 0) { |
| 46 | $parts[] = 'ORDER BY ' . implode(', ', $orderBy); |
| 47 | } |
| 48 | $sql = implode(' ', $parts); |
| 49 | $limit = $query->getLimit(); |
| 50 | if ($limit->isDefined()) { |
| 51 | $sql = $this->platform->modifyLimitQuery($sql, $limit->getMaxResults(), $limit->getFirstResult()); |
| 52 | } |
| 53 | $forUpdate = $query->getForUpdate(); |
| 54 | if ($forUpdate !== null) { |
| 55 | if ($this->forUpdateSQL === null) { |
| 56 | throw Exception::notSupported('FOR UPDATE'); |
| 57 | } |
| 58 | $sql .= ' ' . $this->forUpdateSQL; |
| 59 | if ($forUpdate->getConflictResolutionMode() === ConflictResolutionMode::SKIP_LOCKED) { |
| 60 | if ($this->skipLockedSQL === null) { |
| 61 | throw Exception::notSupported('SKIP LOCKED'); |
| 62 | } |
| 63 | $sql .= ' ' . $this->skipLockedSQL; |
| 64 | } |
| 65 | } |
| 66 | return $sql; |
| 67 | } |
| 68 | } |
| 69 |