Primo rilascio

This commit is contained in:
2026-03-07 00:15:59 +01:00
commit dd5282dd69
609 changed files with 75246 additions and 0 deletions

View File

@@ -0,0 +1,73 @@
<?php
declare(strict_types=1);
namespace Doctrine\DBAL\SQL\Builder;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\Sequence;
use Doctrine\DBAL\Schema\Table;
use function array_merge;
final class CreateSchemaObjectsSQLBuilder
{
public function __construct(private readonly AbstractPlatform $platform)
{
}
/** @return list<string> */
public function buildSQL(Schema $schema): array
{
return array_merge(
$this->buildNamespaceStatements($schema->getNamespaces()),
$this->buildSequenceStatements($schema->getSequences()),
$this->buildTableStatements($schema->getTables()),
);
}
/**
* @param string[] $namespaces
*
* @return list<string>
*/
private function buildNamespaceStatements(array $namespaces): array
{
$statements = [];
if ($this->platform->supportsSchemas()) {
foreach ($namespaces as $namespace) {
$statements[] = $this->platform->getCreateSchemaSQL($namespace);
}
}
return $statements;
}
/**
* @param Table[] $tables
*
* @return list<string>
*/
private function buildTableStatements(array $tables): array
{
return $this->platform->getCreateTablesSQL($tables);
}
/**
* @param Sequence[] $sequences
*
* @return list<string>
*/
private function buildSequenceStatements(array $sequences): array
{
$statements = [];
foreach ($sequences as $sequence) {
$statements[] = $this->platform->getCreateSequenceSQL($sequence);
}
return $statements;
}
}

View File

@@ -0,0 +1,94 @@
<?php
declare(strict_types=1);
namespace Doctrine\DBAL\SQL\Builder;
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\Exception\NotSupported;
use Doctrine\DBAL\Query\ForUpdate\ConflictResolutionMode;
use Doctrine\DBAL\Query\SelectQuery;
use function count;
use function implode;
final class DefaultSelectSQLBuilder implements SelectSQLBuilder
{
/** @internal The SQL builder should be instantiated only by database platforms. */
public function __construct(
private readonly AbstractPlatform $platform,
private readonly ?string $forUpdateSQL,
private readonly ?string $skipLockedSQL,
) {
}
/** @throws Exception */
public function buildSQL(SelectQuery $query): string
{
$parts = ['SELECT'];
if ($query->isDistinct()) {
$parts[] = 'DISTINCT';
}
$parts[] = implode(', ', $query->getColumns());
$from = $query->getFrom();
if (count($from) > 0) {
$parts[] = 'FROM ' . implode(', ', $from);
}
$where = $query->getWhere();
if ($where !== null) {
$parts[] = 'WHERE ' . $where;
}
$groupBy = $query->getGroupBy();
if (count($groupBy) > 0) {
$parts[] = 'GROUP BY ' . implode(', ', $groupBy);
}
$having = $query->getHaving();
if ($having !== null) {
$parts[] = 'HAVING ' . $having;
}
$orderBy = $query->getOrderBy();
if (count($orderBy) > 0) {
$parts[] = 'ORDER BY ' . implode(', ', $orderBy);
}
$sql = implode(' ', $parts);
$limit = $query->getLimit();
if ($limit->isDefined()) {
$sql = $this->platform->modifyLimitQuery($sql, $limit->getMaxResults(), $limit->getFirstResult());
}
$forUpdate = $query->getForUpdate();
if ($forUpdate !== null) {
if ($this->forUpdateSQL === null) {
throw NotSupported::new('FOR UPDATE');
}
$sql .= ' ' . $this->forUpdateSQL;
if ($forUpdate->getConflictResolutionMode() === ConflictResolutionMode::SKIP_LOCKED) {
if ($this->skipLockedSQL === null) {
throw NotSupported::new('SKIP LOCKED');
}
$sql .= ' ' . $this->skipLockedSQL;
}
}
return $sql;
}
}

View File

@@ -0,0 +1,48 @@
<?php
declare(strict_types=1);
namespace Doctrine\DBAL\SQL\Builder;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Query\UnionQuery;
use Doctrine\DBAL\Query\UnionType;
use function count;
use function implode;
final class DefaultUnionSQLBuilder implements UnionSQLBuilder
{
public function __construct(
private readonly AbstractPlatform $platform,
) {
}
public function buildSQL(UnionQuery $query): string
{
$parts = [];
foreach ($query->getUnionParts() as $union) {
if ($union->type !== null) {
$parts[] = $union->type === UnionType::ALL
? $this->platform->getUnionAllSQL()
: $this->platform->getUnionDistinctSQL();
}
$parts[] = $this->platform->getUnionSelectPartSQL((string) $union->query);
}
$orderBy = $query->getOrderBy();
if (count($orderBy) > 0) {
$parts[] = 'ORDER BY ' . implode(', ', $orderBy);
}
$sql = implode(' ', $parts);
$limit = $query->getLimit();
if ($limit->isDefined()) {
$sql = $this->platform->modifyLimitQuery($sql, $limit->getMaxResults(), $limit->getFirstResult());
}
return $sql;
}
}

View File

@@ -0,0 +1,54 @@
<?php
declare(strict_types=1);
namespace Doctrine\DBAL\SQL\Builder;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\Sequence;
use Doctrine\DBAL\Schema\Table;
use function array_merge;
final class DropSchemaObjectsSQLBuilder
{
public function __construct(private readonly AbstractPlatform $platform)
{
}
/** @return list<string> */
public function buildSQL(Schema $schema): array
{
return array_merge(
$this->buildSequenceStatements($schema->getSequences()),
$this->buildTableStatements($schema->getTables()),
);
}
/**
* @param list<Table> $tables
*
* @return list<string>
*/
private function buildTableStatements(array $tables): array
{
return $this->platform->getDropTablesSQL($tables);
}
/**
* @param list<Sequence> $sequences
*
* @return list<string>
*/
private function buildSequenceStatements(array $sequences): array
{
$statements = [];
foreach ($sequences as $sequence) {
$statements[] = $this->platform->getDropSequenceSQL($sequence->getQuotedName($this->platform));
}
return $statements;
}
}

View File

@@ -0,0 +1,14 @@
<?php
declare(strict_types=1);
namespace Doctrine\DBAL\SQL\Builder;
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Query\SelectQuery;
interface SelectSQLBuilder
{
/** @throws Exception */
public function buildSQL(SelectQuery $query): string;
}

View File

@@ -0,0 +1,14 @@
<?php
declare(strict_types=1);
namespace Doctrine\DBAL\SQL\Builder;
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Query\UnionQuery;
interface UnionSQLBuilder
{
/** @throws Exception */
public function buildSQL(UnionQuery $query): string;
}