init
This commit is contained in:
@@ -0,0 +1 @@
|
||||
<?php
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
final class ArrayParameterType
|
||||
{
|
||||
public const INTEGER = ParameterType::INTEGER + Connection::ARRAY_PARAM_OFFSET;
|
||||
public const STRING = ParameterType::STRING + Connection::ARRAY_PARAM_OFFSET;
|
||||
public const ASCII = ParameterType::ASCII + Connection::ARRAY_PARAM_OFFSET;
|
||||
public const BINARY = ParameterType::BINARY + Connection::ARRAY_PARAM_OFFSET;
|
||||
public static function toElementParameterType(int $type) : int
|
||||
{
|
||||
return $type - Connection::ARRAY_PARAM_OFFSET;
|
||||
}
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL\ArrayParameters;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
use Throwable;
|
||||
interface Exception extends Throwable
|
||||
{
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL\ArrayParameters\Exception;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
use MailPoetVendor\Doctrine\DBAL\ArrayParameters\Exception;
|
||||
use LogicException;
|
||||
use function sprintf;
|
||||
class MissingNamedParameter extends LogicException implements Exception
|
||||
{
|
||||
public static function new(string $name) : self
|
||||
{
|
||||
return new self(sprintf('Named parameter "%s" does not have a bound value.', $name));
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL\ArrayParameters\Exception;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
use MailPoetVendor\Doctrine\DBAL\ArrayParameters\Exception;
|
||||
use LogicException;
|
||||
use function sprintf;
|
||||
class MissingPositionalParameter extends LogicException implements Exception
|
||||
{
|
||||
public static function new(int $index) : self
|
||||
{
|
||||
return new self(sprintf('Positional parameter at index %d does not have a bound value.', $index));
|
||||
}
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
<?php
|
||||
+1
@@ -0,0 +1 @@
|
||||
<?php
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Cache;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
use MailPoetVendor\Doctrine\DBAL\Driver\FetchUtils;
|
||||
use MailPoetVendor\Doctrine\DBAL\Driver\Result;
|
||||
use function array_values;
|
||||
use function count;
|
||||
use function reset;
|
||||
final class ArrayResult implements Result
|
||||
{
|
||||
private array $data;
|
||||
private int $columnCount = 0;
|
||||
private int $num = 0;
|
||||
public function __construct(array $data)
|
||||
{
|
||||
$this->data = $data;
|
||||
if (count($data) === 0) {
|
||||
return;
|
||||
}
|
||||
$this->columnCount = count($data[0]);
|
||||
}
|
||||
public function fetchNumeric()
|
||||
{
|
||||
$row = $this->fetch();
|
||||
if ($row === \false) {
|
||||
return \false;
|
||||
}
|
||||
return array_values($row);
|
||||
}
|
||||
public function fetchAssociative()
|
||||
{
|
||||
return $this->fetch();
|
||||
}
|
||||
public function fetchOne()
|
||||
{
|
||||
$row = $this->fetch();
|
||||
if ($row === \false) {
|
||||
return \false;
|
||||
}
|
||||
return reset($row);
|
||||
}
|
||||
public function fetchAllNumeric() : array
|
||||
{
|
||||
return FetchUtils::fetchAllNumeric($this);
|
||||
}
|
||||
public function fetchAllAssociative() : array
|
||||
{
|
||||
return FetchUtils::fetchAllAssociative($this);
|
||||
}
|
||||
public function fetchFirstColumn() : array
|
||||
{
|
||||
return FetchUtils::fetchFirstColumn($this);
|
||||
}
|
||||
public function rowCount() : int
|
||||
{
|
||||
return count($this->data);
|
||||
}
|
||||
public function columnCount() : int
|
||||
{
|
||||
return $this->columnCount;
|
||||
}
|
||||
public function free() : void
|
||||
{
|
||||
$this->data = [];
|
||||
}
|
||||
private function fetch()
|
||||
{
|
||||
if (!isset($this->data[$this->num])) {
|
||||
return \false;
|
||||
}
|
||||
return $this->data[$this->num++];
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Cache;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
use MailPoetVendor\Doctrine\DBAL\Exception;
|
||||
class CacheException extends Exception
|
||||
{
|
||||
public static function noCacheKey()
|
||||
{
|
||||
return new self('No cache key was set.');
|
||||
}
|
||||
public static function noResultDriverConfigured()
|
||||
{
|
||||
return new self('Trying to cache a query but no result driver is configured.');
|
||||
}
|
||||
}
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Cache;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
use MailPoetVendor\Doctrine\Common\Cache\Cache;
|
||||
use MailPoetVendor\Doctrine\Common\Cache\Psr6\CacheAdapter;
|
||||
use MailPoetVendor\Doctrine\Common\Cache\Psr6\DoctrineProvider;
|
||||
use MailPoetVendor\Doctrine\DBAL\Types\Type;
|
||||
use MailPoetVendor\Doctrine\Deprecations\Deprecation;
|
||||
use MailPoetVendor\Psr\Cache\CacheItemPoolInterface;
|
||||
use TypeError;
|
||||
use function get_class;
|
||||
use function hash;
|
||||
use function serialize;
|
||||
use function sha1;
|
||||
use function sprintf;
|
||||
class QueryCacheProfile
|
||||
{
|
||||
private ?CacheItemPoolInterface $resultCache = null;
|
||||
private $lifetime;
|
||||
private $cacheKey;
|
||||
public function __construct($lifetime = 0, $cacheKey = null, ?object $resultCache = null)
|
||||
{
|
||||
$this->lifetime = $lifetime;
|
||||
$this->cacheKey = $cacheKey;
|
||||
if ($resultCache instanceof CacheItemPoolInterface) {
|
||||
$this->resultCache = $resultCache;
|
||||
} elseif ($resultCache instanceof Cache) {
|
||||
Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4620', 'Passing an instance of %s to %s as $resultCache is deprecated. Pass an instance of %s instead.', Cache::class, __METHOD__, CacheItemPoolInterface::class);
|
||||
$this->resultCache = CacheAdapter::wrap($resultCache);
|
||||
} elseif ($resultCache !== null) {
|
||||
throw new TypeError(sprintf('$resultCache: Expected either null or an instance of %s or %s, got %s.', CacheItemPoolInterface::class, Cache::class, get_class($resultCache)));
|
||||
}
|
||||
}
|
||||
public function getResultCache() : ?CacheItemPoolInterface
|
||||
{
|
||||
return $this->resultCache;
|
||||
}
|
||||
public function getResultCacheDriver()
|
||||
{
|
||||
Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4620', '%s is deprecated, call getResultCache() instead.', __METHOD__);
|
||||
return $this->resultCache !== null ? DoctrineProvider::wrap($this->resultCache) : null;
|
||||
}
|
||||
public function getLifetime()
|
||||
{
|
||||
return $this->lifetime;
|
||||
}
|
||||
public function getCacheKey()
|
||||
{
|
||||
if ($this->cacheKey === null) {
|
||||
throw CacheException::noCacheKey();
|
||||
}
|
||||
return $this->cacheKey;
|
||||
}
|
||||
public function generateCacheKeys($sql, $params, $types, array $connectionParams = [])
|
||||
{
|
||||
if (isset($connectionParams['password'])) {
|
||||
unset($connectionParams['password']);
|
||||
}
|
||||
$realCacheKey = 'query=' . $sql . '¶ms=' . serialize($params) . '&types=' . serialize($types) . '&connectionParams=' . hash('sha256', serialize($connectionParams));
|
||||
// should the key be automatically generated using the inputs or is the cache key set?
|
||||
$cacheKey = $this->cacheKey ?? sha1($realCacheKey);
|
||||
return [$cacheKey, $realCacheKey];
|
||||
}
|
||||
public function setResultCache(CacheItemPoolInterface $cache) : QueryCacheProfile
|
||||
{
|
||||
return new QueryCacheProfile($this->lifetime, $this->cacheKey, $cache);
|
||||
}
|
||||
public function setResultCacheDriver(Cache $cache)
|
||||
{
|
||||
Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4620', '%s is deprecated, call setResultCache() instead.', __METHOD__);
|
||||
return new QueryCacheProfile($this->lifetime, $this->cacheKey, CacheAdapter::wrap($cache));
|
||||
}
|
||||
public function setCacheKey($cacheKey)
|
||||
{
|
||||
return new QueryCacheProfile($this->lifetime, $cacheKey, $this->resultCache);
|
||||
}
|
||||
public function setLifetime($lifetime)
|
||||
{
|
||||
return new QueryCacheProfile($lifetime, $this->cacheKey, $this->resultCache);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<?php
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
final class ColumnCase
|
||||
{
|
||||
public const UPPER = 1;
|
||||
public const LOWER = 2;
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
use MailPoetVendor\Doctrine\Common\Cache\Cache;
|
||||
use MailPoetVendor\Doctrine\Common\Cache\Psr6\CacheAdapter;
|
||||
use MailPoetVendor\Doctrine\Common\Cache\Psr6\DoctrineProvider;
|
||||
use MailPoetVendor\Doctrine\DBAL\Driver\Middleware;
|
||||
use MailPoetVendor\Doctrine\DBAL\Logging\SQLLogger;
|
||||
use MailPoetVendor\Doctrine\DBAL\Schema\SchemaManagerFactory;
|
||||
use MailPoetVendor\Doctrine\Deprecations\Deprecation;
|
||||
use MailPoetVendor\Psr\Cache\CacheItemPoolInterface;
|
||||
use function func_num_args;
|
||||
class Configuration
|
||||
{
|
||||
private array $middlewares = [];
|
||||
protected $sqlLogger;
|
||||
private ?CacheItemPoolInterface $resultCache = null;
|
||||
protected $resultCacheImpl;
|
||||
protected $schemaAssetsFilter;
|
||||
protected $autoCommit = \true;
|
||||
private bool $disableTypeComments = \false;
|
||||
private ?SchemaManagerFactory $schemaManagerFactory = null;
|
||||
public function __construct()
|
||||
{
|
||||
$this->schemaAssetsFilter = static function () : bool {
|
||||
return \true;
|
||||
};
|
||||
}
|
||||
public function setSQLLogger(?SQLLogger $logger = null) : void
|
||||
{
|
||||
Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4967', '%s is deprecated, use setMiddlewares() and Logging\\Middleware instead.', __METHOD__);
|
||||
$this->sqlLogger = $logger;
|
||||
}
|
||||
public function getSQLLogger() : ?SQLLogger
|
||||
{
|
||||
Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4967', '%s is deprecated.', __METHOD__);
|
||||
return $this->sqlLogger;
|
||||
}
|
||||
public function getResultCache() : ?CacheItemPoolInterface
|
||||
{
|
||||
return $this->resultCache;
|
||||
}
|
||||
public function getResultCacheImpl() : ?Cache
|
||||
{
|
||||
Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4620', '%s is deprecated, call getResultCache() instead.', __METHOD__);
|
||||
return $this->resultCacheImpl;
|
||||
}
|
||||
public function setResultCache(CacheItemPoolInterface $cache) : void
|
||||
{
|
||||
$this->resultCacheImpl = DoctrineProvider::wrap($cache);
|
||||
$this->resultCache = $cache;
|
||||
}
|
||||
public function setResultCacheImpl(Cache $cacheImpl) : void
|
||||
{
|
||||
Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4620', '%s is deprecated, call setResultCache() instead.', __METHOD__);
|
||||
$this->resultCacheImpl = $cacheImpl;
|
||||
$this->resultCache = CacheAdapter::wrap($cacheImpl);
|
||||
}
|
||||
public function setSchemaAssetsFilter(?callable $callable = null) : void
|
||||
{
|
||||
if (func_num_args() < 1) {
|
||||
Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5483', 'Not passing an argument to %s is deprecated.', __METHOD__);
|
||||
} elseif ($callable === null) {
|
||||
Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5483', 'Using NULL as a schema asset filter is deprecated.' . ' Use a callable that always returns true instead.');
|
||||
}
|
||||
$this->schemaAssetsFilter = $callable;
|
||||
}
|
||||
public function getSchemaAssetsFilter() : ?callable
|
||||
{
|
||||
return $this->schemaAssetsFilter;
|
||||
}
|
||||
public function setAutoCommit(bool $autoCommit) : void
|
||||
{
|
||||
$this->autoCommit = $autoCommit;
|
||||
}
|
||||
public function getAutoCommit() : bool
|
||||
{
|
||||
return $this->autoCommit;
|
||||
}
|
||||
public function setMiddlewares(array $middlewares) : self
|
||||
{
|
||||
$this->middlewares = $middlewares;
|
||||
return $this;
|
||||
}
|
||||
public function getMiddlewares() : array
|
||||
{
|
||||
return $this->middlewares;
|
||||
}
|
||||
public function getSchemaManagerFactory() : ?SchemaManagerFactory
|
||||
{
|
||||
return $this->schemaManagerFactory;
|
||||
}
|
||||
public function setSchemaManagerFactory(SchemaManagerFactory $schemaManagerFactory) : self
|
||||
{
|
||||
$this->schemaManagerFactory = $schemaManagerFactory;
|
||||
return $this;
|
||||
}
|
||||
public function getDisableTypeComments() : bool
|
||||
{
|
||||
return $this->disableTypeComments;
|
||||
}
|
||||
public function setDisableTypeComments(bool $disableTypeComments) : self
|
||||
{
|
||||
$this->disableTypeComments = $disableTypeComments;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,842 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
use Closure;
|
||||
use MailPoetVendor\Doctrine\Common\EventManager;
|
||||
use MailPoetVendor\Doctrine\DBAL\Cache\ArrayResult;
|
||||
use MailPoetVendor\Doctrine\DBAL\Cache\CacheException;
|
||||
use MailPoetVendor\Doctrine\DBAL\Cache\QueryCacheProfile;
|
||||
use MailPoetVendor\Doctrine\DBAL\Driver\API\ExceptionConverter;
|
||||
use MailPoetVendor\Doctrine\DBAL\Driver\Connection as DriverConnection;
|
||||
use MailPoetVendor\Doctrine\DBAL\Driver\ServerInfoAwareConnection;
|
||||
use MailPoetVendor\Doctrine\DBAL\Driver\Statement as DriverStatement;
|
||||
use MailPoetVendor\Doctrine\DBAL\Event\TransactionBeginEventArgs;
|
||||
use MailPoetVendor\Doctrine\DBAL\Event\TransactionCommitEventArgs;
|
||||
use MailPoetVendor\Doctrine\DBAL\Event\TransactionRollBackEventArgs;
|
||||
use MailPoetVendor\Doctrine\DBAL\Exception\ConnectionLost;
|
||||
use MailPoetVendor\Doctrine\DBAL\Exception\DriverException;
|
||||
use MailPoetVendor\Doctrine\DBAL\Exception\InvalidArgumentException;
|
||||
use MailPoetVendor\Doctrine\DBAL\Platforms\AbstractPlatform;
|
||||
use MailPoetVendor\Doctrine\DBAL\Query\Expression\ExpressionBuilder;
|
||||
use MailPoetVendor\Doctrine\DBAL\Query\QueryBuilder;
|
||||
use MailPoetVendor\Doctrine\DBAL\Schema\AbstractSchemaManager;
|
||||
use MailPoetVendor\Doctrine\DBAL\Schema\DefaultSchemaManagerFactory;
|
||||
use MailPoetVendor\Doctrine\DBAL\Schema\LegacySchemaManagerFactory;
|
||||
use MailPoetVendor\Doctrine\DBAL\Schema\SchemaManagerFactory;
|
||||
use MailPoetVendor\Doctrine\DBAL\SQL\Parser;
|
||||
use MailPoetVendor\Doctrine\DBAL\Types\Type;
|
||||
use MailPoetVendor\Doctrine\Deprecations\Deprecation;
|
||||
use LogicException;
|
||||
use MailPoetVendor\SensitiveParameter;
|
||||
use Throwable;
|
||||
use Traversable;
|
||||
use function array_key_exists;
|
||||
use function assert;
|
||||
use function count;
|
||||
use function get_class;
|
||||
use function implode;
|
||||
use function is_array;
|
||||
use function is_int;
|
||||
use function is_string;
|
||||
use function key;
|
||||
use function method_exists;
|
||||
use function sprintf;
|
||||
class Connection
|
||||
{
|
||||
public const PARAM_INT_ARRAY = ArrayParameterType::INTEGER;
|
||||
public const PARAM_STR_ARRAY = ArrayParameterType::STRING;
|
||||
public const PARAM_ASCII_STR_ARRAY = ArrayParameterType::ASCII;
|
||||
public const ARRAY_PARAM_OFFSET = 100;
|
||||
protected $_conn;
|
||||
protected $_config;
|
||||
protected $_eventManager;
|
||||
protected $_expr;
|
||||
private bool $autoCommit = \true;
|
||||
private int $transactionNestingLevel = 0;
|
||||
private $transactionIsolationLevel;
|
||||
private bool $nestTransactionsWithSavepoints = \false;
|
||||
private array $params;
|
||||
private ?AbstractPlatform $platform = null;
|
||||
private ?ExceptionConverter $exceptionConverter = null;
|
||||
private ?Parser $parser = null;
|
||||
protected $_schemaManager;
|
||||
protected $_driver;
|
||||
private bool $isRollbackOnly = \false;
|
||||
private SchemaManagerFactory $schemaManagerFactory;
|
||||
public function __construct( array $params, Driver $driver, ?Configuration $config = null, ?EventManager $eventManager = null)
|
||||
{
|
||||
$this->_driver = $driver;
|
||||
$this->params = $params;
|
||||
// Create default config and event manager if none given
|
||||
$config ??= new Configuration();
|
||||
$eventManager ??= new EventManager();
|
||||
$this->_config = $config;
|
||||
$this->_eventManager = $eventManager;
|
||||
if (isset($params['platform'])) {
|
||||
if (!$params['platform'] instanceof Platforms\AbstractPlatform) {
|
||||
throw Exception::invalidPlatformType($params['platform']);
|
||||
}
|
||||
Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5699', 'The "platform" connection parameter is deprecated.' . ' Use a driver middleware that would instantiate the platform instead.');
|
||||
$this->platform = $params['platform'];
|
||||
$this->platform->setEventManager($this->_eventManager);
|
||||
$this->platform->setDisableTypeComments($config->getDisableTypeComments());
|
||||
}
|
||||
$this->_expr = $this->createExpressionBuilder();
|
||||
$this->autoCommit = $config->getAutoCommit();
|
||||
$schemaManagerFactory = $config->getSchemaManagerFactory();
|
||||
if ($schemaManagerFactory === null) {
|
||||
Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/issues/5812', 'Not configuring a schema manager factory is deprecated.' . ' Use %s which is going to be the default in DBAL 4.', DefaultSchemaManagerFactory::class);
|
||||
$schemaManagerFactory = new LegacySchemaManagerFactory();
|
||||
}
|
||||
$this->schemaManagerFactory = $schemaManagerFactory;
|
||||
}
|
||||
public function getParams()
|
||||
{
|
||||
return $this->params;
|
||||
}
|
||||
public function getDatabase()
|
||||
{
|
||||
$platform = $this->getDatabasePlatform();
|
||||
$query = $platform->getDummySelectSQL($platform->getCurrentDatabaseExpression());
|
||||
$database = $this->fetchOne($query);
|
||||
assert(is_string($database) || $database === null);
|
||||
return $database;
|
||||
}
|
||||
public function getDriver()
|
||||
{
|
||||
return $this->_driver;
|
||||
}
|
||||
public function getConfiguration()
|
||||
{
|
||||
return $this->_config;
|
||||
}
|
||||
public function getEventManager()
|
||||
{
|
||||
Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/issues/5784', '%s is deprecated.', __METHOD__);
|
||||
return $this->_eventManager;
|
||||
}
|
||||
public function getDatabasePlatform()
|
||||
{
|
||||
if ($this->platform === null) {
|
||||
$this->platform = $this->detectDatabasePlatform();
|
||||
$this->platform->setEventManager($this->_eventManager);
|
||||
$this->platform->setDisableTypeComments($this->_config->getDisableTypeComments());
|
||||
}
|
||||
return $this->platform;
|
||||
}
|
||||
public function createExpressionBuilder() : ExpressionBuilder
|
||||
{
|
||||
return new ExpressionBuilder($this);
|
||||
}
|
||||
public function getExpressionBuilder()
|
||||
{
|
||||
Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/issues/4515', 'Connection::getExpressionBuilder() is deprecated,' . ' use Connection::createExpressionBuilder() instead.');
|
||||
return $this->_expr;
|
||||
}
|
||||
public function connect()
|
||||
{
|
||||
Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/issues/4966', 'Public access to Connection::connect() is deprecated.');
|
||||
if ($this->_conn !== null) {
|
||||
return \false;
|
||||
}
|
||||
try {
|
||||
$this->_conn = $this->_driver->connect($this->params);
|
||||
} catch (Driver\Exception $e) {
|
||||
throw $this->convertException($e);
|
||||
}
|
||||
if ($this->autoCommit === \false) {
|
||||
$this->beginTransaction();
|
||||
}
|
||||
if ($this->_eventManager->hasListeners(Events::postConnect)) {
|
||||
Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/issues/5784', 'Subscribing to %s events is deprecated. Implement a middleware instead.', Events::postConnect);
|
||||
$eventArgs = new Event\ConnectionEventArgs($this);
|
||||
$this->_eventManager->dispatchEvent(Events::postConnect, $eventArgs);
|
||||
}
|
||||
return \true;
|
||||
}
|
||||
private function detectDatabasePlatform() : AbstractPlatform
|
||||
{
|
||||
$version = $this->getDatabasePlatformVersion();
|
||||
if ($version !== null) {
|
||||
assert($this->_driver instanceof VersionAwarePlatformDriver);
|
||||
return $this->_driver->createDatabasePlatformForVersion($version);
|
||||
}
|
||||
return $this->_driver->getDatabasePlatform();
|
||||
}
|
||||
private function getDatabasePlatformVersion()
|
||||
{
|
||||
// Driver does not support version specific platforms.
|
||||
if (!$this->_driver instanceof VersionAwarePlatformDriver) {
|
||||
return null;
|
||||
}
|
||||
// Explicit platform version requested (supersedes auto-detection).
|
||||
if (isset($this->params['serverVersion'])) {
|
||||
return $this->params['serverVersion'];
|
||||
}
|
||||
if (isset($this->params['primary']) && isset($this->params['primary']['serverVersion'])) {
|
||||
return $this->params['primary']['serverVersion'];
|
||||
}
|
||||
// If not connected, we need to connect now to determine the platform version.
|
||||
if ($this->_conn === null) {
|
||||
try {
|
||||
$this->connect();
|
||||
} catch (Exception $originalException) {
|
||||
if (!isset($this->params['dbname'])) {
|
||||
throw $originalException;
|
||||
}
|
||||
Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5707', 'Relying on a fallback connection used to determine the database platform while connecting' . ' to a non-existing database is deprecated. Either use an existing database name in' . ' connection parameters or omit the database name if the platform' . ' and the server configuration allow that.');
|
||||
// The database to connect to might not yet exist.
|
||||
// Retry detection without database name connection parameter.
|
||||
$params = $this->params;
|
||||
unset($this->params['dbname']);
|
||||
try {
|
||||
$this->connect();
|
||||
} catch (Exception $fallbackException) {
|
||||
// Either the platform does not support database-less connections
|
||||
// or something else went wrong.
|
||||
throw $originalException;
|
||||
} finally {
|
||||
$this->params = $params;
|
||||
}
|
||||
$serverVersion = $this->getServerVersion();
|
||||
// Close "temporary" connection to allow connecting to the real database again.
|
||||
$this->close();
|
||||
return $serverVersion;
|
||||
}
|
||||
}
|
||||
return $this->getServerVersion();
|
||||
}
|
||||
private function getServerVersion()
|
||||
{
|
||||
$connection = $this->getWrappedConnection();
|
||||
// Automatic platform version detection.
|
||||
if ($connection instanceof ServerInfoAwareConnection) {
|
||||
try {
|
||||
return $connection->getServerVersion();
|
||||
} catch (Driver\Exception $e) {
|
||||
throw $this->convertException($e);
|
||||
}
|
||||
}
|
||||
Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4750', 'Not implementing the ServerInfoAwareConnection interface in %s is deprecated', get_class($connection));
|
||||
// Unable to detect platform version.
|
||||
return null;
|
||||
}
|
||||
public function isAutoCommit()
|
||||
{
|
||||
return $this->autoCommit === \true;
|
||||
}
|
||||
public function setAutoCommit($autoCommit)
|
||||
{
|
||||
$autoCommit = (bool) $autoCommit;
|
||||
// Mode not changed, no-op.
|
||||
if ($autoCommit === $this->autoCommit) {
|
||||
return;
|
||||
}
|
||||
$this->autoCommit = $autoCommit;
|
||||
// Commit all currently active transactions if any when switching auto-commit mode.
|
||||
if ($this->_conn === null || $this->transactionNestingLevel === 0) {
|
||||
return;
|
||||
}
|
||||
$this->commitAll();
|
||||
}
|
||||
public function fetchAssociative(string $query, array $params = [], array $types = [])
|
||||
{
|
||||
return $this->executeQuery($query, $params, $types)->fetchAssociative();
|
||||
}
|
||||
public function fetchNumeric(string $query, array $params = [], array $types = [])
|
||||
{
|
||||
return $this->executeQuery($query, $params, $types)->fetchNumeric();
|
||||
}
|
||||
public function fetchOne(string $query, array $params = [], array $types = [])
|
||||
{
|
||||
return $this->executeQuery($query, $params, $types)->fetchOne();
|
||||
}
|
||||
public function isConnected()
|
||||
{
|
||||
return $this->_conn !== null;
|
||||
}
|
||||
public function isTransactionActive()
|
||||
{
|
||||
return $this->transactionNestingLevel > 0;
|
||||
}
|
||||
private function addCriteriaCondition(array $criteria, array &$columns, array &$values, array &$conditions) : void
|
||||
{
|
||||
$platform = $this->getDatabasePlatform();
|
||||
foreach ($criteria as $columnName => $value) {
|
||||
if ($value === null) {
|
||||
$conditions[] = $platform->getIsNullExpression($columnName);
|
||||
continue;
|
||||
}
|
||||
$columns[] = $columnName;
|
||||
$values[] = $value;
|
||||
$conditions[] = $columnName . ' = ?';
|
||||
}
|
||||
}
|
||||
public function delete($table, array $criteria, array $types = [])
|
||||
{
|
||||
if (count($criteria) === 0) {
|
||||
throw InvalidArgumentException::fromEmptyCriteria();
|
||||
}
|
||||
$columns = $values = $conditions = [];
|
||||
$this->addCriteriaCondition($criteria, $columns, $values, $conditions);
|
||||
return $this->executeStatement('DELETE FROM ' . $table . ' WHERE ' . implode(' AND ', $conditions), $values, is_string(key($types)) ? $this->extractTypeValues($columns, $types) : $types);
|
||||
}
|
||||
public function close()
|
||||
{
|
||||
$this->_conn = null;
|
||||
$this->transactionNestingLevel = 0;
|
||||
}
|
||||
public function setTransactionIsolation($level)
|
||||
{
|
||||
$this->transactionIsolationLevel = $level;
|
||||
return $this->executeStatement($this->getDatabasePlatform()->getSetTransactionIsolationSQL($level));
|
||||
}
|
||||
public function getTransactionIsolation()
|
||||
{
|
||||
return $this->transactionIsolationLevel ??= $this->getDatabasePlatform()->getDefaultTransactionIsolationLevel();
|
||||
}
|
||||
public function update($table, array $data, array $criteria, array $types = [])
|
||||
{
|
||||
$columns = $values = $conditions = $set = [];
|
||||
foreach ($data as $columnName => $value) {
|
||||
$columns[] = $columnName;
|
||||
$values[] = $value;
|
||||
$set[] = $columnName . ' = ?';
|
||||
}
|
||||
$this->addCriteriaCondition($criteria, $columns, $values, $conditions);
|
||||
if (is_string(key($types))) {
|
||||
$types = $this->extractTypeValues($columns, $types);
|
||||
}
|
||||
$sql = 'UPDATE ' . $table . ' SET ' . implode(', ', $set) . ' WHERE ' . implode(' AND ', $conditions);
|
||||
return $this->executeStatement($sql, $values, $types);
|
||||
}
|
||||
public function insert($table, array $data, array $types = [])
|
||||
{
|
||||
if (count($data) === 0) {
|
||||
return $this->executeStatement('INSERT INTO ' . $table . ' () VALUES ()');
|
||||
}
|
||||
$columns = [];
|
||||
$values = [];
|
||||
$set = [];
|
||||
foreach ($data as $columnName => $value) {
|
||||
$columns[] = $columnName;
|
||||
$values[] = $value;
|
||||
$set[] = '?';
|
||||
}
|
||||
return $this->executeStatement('INSERT INTO ' . $table . ' (' . implode(', ', $columns) . ')' . ' VALUES (' . implode(', ', $set) . ')', $values, is_string(key($types)) ? $this->extractTypeValues($columns, $types) : $types);
|
||||
}
|
||||
private function extractTypeValues(array $columnList, array $types) : array
|
||||
{
|
||||
$typeValues = [];
|
||||
foreach ($columnList as $columnName) {
|
||||
$typeValues[] = $types[$columnName] ?? ParameterType::STRING;
|
||||
}
|
||||
return $typeValues;
|
||||
}
|
||||
public function quoteIdentifier($str)
|
||||
{
|
||||
return $this->getDatabasePlatform()->quoteIdentifier($str);
|
||||
}
|
||||
public function quote($value, $type = ParameterType::STRING)
|
||||
{
|
||||
$connection = $this->getWrappedConnection();
|
||||
[$value, $bindingType] = $this->getBindingInfo($value, $type);
|
||||
return $connection->quote($value, $bindingType);
|
||||
}
|
||||
public function fetchAllNumeric(string $query, array $params = [], array $types = []) : array
|
||||
{
|
||||
return $this->executeQuery($query, $params, $types)->fetchAllNumeric();
|
||||
}
|
||||
public function fetchAllAssociative(string $query, array $params = [], array $types = []) : array
|
||||
{
|
||||
return $this->executeQuery($query, $params, $types)->fetchAllAssociative();
|
||||
}
|
||||
public function fetchAllKeyValue(string $query, array $params = [], array $types = []) : array
|
||||
{
|
||||
return $this->executeQuery($query, $params, $types)->fetchAllKeyValue();
|
||||
}
|
||||
public function fetchAllAssociativeIndexed(string $query, array $params = [], array $types = []) : array
|
||||
{
|
||||
return $this->executeQuery($query, $params, $types)->fetchAllAssociativeIndexed();
|
||||
}
|
||||
public function fetchFirstColumn(string $query, array $params = [], array $types = []) : array
|
||||
{
|
||||
return $this->executeQuery($query, $params, $types)->fetchFirstColumn();
|
||||
}
|
||||
public function iterateNumeric(string $query, array $params = [], array $types = []) : Traversable
|
||||
{
|
||||
return $this->executeQuery($query, $params, $types)->iterateNumeric();
|
||||
}
|
||||
public function iterateAssociative(string $query, array $params = [], array $types = []) : Traversable
|
||||
{
|
||||
return $this->executeQuery($query, $params, $types)->iterateAssociative();
|
||||
}
|
||||
public function iterateKeyValue(string $query, array $params = [], array $types = []) : Traversable
|
||||
{
|
||||
return $this->executeQuery($query, $params, $types)->iterateKeyValue();
|
||||
}
|
||||
public function iterateAssociativeIndexed(string $query, array $params = [], array $types = []) : Traversable
|
||||
{
|
||||
return $this->executeQuery($query, $params, $types)->iterateAssociativeIndexed();
|
||||
}
|
||||
public function iterateColumn(string $query, array $params = [], array $types = []) : Traversable
|
||||
{
|
||||
return $this->executeQuery($query, $params, $types)->iterateColumn();
|
||||
}
|
||||
public function prepare(string $sql) : Statement
|
||||
{
|
||||
$connection = $this->getWrappedConnection();
|
||||
try {
|
||||
$statement = $connection->prepare($sql);
|
||||
} catch (Driver\Exception $e) {
|
||||
throw $this->convertExceptionDuringQuery($e, $sql);
|
||||
}
|
||||
return new Statement($this, $statement, $sql);
|
||||
}
|
||||
public function executeQuery(string $sql, array $params = [], $types = [], ?QueryCacheProfile $qcp = null) : Result
|
||||
{
|
||||
if ($qcp !== null) {
|
||||
return $this->executeCacheQuery($sql, $params, $types, $qcp);
|
||||
}
|
||||
$connection = $this->getWrappedConnection();
|
||||
$logger = $this->_config->getSQLLogger();
|
||||
if ($logger !== null) {
|
||||
$logger->startQuery($sql, $params, $types);
|
||||
}
|
||||
try {
|
||||
if (count($params) > 0) {
|
||||
if ($this->needsArrayParameterConversion($params, $types)) {
|
||||
[$sql, $params, $types] = $this->expandArrayParameters($sql, $params, $types);
|
||||
}
|
||||
$stmt = $connection->prepare($sql);
|
||||
$this->bindParameters($stmt, $params, $types);
|
||||
$result = $stmt->execute();
|
||||
} else {
|
||||
$result = $connection->query($sql);
|
||||
}
|
||||
return new Result($result, $this);
|
||||
} catch (Driver\Exception $e) {
|
||||
throw $this->convertExceptionDuringQuery($e, $sql, $params, $types);
|
||||
} finally {
|
||||
if ($logger !== null) {
|
||||
$logger->stopQuery();
|
||||
}
|
||||
}
|
||||
}
|
||||
public function executeCacheQuery($sql, $params, $types, QueryCacheProfile $qcp) : Result
|
||||
{
|
||||
$resultCache = $qcp->getResultCache() ?? $this->_config->getResultCache();
|
||||
if ($resultCache === null) {
|
||||
throw CacheException::noResultDriverConfigured();
|
||||
}
|
||||
$connectionParams = $this->params;
|
||||
unset($connectionParams['platform'], $connectionParams['password'], $connectionParams['url']);
|
||||
[$cacheKey, $realKey] = $qcp->generateCacheKeys($sql, $params, $types, $connectionParams);
|
||||
$item = $resultCache->getItem($cacheKey);
|
||||
if ($item->isHit()) {
|
||||
$value = $item->get();
|
||||
if (!is_array($value)) {
|
||||
$value = [];
|
||||
}
|
||||
if (isset($value[$realKey])) {
|
||||
return new Result(new ArrayResult($value[$realKey]), $this);
|
||||
}
|
||||
} else {
|
||||
$value = [];
|
||||
}
|
||||
$data = $this->fetchAllAssociative($sql, $params, $types);
|
||||
$value[$realKey] = $data;
|
||||
$item->set($value);
|
||||
$lifetime = $qcp->getLifetime();
|
||||
if ($lifetime > 0) {
|
||||
$item->expiresAfter($lifetime);
|
||||
}
|
||||
$resultCache->save($item);
|
||||
return new Result(new ArrayResult($data), $this);
|
||||
}
|
||||
public function executeStatement($sql, array $params = [], array $types = [])
|
||||
{
|
||||
$connection = $this->getWrappedConnection();
|
||||
$logger = $this->_config->getSQLLogger();
|
||||
if ($logger !== null) {
|
||||
$logger->startQuery($sql, $params, $types);
|
||||
}
|
||||
try {
|
||||
if (count($params) > 0) {
|
||||
if ($this->needsArrayParameterConversion($params, $types)) {
|
||||
[$sql, $params, $types] = $this->expandArrayParameters($sql, $params, $types);
|
||||
}
|
||||
$stmt = $connection->prepare($sql);
|
||||
$this->bindParameters($stmt, $params, $types);
|
||||
return $stmt->execute()->rowCount();
|
||||
}
|
||||
return $connection->exec($sql);
|
||||
} catch (Driver\Exception $e) {
|
||||
throw $this->convertExceptionDuringQuery($e, $sql, $params, $types);
|
||||
} finally {
|
||||
if ($logger !== null) {
|
||||
$logger->stopQuery();
|
||||
}
|
||||
}
|
||||
}
|
||||
public function getTransactionNestingLevel()
|
||||
{
|
||||
return $this->transactionNestingLevel;
|
||||
}
|
||||
public function lastInsertId($name = null)
|
||||
{
|
||||
if ($name !== null) {
|
||||
Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/issues/4687', 'The usage of Connection::lastInsertId() with a sequence name is deprecated.');
|
||||
}
|
||||
try {
|
||||
return $this->getWrappedConnection()->lastInsertId($name);
|
||||
} catch (Driver\Exception $e) {
|
||||
throw $this->convertException($e);
|
||||
}
|
||||
}
|
||||
public function transactional(Closure $func)
|
||||
{
|
||||
$this->beginTransaction();
|
||||
try {
|
||||
$res = $func($this);
|
||||
$this->commit();
|
||||
return $res;
|
||||
} catch (Throwable $e) {
|
||||
$this->rollBack();
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
public function setNestTransactionsWithSavepoints($nestTransactionsWithSavepoints)
|
||||
{
|
||||
if (!$nestTransactionsWithSavepoints) {
|
||||
Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5383', <<<'DEPRECATION'
|
||||
Nesting transactions without enabling savepoints is deprecated.
|
||||
Call %s::setNestTransactionsWithSavepoints(true) to enable savepoints.
|
||||
DEPRECATION
|
||||
, self::class);
|
||||
}
|
||||
if ($this->transactionNestingLevel > 0) {
|
||||
throw ConnectionException::mayNotAlterNestedTransactionWithSavepointsInTransaction();
|
||||
}
|
||||
$this->nestTransactionsWithSavepoints = (bool) $nestTransactionsWithSavepoints;
|
||||
}
|
||||
public function getNestTransactionsWithSavepoints()
|
||||
{
|
||||
return $this->nestTransactionsWithSavepoints;
|
||||
}
|
||||
protected function _getNestedTransactionSavePointName()
|
||||
{
|
||||
return 'DOCTRINE_' . $this->transactionNestingLevel;
|
||||
}
|
||||
public function beginTransaction()
|
||||
{
|
||||
$connection = $this->getWrappedConnection();
|
||||
++$this->transactionNestingLevel;
|
||||
$logger = $this->_config->getSQLLogger();
|
||||
if ($this->transactionNestingLevel === 1) {
|
||||
if ($logger !== null) {
|
||||
$logger->startQuery('"START TRANSACTION"');
|
||||
}
|
||||
$connection->beginTransaction();
|
||||
if ($logger !== null) {
|
||||
$logger->stopQuery();
|
||||
}
|
||||
} elseif ($this->nestTransactionsWithSavepoints) {
|
||||
if ($logger !== null) {
|
||||
$logger->startQuery('"SAVEPOINT"');
|
||||
}
|
||||
$this->createSavepoint($this->_getNestedTransactionSavePointName());
|
||||
if ($logger !== null) {
|
||||
$logger->stopQuery();
|
||||
}
|
||||
} else {
|
||||
Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5383', <<<'DEPRECATION'
|
||||
Nesting transactions without enabling savepoints is deprecated.
|
||||
Call %s::setNestTransactionsWithSavepoints(true) to enable savepoints.
|
||||
DEPRECATION
|
||||
, self::class);
|
||||
}
|
||||
$eventManager = $this->getEventManager();
|
||||
if ($eventManager->hasListeners(Events::onTransactionBegin)) {
|
||||
Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/issues/5784', 'Subscribing to %s events is deprecated.', Events::onTransactionBegin);
|
||||
$eventManager->dispatchEvent(Events::onTransactionBegin, new TransactionBeginEventArgs($this));
|
||||
}
|
||||
return \true;
|
||||
}
|
||||
public function commit()
|
||||
{
|
||||
if ($this->transactionNestingLevel === 0) {
|
||||
throw ConnectionException::noActiveTransaction();
|
||||
}
|
||||
if ($this->isRollbackOnly) {
|
||||
throw ConnectionException::commitFailedRollbackOnly();
|
||||
}
|
||||
$result = \true;
|
||||
$connection = $this->getWrappedConnection();
|
||||
if ($this->transactionNestingLevel === 1) {
|
||||
$result = $this->doCommit($connection);
|
||||
} elseif ($this->nestTransactionsWithSavepoints) {
|
||||
$this->releaseSavepoint($this->_getNestedTransactionSavePointName());
|
||||
}
|
||||
--$this->transactionNestingLevel;
|
||||
$eventManager = $this->getEventManager();
|
||||
if ($eventManager->hasListeners(Events::onTransactionCommit)) {
|
||||
Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/issues/5784', 'Subscribing to %s events is deprecated.', Events::onTransactionCommit);
|
||||
$eventManager->dispatchEvent(Events::onTransactionCommit, new TransactionCommitEventArgs($this));
|
||||
}
|
||||
if ($this->autoCommit !== \false || $this->transactionNestingLevel !== 0) {
|
||||
return $result;
|
||||
}
|
||||
$this->beginTransaction();
|
||||
return $result;
|
||||
}
|
||||
private function doCommit(DriverConnection $connection)
|
||||
{
|
||||
$logger = $this->_config->getSQLLogger();
|
||||
if ($logger !== null) {
|
||||
$logger->startQuery('"COMMIT"');
|
||||
}
|
||||
$result = $connection->commit();
|
||||
if ($logger !== null) {
|
||||
$logger->stopQuery();
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
private function commitAll() : void
|
||||
{
|
||||
while ($this->transactionNestingLevel !== 0) {
|
||||
if ($this->autoCommit === \false && $this->transactionNestingLevel === 1) {
|
||||
// When in no auto-commit mode, the last nesting commit immediately starts a new transaction.
|
||||
// Therefore we need to do the final commit here and then leave to avoid an infinite loop.
|
||||
$this->commit();
|
||||
return;
|
||||
}
|
||||
$this->commit();
|
||||
}
|
||||
}
|
||||
public function rollBack()
|
||||
{
|
||||
if ($this->transactionNestingLevel === 0) {
|
||||
throw ConnectionException::noActiveTransaction();
|
||||
}
|
||||
$connection = $this->getWrappedConnection();
|
||||
$logger = $this->_config->getSQLLogger();
|
||||
if ($this->transactionNestingLevel === 1) {
|
||||
if ($logger !== null) {
|
||||
$logger->startQuery('"ROLLBACK"');
|
||||
}
|
||||
$this->transactionNestingLevel = 0;
|
||||
$connection->rollBack();
|
||||
$this->isRollbackOnly = \false;
|
||||
if ($logger !== null) {
|
||||
$logger->stopQuery();
|
||||
}
|
||||
if ($this->autoCommit === \false) {
|
||||
$this->beginTransaction();
|
||||
}
|
||||
} elseif ($this->nestTransactionsWithSavepoints) {
|
||||
if ($logger !== null) {
|
||||
$logger->startQuery('"ROLLBACK TO SAVEPOINT"');
|
||||
}
|
||||
$this->rollbackSavepoint($this->_getNestedTransactionSavePointName());
|
||||
--$this->transactionNestingLevel;
|
||||
if ($logger !== null) {
|
||||
$logger->stopQuery();
|
||||
}
|
||||
} else {
|
||||
$this->isRollbackOnly = \true;
|
||||
--$this->transactionNestingLevel;
|
||||
}
|
||||
$eventManager = $this->getEventManager();
|
||||
if ($eventManager->hasListeners(Events::onTransactionRollBack)) {
|
||||
Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/issues/5784', 'Subscribing to %s events is deprecated.', Events::onTransactionRollBack);
|
||||
$eventManager->dispatchEvent(Events::onTransactionRollBack, new TransactionRollBackEventArgs($this));
|
||||
}
|
||||
return \true;
|
||||
}
|
||||
public function createSavepoint($savepoint)
|
||||
{
|
||||
$platform = $this->getDatabasePlatform();
|
||||
if (!$platform->supportsSavepoints()) {
|
||||
throw ConnectionException::savepointsNotSupported();
|
||||
}
|
||||
$this->executeStatement($platform->createSavePoint($savepoint));
|
||||
}
|
||||
public function releaseSavepoint($savepoint)
|
||||
{
|
||||
$logger = $this->_config->getSQLLogger();
|
||||
$platform = $this->getDatabasePlatform();
|
||||
if (!$platform->supportsSavepoints()) {
|
||||
throw ConnectionException::savepointsNotSupported();
|
||||
}
|
||||
if (!$platform->supportsReleaseSavepoints()) {
|
||||
if ($logger !== null) {
|
||||
$logger->stopQuery();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if ($logger !== null) {
|
||||
$logger->startQuery('"RELEASE SAVEPOINT"');
|
||||
}
|
||||
$this->executeStatement($platform->releaseSavePoint($savepoint));
|
||||
if ($logger === null) {
|
||||
return;
|
||||
}
|
||||
$logger->stopQuery();
|
||||
}
|
||||
public function rollbackSavepoint($savepoint)
|
||||
{
|
||||
$platform = $this->getDatabasePlatform();
|
||||
if (!$platform->supportsSavepoints()) {
|
||||
throw ConnectionException::savepointsNotSupported();
|
||||
}
|
||||
$this->executeStatement($platform->rollbackSavePoint($savepoint));
|
||||
}
|
||||
public function getWrappedConnection()
|
||||
{
|
||||
Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/issues/4966', 'Connection::getWrappedConnection() is deprecated.' . ' Use Connection::getNativeConnection() to access the native connection.');
|
||||
$this->connect();
|
||||
return $this->_conn;
|
||||
}
|
||||
public function getNativeConnection()
|
||||
{
|
||||
$this->connect();
|
||||
if (!method_exists($this->_conn, 'getNativeConnection')) {
|
||||
throw new LogicException(sprintf('The driver connection %s does not support accessing the native connection.', get_class($this->_conn)));
|
||||
}
|
||||
return $this->_conn->getNativeConnection();
|
||||
}
|
||||
public function createSchemaManager() : AbstractSchemaManager
|
||||
{
|
||||
return $this->schemaManagerFactory->createSchemaManager($this);
|
||||
}
|
||||
public function getSchemaManager()
|
||||
{
|
||||
Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/issues/4515', 'Connection::getSchemaManager() is deprecated, use Connection::createSchemaManager() instead.');
|
||||
return $this->_schemaManager ??= $this->createSchemaManager();
|
||||
}
|
||||
public function setRollbackOnly()
|
||||
{
|
||||
if ($this->transactionNestingLevel === 0) {
|
||||
throw ConnectionException::noActiveTransaction();
|
||||
}
|
||||
$this->isRollbackOnly = \true;
|
||||
}
|
||||
public function isRollbackOnly()
|
||||
{
|
||||
if ($this->transactionNestingLevel === 0) {
|
||||
throw ConnectionException::noActiveTransaction();
|
||||
}
|
||||
return $this->isRollbackOnly;
|
||||
}
|
||||
public function convertToDatabaseValue($value, $type)
|
||||
{
|
||||
return Type::getType($type)->convertToDatabaseValue($value, $this->getDatabasePlatform());
|
||||
}
|
||||
public function convertToPHPValue($value, $type)
|
||||
{
|
||||
return Type::getType($type)->convertToPHPValue($value, $this->getDatabasePlatform());
|
||||
}
|
||||
private function bindParameters(DriverStatement $stmt, array $params, array $types) : void
|
||||
{
|
||||
// Check whether parameters are positional or named. Mixing is not allowed.
|
||||
if (is_int(key($params))) {
|
||||
$bindIndex = 1;
|
||||
foreach ($params as $key => $value) {
|
||||
if (isset($types[$key])) {
|
||||
$type = $types[$key];
|
||||
[$value, $bindingType] = $this->getBindingInfo($value, $type);
|
||||
} else {
|
||||
if (array_key_exists($key, $types)) {
|
||||
Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5550', 'Using NULL as prepared statement parameter type is deprecated.' . 'Omit or use ParameterType::STRING instead');
|
||||
}
|
||||
$bindingType = ParameterType::STRING;
|
||||
}
|
||||
$stmt->bindValue($bindIndex, $value, $bindingType);
|
||||
++$bindIndex;
|
||||
}
|
||||
} else {
|
||||
// Named parameters
|
||||
foreach ($params as $name => $value) {
|
||||
if (isset($types[$name])) {
|
||||
$type = $types[$name];
|
||||
[$value, $bindingType] = $this->getBindingInfo($value, $type);
|
||||
} else {
|
||||
if (array_key_exists($name, $types)) {
|
||||
Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5550', 'Using NULL as prepared statement parameter type is deprecated.' . 'Omit or use ParameterType::STRING instead');
|
||||
}
|
||||
$bindingType = ParameterType::STRING;
|
||||
}
|
||||
$stmt->bindValue($name, $value, $bindingType);
|
||||
}
|
||||
}
|
||||
}
|
||||
private function getBindingInfo($value, $type) : array
|
||||
{
|
||||
if (is_string($type)) {
|
||||
$type = Type::getType($type);
|
||||
}
|
||||
if ($type instanceof Type) {
|
||||
$value = $type->convertToDatabaseValue($value, $this->getDatabasePlatform());
|
||||
$bindingType = $type->getBindingType();
|
||||
} else {
|
||||
$bindingType = $type ?? ParameterType::STRING;
|
||||
}
|
||||
return [$value, $bindingType];
|
||||
}
|
||||
public function createQueryBuilder()
|
||||
{
|
||||
return new Query\QueryBuilder($this);
|
||||
}
|
||||
public final function convertExceptionDuringQuery(Driver\Exception $e, string $sql, array $params = [], array $types = []) : DriverException
|
||||
{
|
||||
return $this->handleDriverException($e, new Query($sql, $params, $types));
|
||||
}
|
||||
public final function convertException(Driver\Exception $e) : DriverException
|
||||
{
|
||||
return $this->handleDriverException($e, null);
|
||||
}
|
||||
private function expandArrayParameters(string $sql, array $params, array $types) : array
|
||||
{
|
||||
$this->parser ??= $this->getDatabasePlatform()->createSQLParser();
|
||||
$visitor = new ExpandArrayParameters($params, $types);
|
||||
$this->parser->parse($sql, $visitor);
|
||||
return [$visitor->getSQL(), $visitor->getParameters(), $visitor->getTypes()];
|
||||
}
|
||||
private function needsArrayParameterConversion(array $params, array $types) : bool
|
||||
{
|
||||
if (is_string(key($params))) {
|
||||
return \true;
|
||||
}
|
||||
foreach ($types as $type) {
|
||||
if ($type === ArrayParameterType::INTEGER || $type === ArrayParameterType::STRING || $type === ArrayParameterType::ASCII || $type === ArrayParameterType::BINARY) {
|
||||
return \true;
|
||||
}
|
||||
}
|
||||
return \false;
|
||||
}
|
||||
private function handleDriverException(Driver\Exception $driverException, ?Query $query) : DriverException
|
||||
{
|
||||
$this->exceptionConverter ??= $this->_driver->getExceptionConverter();
|
||||
$exception = $this->exceptionConverter->convert($driverException, $query);
|
||||
if ($exception instanceof ConnectionLost) {
|
||||
$this->close();
|
||||
}
|
||||
return $exception;
|
||||
}
|
||||
public function executeUpdate(string $sql, array $params = [], array $types = []) : int
|
||||
{
|
||||
Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4163', '%s is deprecated, please use executeStatement() instead.', __METHOD__);
|
||||
return $this->executeStatement($sql, $params, $types);
|
||||
}
|
||||
public function query(string $sql) : Result
|
||||
{
|
||||
Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4163', '%s is deprecated, please use executeQuery() instead.', __METHOD__);
|
||||
return $this->executeQuery($sql);
|
||||
}
|
||||
public function exec(string $sql) : int
|
||||
{
|
||||
Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4163', '%s is deprecated, please use executeStatement() instead.', __METHOD__);
|
||||
return $this->executeStatement($sql);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
class ConnectionException extends Exception
|
||||
{
|
||||
public static function commitFailedRollbackOnly()
|
||||
{
|
||||
return new self('Transaction commit failed because the transaction has been marked for rollback only.');
|
||||
}
|
||||
public static function noActiveTransaction()
|
||||
{
|
||||
return new self('There is no active transaction.');
|
||||
}
|
||||
public static function savepointsNotSupported()
|
||||
{
|
||||
return new self('Savepoints are not supported by this driver.');
|
||||
}
|
||||
public static function mayNotAlterNestedTransactionWithSavepointsInTransaction()
|
||||
{
|
||||
return new self('May not alter the nested transaction with savepoints behavior while a transaction is open.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
use MailPoetVendor\Doctrine\DBAL\Driver\API\ExceptionConverter;
|
||||
use MailPoetVendor\Doctrine\DBAL\Driver\Connection as DriverConnection;
|
||||
use MailPoetVendor\Doctrine\DBAL\Driver\Exception;
|
||||
use MailPoetVendor\Doctrine\DBAL\Platforms\AbstractPlatform;
|
||||
use MailPoetVendor\Doctrine\DBAL\Schema\AbstractSchemaManager;
|
||||
use MailPoetVendor\SensitiveParameter;
|
||||
interface Driver
|
||||
{
|
||||
public function connect( array $params);
|
||||
public function getDatabasePlatform();
|
||||
public function getSchemaManager(Connection $conn, AbstractPlatform $platform);
|
||||
public function getExceptionConverter() : ExceptionConverter;
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
declare (strict_types=1);
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Driver\API;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
use MailPoetVendor\Doctrine\DBAL\Driver\Exception;
|
||||
use MailPoetVendor\Doctrine\DBAL\Exception\DriverException;
|
||||
use MailPoetVendor\Doctrine\DBAL\Query;
|
||||
interface ExceptionConverter
|
||||
{
|
||||
public function convert(Exception $exception, ?Query $query) : DriverException;
|
||||
}
|
||||
+98
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
declare (strict_types=1);
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Driver\API\MySQL;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
use MailPoetVendor\Doctrine\DBAL\Driver\API\ExceptionConverter as ExceptionConverterInterface;
|
||||
use MailPoetVendor\Doctrine\DBAL\Driver\Exception;
|
||||
use MailPoetVendor\Doctrine\DBAL\Exception\ConnectionException;
|
||||
use MailPoetVendor\Doctrine\DBAL\Exception\ConnectionLost;
|
||||
use MailPoetVendor\Doctrine\DBAL\Exception\DatabaseDoesNotExist;
|
||||
use MailPoetVendor\Doctrine\DBAL\Exception\DeadlockException;
|
||||
use MailPoetVendor\Doctrine\DBAL\Exception\DriverException;
|
||||
use MailPoetVendor\Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException;
|
||||
use MailPoetVendor\Doctrine\DBAL\Exception\InvalidFieldNameException;
|
||||
use MailPoetVendor\Doctrine\DBAL\Exception\LockWaitTimeoutException;
|
||||
use MailPoetVendor\Doctrine\DBAL\Exception\NonUniqueFieldNameException;
|
||||
use MailPoetVendor\Doctrine\DBAL\Exception\NotNullConstraintViolationException;
|
||||
use MailPoetVendor\Doctrine\DBAL\Exception\SyntaxErrorException;
|
||||
use MailPoetVendor\Doctrine\DBAL\Exception\TableExistsException;
|
||||
use MailPoetVendor\Doctrine\DBAL\Exception\TableNotFoundException;
|
||||
use MailPoetVendor\Doctrine\DBAL\Exception\UniqueConstraintViolationException;
|
||||
use MailPoetVendor\Doctrine\DBAL\Query;
|
||||
final class ExceptionConverter implements ExceptionConverterInterface
|
||||
{
|
||||
public function convert(Exception $exception, ?Query $query) : DriverException
|
||||
{
|
||||
switch ($exception->getCode()) {
|
||||
case 1008:
|
||||
return new DatabaseDoesNotExist($exception, $query);
|
||||
case 1213:
|
||||
return new DeadlockException($exception, $query);
|
||||
case 1205:
|
||||
return new LockWaitTimeoutException($exception, $query);
|
||||
case 1050:
|
||||
return new TableExistsException($exception, $query);
|
||||
case 1051:
|
||||
case 1146:
|
||||
return new TableNotFoundException($exception, $query);
|
||||
case 1216:
|
||||
case 1217:
|
||||
case 1451:
|
||||
case 1452:
|
||||
case 1701:
|
||||
return new ForeignKeyConstraintViolationException($exception, $query);
|
||||
case 1062:
|
||||
case 1557:
|
||||
case 1569:
|
||||
case 1586:
|
||||
return new UniqueConstraintViolationException($exception, $query);
|
||||
case 1054:
|
||||
case 1166:
|
||||
case 1611:
|
||||
return new InvalidFieldNameException($exception, $query);
|
||||
case 1052:
|
||||
case 1060:
|
||||
case 1110:
|
||||
return new NonUniqueFieldNameException($exception, $query);
|
||||
case 1064:
|
||||
case 1149:
|
||||
case 1287:
|
||||
case 1341:
|
||||
case 1342:
|
||||
case 1343:
|
||||
case 1344:
|
||||
case 1382:
|
||||
case 1479:
|
||||
case 1541:
|
||||
case 1554:
|
||||
case 1626:
|
||||
return new SyntaxErrorException($exception, $query);
|
||||
case 1044:
|
||||
case 1045:
|
||||
case 1046:
|
||||
case 1049:
|
||||
case 1095:
|
||||
case 1142:
|
||||
case 1143:
|
||||
case 1227:
|
||||
case 1370:
|
||||
case 1429:
|
||||
case 2002:
|
||||
case 2005:
|
||||
case 2054:
|
||||
return new ConnectionException($exception, $query);
|
||||
case 2006:
|
||||
return new ConnectionLost($exception, $query);
|
||||
case 1048:
|
||||
case 1121:
|
||||
case 1138:
|
||||
case 1171:
|
||||
case 1252:
|
||||
case 1263:
|
||||
case 1364:
|
||||
case 1566:
|
||||
return new NotNullConstraintViolationException($exception, $query);
|
||||
}
|
||||
return new DriverException($exception, $query);
|
||||
}
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
<?php
|
||||
@@ -0,0 +1 @@
|
||||
<?php
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
declare (strict_types=1);
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Driver;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
use Exception as BaseException;
|
||||
use Throwable;
|
||||
abstract class AbstractException extends BaseException implements Exception
|
||||
{
|
||||
private ?string $sqlState = null;
|
||||
public function __construct($message, $sqlState = null, $code = 0, ?Throwable $previous = null)
|
||||
{
|
||||
parent::__construct($message, $code, $previous);
|
||||
$this->sqlState = $sqlState;
|
||||
}
|
||||
public function getSQLState()
|
||||
{
|
||||
return $this->sqlState;
|
||||
}
|
||||
}
|
||||
+99
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Driver;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
use MailPoetVendor\Doctrine\DBAL\Connection;
|
||||
use MailPoetVendor\Doctrine\DBAL\Driver\API\ExceptionConverter;
|
||||
use MailPoetVendor\Doctrine\DBAL\Driver\API\MySQL;
|
||||
use MailPoetVendor\Doctrine\DBAL\Exception;
|
||||
use MailPoetVendor\Doctrine\DBAL\Platforms\AbstractMySQLPlatform;
|
||||
use MailPoetVendor\Doctrine\DBAL\Platforms\AbstractPlatform;
|
||||
use MailPoetVendor\Doctrine\DBAL\Platforms\MariaDb1027Platform;
|
||||
use MailPoetVendor\Doctrine\DBAL\Platforms\MariaDb1043Platform;
|
||||
use MailPoetVendor\Doctrine\DBAL\Platforms\MariaDb1052Platform;
|
||||
use MailPoetVendor\Doctrine\DBAL\Platforms\MariaDb1060Platform;
|
||||
use MailPoetVendor\Doctrine\DBAL\Platforms\MySQL57Platform;
|
||||
use MailPoetVendor\Doctrine\DBAL\Platforms\MySQL80Platform;
|
||||
use MailPoetVendor\Doctrine\DBAL\Platforms\MySQLPlatform;
|
||||
use MailPoetVendor\Doctrine\DBAL\Schema\MySQLSchemaManager;
|
||||
use MailPoetVendor\Doctrine\DBAL\VersionAwarePlatformDriver;
|
||||
use MailPoetVendor\Doctrine\Deprecations\Deprecation;
|
||||
use function assert;
|
||||
use function preg_match;
|
||||
use function stripos;
|
||||
use function version_compare;
|
||||
abstract class AbstractMySQLDriver implements VersionAwarePlatformDriver
|
||||
{
|
||||
public function createDatabasePlatformForVersion($version)
|
||||
{
|
||||
$mariadb = stripos($version, 'mariadb') !== \false;
|
||||
if ($mariadb) {
|
||||
$mariaDbVersion = $this->getMariaDbMysqlVersionNumber($version);
|
||||
if (version_compare($mariaDbVersion, '10.6.0', '>=')) {
|
||||
return new MariaDb1060Platform();
|
||||
}
|
||||
if (version_compare($mariaDbVersion, '10.5.2', '>=')) {
|
||||
return new MariaDb1052Platform();
|
||||
}
|
||||
if (version_compare($mariaDbVersion, '10.4.3', '>=')) {
|
||||
return new MariaDb1043Platform();
|
||||
}
|
||||
Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/6110', 'Support for MariaDB < 10.4 is deprecated and will be removed in DBAL 4.' . ' Consider upgrading to a more recent version of MariaDB.');
|
||||
if (version_compare($mariaDbVersion, '10.2.7', '>=')) {
|
||||
return new MariaDb1027Platform();
|
||||
}
|
||||
} else {
|
||||
$oracleMysqlVersion = $this->getOracleMysqlVersionNumber($version);
|
||||
if (version_compare($oracleMysqlVersion, '8', '>=')) {
|
||||
if (!version_compare($version, '8.0.0', '>=')) {
|
||||
Deprecation::trigger('doctrine/orm', 'https://github.com/doctrine/dbal/pull/5779', 'Version detection logic for MySQL will change in DBAL 4. ' . 'Please specify the version as the server reports it, e.g. "8.0.31" instead of "8".');
|
||||
}
|
||||
return new MySQL80Platform();
|
||||
}
|
||||
if (version_compare($oracleMysqlVersion, '5.7.9', '>=')) {
|
||||
if (!version_compare($version, '5.7.9', '>=')) {
|
||||
Deprecation::trigger('doctrine/orm', 'https://github.com/doctrine/dbal/pull/5779', 'Version detection logic for MySQL will change in DBAL 4. ' . 'Please specify the version as the server reports it, e.g. "5.7.40" instead of "5.7".');
|
||||
}
|
||||
return new MySQL57Platform();
|
||||
}
|
||||
Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5072', 'MySQL 5.6 support is deprecated and will be removed in DBAL 4.' . ' Consider upgrading to MySQL 5.7 or later.');
|
||||
}
|
||||
return $this->getDatabasePlatform();
|
||||
}
|
||||
private function getOracleMysqlVersionNumber(string $versionString) : string
|
||||
{
|
||||
if (preg_match('/^(?P<major>\\d+)(?:\\.(?P<minor>\\d+)(?:\\.(?P<patch>\\d+))?)?/', $versionString, $versionParts) === 0) {
|
||||
throw Exception::invalidPlatformVersionSpecified($versionString, '<major_version>.<minor_version>.<patch_version>');
|
||||
}
|
||||
$majorVersion = $versionParts['major'];
|
||||
$minorVersion = $versionParts['minor'] ?? 0;
|
||||
$patchVersion = $versionParts['patch'] ?? null;
|
||||
if ($majorVersion === '5' && $minorVersion === '7') {
|
||||
$patchVersion ??= '9';
|
||||
}
|
||||
return $majorVersion . '.' . $minorVersion . '.' . $patchVersion;
|
||||
}
|
||||
private function getMariaDbMysqlVersionNumber(string $versionString) : string
|
||||
{
|
||||
if (stripos($versionString, 'MariaDB') === 0) {
|
||||
Deprecation::trigger('doctrine/orm', 'https://github.com/doctrine/dbal/pull/5779', 'Version detection logic for MySQL will change in DBAL 4. ' . 'Please specify the version as the server reports it, ' . 'e.g. "10.9.3-MariaDB" instead of "mariadb-10.9".');
|
||||
}
|
||||
if (preg_match('/^(?:5\\.5\\.5-)?(mariadb-)?(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)/i', $versionString, $versionParts) === 0) {
|
||||
throw Exception::invalidPlatformVersionSpecified($versionString, '^(?:5\\.5\\.5-)?(mariadb-)?<major_version>.<minor_version>.<patch_version>');
|
||||
}
|
||||
return $versionParts['major'] . '.' . $versionParts['minor'] . '.' . $versionParts['patch'];
|
||||
}
|
||||
public function getDatabasePlatform()
|
||||
{
|
||||
return new MySQLPlatform();
|
||||
}
|
||||
public function getSchemaManager(Connection $conn, AbstractPlatform $platform)
|
||||
{
|
||||
Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5458', 'AbstractMySQLDriver::getSchemaManager() is deprecated.' . ' Use MySQLPlatform::createSchemaManager() instead.');
|
||||
assert($platform instanceof AbstractMySQLPlatform);
|
||||
return new MySQLSchemaManager($conn, $platform);
|
||||
}
|
||||
public function getExceptionConverter() : ExceptionConverter
|
||||
{
|
||||
return new MySQL\ExceptionConverter();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Driver;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
use MailPoetVendor\Doctrine\DBAL\ParameterType;
|
||||
interface Connection
|
||||
{
|
||||
public function prepare(string $sql) : Statement;
|
||||
public function query(string $sql) : Result;
|
||||
public function quote($value, $type = ParameterType::STRING);
|
||||
public function exec(string $sql) : int;
|
||||
public function lastInsertId($name = null);
|
||||
public function beginTransaction();
|
||||
public function commit();
|
||||
public function rollBack();
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
declare (strict_types=1);
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Driver;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
use Throwable;
|
||||
interface Exception extends Throwable
|
||||
{
|
||||
public function getSQLState();
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
declare (strict_types=1);
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Driver\Exception;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
use MailPoetVendor\Doctrine\DBAL\Driver\AbstractException;
|
||||
use function sprintf;
|
||||
final class UnknownParameterType extends AbstractException
|
||||
{
|
||||
public static function new($type) : self
|
||||
{
|
||||
return new self(sprintf('Unknown parameter type, %d given.', $type));
|
||||
}
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
<?php
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
declare (strict_types=1);
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Driver;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
final class FetchUtils
|
||||
{
|
||||
public static function fetchOne(Result $result)
|
||||
{
|
||||
$row = $result->fetchNumeric();
|
||||
if ($row === \false) {
|
||||
return \false;
|
||||
}
|
||||
return $row[0];
|
||||
}
|
||||
public static function fetchAllNumeric(Result $result) : array
|
||||
{
|
||||
$rows = [];
|
||||
while (($row = $result->fetchNumeric()) !== \false) {
|
||||
$rows[] = $row;
|
||||
}
|
||||
return $rows;
|
||||
}
|
||||
public static function fetchAllAssociative(Result $result) : array
|
||||
{
|
||||
$rows = [];
|
||||
while (($row = $result->fetchAssociative()) !== \false) {
|
||||
$rows[] = $row;
|
||||
}
|
||||
return $rows;
|
||||
}
|
||||
public static function fetchFirstColumn(Result $result) : array
|
||||
{
|
||||
$rows = [];
|
||||
while (($row = $result->fetchOne()) !== \false) {
|
||||
$rows[] = $row;
|
||||
}
|
||||
return $rows;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
declare (strict_types=1);
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Driver;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
use MailPoetVendor\Doctrine\DBAL\Driver;
|
||||
interface Middleware
|
||||
{
|
||||
public function wrap(Driver $driver) : Driver;
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Driver\Middleware;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
use MailPoetVendor\Doctrine\DBAL\Driver\Connection;
|
||||
use MailPoetVendor\Doctrine\DBAL\Driver\Result;
|
||||
use MailPoetVendor\Doctrine\DBAL\Driver\ServerInfoAwareConnection;
|
||||
use MailPoetVendor\Doctrine\DBAL\Driver\Statement;
|
||||
use MailPoetVendor\Doctrine\DBAL\ParameterType;
|
||||
use MailPoetVendor\Doctrine\Deprecations\Deprecation;
|
||||
use LogicException;
|
||||
use function get_class;
|
||||
use function method_exists;
|
||||
use function sprintf;
|
||||
abstract class AbstractConnectionMiddleware implements ServerInfoAwareConnection
|
||||
{
|
||||
private Connection $wrappedConnection;
|
||||
public function __construct(Connection $wrappedConnection)
|
||||
{
|
||||
$this->wrappedConnection = $wrappedConnection;
|
||||
}
|
||||
public function prepare(string $sql) : Statement
|
||||
{
|
||||
return $this->wrappedConnection->prepare($sql);
|
||||
}
|
||||
public function query(string $sql) : Result
|
||||
{
|
||||
return $this->wrappedConnection->query($sql);
|
||||
}
|
||||
public function quote($value, $type = ParameterType::STRING)
|
||||
{
|
||||
return $this->wrappedConnection->quote($value, $type);
|
||||
}
|
||||
public function exec(string $sql) : int
|
||||
{
|
||||
return $this->wrappedConnection->exec($sql);
|
||||
}
|
||||
public function lastInsertId($name = null)
|
||||
{
|
||||
if ($name !== null) {
|
||||
Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/issues/4687', 'The usage of Connection::lastInsertId() with a sequence name is deprecated.');
|
||||
}
|
||||
return $this->wrappedConnection->lastInsertId($name);
|
||||
}
|
||||
public function beginTransaction()
|
||||
{
|
||||
return $this->wrappedConnection->beginTransaction();
|
||||
}
|
||||
public function commit()
|
||||
{
|
||||
return $this->wrappedConnection->commit();
|
||||
}
|
||||
public function rollBack()
|
||||
{
|
||||
return $this->wrappedConnection->rollBack();
|
||||
}
|
||||
public function getServerVersion()
|
||||
{
|
||||
if (!$this->wrappedConnection instanceof ServerInfoAwareConnection) {
|
||||
throw new LogicException('The underlying connection is not a ServerInfoAwareConnection');
|
||||
}
|
||||
return $this->wrappedConnection->getServerVersion();
|
||||
}
|
||||
public function getNativeConnection()
|
||||
{
|
||||
if (!method_exists($this->wrappedConnection, 'getNativeConnection')) {
|
||||
throw new LogicException(sprintf('The driver connection %s does not support accessing the native connection.', get_class($this->wrappedConnection)));
|
||||
}
|
||||
return $this->wrappedConnection->getNativeConnection();
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Driver\Middleware;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
use MailPoetVendor\Doctrine\DBAL\Connection;
|
||||
use MailPoetVendor\Doctrine\DBAL\Driver;
|
||||
use MailPoetVendor\Doctrine\DBAL\Driver\API\ExceptionConverter;
|
||||
use MailPoetVendor\Doctrine\DBAL\Platforms\AbstractPlatform;
|
||||
use MailPoetVendor\Doctrine\DBAL\VersionAwarePlatformDriver;
|
||||
use MailPoetVendor\Doctrine\Deprecations\Deprecation;
|
||||
use MailPoetVendor\SensitiveParameter;
|
||||
abstract class AbstractDriverMiddleware implements VersionAwarePlatformDriver
|
||||
{
|
||||
private Driver $wrappedDriver;
|
||||
public function __construct(Driver $wrappedDriver)
|
||||
{
|
||||
$this->wrappedDriver = $wrappedDriver;
|
||||
}
|
||||
public function connect( array $params)
|
||||
{
|
||||
return $this->wrappedDriver->connect($params);
|
||||
}
|
||||
public function getDatabasePlatform()
|
||||
{
|
||||
return $this->wrappedDriver->getDatabasePlatform();
|
||||
}
|
||||
public function getSchemaManager(Connection $conn, AbstractPlatform $platform)
|
||||
{
|
||||
Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5458', 'AbstractDriverMiddleware::getSchemaManager() is deprecated.' . ' Use AbstractPlatform::createSchemaManager() instead.');
|
||||
return $this->wrappedDriver->getSchemaManager($conn, $platform);
|
||||
}
|
||||
public function getExceptionConverter() : ExceptionConverter
|
||||
{
|
||||
return $this->wrappedDriver->getExceptionConverter();
|
||||
}
|
||||
public function createDatabasePlatformForVersion($version)
|
||||
{
|
||||
if ($this->wrappedDriver instanceof VersionAwarePlatformDriver) {
|
||||
return $this->wrappedDriver->createDatabasePlatformForVersion($version);
|
||||
}
|
||||
return $this->wrappedDriver->getDatabasePlatform();
|
||||
}
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Driver\Middleware;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
use MailPoetVendor\Doctrine\DBAL\Driver\Result;
|
||||
abstract class AbstractResultMiddleware implements Result
|
||||
{
|
||||
private Result $wrappedResult;
|
||||
public function __construct(Result $result)
|
||||
{
|
||||
$this->wrappedResult = $result;
|
||||
}
|
||||
public function fetchNumeric()
|
||||
{
|
||||
return $this->wrappedResult->fetchNumeric();
|
||||
}
|
||||
public function fetchAssociative()
|
||||
{
|
||||
return $this->wrappedResult->fetchAssociative();
|
||||
}
|
||||
public function fetchOne()
|
||||
{
|
||||
return $this->wrappedResult->fetchOne();
|
||||
}
|
||||
public function fetchAllNumeric() : array
|
||||
{
|
||||
return $this->wrappedResult->fetchAllNumeric();
|
||||
}
|
||||
public function fetchAllAssociative() : array
|
||||
{
|
||||
return $this->wrappedResult->fetchAllAssociative();
|
||||
}
|
||||
public function fetchFirstColumn() : array
|
||||
{
|
||||
return $this->wrappedResult->fetchFirstColumn();
|
||||
}
|
||||
public function rowCount() : int
|
||||
{
|
||||
return $this->wrappedResult->rowCount();
|
||||
}
|
||||
public function columnCount() : int
|
||||
{
|
||||
return $this->wrappedResult->columnCount();
|
||||
}
|
||||
public function free() : void
|
||||
{
|
||||
$this->wrappedResult->free();
|
||||
}
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Driver\Middleware;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
use MailPoetVendor\Doctrine\DBAL\Driver\Result;
|
||||
use MailPoetVendor\Doctrine\DBAL\Driver\Statement;
|
||||
use MailPoetVendor\Doctrine\DBAL\ParameterType;
|
||||
use MailPoetVendor\Doctrine\Deprecations\Deprecation;
|
||||
use function func_num_args;
|
||||
abstract class AbstractStatementMiddleware implements Statement
|
||||
{
|
||||
private Statement $wrappedStatement;
|
||||
public function __construct(Statement $wrappedStatement)
|
||||
{
|
||||
$this->wrappedStatement = $wrappedStatement;
|
||||
}
|
||||
public function bindValue($param, $value, $type = ParameterType::STRING)
|
||||
{
|
||||
if (func_num_args() < 3) {
|
||||
Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5558', 'Not passing $type to Statement::bindValue() is deprecated.' . ' Pass the type corresponding to the parameter being bound.');
|
||||
}
|
||||
return $this->wrappedStatement->bindValue($param, $value, $type);
|
||||
}
|
||||
public function bindParam($param, &$variable, $type = ParameterType::STRING, $length = null)
|
||||
{
|
||||
Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5563', '%s is deprecated. Use bindValue() instead.', __METHOD__);
|
||||
if (func_num_args() < 3) {
|
||||
Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5558', 'Not passing $type to Statement::bindParam() is deprecated.' . ' Pass the type corresponding to the parameter being bound.');
|
||||
}
|
||||
return $this->wrappedStatement->bindParam($param, $variable, $type, $length);
|
||||
}
|
||||
public function execute($params = null) : Result
|
||||
{
|
||||
return $this->wrappedStatement->execute($params);
|
||||
}
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
<?php
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
declare (strict_types=1);
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Driver;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
interface Result
|
||||
{
|
||||
public function fetchNumeric();
|
||||
public function fetchAssociative();
|
||||
public function fetchOne();
|
||||
public function fetchAllNumeric() : array;
|
||||
public function fetchAllAssociative() : array;
|
||||
public function fetchFirstColumn() : array;
|
||||
public function rowCount() : int;
|
||||
public function columnCount() : int;
|
||||
public function free() : void;
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Driver;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
interface ServerInfoAwareConnection extends Connection
|
||||
{
|
||||
public function getServerVersion();
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Driver;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
use MailPoetVendor\Doctrine\DBAL\ParameterType;
|
||||
interface Statement
|
||||
{
|
||||
public function bindValue($param, $value, $type = ParameterType::STRING);
|
||||
public function bindParam($param, &$variable, $type = ParameterType::STRING, $length = null);
|
||||
public function execute($params = null) : Result;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<?php
|
||||
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
use MailPoetVendor\Doctrine\Common\EventManager;
|
||||
use MailPoetVendor\Doctrine\DBAL\Driver\IBMDB2;
|
||||
use MailPoetVendor\Doctrine\DBAL\Driver\Mysqli;
|
||||
use MailPoetVendor\Doctrine\DBAL\Driver\OCI8;
|
||||
use MailPoetVendor\Doctrine\DBAL\Driver\PDO;
|
||||
use MailPoetVendor\Doctrine\DBAL\Driver\PgSQL;
|
||||
use MailPoetVendor\Doctrine\DBAL\Driver\SQLite3;
|
||||
use MailPoetVendor\Doctrine\DBAL\Driver\SQLSrv;
|
||||
use MailPoetVendor\Doctrine\DBAL\Exception\MalformedDsnException;
|
||||
use MailPoetVendor\Doctrine\DBAL\Tools\DsnParser;
|
||||
use MailPoetVendor\Doctrine\Deprecations\Deprecation;
|
||||
use MailPoetVendor\SensitiveParameter;
|
||||
use function array_keys;
|
||||
use function array_merge;
|
||||
use function is_a;
|
||||
final class DriverManager
|
||||
{
|
||||
private const DRIVER_MAP = ['pdo_mysql' => PDO\MySQL\Driver::class, 'pdo_sqlite' => PDO\SQLite\Driver::class, 'pdo_pgsql' => PDO\PgSQL\Driver::class, 'pdo_oci' => PDO\OCI\Driver::class, 'oci8' => OCI8\Driver::class, 'ibm_db2' => IBMDB2\Driver::class, 'pdo_sqlsrv' => PDO\SQLSrv\Driver::class, 'mysqli' => Mysqli\Driver::class, 'pgsql' => PgSQL\Driver::class, 'sqlsrv' => SQLSrv\Driver::class, 'sqlite3' => SQLite3\Driver::class];
|
||||
private static array $driverSchemeAliases = [
|
||||
'db2' => 'ibm_db2',
|
||||
'mssql' => 'pdo_sqlsrv',
|
||||
'mysql' => 'pdo_mysql',
|
||||
'mysql2' => 'pdo_mysql',
|
||||
// Amazon RDS, for some weird reason
|
||||
'postgres' => 'pdo_pgsql',
|
||||
'postgresql' => 'pdo_pgsql',
|
||||
'pgsql' => 'pdo_pgsql',
|
||||
'sqlite' => 'pdo_sqlite',
|
||||
'sqlite3' => 'pdo_sqlite',
|
||||
];
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
public static function getConnection( array $params, ?Configuration $config = null, ?EventManager $eventManager = null) : Connection
|
||||
{
|
||||
// create default config and event manager, if not set
|
||||
$config ??= new Configuration();
|
||||
$eventManager ??= new EventManager();
|
||||
$params = self::parseDatabaseUrl($params);
|
||||
// URL support for PrimaryReplicaConnection
|
||||
if (isset($params['primary'])) {
|
||||
$params['primary'] = self::parseDatabaseUrl($params['primary']);
|
||||
}
|
||||
if (isset($params['replica'])) {
|
||||
foreach ($params['replica'] as $key => $replicaParams) {
|
||||
$params['replica'][$key] = self::parseDatabaseUrl($replicaParams);
|
||||
}
|
||||
}
|
||||
$driver = self::createDriver($params['driver'] ?? null, $params['driverClass'] ?? null);
|
||||
foreach ($config->getMiddlewares() as $middleware) {
|
||||
$driver = $middleware->wrap($driver);
|
||||
}
|
||||
$wrapperClass = $params['wrapperClass'] ?? Connection::class;
|
||||
if (!is_a($wrapperClass, Connection::class, \true)) {
|
||||
throw Exception::invalidWrapperClass($wrapperClass);
|
||||
}
|
||||
return new $wrapperClass($params, $driver, $config, $eventManager);
|
||||
}
|
||||
public static function getAvailableDrivers() : array
|
||||
{
|
||||
return array_keys(self::DRIVER_MAP);
|
||||
}
|
||||
private static function createDriver(?string $driver, ?string $driverClass) : Driver
|
||||
{
|
||||
if ($driverClass === null) {
|
||||
if ($driver === null) {
|
||||
throw Exception::driverRequired();
|
||||
}
|
||||
if (!isset(self::DRIVER_MAP[$driver])) {
|
||||
throw Exception::unknownDriver($driver, array_keys(self::DRIVER_MAP));
|
||||
}
|
||||
$driverClass = self::DRIVER_MAP[$driver];
|
||||
} elseif (!is_a($driverClass, Driver::class, \true)) {
|
||||
throw Exception::invalidDriverClass($driverClass);
|
||||
}
|
||||
return new $driverClass();
|
||||
}
|
||||
private static function parseDatabaseUrl( array $params) : array
|
||||
{
|
||||
if (!isset($params['url'])) {
|
||||
return $params;
|
||||
}
|
||||
Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5843', 'The "url" connection parameter is deprecated. Please use %s to parse a database url before calling %s.', DsnParser::class, self::class);
|
||||
$parser = new DsnParser(self::$driverSchemeAliases);
|
||||
try {
|
||||
$parsedParams = $parser->parse($params['url']);
|
||||
} catch (MalformedDsnException $e) {
|
||||
throw new Exception('Malformed parameter "url".', 0, $e);
|
||||
}
|
||||
if (isset($parsedParams['driver'])) {
|
||||
// The requested driver from the URL scheme takes precedence
|
||||
// over the default custom driver from the connection parameters (if any).
|
||||
unset($params['driverClass']);
|
||||
}
|
||||
$params = array_merge($params, $parsedParams);
|
||||
// If a schemeless connection URL is given, we require a default driver or default custom driver
|
||||
// as connection parameter.
|
||||
if (!isset($params['driverClass']) && !isset($params['driver'])) {
|
||||
throw Exception::driverRequired($params['url']);
|
||||
}
|
||||
return $params;
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Event\Listeners;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
use MailPoetVendor\Doctrine\Common\EventSubscriber;
|
||||
use MailPoetVendor\Doctrine\DBAL\Event\ConnectionEventArgs;
|
||||
use MailPoetVendor\Doctrine\DBAL\Events;
|
||||
use MailPoetVendor\Doctrine\DBAL\Exception;
|
||||
class SQLSessionInit implements EventSubscriber
|
||||
{
|
||||
protected $sql;
|
||||
public function __construct($sql)
|
||||
{
|
||||
$this->sql = $sql;
|
||||
}
|
||||
public function postConnect(ConnectionEventArgs $args)
|
||||
{
|
||||
$args->getConnection()->executeStatement($this->sql);
|
||||
}
|
||||
public function getSubscribedEvents()
|
||||
{
|
||||
return [Events::postConnect];
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Event\Listeners;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
use MailPoetVendor\Doctrine\Common\EventSubscriber;
|
||||
use MailPoetVendor\Doctrine\DBAL\Event\ConnectionEventArgs;
|
||||
use MailPoetVendor\Doctrine\DBAL\Events;
|
||||
use MailPoetVendor\Doctrine\DBAL\Exception;
|
||||
class SQLiteSessionInit implements EventSubscriber
|
||||
{
|
||||
public function postConnect(ConnectionEventArgs $args)
|
||||
{
|
||||
$args->getConnection()->executeStatement('PRAGMA foreign_keys=ON');
|
||||
}
|
||||
public function getSubscribedEvents()
|
||||
{
|
||||
return [Events::postConnect];
|
||||
}
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
<?php
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
declare (strict_types=1);
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Event;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
class TransactionBeginEventArgs extends TransactionEventArgs
|
||||
{
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
declare (strict_types=1);
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Event;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
class TransactionCommitEventArgs extends TransactionEventArgs
|
||||
{
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
declare (strict_types=1);
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Event;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
use MailPoetVendor\Doctrine\Common\EventArgs;
|
||||
use MailPoetVendor\Doctrine\DBAL\Connection;
|
||||
abstract class TransactionEventArgs extends EventArgs
|
||||
{
|
||||
private Connection $connection;
|
||||
public function __construct(Connection $connection)
|
||||
{
|
||||
$this->connection = $connection;
|
||||
}
|
||||
public function getConnection() : Connection
|
||||
{
|
||||
return $this->connection;
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
declare (strict_types=1);
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Event;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
class TransactionRollBackEventArgs extends TransactionEventArgs
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<?php
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
final class Events
|
||||
{
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
public const postConnect = 'postConnect';
|
||||
public const onSchemaCreateTable = 'onSchemaCreateTable';
|
||||
public const onSchemaCreateTableColumn = 'onSchemaCreateTableColumn';
|
||||
public const onSchemaDropTable = 'onSchemaDropTable';
|
||||
public const onSchemaAlterTable = 'onSchemaAlterTable';
|
||||
public const onSchemaAlterTableAddColumn = 'onSchemaAlterTableAddColumn';
|
||||
public const onSchemaAlterTableRemoveColumn = 'onSchemaAlterTableRemoveColumn';
|
||||
public const onSchemaAlterTableChangeColumn = 'onSchemaAlterTableChangeColumn';
|
||||
public const onSchemaAlterTableRenameColumn = 'onSchemaAlterTableRenameColumn';
|
||||
public const onSchemaColumnDefinition = 'onSchemaColumnDefinition';
|
||||
public const onSchemaIndexDefinition = 'onSchemaIndexDefinition';
|
||||
public const onTransactionBegin = 'onTransactionBegin';
|
||||
public const onTransactionCommit = 'onTransactionCommit';
|
||||
public const onTransactionRollBack = 'onTransactionRollBack';
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
use MailPoetVendor\Doctrine\DBAL\Platforms\AbstractPlatform;
|
||||
use MailPoetVendor\Doctrine\DBAL\Types\Type;
|
||||
use MailPoetVendor\SensitiveParameter;
|
||||
use function get_class;
|
||||
use function gettype;
|
||||
use function implode;
|
||||
use function is_object;
|
||||
use function spl_object_hash;
|
||||
use function sprintf;
|
||||
class Exception extends \Exception
|
||||
{
|
||||
public static function notSupported(string $method) : self
|
||||
{
|
||||
return new self(sprintf("Operation '%s' is not supported by platform.", $method));
|
||||
}
|
||||
public static function invalidPlatformType($invalidPlatform) : self
|
||||
{
|
||||
if (is_object($invalidPlatform)) {
|
||||
return new self(sprintf("Option 'platform' must be a subtype of '%s', instance of '%s' given", AbstractPlatform::class, get_class($invalidPlatform)));
|
||||
}
|
||||
return new self(sprintf("Option 'platform' must be an object and subtype of '%s'. Got '%s'", AbstractPlatform::class, gettype($invalidPlatform)));
|
||||
}
|
||||
public static function invalidPlatformVersionSpecified(string $version, string $expectedFormat) : self
|
||||
{
|
||||
return new self(sprintf('Invalid platform version "%s" specified. ' . 'The platform version has to be specified in the format: "%s".', $version, $expectedFormat));
|
||||
}
|
||||
public static function driverRequired( ?string $url = null) : self
|
||||
{
|
||||
if ($url !== null) {
|
||||
return new self(sprintf("The options 'driver' or 'driverClass' are mandatory if a connection URL without scheme " . 'is given to DriverManager::getConnection(). Given URL: %s', $url));
|
||||
}
|
||||
return new self("The options 'driver' or 'driverClass' are mandatory if no PDO " . 'instance is given to DriverManager::getConnection().');
|
||||
}
|
||||
public static function unknownDriver(string $unknownDriverName, array $knownDrivers) : self
|
||||
{
|
||||
return new self("The given 'driver' " . $unknownDriverName . ' is unknown, ' . 'Doctrine currently supports only the following drivers: ' . implode(', ', $knownDrivers));
|
||||
}
|
||||
public static function invalidWrapperClass(string $wrapperClass) : self
|
||||
{
|
||||
return new self("The given 'wrapperClass' " . $wrapperClass . ' has to be a ' . 'subtype of \\Doctrine\\DBAL\\Connection.');
|
||||
}
|
||||
public static function invalidDriverClass(string $driverClass) : self
|
||||
{
|
||||
return new self("The given 'driverClass' " . $driverClass . ' has to implement the ' . Driver::class . ' interface.');
|
||||
}
|
||||
public static function noColumnsSpecifiedForTable(string $tableName) : self
|
||||
{
|
||||
return new self('No columns specified for table ' . $tableName);
|
||||
}
|
||||
public static function typeExists(string $name) : self
|
||||
{
|
||||
return new self('Type ' . $name . ' already exists.');
|
||||
}
|
||||
public static function unknownColumnType(string $name) : self
|
||||
{
|
||||
return new self('Unknown column type "' . $name . '" requested. Any Doctrine type that you use has ' . 'to be registered with \\Doctrine\\DBAL\\Types\\Type::addType(). You can get a list of all the ' . 'known types with \\Doctrine\\DBAL\\Types\\Type::getTypesMap(). If this error occurs during database ' . 'introspection then you might have forgotten to register all database types for a Doctrine Type. Use ' . 'AbstractPlatform#registerDoctrineTypeMapping() or have your custom types implement ' . 'Type#getMappedDatabaseTypes(). If the type name is empty you might ' . 'have a problem with the cache or forgot some mapping information.');
|
||||
}
|
||||
public static function typeNotFound(string $name) : self
|
||||
{
|
||||
return new self('Type to be overwritten ' . $name . ' does not exist.');
|
||||
}
|
||||
public static function typeNotRegistered(Type $type) : self
|
||||
{
|
||||
return new self(sprintf('Type of the class %s@%s is not registered.', get_class($type), spl_object_hash($type)));
|
||||
}
|
||||
public static function typeAlreadyRegistered(Type $type) : self
|
||||
{
|
||||
return new self(sprintf('Type of the class %s@%s is already registered.', get_class($type), spl_object_hash($type)));
|
||||
}
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Exception;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
class ConnectionException extends DriverException
|
||||
{
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Exception;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
final class ConnectionLost extends ConnectionException
|
||||
{
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Exception;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
class ConstraintViolationException extends ServerException
|
||||
{
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Exception;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
class DatabaseDoesNotExist extends DatabaseObjectNotFoundException
|
||||
{
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Exception;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
class DatabaseObjectExistsException extends ServerException
|
||||
{
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Exception;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
class DatabaseObjectNotFoundException extends ServerException
|
||||
{
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
declare (strict_types=1);
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Exception;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
use MailPoetVendor\Doctrine\DBAL\Exception;
|
||||
use function sprintf;
|
||||
class DatabaseRequired extends Exception
|
||||
{
|
||||
public static function new(string $methodName) : self
|
||||
{
|
||||
return new self(sprintf('A database is required for the method: %s.', $methodName));
|
||||
}
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Exception;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
class DeadlockException extends ServerException implements RetryableException
|
||||
{
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Exception;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
use MailPoetVendor\Doctrine\DBAL\Driver\Exception as TheDriverException;
|
||||
use MailPoetVendor\Doctrine\DBAL\Exception;
|
||||
use MailPoetVendor\Doctrine\DBAL\Query;
|
||||
use function assert;
|
||||
class DriverException extends Exception implements TheDriverException
|
||||
{
|
||||
private ?Query $query;
|
||||
public function __construct(TheDriverException $driverException, ?Query $query)
|
||||
{
|
||||
if ($query !== null) {
|
||||
$message = 'An exception occurred while executing a query: ' . $driverException->getMessage();
|
||||
} else {
|
||||
$message = 'An exception occurred in the driver: ' . $driverException->getMessage();
|
||||
}
|
||||
parent::__construct($message, $driverException->getCode(), $driverException);
|
||||
$this->query = $query;
|
||||
}
|
||||
public function getSQLState()
|
||||
{
|
||||
$previous = $this->getPrevious();
|
||||
assert($previous instanceof TheDriverException);
|
||||
return $previous->getSQLState();
|
||||
}
|
||||
public function getQuery() : ?Query
|
||||
{
|
||||
return $this->query;
|
||||
}
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Exception;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
class ForeignKeyConstraintViolationException extends ConstraintViolationException
|
||||
{
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Exception;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
use MailPoetVendor\Doctrine\DBAL\Exception;
|
||||
class InvalidArgumentException extends Exception
|
||||
{
|
||||
public static function fromEmptyCriteria()
|
||||
{
|
||||
return new self('Empty criteria was used, expected non-empty criteria');
|
||||
}
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Exception;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
class InvalidFieldNameException extends ServerException
|
||||
{
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Exception;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
use MailPoetVendor\Doctrine\DBAL\Exception;
|
||||
use function sprintf;
|
||||
class InvalidLockMode extends Exception
|
||||
{
|
||||
public static function fromLockMode(int $lockMode) : self
|
||||
{
|
||||
return new self(sprintf('Lock mode %d is invalid. The valid values are LockMode::NONE, LockMode::OPTIMISTIC' . ', LockMode::PESSIMISTIC_READ and LockMode::PESSIMISTIC_WRITE', $lockMode));
|
||||
}
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Exception;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
class LockWaitTimeoutException extends ServerException implements RetryableException
|
||||
{
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Exception;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
use InvalidArgumentException;
|
||||
class MalformedDsnException extends InvalidArgumentException
|
||||
{
|
||||
public static function new() : self
|
||||
{
|
||||
return new self('Malformed database connection URL');
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Exception;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
use MailPoetVendor\Doctrine\DBAL\Exception;
|
||||
use function sprintf;
|
||||
final class NoKeyValue extends Exception
|
||||
{
|
||||
public static function fromColumnCount(int $columnCount) : self
|
||||
{
|
||||
return new self(sprintf('Fetching as key-value pairs requires the result to contain at least 2 columns, %d given.', $columnCount));
|
||||
}
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Exception;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
class NonUniqueFieldNameException extends ServerException
|
||||
{
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Exception;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
class NotNullConstraintViolationException extends ConstraintViolationException
|
||||
{
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Exception;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
class ReadOnlyException extends ServerException
|
||||
{
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Exception;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
use Throwable;
|
||||
interface RetryableException extends Throwable
|
||||
{
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Exception;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
class SchemaDoesNotExist extends DatabaseObjectNotFoundException
|
||||
{
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Exception;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
class ServerException extends DriverException
|
||||
{
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Exception;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
class SyntaxErrorException extends ServerException
|
||||
{
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Exception;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
class TableExistsException extends DatabaseObjectExistsException
|
||||
{
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Exception;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
class TableNotFoundException extends DatabaseObjectNotFoundException
|
||||
{
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Exception;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
class UniqueConstraintViolationException extends ConstraintViolationException
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<?php
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
use MailPoetVendor\Doctrine\DBAL\ArrayParameters\Exception\MissingNamedParameter;
|
||||
use MailPoetVendor\Doctrine\DBAL\ArrayParameters\Exception\MissingPositionalParameter;
|
||||
use MailPoetVendor\Doctrine\DBAL\SQL\Parser\Visitor;
|
||||
use MailPoetVendor\Doctrine\DBAL\Types\Type;
|
||||
use function array_fill;
|
||||
use function array_key_exists;
|
||||
use function count;
|
||||
use function implode;
|
||||
use function substr;
|
||||
final class ExpandArrayParameters implements Visitor
|
||||
{
|
||||
private array $originalParameters;
|
||||
private array $originalTypes;
|
||||
private int $originalParameterIndex = 0;
|
||||
private array $convertedSQL = [];
|
||||
private array $convertedParameters = [];
|
||||
private array $convertedTypes = [];
|
||||
public function __construct(array $parameters, array $types)
|
||||
{
|
||||
$this->originalParameters = $parameters;
|
||||
$this->originalTypes = $types;
|
||||
}
|
||||
public function acceptPositionalParameter(string $sql) : void
|
||||
{
|
||||
$index = $this->originalParameterIndex;
|
||||
if (!array_key_exists($index, $this->originalParameters)) {
|
||||
throw MissingPositionalParameter::new($index);
|
||||
}
|
||||
$this->acceptParameter($index, $this->originalParameters[$index]);
|
||||
$this->originalParameterIndex++;
|
||||
}
|
||||
public function acceptNamedParameter(string $sql) : void
|
||||
{
|
||||
$name = substr($sql, 1);
|
||||
if (!array_key_exists($name, $this->originalParameters)) {
|
||||
throw MissingNamedParameter::new($name);
|
||||
}
|
||||
$this->acceptParameter($name, $this->originalParameters[$name]);
|
||||
}
|
||||
public function acceptOther(string $sql) : void
|
||||
{
|
||||
$this->convertedSQL[] = $sql;
|
||||
}
|
||||
public function getSQL() : string
|
||||
{
|
||||
return implode('', $this->convertedSQL);
|
||||
}
|
||||
public function getParameters() : array
|
||||
{
|
||||
return $this->convertedParameters;
|
||||
}
|
||||
private function acceptParameter($key, $value) : void
|
||||
{
|
||||
if (!isset($this->originalTypes[$key])) {
|
||||
$this->convertedSQL[] = '?';
|
||||
$this->convertedParameters[] = $value;
|
||||
return;
|
||||
}
|
||||
$type = $this->originalTypes[$key];
|
||||
if ($type !== ArrayParameterType::INTEGER && $type !== ArrayParameterType::STRING && $type !== ArrayParameterType::ASCII && $type !== ArrayParameterType::BINARY) {
|
||||
$this->appendTypedParameter([$value], $type);
|
||||
return;
|
||||
}
|
||||
if (count($value) === 0) {
|
||||
$this->convertedSQL[] = 'NULL';
|
||||
return;
|
||||
}
|
||||
$this->appendTypedParameter($value, ArrayParameterType::toElementParameterType($type));
|
||||
}
|
||||
public function getTypes() : array
|
||||
{
|
||||
return $this->convertedTypes;
|
||||
}
|
||||
private function appendTypedParameter(array $values, $type) : void
|
||||
{
|
||||
$this->convertedSQL[] = implode(', ', array_fill(0, count($values), '?'));
|
||||
$index = count($this->convertedParameters);
|
||||
foreach ($values as $value) {
|
||||
$this->convertedParameters[] = $value;
|
||||
$this->convertedTypes[$index] = $type;
|
||||
$index++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
class FetchMode
|
||||
{
|
||||
public const ASSOCIATIVE = 2;
|
||||
public const NUMERIC = 3;
|
||||
public const COLUMN = 7;
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Id;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
use MailPoetVendor\Doctrine\DBAL\Connection;
|
||||
use MailPoetVendor\Doctrine\DBAL\Driver;
|
||||
use MailPoetVendor\Doctrine\DBAL\DriverManager;
|
||||
use MailPoetVendor\Doctrine\DBAL\Exception;
|
||||
use MailPoetVendor\Doctrine\Deprecations\Deprecation;
|
||||
use Throwable;
|
||||
use function array_change_key_case;
|
||||
use function assert;
|
||||
use function is_int;
|
||||
use const CASE_LOWER;
|
||||
class TableGenerator
|
||||
{
|
||||
private Connection $conn;
|
||||
private $generatorTableName;
|
||||
private array $sequences = [];
|
||||
public function __construct(Connection $conn, $generatorTableName = 'sequences')
|
||||
{
|
||||
Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4681', 'The TableGenerator class is is deprecated.');
|
||||
if ($conn->getDriver() instanceof Driver\PDO\SQLite\Driver) {
|
||||
throw new Exception('Cannot use TableGenerator with SQLite.');
|
||||
}
|
||||
$this->conn = DriverManager::getConnection($conn->getParams(), $conn->getConfiguration(), $conn->getEventManager());
|
||||
$this->generatorTableName = $generatorTableName;
|
||||
}
|
||||
public function nextValue($sequence)
|
||||
{
|
||||
if (isset($this->sequences[$sequence])) {
|
||||
$value = $this->sequences[$sequence]['value'];
|
||||
$this->sequences[$sequence]['value']++;
|
||||
if ($this->sequences[$sequence]['value'] >= $this->sequences[$sequence]['max']) {
|
||||
unset($this->sequences[$sequence]);
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
$this->conn->beginTransaction();
|
||||
try {
|
||||
$row = $this->conn->createQueryBuilder()->select('sequence_value', 'sequence_increment_by')->from($this->generatorTableName)->where('sequence_name = ?')->forUpdate()->setParameter(1, $sequence)->fetchAssociative();
|
||||
if ($row !== \false) {
|
||||
$row = array_change_key_case($row, CASE_LOWER);
|
||||
$value = $row['sequence_value'];
|
||||
$value++;
|
||||
assert(is_int($value));
|
||||
if ($row['sequence_increment_by'] > 1) {
|
||||
$this->sequences[$sequence] = ['value' => $value, 'max' => $row['sequence_value'] + $row['sequence_increment_by']];
|
||||
}
|
||||
$sql = 'UPDATE ' . $this->generatorTableName . ' ' . 'SET sequence_value = sequence_value + sequence_increment_by ' . 'WHERE sequence_name = ? AND sequence_value = ?';
|
||||
$rows = $this->conn->executeStatement($sql, [$sequence, $row['sequence_value']]);
|
||||
if ($rows !== 1) {
|
||||
throw new Exception('Race-condition detected while updating sequence. Aborting generation');
|
||||
}
|
||||
} else {
|
||||
$this->conn->insert($this->generatorTableName, ['sequence_name' => $sequence, 'sequence_value' => 1, 'sequence_increment_by' => 1]);
|
||||
$value = 1;
|
||||
}
|
||||
$this->conn->commit();
|
||||
} catch (Throwable $e) {
|
||||
$this->conn->rollBack();
|
||||
throw new Exception('Error occurred while generating ID with TableGenerator, aborted generation: ' . $e->getMessage(), 0, $e);
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Id;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
use MailPoetVendor\Doctrine\DBAL\Schema\Column;
|
||||
use MailPoetVendor\Doctrine\DBAL\Schema\ForeignKeyConstraint;
|
||||
use MailPoetVendor\Doctrine\DBAL\Schema\Index;
|
||||
use MailPoetVendor\Doctrine\DBAL\Schema\Schema;
|
||||
use MailPoetVendor\Doctrine\DBAL\Schema\Sequence;
|
||||
use MailPoetVendor\Doctrine\DBAL\Schema\Table;
|
||||
use MailPoetVendor\Doctrine\DBAL\Schema\Visitor\Visitor;
|
||||
use MailPoetVendor\Doctrine\Deprecations\Deprecation;
|
||||
class TableGeneratorSchemaVisitor implements Visitor
|
||||
{
|
||||
private $generatorTableName;
|
||||
public function __construct($generatorTableName = 'sequences')
|
||||
{
|
||||
Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4681', 'The TableGeneratorSchemaVisitor class is is deprecated.');
|
||||
$this->generatorTableName = $generatorTableName;
|
||||
}
|
||||
public function acceptSchema(Schema $schema)
|
||||
{
|
||||
$table = $schema->createTable($this->generatorTableName);
|
||||
$table->addColumn('sequence_name', 'string');
|
||||
$table->addColumn('sequence_value', 'integer', ['default' => 1]);
|
||||
$table->addColumn('sequence_increment_by', 'integer', ['default' => 1]);
|
||||
}
|
||||
public function acceptTable(Table $table)
|
||||
{
|
||||
}
|
||||
public function acceptColumn(Table $table, Column $column)
|
||||
{
|
||||
}
|
||||
public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint)
|
||||
{
|
||||
}
|
||||
public function acceptIndex(Table $table, Index $index)
|
||||
{
|
||||
}
|
||||
public function acceptSequence(Sequence $sequence)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<?php
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
class LockMode
|
||||
{
|
||||
public const NONE = 0;
|
||||
public const OPTIMISTIC = 1;
|
||||
public const PESSIMISTIC_READ = 2;
|
||||
public const PESSIMISTIC_WRITE = 4;
|
||||
private final function __construct()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
declare (strict_types=1);
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Logging;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
use MailPoetVendor\Doctrine\DBAL\Driver\Connection as ConnectionInterface;
|
||||
use MailPoetVendor\Doctrine\DBAL\Driver\Middleware\AbstractConnectionMiddleware;
|
||||
use MailPoetVendor\Doctrine\DBAL\Driver\Result;
|
||||
use MailPoetVendor\Doctrine\DBAL\Driver\Statement as DriverStatement;
|
||||
use MailPoetVendor\Psr\Log\LoggerInterface;
|
||||
final class Connection extends AbstractConnectionMiddleware
|
||||
{
|
||||
private LoggerInterface $logger;
|
||||
public function __construct(ConnectionInterface $connection, LoggerInterface $logger)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->logger = $logger;
|
||||
}
|
||||
public function __destruct()
|
||||
{
|
||||
$this->logger->info('Disconnecting');
|
||||
}
|
||||
public function prepare(string $sql) : DriverStatement
|
||||
{
|
||||
return new Statement(parent::prepare($sql), $this->logger, $sql);
|
||||
}
|
||||
public function query(string $sql) : Result
|
||||
{
|
||||
$this->logger->debug('Executing query: {sql}', ['sql' => $sql]);
|
||||
return parent::query($sql);
|
||||
}
|
||||
public function exec(string $sql) : int
|
||||
{
|
||||
$this->logger->debug('Executing statement: {sql}', ['sql' => $sql]);
|
||||
return parent::exec($sql);
|
||||
}
|
||||
public function beginTransaction()
|
||||
{
|
||||
$this->logger->debug('Beginning transaction');
|
||||
return parent::beginTransaction();
|
||||
}
|
||||
public function commit()
|
||||
{
|
||||
$this->logger->debug('Committing transaction');
|
||||
return parent::commit();
|
||||
}
|
||||
public function rollBack()
|
||||
{
|
||||
$this->logger->debug('Rolling back transaction');
|
||||
return parent::rollBack();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Logging;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
use MailPoetVendor\Doctrine\Deprecations\Deprecation;
|
||||
use function microtime;
|
||||
class DebugStack implements SQLLogger
|
||||
{
|
||||
public $queries = [];
|
||||
public $enabled = \true;
|
||||
public $start = null;
|
||||
public $currentQuery = 0;
|
||||
public function __construct()
|
||||
{
|
||||
Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4967', 'DebugStack is deprecated.');
|
||||
}
|
||||
public function startQuery($sql, ?array $params = null, ?array $types = null)
|
||||
{
|
||||
if (!$this->enabled) {
|
||||
return;
|
||||
}
|
||||
$this->start = microtime(\true);
|
||||
$this->queries[++$this->currentQuery] = ['sql' => $sql, 'params' => $params, 'types' => $types, 'executionMS' => 0];
|
||||
}
|
||||
public function stopQuery()
|
||||
{
|
||||
if (!$this->enabled) {
|
||||
return;
|
||||
}
|
||||
$this->queries[$this->currentQuery]['executionMS'] = microtime(\true) - $this->start;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
declare (strict_types=1);
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Logging;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
use MailPoetVendor\Doctrine\DBAL\Driver as DriverInterface;
|
||||
use MailPoetVendor\Doctrine\DBAL\Driver\Middleware\AbstractDriverMiddleware;
|
||||
use MailPoetVendor\Psr\Log\LoggerInterface;
|
||||
use MailPoetVendor\SensitiveParameter;
|
||||
final class Driver extends AbstractDriverMiddleware
|
||||
{
|
||||
private LoggerInterface $logger;
|
||||
public function __construct(DriverInterface $driver, LoggerInterface $logger)
|
||||
{
|
||||
parent::__construct($driver);
|
||||
$this->logger = $logger;
|
||||
}
|
||||
public function connect( array $params)
|
||||
{
|
||||
$this->logger->info('Connecting with parameters {params}', ['params' => $this->maskPassword($params)]);
|
||||
return new Connection(parent::connect($params), $this->logger);
|
||||
}
|
||||
private function maskPassword( array $params) : array
|
||||
{
|
||||
if (isset($params['password'])) {
|
||||
$params['password'] = '<redacted>';
|
||||
}
|
||||
if (isset($params['url'])) {
|
||||
$params['url'] = '<redacted>';
|
||||
}
|
||||
return $params;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Logging;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
use MailPoetVendor\Doctrine\Deprecations\Deprecation;
|
||||
class LoggerChain implements SQLLogger
|
||||
{
|
||||
private iterable $loggers;
|
||||
public function __construct(iterable $loggers = [])
|
||||
{
|
||||
Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4967', 'LoggerChain is deprecated');
|
||||
$this->loggers = $loggers;
|
||||
}
|
||||
public function startQuery($sql, ?array $params = null, ?array $types = null)
|
||||
{
|
||||
foreach ($this->loggers as $logger) {
|
||||
$logger->startQuery($sql, $params, $types);
|
||||
}
|
||||
}
|
||||
public function stopQuery()
|
||||
{
|
||||
foreach ($this->loggers as $logger) {
|
||||
$logger->stopQuery();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
declare (strict_types=1);
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Logging;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
use MailPoetVendor\Doctrine\DBAL\Driver as DriverInterface;
|
||||
use MailPoetVendor\Doctrine\DBAL\Driver\Middleware as MiddlewareInterface;
|
||||
use MailPoetVendor\Psr\Log\LoggerInterface;
|
||||
final class Middleware implements MiddlewareInterface
|
||||
{
|
||||
private LoggerInterface $logger;
|
||||
public function __construct(LoggerInterface $logger)
|
||||
{
|
||||
$this->logger = $logger;
|
||||
}
|
||||
public function wrap(DriverInterface $driver) : DriverInterface
|
||||
{
|
||||
return new Driver($driver, $this->logger);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Logging;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
use MailPoetVendor\Doctrine\DBAL\Types\Type;
|
||||
interface SQLLogger
|
||||
{
|
||||
public function startQuery($sql, ?array $params = null, ?array $types = null);
|
||||
public function stopQuery();
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
declare (strict_types=1);
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Logging;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
use MailPoetVendor\Doctrine\DBAL\Driver\Middleware\AbstractStatementMiddleware;
|
||||
use MailPoetVendor\Doctrine\DBAL\Driver\Result as ResultInterface;
|
||||
use MailPoetVendor\Doctrine\DBAL\Driver\Statement as StatementInterface;
|
||||
use MailPoetVendor\Doctrine\DBAL\ParameterType;
|
||||
use MailPoetVendor\Doctrine\Deprecations\Deprecation;
|
||||
use MailPoetVendor\Psr\Log\LoggerInterface;
|
||||
use function array_slice;
|
||||
use function func_get_args;
|
||||
use function func_num_args;
|
||||
final class Statement extends AbstractStatementMiddleware
|
||||
{
|
||||
private LoggerInterface $logger;
|
||||
private string $sql;
|
||||
private array $params = [];
|
||||
private array $types = [];
|
||||
public function __construct(StatementInterface $statement, LoggerInterface $logger, string $sql)
|
||||
{
|
||||
parent::__construct($statement);
|
||||
$this->logger = $logger;
|
||||
$this->sql = $sql;
|
||||
}
|
||||
public function bindParam($param, &$variable, $type = ParameterType::STRING, $length = null)
|
||||
{
|
||||
Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5563', '%s is deprecated. Use bindValue() instead.', __METHOD__);
|
||||
if (func_num_args() < 3) {
|
||||
Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5558', 'Not passing $type to Statement::bindParam() is deprecated.' . ' Pass the type corresponding to the parameter being bound.');
|
||||
}
|
||||
$this->params[$param] =& $variable;
|
||||
$this->types[$param] = $type;
|
||||
return parent::bindParam($param, $variable, $type, ...array_slice(func_get_args(), 3));
|
||||
}
|
||||
public function bindValue($param, $value, $type = ParameterType::STRING)
|
||||
{
|
||||
if (func_num_args() < 3) {
|
||||
Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5558', 'Not passing $type to Statement::bindValue() is deprecated.' . ' Pass the type corresponding to the parameter being bound.');
|
||||
}
|
||||
$this->params[$param] = $value;
|
||||
$this->types[$param] = $type;
|
||||
return parent::bindValue($param, $value, $type);
|
||||
}
|
||||
public function execute($params = null) : ResultInterface
|
||||
{
|
||||
$this->logger->debug('Executing statement: {sql} (parameters: {params}, types: {types})', ['sql' => $this->sql, 'params' => $params ?? $this->params, 'types' => $this->types]);
|
||||
return parent::execute($params);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<?php
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
final class ParameterType
|
||||
{
|
||||
public const NULL = 0;
|
||||
public const INTEGER = 1;
|
||||
public const STRING = 2;
|
||||
public const LARGE_OBJECT = 3;
|
||||
public const BOOLEAN = 5;
|
||||
public const BINARY = 16;
|
||||
public const ASCII = 17;
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
}
|
||||
+757
@@ -0,0 +1,757 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Platforms;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
use MailPoetVendor\Doctrine\DBAL\Connection;
|
||||
use MailPoetVendor\Doctrine\DBAL\Exception;
|
||||
use MailPoetVendor\Doctrine\DBAL\Schema\AbstractAsset;
|
||||
use MailPoetVendor\Doctrine\DBAL\Schema\ForeignKeyConstraint;
|
||||
use MailPoetVendor\Doctrine\DBAL\Schema\Identifier;
|
||||
use MailPoetVendor\Doctrine\DBAL\Schema\Index;
|
||||
use MailPoetVendor\Doctrine\DBAL\Schema\MySQLSchemaManager;
|
||||
use MailPoetVendor\Doctrine\DBAL\Schema\Table;
|
||||
use MailPoetVendor\Doctrine\DBAL\Schema\TableDiff;
|
||||
use MailPoetVendor\Doctrine\DBAL\SQL\Builder\DefaultSelectSQLBuilder;
|
||||
use MailPoetVendor\Doctrine\DBAL\SQL\Builder\SelectSQLBuilder;
|
||||
use MailPoetVendor\Doctrine\DBAL\TransactionIsolationLevel;
|
||||
use MailPoetVendor\Doctrine\DBAL\Types\BlobType;
|
||||
use MailPoetVendor\Doctrine\DBAL\Types\TextType;
|
||||
use MailPoetVendor\Doctrine\DBAL\Types\Types;
|
||||
use MailPoetVendor\Doctrine\Deprecations\Deprecation;
|
||||
use InvalidArgumentException;
|
||||
use function array_diff_key;
|
||||
use function array_merge;
|
||||
use function array_unique;
|
||||
use function array_values;
|
||||
use function count;
|
||||
use function func_get_arg;
|
||||
use function func_get_args;
|
||||
use function func_num_args;
|
||||
use function implode;
|
||||
use function in_array;
|
||||
use function is_numeric;
|
||||
use function is_string;
|
||||
use function sprintf;
|
||||
use function str_replace;
|
||||
use function strcasecmp;
|
||||
use function strtolower;
|
||||
use function strtoupper;
|
||||
use function trim;
|
||||
abstract class AbstractMySQLPlatform extends AbstractPlatform
|
||||
{
|
||||
public const LENGTH_LIMIT_TINYTEXT = 255;
|
||||
public const LENGTH_LIMIT_TEXT = 65535;
|
||||
public const LENGTH_LIMIT_MEDIUMTEXT = 16777215;
|
||||
public const LENGTH_LIMIT_TINYBLOB = 255;
|
||||
public const LENGTH_LIMIT_BLOB = 65535;
|
||||
public const LENGTH_LIMIT_MEDIUMBLOB = 16777215;
|
||||
protected function doModifyLimitQuery($query, $limit, $offset)
|
||||
{
|
||||
if ($limit !== null) {
|
||||
$query .= sprintf(' LIMIT %d', $limit);
|
||||
if ($offset > 0) {
|
||||
$query .= sprintf(' OFFSET %d', $offset);
|
||||
}
|
||||
} elseif ($offset > 0) {
|
||||
// 2^64-1 is the maximum of unsigned BIGINT, the biggest limit possible
|
||||
$query .= sprintf(' LIMIT 18446744073709551615 OFFSET %d', $offset);
|
||||
}
|
||||
return $query;
|
||||
}
|
||||
public function getIdentifierQuoteCharacter()
|
||||
{
|
||||
Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5388', 'AbstractMySQLPlatform::getIdentifierQuoteCharacter() is deprecated. Use quoteIdentifier() instead.');
|
||||
return '`';
|
||||
}
|
||||
public function getRegexpExpression()
|
||||
{
|
||||
return 'RLIKE';
|
||||
}
|
||||
public function getLocateExpression($str, $substr, $startPos = \false)
|
||||
{
|
||||
if ($startPos === \false) {
|
||||
return 'LOCATE(' . $substr . ', ' . $str . ')';
|
||||
}
|
||||
return 'LOCATE(' . $substr . ', ' . $str . ', ' . $startPos . ')';
|
||||
}
|
||||
public function getConcatExpression()
|
||||
{
|
||||
return sprintf('CONCAT(%s)', implode(', ', func_get_args()));
|
||||
}
|
||||
protected function getDateArithmeticIntervalExpression($date, $operator, $interval, $unit)
|
||||
{
|
||||
$function = $operator === '+' ? 'DATE_ADD' : 'DATE_SUB';
|
||||
return $function . '(' . $date . ', INTERVAL ' . $interval . ' ' . $unit . ')';
|
||||
}
|
||||
public function getDateDiffExpression($date1, $date2)
|
||||
{
|
||||
return 'DATEDIFF(' . $date1 . ', ' . $date2 . ')';
|
||||
}
|
||||
public function getCurrentDatabaseExpression() : string
|
||||
{
|
||||
return 'DATABASE()';
|
||||
}
|
||||
public function getLengthExpression($column)
|
||||
{
|
||||
return 'CHAR_LENGTH(' . $column . ')';
|
||||
}
|
||||
public function getListDatabasesSQL()
|
||||
{
|
||||
return 'SHOW DATABASES';
|
||||
}
|
||||
public function getListTableConstraintsSQL($table)
|
||||
{
|
||||
return 'SHOW INDEX FROM ' . $table;
|
||||
}
|
||||
public function getListTableIndexesSQL($table, $database = null)
|
||||
{
|
||||
if ($database !== null) {
|
||||
return 'SELECT NON_UNIQUE AS Non_Unique, INDEX_NAME AS Key_name, COLUMN_NAME AS Column_Name,' . ' SUB_PART AS Sub_Part, INDEX_TYPE AS Index_Type' . ' FROM information_schema.STATISTICS WHERE TABLE_NAME = ' . $this->quoteStringLiteral($table) . ' AND TABLE_SCHEMA = ' . $this->quoteStringLiteral($database) . ' ORDER BY SEQ_IN_INDEX ASC';
|
||||
}
|
||||
return 'SHOW INDEX FROM ' . $table;
|
||||
}
|
||||
public function getListViewsSQL($database)
|
||||
{
|
||||
return 'SELECT * FROM information_schema.VIEWS WHERE TABLE_SCHEMA = ' . $this->quoteStringLiteral($database);
|
||||
}
|
||||
public function getListTableForeignKeysSQL($table, $database = null)
|
||||
{
|
||||
// The schema name is passed multiple times as a literal in the WHERE clause instead of using a JOIN condition
|
||||
// in order to avoid performance issues on MySQL older than 8.0 and the corresponding MariaDB versions
|
||||
// caused by https://bugs.mysql.com/bug.php?id=81347
|
||||
return 'SELECT k.CONSTRAINT_NAME, k.COLUMN_NAME, k.REFERENCED_TABLE_NAME, ' . 'k.REFERENCED_COLUMN_NAME /*!50116 , c.UPDATE_RULE, c.DELETE_RULE */ ' . 'FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE k /*!50116 ' . 'INNER JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS c ON ' . 'c.CONSTRAINT_NAME = k.CONSTRAINT_NAME AND ' . 'c.TABLE_NAME = k.TABLE_NAME */ ' . 'WHERE k.TABLE_NAME = ' . $this->quoteStringLiteral($table) . ' ' . 'AND k.TABLE_SCHEMA = ' . $this->getDatabaseNameSQL($database) . ' /*!50116 ' . 'AND c.CONSTRAINT_SCHEMA = ' . $this->getDatabaseNameSQL($database) . ' */' . 'ORDER BY k.ORDINAL_POSITION';
|
||||
}
|
||||
protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed)
|
||||
{
|
||||
if ($length <= 0 || func_num_args() > 2 && func_get_arg(2)) {
|
||||
Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/issues/3263', 'Relying on the default string column length on MySQL is deprecated' . ', specify the length explicitly.');
|
||||
}
|
||||
return $fixed ? $length > 0 ? 'CHAR(' . $length . ')' : 'CHAR(255)' : ($length > 0 ? 'VARCHAR(' . $length . ')' : 'VARCHAR(255)');
|
||||
}
|
||||
protected function getBinaryTypeDeclarationSQLSnippet($length, $fixed)
|
||||
{
|
||||
if ($length <= 0 || func_num_args() > 2 && func_get_arg(2)) {
|
||||
Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/issues/3263', 'Relying on the default binary column length on MySQL is deprecated' . ', specify the length explicitly.');
|
||||
}
|
||||
return $fixed ? 'BINARY(' . ($length > 0 ? $length : 255) . ')' : 'VARBINARY(' . ($length > 0 ? $length : 255) . ')';
|
||||
}
|
||||
public function getClobTypeDeclarationSQL(array $column)
|
||||
{
|
||||
if (!empty($column['length']) && is_numeric($column['length'])) {
|
||||
$length = $column['length'];
|
||||
if ($length <= static::LENGTH_LIMIT_TINYTEXT) {
|
||||
return 'TINYTEXT';
|
||||
}
|
||||
if ($length <= static::LENGTH_LIMIT_TEXT) {
|
||||
return 'TEXT';
|
||||
}
|
||||
if ($length <= static::LENGTH_LIMIT_MEDIUMTEXT) {
|
||||
return 'MEDIUMTEXT';
|
||||
}
|
||||
}
|
||||
return 'LONGTEXT';
|
||||
}
|
||||
public function getDateTimeTypeDeclarationSQL(array $column)
|
||||
{
|
||||
if (isset($column['version']) && $column['version'] === \true) {
|
||||
return 'TIMESTAMP';
|
||||
}
|
||||
return 'DATETIME';
|
||||
}
|
||||
public function getDateTypeDeclarationSQL(array $column)
|
||||
{
|
||||
return 'DATE';
|
||||
}
|
||||
public function getTimeTypeDeclarationSQL(array $column)
|
||||
{
|
||||
return 'TIME';
|
||||
}
|
||||
public function getBooleanTypeDeclarationSQL(array $column)
|
||||
{
|
||||
return 'TINYINT(1)';
|
||||
}
|
||||
public function prefersIdentityColumns()
|
||||
{
|
||||
Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/1519', 'AbstractMySQLPlatform::prefersIdentityColumns() is deprecated.');
|
||||
return \true;
|
||||
}
|
||||
public function supportsIdentityColumns()
|
||||
{
|
||||
return \true;
|
||||
}
|
||||
public function supportsInlineColumnComments()
|
||||
{
|
||||
return \true;
|
||||
}
|
||||
public function supportsColumnCollation()
|
||||
{
|
||||
return \true;
|
||||
}
|
||||
public function getListTablesSQL()
|
||||
{
|
||||
return "SHOW FULL TABLES WHERE Table_type = 'BASE TABLE'";
|
||||
}
|
||||
public function getListTableColumnsSQL($table, $database = null)
|
||||
{
|
||||
return 'SELECT COLUMN_NAME AS Field, COLUMN_TYPE AS Type, IS_NULLABLE AS `Null`, ' . 'COLUMN_KEY AS `Key`, COLUMN_DEFAULT AS `Default`, EXTRA AS Extra, COLUMN_COMMENT AS Comment, ' . 'CHARACTER_SET_NAME AS CharacterSet, COLLATION_NAME AS Collation ' . 'FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = ' . $this->getDatabaseNameSQL($database) . ' AND TABLE_NAME = ' . $this->quoteStringLiteral($table) . ' ORDER BY ORDINAL_POSITION ASC';
|
||||
}
|
||||
public function getColumnTypeSQLSnippets(string $tableAlias = 'c') : array
|
||||
{
|
||||
Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/6202', 'AbstractMySQLPlatform::getColumnTypeSQLSnippets() is deprecated. ' . 'Use AbstractMySQLPlatform::getColumnTypeSQLSnippet() instead.');
|
||||
return [$this->getColumnTypeSQLSnippet(...func_get_args()), ''];
|
||||
}
|
||||
public function getColumnTypeSQLSnippet(string $tableAlias = 'c', ?string $databaseName = null) : string
|
||||
{
|
||||
return $tableAlias . '.COLUMN_TYPE';
|
||||
}
|
||||
public function getListTableMetadataSQL(string $table, ?string $database = null) : string
|
||||
{
|
||||
return sprintf(<<<'SQL'
|
||||
SELECT t.ENGINE,
|
||||
t.AUTO_INCREMENT,
|
||||
t.TABLE_COMMENT,
|
||||
t.CREATE_OPTIONS,
|
||||
t.TABLE_COLLATION,
|
||||
ccsa.CHARACTER_SET_NAME
|
||||
FROM information_schema.TABLES t
|
||||
INNER JOIN information_schema.`COLLATION_CHARACTER_SET_APPLICABILITY` ccsa
|
||||
ON ccsa.COLLATION_NAME = t.TABLE_COLLATION
|
||||
WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_SCHEMA = %s AND TABLE_NAME = %s
|
||||
SQL
|
||||
, $this->getDatabaseNameSQL($database), $this->quoteStringLiteral($table));
|
||||
}
|
||||
public function getCreateTablesSQL(array $tables) : array
|
||||
{
|
||||
$sql = [];
|
||||
foreach ($tables as $table) {
|
||||
$sql = array_merge($sql, $this->getCreateTableWithoutForeignKeysSQL($table));
|
||||
}
|
||||
foreach ($tables as $table) {
|
||||
if (!$table->hasOption('engine') || $this->engineSupportsForeignKeys($table->getOption('engine'))) {
|
||||
foreach ($table->getForeignKeys() as $foreignKey) {
|
||||
$sql[] = $this->getCreateForeignKeySQL($foreignKey, $table->getQuotedName($this));
|
||||
}
|
||||
} elseif (count($table->getForeignKeys()) > 0) {
|
||||
Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5414', 'Relying on the DBAL not generating DDL for foreign keys on MySQL engines' . ' other than InnoDB is deprecated.' . ' Define foreign key constraints only if they are necessary.');
|
||||
}
|
||||
}
|
||||
return $sql;
|
||||
}
|
||||
protected function _getCreateTableSQL($name, array $columns, array $options = [])
|
||||
{
|
||||
$queryFields = $this->getColumnDeclarationListSQL($columns);
|
||||
if (isset($options['uniqueConstraints']) && !empty($options['uniqueConstraints'])) {
|
||||
foreach ($options['uniqueConstraints'] as $constraintName => $definition) {
|
||||
$queryFields .= ', ' . $this->getUniqueConstraintDeclarationSQL($constraintName, $definition);
|
||||
}
|
||||
}
|
||||
// add all indexes
|
||||
if (isset($options['indexes']) && !empty($options['indexes'])) {
|
||||
foreach ($options['indexes'] as $indexName => $definition) {
|
||||
$queryFields .= ', ' . $this->getIndexDeclarationSQL($indexName, $definition);
|
||||
}
|
||||
}
|
||||
// attach all primary keys
|
||||
if (isset($options['primary']) && !empty($options['primary'])) {
|
||||
$keyColumns = array_unique(array_values($options['primary']));
|
||||
$queryFields .= ', PRIMARY KEY(' . implode(', ', $keyColumns) . ')';
|
||||
}
|
||||
$query = 'CREATE ';
|
||||
if (!empty($options['temporary'])) {
|
||||
$query .= 'TEMPORARY ';
|
||||
}
|
||||
$query .= 'TABLE ' . $name . ' (' . $queryFields . ') ';
|
||||
$query .= $this->buildTableOptions($options);
|
||||
$query .= $this->buildPartitionOptions($options);
|
||||
$sql = [$query];
|
||||
// Propagate foreign key constraints only for InnoDB.
|
||||
if (isset($options['foreignKeys'])) {
|
||||
if (!isset($options['engine']) || $this->engineSupportsForeignKeys($options['engine'])) {
|
||||
foreach ($options['foreignKeys'] as $definition) {
|
||||
$sql[] = $this->getCreateForeignKeySQL($definition, $name);
|
||||
}
|
||||
} elseif (count($options['foreignKeys']) > 0) {
|
||||
Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5414', 'Relying on the DBAL not generating DDL for foreign keys on MySQL engines' . ' other than InnoDB is deprecated.' . ' Define foreign key constraints only if they are necessary.');
|
||||
}
|
||||
}
|
||||
return $sql;
|
||||
}
|
||||
public function createSelectSQLBuilder() : SelectSQLBuilder
|
||||
{
|
||||
return new DefaultSelectSQLBuilder($this, 'FOR UPDATE', null);
|
||||
}
|
||||
public function getDefaultValueDeclarationSQL($column)
|
||||
{
|
||||
// Unset the default value if the given column definition does not allow default values.
|
||||
if ($column['type'] instanceof TextType || $column['type'] instanceof BlobType) {
|
||||
$column['default'] = null;
|
||||
}
|
||||
return parent::getDefaultValueDeclarationSQL($column);
|
||||
}
|
||||
private function buildTableOptions(array $options) : string
|
||||
{
|
||||
if (isset($options['table_options'])) {
|
||||
return $options['table_options'];
|
||||
}
|
||||
$tableOptions = [];
|
||||
// Charset
|
||||
if (!isset($options['charset'])) {
|
||||
$options['charset'] = 'utf8';
|
||||
}
|
||||
$tableOptions[] = sprintf('DEFAULT CHARACTER SET %s', $options['charset']);
|
||||
if (isset($options['collate'])) {
|
||||
Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/issues/5214', 'The "collate" option is deprecated in favor of "collation" and will be removed in 4.0.');
|
||||
$options['collation'] = $options['collate'];
|
||||
}
|
||||
// Collation
|
||||
if (!isset($options['collation'])) {
|
||||
$options['collation'] = $options['charset'] . '_unicode_ci';
|
||||
}
|
||||
$tableOptions[] = $this->getColumnCollationDeclarationSQL($options['collation']);
|
||||
// Engine
|
||||
if (!isset($options['engine'])) {
|
||||
$options['engine'] = 'InnoDB';
|
||||
}
|
||||
$tableOptions[] = sprintf('ENGINE = %s', $options['engine']);
|
||||
// Auto increment
|
||||
if (isset($options['auto_increment'])) {
|
||||
$tableOptions[] = sprintf('AUTO_INCREMENT = %s', $options['auto_increment']);
|
||||
}
|
||||
// Comment
|
||||
if (isset($options['comment'])) {
|
||||
$tableOptions[] = sprintf('COMMENT = %s ', $this->quoteStringLiteral($options['comment']));
|
||||
}
|
||||
// Row format
|
||||
if (isset($options['row_format'])) {
|
||||
$tableOptions[] = sprintf('ROW_FORMAT = %s', $options['row_format']);
|
||||
}
|
||||
return implode(' ', $tableOptions);
|
||||
}
|
||||
private function buildPartitionOptions(array $options) : string
|
||||
{
|
||||
return isset($options['partition_options']) ? ' ' . $options['partition_options'] : '';
|
||||
}
|
||||
private function engineSupportsForeignKeys(string $engine) : bool
|
||||
{
|
||||
return strcasecmp(trim($engine), 'InnoDB') === 0;
|
||||
}
|
||||
public function getAlterTableSQL(TableDiff $diff)
|
||||
{
|
||||
$columnSql = [];
|
||||
$queryParts = [];
|
||||
$newName = $diff->getNewName();
|
||||
if ($newName !== \false) {
|
||||
Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5663', 'Generation of SQL that renames a table using %s is deprecated. Use getRenameTableSQL() instead.', __METHOD__);
|
||||
$queryParts[] = 'RENAME TO ' . $newName->getQuotedName($this);
|
||||
}
|
||||
foreach ($diff->getAddedColumns() as $column) {
|
||||
if ($this->onSchemaAlterTableAddColumn($column, $diff, $columnSql)) {
|
||||
continue;
|
||||
}
|
||||
$columnProperties = array_merge($column->toArray(), ['comment' => $this->getColumnComment($column)]);
|
||||
$queryParts[] = 'ADD ' . $this->getColumnDeclarationSQL($column->getQuotedName($this), $columnProperties);
|
||||
}
|
||||
foreach ($diff->getDroppedColumns() as $column) {
|
||||
if ($this->onSchemaAlterTableRemoveColumn($column, $diff, $columnSql)) {
|
||||
continue;
|
||||
}
|
||||
$queryParts[] = 'DROP ' . $column->getQuotedName($this);
|
||||
}
|
||||
foreach ($diff->getModifiedColumns() as $columnDiff) {
|
||||
if ($this->onSchemaAlterTableChangeColumn($columnDiff, $diff, $columnSql)) {
|
||||
continue;
|
||||
}
|
||||
$newColumn = $columnDiff->getNewColumn();
|
||||
$newColumnProperties = array_merge($newColumn->toArray(), ['comment' => $this->getColumnComment($newColumn)]);
|
||||
$oldColumn = $columnDiff->getOldColumn() ?? $columnDiff->getOldColumnName();
|
||||
$queryParts[] = 'CHANGE ' . $oldColumn->getQuotedName($this) . ' ' . $this->getColumnDeclarationSQL($newColumn->getQuotedName($this), $newColumnProperties);
|
||||
}
|
||||
foreach ($diff->getRenamedColumns() as $oldColumnName => $column) {
|
||||
if ($this->onSchemaAlterTableRenameColumn($oldColumnName, $column, $diff, $columnSql)) {
|
||||
continue;
|
||||
}
|
||||
$oldColumnName = new Identifier($oldColumnName);
|
||||
$columnProperties = array_merge($column->toArray(), ['comment' => $this->getColumnComment($column)]);
|
||||
$queryParts[] = 'CHANGE ' . $oldColumnName->getQuotedName($this) . ' ' . $this->getColumnDeclarationSQL($column->getQuotedName($this), $columnProperties);
|
||||
}
|
||||
$addedIndexes = $this->indexAssetsByLowerCaseName($diff->getAddedIndexes());
|
||||
$modifiedIndexes = $this->indexAssetsByLowerCaseName($diff->getModifiedIndexes());
|
||||
$diffModified = \false;
|
||||
if (isset($addedIndexes['primary'])) {
|
||||
$keyColumns = array_unique(array_values($addedIndexes['primary']->getColumns()));
|
||||
$queryParts[] = 'ADD PRIMARY KEY (' . implode(', ', $keyColumns) . ')';
|
||||
unset($addedIndexes['primary']);
|
||||
$diffModified = \true;
|
||||
} elseif (isset($modifiedIndexes['primary'])) {
|
||||
$addedColumns = $this->indexAssetsByLowerCaseName($diff->getAddedColumns());
|
||||
// Necessary in case the new primary key includes a new auto_increment column
|
||||
foreach ($modifiedIndexes['primary']->getColumns() as $columnName) {
|
||||
if (isset($addedColumns[$columnName]) && $addedColumns[$columnName]->getAutoincrement()) {
|
||||
$keyColumns = array_unique(array_values($modifiedIndexes['primary']->getColumns()));
|
||||
$queryParts[] = 'DROP PRIMARY KEY';
|
||||
$queryParts[] = 'ADD PRIMARY KEY (' . implode(', ', $keyColumns) . ')';
|
||||
unset($modifiedIndexes['primary']);
|
||||
$diffModified = \true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($diffModified) {
|
||||
$diff = new TableDiff($diff->name, $diff->getAddedColumns(), $diff->getModifiedColumns(), $diff->getDroppedColumns(), array_values($addedIndexes), array_values($modifiedIndexes), $diff->getDroppedIndexes(), $diff->getOldTable(), $diff->getAddedForeignKeys(), $diff->getModifiedForeignKeys(), $diff->getDroppedForeignKeys(), $diff->getRenamedColumns(), $diff->getRenamedIndexes());
|
||||
}
|
||||
$sql = [];
|
||||
$tableSql = [];
|
||||
if (!$this->onSchemaAlterTable($diff, $tableSql)) {
|
||||
if (count($queryParts) > 0) {
|
||||
$sql[] = 'ALTER TABLE ' . ($diff->getOldTable() ?? $diff->getName($this))->getQuotedName($this) . ' ' . implode(', ', $queryParts);
|
||||
}
|
||||
$sql = array_merge($this->getPreAlterTableIndexForeignKeySQL($diff), $sql, $this->getPostAlterTableIndexForeignKeySQL($diff));
|
||||
}
|
||||
return array_merge($sql, $tableSql, $columnSql);
|
||||
}
|
||||
protected function getPreAlterTableIndexForeignKeySQL(TableDiff $diff)
|
||||
{
|
||||
$sql = [];
|
||||
$tableNameSQL = ($diff->getOldTable() ?? $diff->getName($this))->getQuotedName($this);
|
||||
foreach ($diff->getModifiedIndexes() as $changedIndex) {
|
||||
$sql = array_merge($sql, $this->getPreAlterTableAlterPrimaryKeySQL($diff, $changedIndex));
|
||||
}
|
||||
foreach ($diff->getDroppedIndexes() as $droppedIndex) {
|
||||
$sql = array_merge($sql, $this->getPreAlterTableAlterPrimaryKeySQL($diff, $droppedIndex));
|
||||
foreach ($diff->getAddedIndexes() as $addedIndex) {
|
||||
if ($droppedIndex->getColumns() !== $addedIndex->getColumns()) {
|
||||
continue;
|
||||
}
|
||||
$indexClause = 'INDEX ' . $addedIndex->getName();
|
||||
if ($addedIndex->isPrimary()) {
|
||||
$indexClause = 'PRIMARY KEY';
|
||||
} elseif ($addedIndex->isUnique()) {
|
||||
$indexClause = 'UNIQUE INDEX ' . $addedIndex->getName();
|
||||
}
|
||||
$query = 'ALTER TABLE ' . $tableNameSQL . ' DROP INDEX ' . $droppedIndex->getName() . ', ';
|
||||
$query .= 'ADD ' . $indexClause;
|
||||
$query .= ' (' . $this->getIndexFieldDeclarationListSQL($addedIndex) . ')';
|
||||
$sql[] = $query;
|
||||
$diff->unsetAddedIndex($addedIndex);
|
||||
$diff->unsetDroppedIndex($droppedIndex);
|
||||
break;
|
||||
}
|
||||
}
|
||||
$engine = 'INNODB';
|
||||
$table = $diff->getOldTable();
|
||||
if ($table !== null && $table->hasOption('engine')) {
|
||||
$engine = strtoupper(trim($table->getOption('engine')));
|
||||
}
|
||||
// Suppress foreign key constraint propagation on non-supporting engines.
|
||||
if ($engine !== 'INNODB') {
|
||||
$diff->addedForeignKeys = [];
|
||||
$diff->changedForeignKeys = [];
|
||||
$diff->removedForeignKeys = [];
|
||||
}
|
||||
$sql = array_merge($sql, $this->getPreAlterTableAlterIndexForeignKeySQL($diff), parent::getPreAlterTableIndexForeignKeySQL($diff), $this->getPreAlterTableRenameIndexForeignKeySQL($diff));
|
||||
return $sql;
|
||||
}
|
||||
private function getPreAlterTableAlterPrimaryKeySQL(TableDiff $diff, Index $index) : array
|
||||
{
|
||||
if (!$index->isPrimary()) {
|
||||
return [];
|
||||
}
|
||||
$table = $diff->getOldTable();
|
||||
if ($table === null) {
|
||||
return [];
|
||||
}
|
||||
$sql = [];
|
||||
$tableNameSQL = ($diff->getOldTable() ?? $diff->getName($this))->getQuotedName($this);
|
||||
// Dropping primary keys requires to unset autoincrement attribute on the particular column first.
|
||||
foreach ($index->getColumns() as $columnName) {
|
||||
if (!$table->hasColumn($columnName)) {
|
||||
continue;
|
||||
}
|
||||
$column = $table->getColumn($columnName);
|
||||
if ($column->getAutoincrement() !== \true) {
|
||||
continue;
|
||||
}
|
||||
$column->setAutoincrement(\false);
|
||||
$sql[] = 'ALTER TABLE ' . $tableNameSQL . ' MODIFY ' . $this->getColumnDeclarationSQL($column->getQuotedName($this), $column->toArray());
|
||||
// original autoincrement information might be needed later on by other parts of the table alteration
|
||||
$column->setAutoincrement(\true);
|
||||
}
|
||||
return $sql;
|
||||
}
|
||||
private function getPreAlterTableAlterIndexForeignKeySQL(TableDiff $diff) : array
|
||||
{
|
||||
$table = $diff->getOldTable();
|
||||
if ($table === null) {
|
||||
return [];
|
||||
}
|
||||
$primaryKey = $table->getPrimaryKey();
|
||||
if ($primaryKey === null) {
|
||||
return [];
|
||||
}
|
||||
$primaryKeyColumns = [];
|
||||
foreach ($primaryKey->getColumns() as $columnName) {
|
||||
if (!$table->hasColumn($columnName)) {
|
||||
continue;
|
||||
}
|
||||
$primaryKeyColumns[] = $table->getColumn($columnName);
|
||||
}
|
||||
if (count($primaryKeyColumns) === 0) {
|
||||
return [];
|
||||
}
|
||||
$sql = [];
|
||||
$tableNameSQL = $table->getQuotedName($this);
|
||||
foreach ($diff->getModifiedIndexes() as $changedIndex) {
|
||||
// Changed primary key
|
||||
if (!$changedIndex->isPrimary()) {
|
||||
continue;
|
||||
}
|
||||
foreach ($primaryKeyColumns as $column) {
|
||||
// Check if an autoincrement column was dropped from the primary key.
|
||||
if (!$column->getAutoincrement() || in_array($column->getName(), $changedIndex->getColumns(), \true)) {
|
||||
continue;
|
||||
}
|
||||
// The autoincrement attribute needs to be removed from the dropped column
|
||||
// before we can drop and recreate the primary key.
|
||||
$column->setAutoincrement(\false);
|
||||
$sql[] = 'ALTER TABLE ' . $tableNameSQL . ' MODIFY ' . $this->getColumnDeclarationSQL($column->getQuotedName($this), $column->toArray());
|
||||
// Restore the autoincrement attribute as it might be needed later on
|
||||
// by other parts of the table alteration.
|
||||
$column->setAutoincrement(\true);
|
||||
}
|
||||
}
|
||||
return $sql;
|
||||
}
|
||||
protected function getPreAlterTableRenameIndexForeignKeySQL(TableDiff $diff)
|
||||
{
|
||||
$sql = [];
|
||||
$tableNameSQL = ($diff->getOldTable() ?? $diff->getName($this))->getQuotedName($this);
|
||||
foreach ($this->getRemainingForeignKeyConstraintsRequiringRenamedIndexes($diff) as $foreignKey) {
|
||||
if (in_array($foreignKey, $diff->getModifiedForeignKeys(), \true)) {
|
||||
continue;
|
||||
}
|
||||
$sql[] = $this->getDropForeignKeySQL($foreignKey->getQuotedName($this), $tableNameSQL);
|
||||
}
|
||||
return $sql;
|
||||
}
|
||||
private function getRemainingForeignKeyConstraintsRequiringRenamedIndexes(TableDiff $diff) : array
|
||||
{
|
||||
if (count($diff->getRenamedIndexes()) === 0) {
|
||||
return [];
|
||||
}
|
||||
$table = $diff->getOldTable();
|
||||
if ($table === null) {
|
||||
return [];
|
||||
}
|
||||
$foreignKeys = [];
|
||||
$remainingForeignKeys = array_diff_key($table->getForeignKeys(), $diff->getDroppedForeignKeys());
|
||||
foreach ($remainingForeignKeys as $foreignKey) {
|
||||
foreach ($diff->getRenamedIndexes() as $index) {
|
||||
if ($foreignKey->intersectsIndexColumns($index)) {
|
||||
$foreignKeys[] = $foreignKey;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $foreignKeys;
|
||||
}
|
||||
protected function getPostAlterTableIndexForeignKeySQL(TableDiff $diff)
|
||||
{
|
||||
return array_merge(parent::getPostAlterTableIndexForeignKeySQL($diff), $this->getPostAlterTableRenameIndexForeignKeySQL($diff));
|
||||
}
|
||||
protected function getPostAlterTableRenameIndexForeignKeySQL(TableDiff $diff)
|
||||
{
|
||||
$sql = [];
|
||||
$newName = $diff->getNewName();
|
||||
if ($newName !== \false) {
|
||||
$tableNameSQL = $newName->getQuotedName($this);
|
||||
} else {
|
||||
$tableNameSQL = ($diff->getOldTable() ?? $diff->getName($this))->getQuotedName($this);
|
||||
}
|
||||
foreach ($this->getRemainingForeignKeyConstraintsRequiringRenamedIndexes($diff) as $foreignKey) {
|
||||
if (in_array($foreignKey, $diff->getModifiedForeignKeys(), \true)) {
|
||||
continue;
|
||||
}
|
||||
$sql[] = $this->getCreateForeignKeySQL($foreignKey, $tableNameSQL);
|
||||
}
|
||||
return $sql;
|
||||
}
|
||||
protected function getCreateIndexSQLFlags(Index $index)
|
||||
{
|
||||
$type = '';
|
||||
if ($index->isUnique()) {
|
||||
$type .= 'UNIQUE ';
|
||||
} elseif ($index->hasFlag('fulltext')) {
|
||||
$type .= 'FULLTEXT ';
|
||||
} elseif ($index->hasFlag('spatial')) {
|
||||
$type .= 'SPATIAL ';
|
||||
}
|
||||
return $type;
|
||||
}
|
||||
public function getIntegerTypeDeclarationSQL(array $column)
|
||||
{
|
||||
return 'INT' . $this->_getCommonIntegerTypeDeclarationSQL($column);
|
||||
}
|
||||
public function getBigIntTypeDeclarationSQL(array $column)
|
||||
{
|
||||
return 'BIGINT' . $this->_getCommonIntegerTypeDeclarationSQL($column);
|
||||
}
|
||||
public function getSmallIntTypeDeclarationSQL(array $column)
|
||||
{
|
||||
return 'SMALLINT' . $this->_getCommonIntegerTypeDeclarationSQL($column);
|
||||
}
|
||||
public function getFloatDeclarationSQL(array $column)
|
||||
{
|
||||
return 'DOUBLE PRECISION' . $this->getUnsignedDeclaration($column);
|
||||
}
|
||||
public function getDecimalTypeDeclarationSQL(array $column)
|
||||
{
|
||||
return parent::getDecimalTypeDeclarationSQL($column) . $this->getUnsignedDeclaration($column);
|
||||
}
|
||||
private function getUnsignedDeclaration(array $columnDef) : string
|
||||
{
|
||||
return !empty($columnDef['unsigned']) ? ' UNSIGNED' : '';
|
||||
}
|
||||
protected function _getCommonIntegerTypeDeclarationSQL(array $column)
|
||||
{
|
||||
$autoinc = '';
|
||||
if (!empty($column['autoincrement'])) {
|
||||
$autoinc = ' AUTO_INCREMENT';
|
||||
}
|
||||
return $this->getUnsignedDeclaration($column) . $autoinc;
|
||||
}
|
||||
public function getColumnCharsetDeclarationSQL($charset)
|
||||
{
|
||||
return 'CHARACTER SET ' . $charset;
|
||||
}
|
||||
public function getAdvancedForeignKeyOptionsSQL(ForeignKeyConstraint $foreignKey)
|
||||
{
|
||||
$query = '';
|
||||
if ($foreignKey->hasOption('match')) {
|
||||
$query .= ' MATCH ' . $foreignKey->getOption('match');
|
||||
}
|
||||
$query .= parent::getAdvancedForeignKeyOptionsSQL($foreignKey);
|
||||
return $query;
|
||||
}
|
||||
public function getDropIndexSQL($index, $table = null)
|
||||
{
|
||||
if ($index instanceof Index) {
|
||||
Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/issues/4798', 'Passing $index as an Index object to %s is deprecated. Pass it as a quoted name instead.', __METHOD__);
|
||||
$indexName = $index->getQuotedName($this);
|
||||
} elseif (is_string($index)) {
|
||||
$indexName = $index;
|
||||
} else {
|
||||
throw new InvalidArgumentException(__METHOD__ . '() expects $index parameter to be string or ' . Index::class . '.');
|
||||
}
|
||||
if ($table instanceof Table) {
|
||||
Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/issues/4798', 'Passing $table as a Table object to %s is deprecated. Pass it as a quoted name instead.', __METHOD__);
|
||||
$table = $table->getQuotedName($this);
|
||||
} elseif (!is_string($table)) {
|
||||
throw new InvalidArgumentException(__METHOD__ . '() expects $table parameter to be string or ' . Table::class . '.');
|
||||
}
|
||||
if ($index instanceof Index && $index->isPrimary()) {
|
||||
// MySQL primary keys are always named "PRIMARY",
|
||||
// so we cannot use them in statements because of them being keyword.
|
||||
return $this->getDropPrimaryKeySQL($table);
|
||||
}
|
||||
return 'DROP INDEX ' . $indexName . ' ON ' . $table;
|
||||
}
|
||||
protected function getDropPrimaryKeySQL($table)
|
||||
{
|
||||
return 'ALTER TABLE ' . $table . ' DROP PRIMARY KEY';
|
||||
}
|
||||
public function getDropUniqueConstraintSQL(string $name, string $tableName) : string
|
||||
{
|
||||
return $this->getDropIndexSQL($name, $tableName);
|
||||
}
|
||||
public function getSetTransactionIsolationSQL($level)
|
||||
{
|
||||
return 'SET SESSION TRANSACTION ISOLATION LEVEL ' . $this->_getTransactionIsolationLevelSQL($level);
|
||||
}
|
||||
public function getName()
|
||||
{
|
||||
Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/issues/4749', 'AbstractMySQLPlatform::getName() is deprecated. Identify platforms by their class.');
|
||||
return 'mysql';
|
||||
}
|
||||
public function getReadLockSQL()
|
||||
{
|
||||
return 'LOCK IN SHARE MODE';
|
||||
}
|
||||
protected function initializeDoctrineTypeMappings()
|
||||
{
|
||||
$this->doctrineTypeMapping = ['bigint' => Types::BIGINT, 'binary' => Types::BINARY, 'blob' => Types::BLOB, 'char' => Types::STRING, 'date' => Types::DATE_MUTABLE, 'datetime' => Types::DATETIME_MUTABLE, 'decimal' => Types::DECIMAL, 'double' => Types::FLOAT, 'float' => Types::FLOAT, 'int' => Types::INTEGER, 'integer' => Types::INTEGER, 'longblob' => Types::BLOB, 'longtext' => Types::TEXT, 'mediumblob' => Types::BLOB, 'mediumint' => Types::INTEGER, 'mediumtext' => Types::TEXT, 'numeric' => Types::DECIMAL, 'real' => Types::FLOAT, 'set' => Types::SIMPLE_ARRAY, 'smallint' => Types::SMALLINT, 'string' => Types::STRING, 'text' => Types::TEXT, 'time' => Types::TIME_MUTABLE, 'timestamp' => Types::DATETIME_MUTABLE, 'tinyblob' => Types::BLOB, 'tinyint' => Types::BOOLEAN, 'tinytext' => Types::TEXT, 'varbinary' => Types::BINARY, 'varchar' => Types::STRING, 'year' => Types::DATE_MUTABLE];
|
||||
}
|
||||
public function getVarcharMaxLength()
|
||||
{
|
||||
Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/issues/3263', 'AbstractMySQLPlatform::getVarcharMaxLength() is deprecated.');
|
||||
return 65535;
|
||||
}
|
||||
public function getBinaryMaxLength()
|
||||
{
|
||||
Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/issues/3263', 'AbstractMySQLPlatform::getBinaryMaxLength() is deprecated.');
|
||||
return 65535;
|
||||
}
|
||||
protected function getReservedKeywordsClass()
|
||||
{
|
||||
Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/issues/4510', 'AbstractMySQLPlatform::getReservedKeywordsClass() is deprecated,' . ' use AbstractMySQLPlatform::createReservedKeywordsList() instead.');
|
||||
return Keywords\MySQLKeywords::class;
|
||||
}
|
||||
public function getDropTemporaryTableSQL($table)
|
||||
{
|
||||
if ($table instanceof Table) {
|
||||
Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/issues/4798', 'Passing $table as a Table object to %s is deprecated. Pass it as a quoted name instead.', __METHOD__);
|
||||
$table = $table->getQuotedName($this);
|
||||
} elseif (!is_string($table)) {
|
||||
throw new InvalidArgumentException(__METHOD__ . '() expects $table parameter to be string or ' . Table::class . '.');
|
||||
}
|
||||
return 'DROP TEMPORARY TABLE ' . $table;
|
||||
}
|
||||
public function getBlobTypeDeclarationSQL(array $column)
|
||||
{
|
||||
if (!empty($column['length']) && is_numeric($column['length'])) {
|
||||
$length = $column['length'];
|
||||
if ($length <= static::LENGTH_LIMIT_TINYBLOB) {
|
||||
return 'TINYBLOB';
|
||||
}
|
||||
if ($length <= static::LENGTH_LIMIT_BLOB) {
|
||||
return 'BLOB';
|
||||
}
|
||||
if ($length <= static::LENGTH_LIMIT_MEDIUMBLOB) {
|
||||
return 'MEDIUMBLOB';
|
||||
}
|
||||
}
|
||||
return 'LONGBLOB';
|
||||
}
|
||||
public function quoteStringLiteral($str)
|
||||
{
|
||||
$str = str_replace('\\', '\\\\', $str);
|
||||
// MySQL requires backslashes to be escaped
|
||||
return parent::quoteStringLiteral($str);
|
||||
}
|
||||
public function getDefaultTransactionIsolationLevel()
|
||||
{
|
||||
return TransactionIsolationLevel::REPEATABLE_READ;
|
||||
}
|
||||
public function supportsColumnLengthIndexes() : bool
|
||||
{
|
||||
return \true;
|
||||
}
|
||||
protected function getDatabaseNameSQL(?string $databaseName) : string
|
||||
{
|
||||
Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/6215', '%s is deprecated without replacement.', __METHOD__);
|
||||
if ($databaseName !== null) {
|
||||
return $this->quoteStringLiteral($databaseName);
|
||||
}
|
||||
return $this->getCurrentDatabaseExpression();
|
||||
}
|
||||
public function createSchemaManager(Connection $connection) : MySQLSchemaManager
|
||||
{
|
||||
return new MySQLSchemaManager($connection, $this);
|
||||
}
|
||||
private function indexAssetsByLowerCaseName(array $assets) : array
|
||||
{
|
||||
$result = [];
|
||||
foreach ($assets as $asset) {
|
||||
$result[strtolower($asset->getName())] = $asset;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
+1734
File diff suppressed because it is too large
Load Diff
+18
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
declare (strict_types=1);
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Platforms;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
final class DateIntervalUnit
|
||||
{
|
||||
public const SECOND = 'SECOND';
|
||||
public const MINUTE = 'MINUTE';
|
||||
public const HOUR = 'HOUR';
|
||||
public const DAY = 'DAY';
|
||||
public const WEEK = 'WEEK';
|
||||
public const MONTH = 'MONTH';
|
||||
public const QUARTER = 'QUARTER';
|
||||
public const YEAR = 'YEAR';
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Platforms\Keywords;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
use function array_flip;
|
||||
use function array_map;
|
||||
use function strtoupper;
|
||||
abstract class KeywordList
|
||||
{
|
||||
private ?array $keywords = null;
|
||||
public function isKeyword($word)
|
||||
{
|
||||
if ($this->keywords === null) {
|
||||
$this->initializeKeywords();
|
||||
}
|
||||
return isset($this->keywords[strtoupper($word)]);
|
||||
}
|
||||
protected function initializeKeywords()
|
||||
{
|
||||
$this->keywords = array_flip(array_map('strtoupper', $this->getKeywords()));
|
||||
}
|
||||
protected abstract function getKeywords();
|
||||
public abstract function getName();
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Platforms\Keywords;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
use MailPoetVendor\Doctrine\Deprecations\Deprecation;
|
||||
class MariaDBKeywords extends MySQLKeywords
|
||||
{
|
||||
public function getName() : string
|
||||
{
|
||||
Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5433', 'MariaDBKeywords::getName() is deprecated.');
|
||||
return 'MariaDB';
|
||||
}
|
||||
protected function getKeywords() : array
|
||||
{
|
||||
return ['ACCESSIBLE', 'ADD', 'ALL', 'ALTER', 'ANALYZE', 'AND', 'AS', 'ASC', 'ASENSITIVE', 'BEFORE', 'BETWEEN', 'BIGINT', 'BINARY', 'BLOB', 'BOTH', 'BY', 'CALL', 'CASCADE', 'CASE', 'CHANGE', 'CHAR', 'CHARACTER', 'CHECK', 'COLLATE', 'COLUMN', 'CONDITION', 'CONSTRAINT', 'CONTINUE', 'CONVERT', 'CREATE', 'CROSS', 'CURRENT_DATE', 'CURRENT_TIME', 'CURRENT_TIMESTAMP', 'CURRENT_USER', 'CURSOR', 'DATABASE', 'DATABASES', 'DAY_HOUR', 'DAY_MICROSECOND', 'DAY_MINUTE', 'DAY_SECOND', 'DEC', 'DECIMAL', 'DECLARE', 'DEFAULT', 'DELAYED', 'DELETE', 'DESC', 'DESCRIBE', 'DETERMINISTIC', 'DISTINCT', 'DISTINCTROW', 'DIV', 'DOUBLE', 'DROP', 'DUAL', 'EACH', 'ELSE', 'ELSEIF', 'ENCLOSED', 'ESCAPED', 'EXCEPT', 'EXISTS', 'EXIT', 'EXPLAIN', 'FALSE', 'FETCH', 'FLOAT', 'FLOAT4', 'FLOAT8', 'FOR', 'FORCE', 'FOREIGN', 'FROM', 'FULLTEXT', 'GENERATED', 'GET', 'GENERAL', 'GRANT', 'GROUP', 'HAVING', 'HIGH_PRIORITY', 'HOUR_MICROSECOND', 'HOUR_MINUTE', 'HOUR_SECOND', 'IF', 'IGNORE', 'IGNORE_SERVER_IDS', 'IN', 'INDEX', 'INFILE', 'INNER', 'INOUT', 'INSENSITIVE', 'INSERT', 'INT', 'INT1', 'INT2', 'INT3', 'INT4', 'INT8', 'INTEGER', 'INTERSECT', 'INTERVAL', 'INTO', 'IO_AFTER_GTIDS', 'IO_BEFORE_GTIDS', 'IS', 'ITERATE', 'JOIN', 'KEY', 'KEYS', 'KILL', 'LEADING', 'LEAVE', 'LEFT', 'LIKE', 'LIMIT', 'LINEAR', 'LINES', 'LOAD', 'LOCALTIME', 'LOCALTIMESTAMP', 'LOCK', 'LONG', 'LONGBLOB', 'LONGTEXT', 'LOOP', 'LOW_PRIORITY', 'MASTER_BIND', 'MASTER_HEARTBEAT_PERIOD', 'MASTER_SSL_VERIFY_SERVER_CERT', 'MATCH', 'MAXVALUE', 'MEDIUMBLOB', 'MEDIUMINT', 'MEDIUMTEXT', 'MIDDLEINT', 'MINUTE_MICROSECOND', 'MINUTE_SECOND', 'MOD', 'MODIFIES', 'NATURAL', 'NO_WRITE_TO_BINLOG', 'NOT', 'NULL', 'NUMERIC', 'OFFSET', 'ON', 'OPTIMIZE', 'OPTIMIZER_COSTS', 'OPTION', 'OPTIONALLY', 'OR', 'ORDER', 'OUT', 'OUTER', 'OUTFILE', 'OVER', 'PARTITION', 'PRECISION', 'PRIMARY', 'PROCEDURE', 'PURGE', 'RANGE', 'READ', 'READ_WRITE', 'READS', 'REAL', 'RECURSIVE', 'REFERENCES', 'REGEXP', 'RELEASE', 'RENAME', 'REPEAT', 'REPLACE', 'REQUIRE', 'RESIGNAL', 'RESTRICT', 'RETURN', 'RETURNING', 'REVOKE', 'RIGHT', 'RLIKE', 'ROWS', 'SCHEMA', 'SCHEMAS', 'SECOND_MICROSECOND', 'SELECT', 'SENSITIVE', 'SEPARATOR', 'SET', 'SHOW', 'SIGNAL', 'SLOW', 'SMALLINT', 'SPATIAL', 'SPECIFIC', 'SQL', 'SQL_BIG_RESULT', 'SQL_CALC_FOUND_ROWS', 'SQL_SMALL_RESULT', 'SQLEXCEPTION', 'SQLSTATE', 'SQLWARNING', 'SSL', 'STARTING', 'STORED', 'STRAIGHT_JOIN', 'TABLE', 'TERMINATED', 'THEN', 'TINYBLOB', 'TINYINT', 'TINYTEXT', 'TO', 'TRAILING', 'TRIGGER', 'TRUE', 'UNDO', 'UNION', 'UNIQUE', 'UNLOCK', 'UNSIGNED', 'UPDATE', 'USAGE', 'USE', 'USING', 'UTC_DATE', 'UTC_TIME', 'UTC_TIMESTAMP', 'VALUES', 'VARBINARY', 'VARCHAR', 'VARCHARACTER', 'VARYING', 'VIRTUAL', 'WHEN', 'WHERE', 'WHILE', 'WINDOW', 'WITH', 'WRITE', 'XOR', 'YEAR_MONTH', 'ZEROFILL'];
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Platforms\Keywords;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
use MailPoetVendor\Doctrine\Deprecations\Deprecation;
|
||||
final class MariaDb102Keywords extends MariaDBKeywords
|
||||
{
|
||||
public function getName() : string
|
||||
{
|
||||
Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5433', 'MariaDb102Keywords::getName() is deprecated.');
|
||||
return 'MariaDb102';
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Platforms\Keywords;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
use MailPoetVendor\Doctrine\Deprecations\Deprecation;
|
||||
class MySQL57Keywords extends MySQLKeywords
|
||||
{
|
||||
public function getName()
|
||||
{
|
||||
Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5433', 'MySQL57Keywords::getName() is deprecated.');
|
||||
return 'MySQL57';
|
||||
}
|
||||
protected function getKeywords()
|
||||
{
|
||||
return ['ACCESSIBLE', 'ADD', 'ALL', 'ALTER', 'ANALYZE', 'AND', 'AS', 'ASC', 'ASENSITIVE', 'BEFORE', 'BETWEEN', 'BIGINT', 'BINARY', 'BLOB', 'BOTH', 'BY', 'CALL', 'CASCADE', 'CASE', 'CHANGE', 'CHAR', 'CHARACTER', 'CHECK', 'COLLATE', 'COLUMN', 'CONDITION', 'CONSTRAINT', 'CONTINUE', 'CONVERT', 'CREATE', 'CROSS', 'CURRENT_DATE', 'CURRENT_TIME', 'CURRENT_TIMESTAMP', 'CURRENT_USER', 'CURSOR', 'DATABASE', 'DATABASES', 'DAY_HOUR', 'DAY_MICROSECOND', 'DAY_MINUTE', 'DAY_SECOND', 'DEC', 'DECIMAL', 'DECLARE', 'DEFAULT', 'DELAYED', 'DELETE', 'DESC', 'DESCRIBE', 'DETERMINISTIC', 'DISTINCT', 'DISTINCTROW', 'DIV', 'DOUBLE', 'DROP', 'DUAL', 'EACH', 'ELSE', 'ELSEIF', 'ENCLOSED', 'ESCAPED', 'EXISTS', 'EXIT', 'EXPLAIN', 'FALSE', 'FETCH', 'FLOAT', 'FLOAT4', 'FLOAT8', 'FOR', 'FORCE', 'FOREIGN', 'FROM', 'FULLTEXT', 'GENERATED', 'GET', 'GRANT', 'GROUP', 'HAVING', 'HIGH_PRIORITY', 'HOUR_MICROSECOND', 'HOUR_MINUTE', 'HOUR_SECOND', 'IF', 'IGNORE', 'IN', 'INDEX', 'INFILE', 'INNER', 'INOUT', 'INSENSITIVE', 'INSERT', 'INT', 'INT1', 'INT2', 'INT3', 'INT4', 'INT8', 'INTEGER', 'INTERVAL', 'INTO', 'IO_AFTER_GTIDS', 'IO_BEFORE_GTIDS', 'IS', 'ITERATE', 'JOIN', 'KEY', 'KEYS', 'KILL', 'LEADING', 'LEAVE', 'LEFT', 'LIKE', 'LIMIT', 'LINEAR', 'LINES', 'LOAD', 'LOCALTIME', 'LOCALTIMESTAMP', 'LOCK', 'LONG', 'LONGBLOB', 'LONGTEXT', 'LOOP', 'LOW_PRIORITY', 'MASTER_BIND', 'MASTER_SSL_VERIFY_SERVER_CERT', 'MATCH', 'MAXVALUE', 'MEDIUMBLOB', 'MEDIUMINT', 'MEDIUMTEXT', 'MIDDLEINT', 'MINUTE_MICROSECOND', 'MINUTE_SECOND', 'MOD', 'MODIFIES', 'NATURAL', 'NO_WRITE_TO_BINLOG', 'NOT', 'NULL', 'NUMERIC', 'ON', 'OPTIMIZE', 'OPTIMIZER_COSTS', 'OPTION', 'OPTIONALLY', 'OR', 'ORDER', 'OUT', 'OUTER', 'OUTFILE', 'PARTITION', 'PRECISION', 'PRIMARY', 'PROCEDURE', 'PURGE', 'RANGE', 'READ', 'READ_WRITE', 'READS', 'REAL', 'REFERENCES', 'REGEXP', 'RELEASE', 'RENAME', 'REPEAT', 'REPLACE', 'REQUIRE', 'RESIGNAL', 'RESTRICT', 'RETURN', 'REVOKE', 'RIGHT', 'RLIKE', 'SCHEMA', 'SCHEMAS', 'SECOND_MICROSECOND', 'SELECT', 'SENSITIVE', 'SEPARATOR', 'SET', 'SHOW', 'SIGNAL', 'SMALLINT', 'SPATIAL', 'SPECIFIC', 'SQL', 'SQL_BIG_RESULT', 'SQL_CALC_FOUND_ROWS', 'SQL_SMALL_RESULT', 'SQLEXCEPTION', 'SQLSTATE', 'SQLWARNING', 'SSL', 'STARTING', 'STORED', 'STRAIGHT_JOIN', 'TABLE', 'TERMINATED', 'THEN', 'TINYBLOB', 'TINYINT', 'TINYTEXT', 'TO', 'TRAILING', 'TRIGGER', 'TRUE', 'UNDO', 'UNION', 'UNIQUE', 'UNLOCK', 'UNSIGNED', 'UPDATE', 'USAGE', 'USE', 'USING', 'UTC_DATE', 'UTC_TIME', 'UTC_TIMESTAMP', 'VALUES', 'VARBINARY', 'VARCHAR', 'VARCHARACTER', 'VARYING', 'VIRTUAL', 'WHEN', 'WHERE', 'WHILE', 'WITH', 'WRITE', 'XOR', 'YEAR_MONTH', 'ZEROFILL'];
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Platforms\Keywords;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
use MailPoetVendor\Doctrine\Deprecations\Deprecation;
|
||||
use function array_merge;
|
||||
class MySQL80Keywords extends MySQL57Keywords
|
||||
{
|
||||
public function getName()
|
||||
{
|
||||
Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5433', 'MySQL80Keywords::getName() is deprecated.');
|
||||
return 'MySQL80';
|
||||
}
|
||||
protected function getKeywords()
|
||||
{
|
||||
$keywords = parent::getKeywords();
|
||||
$keywords = array_merge($keywords, ['ADMIN', 'ARRAY', 'CUBE', 'CUME_DIST', 'DENSE_RANK', 'EMPTY', 'EXCEPT', 'FIRST_VALUE', 'FUNCTION', 'GROUPING', 'GROUPS', 'JSON_TABLE', 'LAG', 'LAST_VALUE', 'LATERAL', 'LEAD', 'MEMBER', 'NTH_VALUE', 'NTILE', 'OF', 'OVER', 'PERCENT_RANK', 'PERSIST', 'PERSIST_ONLY', 'RANK', 'RECURSIVE', 'ROW', 'ROWS', 'ROW_NUMBER', 'SYSTEM', 'WINDOW']);
|
||||
return $keywords;
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Platforms\Keywords;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
use MailPoetVendor\Doctrine\Deprecations\Deprecation;
|
||||
class MySQLKeywords extends KeywordList
|
||||
{
|
||||
public function getName()
|
||||
{
|
||||
Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5433', 'MySQLKeywords::getName() is deprecated.');
|
||||
return 'MySQL';
|
||||
}
|
||||
protected function getKeywords()
|
||||
{
|
||||
return ['ACCESSIBLE', 'ADD', 'ALL', 'ALTER', 'ANALYZE', 'AND', 'AS', 'ASC', 'ASENSITIVE', 'BEFORE', 'BETWEEN', 'BIGINT', 'BINARY', 'BLOB', 'BOTH', 'BY', 'CALL', 'CASCADE', 'CASE', 'CHANGE', 'CHAR', 'CHARACTER', 'CHECK', 'COLLATE', 'COLUMN', 'CONDITION', 'CONNECTION', 'CONSTRAINT', 'CONTINUE', 'CONVERT', 'CREATE', 'CROSS', 'CURRENT_DATE', 'CURRENT_TIME', 'CURRENT_TIMESTAMP', 'CURRENT_USER', 'CURSOR', 'DATABASE', 'DATABASES', 'DAY_HOUR', 'DAY_MICROSECOND', 'DAY_MINUTE', 'DAY_SECOND', 'DEC', 'DECIMAL', 'DECLARE', 'DEFAULT', 'DELAYED', 'DELETE', 'DESC', 'DESCRIBE', 'DETERMINISTIC', 'DISTINCT', 'DISTINCTROW', 'DIV', 'DOUBLE', 'DROP', 'DUAL', 'EACH', 'ELSE', 'ELSEIF', 'ENCLOSED', 'ESCAPED', 'EXISTS', 'EXIT', 'EXPLAIN', 'FALSE', 'FETCH', 'FLOAT', 'FLOAT4', 'FLOAT8', 'FOR', 'FORCE', 'FOREIGN', 'FROM', 'FULLTEXT', 'GENERAL', 'GOTO', 'GRANT', 'GROUP', 'HAVING', 'HIGH_PRIORITY', 'HOUR_MICROSECOND', 'HOUR_MINUTE', 'HOUR_SECOND', 'IF', 'IGNORE', 'IGNORE_SERVER_IDS', 'IN', 'INDEX', 'INFILE', 'INNER', 'INOUT', 'INSENSITIVE', 'INSERT', 'INT', 'INT1', 'INT2', 'INT3', 'INT4', 'INT8', 'INTEGER', 'INTERVAL', 'INTO', 'IS', 'ITERATE', 'JOIN', 'KEY', 'KEYS', 'KILL', 'LABEL', 'LEADING', 'LEAVE', 'LEFT', 'LIKE', 'LIMIT', 'LINEAR', 'LINES', 'LOAD', 'LOCALTIME', 'LOCALTIMESTAMP', 'LOCK', 'LONG', 'LONGBLOB', 'LONGTEXT', 'LOOP', 'LOW_PRIORITY', 'MASTER_HEARTBEAT_PERIOD', 'MASTER_SSL_VERIFY_SERVER_CERT', 'MATCH', 'MAXVALUE', 'MEDIUMBLOB', 'MEDIUMINT', 'MEDIUMTEXT', 'MIDDLEINT', 'MINUTE_MICROSECOND', 'MINUTE_SECOND', 'MOD', 'MODIFIES', 'NATURAL', 'NO_WRITE_TO_BINLOG', 'NOT', 'NULL', 'NUMERIC', 'ON', 'OPTIMIZE', 'OPTION', 'OPTIONALLY', 'OR', 'ORDER', 'OUT', 'OUTER', 'OUTFILE', 'PARTITION', 'PRECISION', 'PRIMARY', 'PROCEDURE', 'PURGE', 'RAID0', 'RANGE', 'READ', 'READ_WRITE', 'READS', 'REAL', 'RECURSIVE', 'REFERENCES', 'REGEXP', 'RELEASE', 'RENAME', 'REPEAT', 'REPLACE', 'REQUIRE', 'RESIGNAL', 'RESTRICT', 'RETURN', 'REVOKE', 'RIGHT', 'RLIKE', 'ROWS', 'SCHEMA', 'SCHEMAS', 'SECOND_MICROSECOND', 'SELECT', 'SENSITIVE', 'SEPARATOR', 'SET', 'SHOW', 'SIGNAL', 'SLOW', 'SMALLINT', 'SONAME', 'SPATIAL', 'SPECIFIC', 'SQL', 'SQL_BIG_RESULT', 'SQL_CALC_FOUND_ROWS', 'SQL_SMALL_RESULT', 'SQLEXCEPTION', 'SQLSTATE', 'SQLWARNING', 'SSL', 'STARTING', 'STRAIGHT_JOIN', 'TABLE', 'TERMINATED', 'THEN', 'TINYBLOB', 'TINYINT', 'TINYTEXT', 'TO', 'TRAILING', 'TRIGGER', 'TRUE', 'UNDO', 'UNION', 'UNIQUE', 'UNLOCK', 'UNSIGNED', 'UPDATE', 'USAGE', 'USE', 'USING', 'UTC_DATE', 'UTC_TIME', 'UTC_TIMESTAMP', 'VALUES', 'VARBINARY', 'VARCHAR', 'VARCHARACTER', 'VARYING', 'WHEN', 'WHERE', 'WHILE', 'WITH', 'WRITE', 'X509', 'XOR', 'YEAR_MONTH', 'ZEROFILL'];
|
||||
}
|
||||
}
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\DBAL\Platforms\Keywords;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
use MailPoetVendor\Doctrine\DBAL\Schema\Column;
|
||||
use MailPoetVendor\Doctrine\DBAL\Schema\ForeignKeyConstraint;
|
||||
use MailPoetVendor\Doctrine\DBAL\Schema\Index;
|
||||
use MailPoetVendor\Doctrine\DBAL\Schema\Schema;
|
||||
use MailPoetVendor\Doctrine\DBAL\Schema\Sequence;
|
||||
use MailPoetVendor\Doctrine\DBAL\Schema\Table;
|
||||
use MailPoetVendor\Doctrine\DBAL\Schema\Visitor\Visitor;
|
||||
use MailPoetVendor\Doctrine\Deprecations\Deprecation;
|
||||
use function count;
|
||||
use function implode;
|
||||
use function str_replace;
|
||||
class ReservedKeywordsValidator implements Visitor
|
||||
{
|
||||
private array $keywordLists;
|
||||
private array $violations = [];
|
||||
public function __construct(array $keywordLists)
|
||||
{
|
||||
Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5431', 'ReservedKeywordsValidator is deprecated. Use database documentation instead.');
|
||||
$this->keywordLists = $keywordLists;
|
||||
}
|
||||
public function getViolations()
|
||||
{
|
||||
return $this->violations;
|
||||
}
|
||||
private function isReservedWord($word) : array
|
||||
{
|
||||
if ($word[0] === '`') {
|
||||
$word = str_replace('`', '', $word);
|
||||
}
|
||||
$keywordLists = [];
|
||||
foreach ($this->keywordLists as $keywordList) {
|
||||
if (!$keywordList->isKeyword($word)) {
|
||||
continue;
|
||||
}
|
||||
$keywordLists[] = $keywordList->getName();
|
||||
}
|
||||
return $keywordLists;
|
||||
}
|
||||
private function addViolation($asset, $violatedPlatforms) : void
|
||||
{
|
||||
if (count($violatedPlatforms) === 0) {
|
||||
return;
|
||||
}
|
||||
$this->violations[] = $asset . ' keyword violations: ' . implode(', ', $violatedPlatforms);
|
||||
}
|
||||
public function acceptColumn(Table $table, Column $column)
|
||||
{
|
||||
$this->addViolation('Table ' . $table->getName() . ' column ' . $column->getName(), $this->isReservedWord($column->getName()));
|
||||
}
|
||||
public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint)
|
||||
{
|
||||
}
|
||||
public function acceptIndex(Table $table, Index $index)
|
||||
{
|
||||
}
|
||||
public function acceptSchema(Schema $schema)
|
||||
{
|
||||
}
|
||||
public function acceptSequence(Sequence $sequence)
|
||||
{
|
||||
}
|
||||
public function acceptTable(Table $table)
|
||||
{
|
||||
$this->addViolation('Table ' . $table->getName(), $this->isReservedWord($table->getName()));
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user