Keywords
9 months ago
MySQL
2 years ago
AbstractMySQLPlatform.php
9 months ago
AbstractPlatform.php
9 months ago
DateIntervalUnit.php
2 years ago
MariaDBPlatform.php
2 years ago
MariaDb1010Platform.php
9 months ago
MariaDb1027Platform.php
2 years ago
MariaDb1043Platform.php
2 years ago
MariaDb1052Platform.php
2 years ago
MariaDb1060Platform.php
2 years ago
MariaDb110700Platform.php
9 months ago
MySQL57Platform.php
2 years ago
MySQL80Platform.php
2 years ago
MySQL84Platform.php
9 months ago
MySQLPlatform.php
2 years ago
PostgreSQL120Platform.php
9 months ago
TrimMode.php
2 years ago
index.php
2 years ago
AbstractPlatform.php
1739 lines
| 1 | <?php |
| 2 | namespace MailPoetVendor\Doctrine\DBAL\Platforms; |
| 3 | if (!defined('ABSPATH')) exit; |
| 4 | use MailPoetVendor\Doctrine\Common\EventManager; |
| 5 | use MailPoetVendor\Doctrine\DBAL\Connection; |
| 6 | use MailPoetVendor\Doctrine\DBAL\Event\SchemaAlterTableAddColumnEventArgs; |
| 7 | use MailPoetVendor\Doctrine\DBAL\Event\SchemaAlterTableChangeColumnEventArgs; |
| 8 | use MailPoetVendor\Doctrine\DBAL\Event\SchemaAlterTableEventArgs; |
| 9 | use MailPoetVendor\Doctrine\DBAL\Event\SchemaAlterTableRemoveColumnEventArgs; |
| 10 | use MailPoetVendor\Doctrine\DBAL\Event\SchemaAlterTableRenameColumnEventArgs; |
| 11 | use MailPoetVendor\Doctrine\DBAL\Event\SchemaCreateTableColumnEventArgs; |
| 12 | use MailPoetVendor\Doctrine\DBAL\Event\SchemaCreateTableEventArgs; |
| 13 | use MailPoetVendor\Doctrine\DBAL\Event\SchemaDropTableEventArgs; |
| 14 | use MailPoetVendor\Doctrine\DBAL\Events; |
| 15 | use MailPoetVendor\Doctrine\DBAL\Exception; |
| 16 | use MailPoetVendor\Doctrine\DBAL\Exception\InvalidLockMode; |
| 17 | use MailPoetVendor\Doctrine\DBAL\LockMode; |
| 18 | use MailPoetVendor\Doctrine\DBAL\Platforms\Keywords\KeywordList; |
| 19 | use MailPoetVendor\Doctrine\DBAL\Schema\AbstractSchemaManager; |
| 20 | use MailPoetVendor\Doctrine\DBAL\Schema\Column; |
| 21 | use MailPoetVendor\Doctrine\DBAL\Schema\ColumnDiff; |
| 22 | use MailPoetVendor\Doctrine\DBAL\Schema\Constraint; |
| 23 | use MailPoetVendor\Doctrine\DBAL\Schema\ForeignKeyConstraint; |
| 24 | use MailPoetVendor\Doctrine\DBAL\Schema\Identifier; |
| 25 | use MailPoetVendor\Doctrine\DBAL\Schema\Index; |
| 26 | use MailPoetVendor\Doctrine\DBAL\Schema\SchemaDiff; |
| 27 | use MailPoetVendor\Doctrine\DBAL\Schema\Sequence; |
| 28 | use MailPoetVendor\Doctrine\DBAL\Schema\Table; |
| 29 | use MailPoetVendor\Doctrine\DBAL\Schema\TableDiff; |
| 30 | use MailPoetVendor\Doctrine\DBAL\Schema\UniqueConstraint; |
| 31 | use MailPoetVendor\Doctrine\DBAL\SQL\Builder\DefaultSelectSQLBuilder; |
| 32 | use MailPoetVendor\Doctrine\DBAL\SQL\Builder\SelectSQLBuilder; |
| 33 | use MailPoetVendor\Doctrine\DBAL\SQL\Parser; |
| 34 | use MailPoetVendor\Doctrine\DBAL\TransactionIsolationLevel; |
| 35 | use MailPoetVendor\Doctrine\DBAL\Types; |
| 36 | use MailPoetVendor\Doctrine\DBAL\Types\Type; |
| 37 | use MailPoetVendor\Doctrine\Deprecations\Deprecation; |
| 38 | use InvalidArgumentException; |
| 39 | use UnexpectedValueException; |
| 40 | use function addcslashes; |
| 41 | use function array_map; |
| 42 | use function array_merge; |
| 43 | use function array_unique; |
| 44 | use function array_values; |
| 45 | use function assert; |
| 46 | use function count; |
| 47 | use function explode; |
| 48 | use function func_get_arg; |
| 49 | use function func_get_args; |
| 50 | use function func_num_args; |
| 51 | use function implode; |
| 52 | use function in_array; |
| 53 | use function is_array; |
| 54 | use function is_bool; |
| 55 | use function is_int; |
| 56 | use function is_string; |
| 57 | use function preg_quote; |
| 58 | use function preg_replace; |
| 59 | use function sprintf; |
| 60 | use function str_replace; |
| 61 | use function strlen; |
| 62 | use function strpos; |
| 63 | use function strtolower; |
| 64 | use function strtoupper; |
| 65 | abstract class AbstractPlatform |
| 66 | { |
| 67 | public const CREATE_INDEXES = 1; |
| 68 | public const CREATE_FOREIGNKEYS = 2; |
| 69 | protected $doctrineTypeMapping; |
| 70 | protected $doctrineTypeComments; |
| 71 | protected $_eventManager; |
| 72 | protected $_keywords; |
| 73 | private bool $disableTypeComments = \false; |
| 74 | public final function setDisableTypeComments(bool $value) : void |
| 75 | { |
| 76 | $this->disableTypeComments = $value; |
| 77 | } |
| 78 | public function setEventManager(EventManager $eventManager) |
| 79 | { |
| 80 | Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/issues/5784', '%s is deprecated.', __METHOD__); |
| 81 | $this->_eventManager = $eventManager; |
| 82 | } |
| 83 | public function getEventManager() |
| 84 | { |
| 85 | Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/issues/5784', '%s is deprecated.', __METHOD__); |
| 86 | return $this->_eventManager; |
| 87 | } |
| 88 | public abstract function getBooleanTypeDeclarationSQL(array $column); |
| 89 | public abstract function getIntegerTypeDeclarationSQL(array $column); |
| 90 | public abstract function getBigIntTypeDeclarationSQL(array $column); |
| 91 | public abstract function getSmallIntTypeDeclarationSQL(array $column); |
| 92 | protected abstract function _getCommonIntegerTypeDeclarationSQL(array $column); |
| 93 | protected abstract function initializeDoctrineTypeMappings(); |
| 94 | private function initializeAllDoctrineTypeMappings() : void |
| 95 | { |
| 96 | $this->initializeDoctrineTypeMappings(); |
| 97 | foreach (Type::getTypesMap() as $typeName => $className) { |
| 98 | foreach (Type::getType($typeName)->getMappedDatabaseTypes($this) as $dbType) { |
| 99 | $dbType = strtolower($dbType); |
| 100 | $this->doctrineTypeMapping[$dbType] = $typeName; |
| 101 | } |
| 102 | } |
| 103 | } |
| 104 | public function getAsciiStringTypeDeclarationSQL(array $column) : string |
| 105 | { |
| 106 | return $this->getStringTypeDeclarationSQL($column); |
| 107 | } |
| 108 | public function getVarcharTypeDeclarationSQL(array $column) |
| 109 | { |
| 110 | if (isset($column['length'])) { |
| 111 | $lengthOmitted = \false; |
| 112 | } else { |
| 113 | $column['length'] = $this->getVarcharDefaultLength(); |
| 114 | $lengthOmitted = \true; |
| 115 | } |
| 116 | $fixed = $column['fixed'] ?? \false; |
| 117 | $maxLength = $fixed ? $this->getCharMaxLength() : $this->getVarcharMaxLength(); |
| 118 | if ($column['length'] > $maxLength) { |
| 119 | return $this->getClobTypeDeclarationSQL($column); |
| 120 | } |
| 121 | return $this->getVarcharTypeDeclarationSQLSnippet($column['length'], $fixed, $lengthOmitted); |
| 122 | } |
| 123 | public function getStringTypeDeclarationSQL(array $column) |
| 124 | { |
| 125 | return $this->getVarcharTypeDeclarationSQL($column); |
| 126 | } |
| 127 | public function getBinaryTypeDeclarationSQL(array $column) |
| 128 | { |
| 129 | if (isset($column['length'])) { |
| 130 | $lengthOmitted = \false; |
| 131 | } else { |
| 132 | $column['length'] = $this->getBinaryDefaultLength(); |
| 133 | $lengthOmitted = \true; |
| 134 | } |
| 135 | $fixed = $column['fixed'] ?? \false; |
| 136 | $maxLength = $this->getBinaryMaxLength(); |
| 137 | if ($column['length'] > $maxLength) { |
| 138 | if ($maxLength > 0) { |
| 139 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/issues/3187', 'Binary column length %d is greater than supported by the platform (%d).' . ' Reduce the column length or use a BLOB column instead.', $column['length'], $maxLength); |
| 140 | } |
| 141 | return $this->getBlobTypeDeclarationSQL($column); |
| 142 | } |
| 143 | return $this->getBinaryTypeDeclarationSQLSnippet($column['length'], $fixed, $lengthOmitted); |
| 144 | } |
| 145 | public function getGuidTypeDeclarationSQL(array $column) |
| 146 | { |
| 147 | $column['length'] = 36; |
| 148 | $column['fixed'] = \true; |
| 149 | return $this->getStringTypeDeclarationSQL($column); |
| 150 | } |
| 151 | public function getJsonTypeDeclarationSQL(array $column) |
| 152 | { |
| 153 | return $this->getClobTypeDeclarationSQL($column); |
| 154 | } |
| 155 | protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed) |
| 156 | { |
| 157 | throw Exception::notSupported('VARCHARs not supported by Platform.'); |
| 158 | } |
| 159 | protected function getBinaryTypeDeclarationSQLSnippet($length, $fixed) |
| 160 | { |
| 161 | throw Exception::notSupported('BINARY/VARBINARY column types are not supported by this platform.'); |
| 162 | } |
| 163 | public abstract function getClobTypeDeclarationSQL(array $column); |
| 164 | public abstract function getBlobTypeDeclarationSQL(array $column); |
| 165 | public abstract function getName(); |
| 166 | public function registerDoctrineTypeMapping($dbType, $doctrineType) |
| 167 | { |
| 168 | if ($this->doctrineTypeMapping === null) { |
| 169 | $this->initializeAllDoctrineTypeMappings(); |
| 170 | } |
| 171 | if (!Types\Type::hasType($doctrineType)) { |
| 172 | throw Exception::typeNotFound($doctrineType); |
| 173 | } |
| 174 | $dbType = strtolower($dbType); |
| 175 | $this->doctrineTypeMapping[$dbType] = $doctrineType; |
| 176 | $doctrineType = Type::getType($doctrineType); |
| 177 | if (!$doctrineType->requiresSQLCommentHint($this)) { |
| 178 | return; |
| 179 | } |
| 180 | $this->markDoctrineTypeCommented($doctrineType); |
| 181 | } |
| 182 | public function getDoctrineTypeMapping($dbType) |
| 183 | { |
| 184 | if ($this->doctrineTypeMapping === null) { |
| 185 | $this->initializeAllDoctrineTypeMappings(); |
| 186 | } |
| 187 | $dbType = strtolower($dbType); |
| 188 | if (!isset($this->doctrineTypeMapping[$dbType])) { |
| 189 | throw new Exception('Unknown database type ' . $dbType . ' requested, ' . static::class . ' may not support it.'); |
| 190 | } |
| 191 | return $this->doctrineTypeMapping[$dbType]; |
| 192 | } |
| 193 | public function hasDoctrineTypeMappingFor($dbType) |
| 194 | { |
| 195 | if ($this->doctrineTypeMapping === null) { |
| 196 | $this->initializeAllDoctrineTypeMappings(); |
| 197 | } |
| 198 | $dbType = strtolower($dbType); |
| 199 | return isset($this->doctrineTypeMapping[$dbType]); |
| 200 | } |
| 201 | protected function initializeCommentedDoctrineTypes() |
| 202 | { |
| 203 | Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5058', '%s is deprecated and will be removed in Doctrine DBAL 4.0.', __METHOD__); |
| 204 | $this->doctrineTypeComments = []; |
| 205 | foreach (Type::getTypesMap() as $typeName => $className) { |
| 206 | $type = Type::getType($typeName); |
| 207 | if (!$type->requiresSQLCommentHint($this)) { |
| 208 | continue; |
| 209 | } |
| 210 | $this->doctrineTypeComments[] = $typeName; |
| 211 | } |
| 212 | } |
| 213 | public function isCommentedDoctrineType(Type $doctrineType) |
| 214 | { |
| 215 | Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5058', '%s is deprecated and will be removed in Doctrine DBAL 4.0. Use Type::requiresSQLCommentHint() instead.', __METHOD__); |
| 216 | if ($this->doctrineTypeComments === null) { |
| 217 | $this->initializeCommentedDoctrineTypes(); |
| 218 | } |
| 219 | return $doctrineType->requiresSQLCommentHint($this); |
| 220 | } |
| 221 | public function markDoctrineTypeCommented($doctrineType) |
| 222 | { |
| 223 | Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5058', '%s is deprecated and will be removed in Doctrine DBAL 4.0. Use Type::requiresSQLCommentHint() instead.', __METHOD__); |
| 224 | if ($this->doctrineTypeComments === null) { |
| 225 | $this->initializeCommentedDoctrineTypes(); |
| 226 | } |
| 227 | assert(is_array($this->doctrineTypeComments)); |
| 228 | $this->doctrineTypeComments[] = $doctrineType instanceof Type ? $doctrineType->getName() : $doctrineType; |
| 229 | } |
| 230 | public function getDoctrineTypeComment(Type $doctrineType) |
| 231 | { |
| 232 | Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5107', '%s is deprecated and will be removed in Doctrine DBAL 4.0.', __METHOD__); |
| 233 | return '(DC2Type:' . $doctrineType->getName() . ')'; |
| 234 | } |
| 235 | protected function getColumnComment(Column $column) |
| 236 | { |
| 237 | Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5107', '%s is deprecated and will be removed in Doctrine DBAL 4.0.', __METHOD__); |
| 238 | $comment = $column->getComment(); |
| 239 | if (!$this->disableTypeComments && $column->getType()->requiresSQLCommentHint($this)) { |
| 240 | $comment .= $this->getDoctrineTypeComment($column->getType()); |
| 241 | } |
| 242 | return $comment; |
| 243 | } |
| 244 | public function getIdentifierQuoteCharacter() |
| 245 | { |
| 246 | Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5388', 'AbstractPlatform::getIdentifierQuoteCharacter() is deprecated. Use quoteIdentifier() instead.'); |
| 247 | return '"'; |
| 248 | } |
| 249 | public function getSqlCommentStartString() |
| 250 | { |
| 251 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4724', 'AbstractPlatform::getSqlCommentStartString() is deprecated.'); |
| 252 | return '--'; |
| 253 | } |
| 254 | public function getSqlCommentEndString() |
| 255 | { |
| 256 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4724', 'AbstractPlatform::getSqlCommentEndString() is deprecated.'); |
| 257 | return "\n"; |
| 258 | } |
| 259 | public function getCharMaxLength() : int |
| 260 | { |
| 261 | Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/issues/3263', 'AbstractPlatform::getCharMaxLength() is deprecated.'); |
| 262 | return $this->getVarcharMaxLength(); |
| 263 | } |
| 264 | public function getVarcharMaxLength() |
| 265 | { |
| 266 | Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/issues/3263', 'AbstractPlatform::getVarcharMaxLength() is deprecated.'); |
| 267 | return 4000; |
| 268 | } |
| 269 | public function getVarcharDefaultLength() |
| 270 | { |
| 271 | Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/issues/3263', 'Relying on the default varchar column length is deprecated, specify the length explicitly.'); |
| 272 | return 255; |
| 273 | } |
| 274 | public function getBinaryMaxLength() |
| 275 | { |
| 276 | Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/issues/3263', 'AbstractPlatform::getBinaryMaxLength() is deprecated.'); |
| 277 | return 4000; |
| 278 | } |
| 279 | public function getBinaryDefaultLength() |
| 280 | { |
| 281 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/issues/3263', 'Relying on the default binary column length is deprecated, specify the length explicitly.'); |
| 282 | return 255; |
| 283 | } |
| 284 | public function getWildcards() |
| 285 | { |
| 286 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4724', 'AbstractPlatform::getWildcards() is deprecated.' . ' Use AbstractPlatform::getLikeWildcardCharacters() instead.'); |
| 287 | return ['%', '_']; |
| 288 | } |
| 289 | public function getRegexpExpression() |
| 290 | { |
| 291 | throw Exception::notSupported(__METHOD__); |
| 292 | } |
| 293 | public function getAvgExpression($column) |
| 294 | { |
| 295 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4724', 'AbstractPlatform::getAvgExpression() is deprecated. Use AVG() in SQL instead.'); |
| 296 | return 'AVG(' . $column . ')'; |
| 297 | } |
| 298 | public function getCountExpression($column) |
| 299 | { |
| 300 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4724', 'AbstractPlatform::getCountExpression() is deprecated. Use COUNT() in SQL instead.'); |
| 301 | return 'COUNT(' . $column . ')'; |
| 302 | } |
| 303 | public function getMaxExpression($column) |
| 304 | { |
| 305 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4724', 'AbstractPlatform::getMaxExpression() is deprecated. Use MAX() in SQL instead.'); |
| 306 | return 'MAX(' . $column . ')'; |
| 307 | } |
| 308 | public function getMinExpression($column) |
| 309 | { |
| 310 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4724', 'AbstractPlatform::getMinExpression() is deprecated. Use MIN() in SQL instead.'); |
| 311 | return 'MIN(' . $column . ')'; |
| 312 | } |
| 313 | public function getSumExpression($column) |
| 314 | { |
| 315 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4724', 'AbstractPlatform::getSumExpression() is deprecated. Use SUM() in SQL instead.'); |
| 316 | return 'SUM(' . $column . ')'; |
| 317 | } |
| 318 | // scalar functions |
| 319 | public function getMd5Expression($column) |
| 320 | { |
| 321 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4724', 'AbstractPlatform::getMd5Expression() is deprecated.'); |
| 322 | return 'MD5(' . $column . ')'; |
| 323 | } |
| 324 | public function getLengthExpression($column) |
| 325 | { |
| 326 | return 'LENGTH(' . $column . ')'; |
| 327 | } |
| 328 | public function getSqrtExpression($column) |
| 329 | { |
| 330 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4724', 'AbstractPlatform::getSqrtExpression() is deprecated. Use SQRT() in SQL instead.'); |
| 331 | return 'SQRT(' . $column . ')'; |
| 332 | } |
| 333 | public function getRoundExpression($column, $decimals = 0) |
| 334 | { |
| 335 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4724', 'AbstractPlatform::getRoundExpression() is deprecated. Use ROUND() in SQL instead.'); |
| 336 | return 'ROUND(' . $column . ', ' . $decimals . ')'; |
| 337 | } |
| 338 | public function getModExpression($expression1, $expression2) |
| 339 | { |
| 340 | return 'MOD(' . $expression1 . ', ' . $expression2 . ')'; |
| 341 | } |
| 342 | public function getTrimExpression($str, $mode = TrimMode::UNSPECIFIED, $char = \false) |
| 343 | { |
| 344 | $expression = ''; |
| 345 | switch ($mode) { |
| 346 | case TrimMode::LEADING: |
| 347 | $expression = 'LEADING '; |
| 348 | break; |
| 349 | case TrimMode::TRAILING: |
| 350 | $expression = 'TRAILING '; |
| 351 | break; |
| 352 | case TrimMode::BOTH: |
| 353 | $expression = 'BOTH '; |
| 354 | break; |
| 355 | } |
| 356 | if ($char !== \false) { |
| 357 | $expression .= $char . ' '; |
| 358 | } |
| 359 | if ($mode !== TrimMode::UNSPECIFIED || $char !== \false) { |
| 360 | $expression .= 'FROM '; |
| 361 | } |
| 362 | return 'TRIM(' . $expression . $str . ')'; |
| 363 | } |
| 364 | public function getRtrimExpression($str) |
| 365 | { |
| 366 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4724', 'AbstractPlatform::getRtrimExpression() is deprecated. Use RTRIM() in SQL instead.'); |
| 367 | return 'RTRIM(' . $str . ')'; |
| 368 | } |
| 369 | public function getLtrimExpression($str) |
| 370 | { |
| 371 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4724', 'AbstractPlatform::getLtrimExpression() is deprecated. Use LTRIM() in SQL instead.'); |
| 372 | return 'LTRIM(' . $str . ')'; |
| 373 | } |
| 374 | public function getUpperExpression($str) |
| 375 | { |
| 376 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4724', 'AbstractPlatform::getUpperExpression() is deprecated. Use UPPER() in SQL instead.'); |
| 377 | return 'UPPER(' . $str . ')'; |
| 378 | } |
| 379 | public function getLowerExpression($str) |
| 380 | { |
| 381 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4724', 'AbstractPlatform::getLowerExpression() is deprecated. Use LOWER() in SQL instead.'); |
| 382 | return 'LOWER(' . $str . ')'; |
| 383 | } |
| 384 | public function getLocateExpression($str, $substr, $startPos = \false) |
| 385 | { |
| 386 | throw Exception::notSupported(__METHOD__); |
| 387 | } |
| 388 | public function getNowExpression() |
| 389 | { |
| 390 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4753', 'AbstractPlatform::getNowExpression() is deprecated. Generate dates within the application.'); |
| 391 | return 'NOW()'; |
| 392 | } |
| 393 | public function getSubstringExpression($string, $start, $length = null) |
| 394 | { |
| 395 | if ($length === null) { |
| 396 | return 'SUBSTRING(' . $string . ' FROM ' . $start . ')'; |
| 397 | } |
| 398 | return 'SUBSTRING(' . $string . ' FROM ' . $start . ' FOR ' . $length . ')'; |
| 399 | } |
| 400 | public function getConcatExpression() |
| 401 | { |
| 402 | return implode(' || ', func_get_args()); |
| 403 | } |
| 404 | public function getNotExpression($expression) |
| 405 | { |
| 406 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4724', 'AbstractPlatform::getNotExpression() is deprecated. Use NOT() in SQL instead.'); |
| 407 | return 'NOT(' . $expression . ')'; |
| 408 | } |
| 409 | public function getIsNullExpression($expression) |
| 410 | { |
| 411 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4724', 'AbstractPlatform::getIsNullExpression() is deprecated. Use IS NULL in SQL instead.'); |
| 412 | return $expression . ' IS NULL'; |
| 413 | } |
| 414 | public function getIsNotNullExpression($expression) |
| 415 | { |
| 416 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4724', 'AbstractPlatform::getIsNotNullExpression() is deprecated. Use IS NOT NULL in SQL instead.'); |
| 417 | return $expression . ' IS NOT NULL'; |
| 418 | } |
| 419 | public function getBetweenExpression($expression, $value1, $value2) |
| 420 | { |
| 421 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4724', 'AbstractPlatform::getBetweenExpression() is deprecated. Use BETWEEN in SQL instead.'); |
| 422 | return $expression . ' BETWEEN ' . $value1 . ' AND ' . $value2; |
| 423 | } |
| 424 | public function getAcosExpression($value) |
| 425 | { |
| 426 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4724', 'AbstractPlatform::getAcosExpression() is deprecated. Use ACOS() in SQL instead.'); |
| 427 | return 'ACOS(' . $value . ')'; |
| 428 | } |
| 429 | public function getSinExpression($value) |
| 430 | { |
| 431 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4724', 'AbstractPlatform::getSinExpression() is deprecated. Use SIN() in SQL instead.'); |
| 432 | return 'SIN(' . $value . ')'; |
| 433 | } |
| 434 | public function getPiExpression() |
| 435 | { |
| 436 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4724', 'AbstractPlatform::getPiExpression() is deprecated. Use PI() in SQL instead.'); |
| 437 | return 'PI()'; |
| 438 | } |
| 439 | public function getCosExpression($value) |
| 440 | { |
| 441 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4724', 'AbstractPlatform::getCosExpression() is deprecated. Use COS() in SQL instead.'); |
| 442 | return 'COS(' . $value . ')'; |
| 443 | } |
| 444 | public function getDateDiffExpression($date1, $date2) |
| 445 | { |
| 446 | throw Exception::notSupported(__METHOD__); |
| 447 | } |
| 448 | public function getDateAddSecondsExpression($date, $seconds) |
| 449 | { |
| 450 | if (is_int($seconds)) { |
| 451 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/3498', 'Passing $seconds as an integer is deprecated. Pass it as a numeric string instead.'); |
| 452 | } |
| 453 | return $this->getDateArithmeticIntervalExpression($date, '+', $seconds, DateIntervalUnit::SECOND); |
| 454 | } |
| 455 | public function getDateSubSecondsExpression($date, $seconds) |
| 456 | { |
| 457 | if (is_int($seconds)) { |
| 458 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/3498', 'Passing $seconds as an integer is deprecated. Pass it as a numeric string instead.'); |
| 459 | } |
| 460 | return $this->getDateArithmeticIntervalExpression($date, '-', $seconds, DateIntervalUnit::SECOND); |
| 461 | } |
| 462 | public function getDateAddMinutesExpression($date, $minutes) |
| 463 | { |
| 464 | if (is_int($minutes)) { |
| 465 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/3498', 'Passing $minutes as an integer is deprecated. Pass it as a numeric string instead.'); |
| 466 | } |
| 467 | return $this->getDateArithmeticIntervalExpression($date, '+', $minutes, DateIntervalUnit::MINUTE); |
| 468 | } |
| 469 | public function getDateSubMinutesExpression($date, $minutes) |
| 470 | { |
| 471 | if (is_int($minutes)) { |
| 472 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/3498', 'Passing $minutes as an integer is deprecated. Pass it as a numeric string instead.'); |
| 473 | } |
| 474 | return $this->getDateArithmeticIntervalExpression($date, '-', $minutes, DateIntervalUnit::MINUTE); |
| 475 | } |
| 476 | public function getDateAddHourExpression($date, $hours) |
| 477 | { |
| 478 | if (is_int($hours)) { |
| 479 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/3498', 'Passing $hours as an integer is deprecated. Pass it as a numeric string instead.'); |
| 480 | } |
| 481 | return $this->getDateArithmeticIntervalExpression($date, '+', $hours, DateIntervalUnit::HOUR); |
| 482 | } |
| 483 | public function getDateSubHourExpression($date, $hours) |
| 484 | { |
| 485 | if (is_int($hours)) { |
| 486 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/3498', 'Passing $hours as an integer is deprecated. Pass it as a numeric string instead.'); |
| 487 | } |
| 488 | return $this->getDateArithmeticIntervalExpression($date, '-', $hours, DateIntervalUnit::HOUR); |
| 489 | } |
| 490 | public function getDateAddDaysExpression($date, $days) |
| 491 | { |
| 492 | if (is_int($days)) { |
| 493 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/3498', 'Passing $days as an integer is deprecated. Pass it as a numeric string instead.'); |
| 494 | } |
| 495 | return $this->getDateArithmeticIntervalExpression($date, '+', $days, DateIntervalUnit::DAY); |
| 496 | } |
| 497 | public function getDateSubDaysExpression($date, $days) |
| 498 | { |
| 499 | if (is_int($days)) { |
| 500 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/3498', 'Passing $days as an integer is deprecated. Pass it as a numeric string instead.'); |
| 501 | } |
| 502 | return $this->getDateArithmeticIntervalExpression($date, '-', $days, DateIntervalUnit::DAY); |
| 503 | } |
| 504 | public function getDateAddWeeksExpression($date, $weeks) |
| 505 | { |
| 506 | if (is_int($weeks)) { |
| 507 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/3498', 'Passing $weeks as an integer is deprecated. Pass it as a numeric string instead.'); |
| 508 | } |
| 509 | return $this->getDateArithmeticIntervalExpression($date, '+', $weeks, DateIntervalUnit::WEEK); |
| 510 | } |
| 511 | public function getDateSubWeeksExpression($date, $weeks) |
| 512 | { |
| 513 | if (is_int($weeks)) { |
| 514 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/3498', 'Passing $weeks as an integer is deprecated. Pass it as a numeric string instead.'); |
| 515 | } |
| 516 | return $this->getDateArithmeticIntervalExpression($date, '-', $weeks, DateIntervalUnit::WEEK); |
| 517 | } |
| 518 | public function getDateAddMonthExpression($date, $months) |
| 519 | { |
| 520 | if (is_int($months)) { |
| 521 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/3498', 'Passing $months as an integer is deprecated. Pass it as a numeric string instead.'); |
| 522 | } |
| 523 | return $this->getDateArithmeticIntervalExpression($date, '+', $months, DateIntervalUnit::MONTH); |
| 524 | } |
| 525 | public function getDateSubMonthExpression($date, $months) |
| 526 | { |
| 527 | if (is_int($months)) { |
| 528 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/3498', 'Passing $months as an integer is deprecated. Pass it as a numeric string instead.'); |
| 529 | } |
| 530 | return $this->getDateArithmeticIntervalExpression($date, '-', $months, DateIntervalUnit::MONTH); |
| 531 | } |
| 532 | public function getDateAddQuartersExpression($date, $quarters) |
| 533 | { |
| 534 | if (is_int($quarters)) { |
| 535 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/3498', 'Passing $quarters as an integer is deprecated. Pass it as a numeric string instead.'); |
| 536 | } |
| 537 | return $this->getDateArithmeticIntervalExpression($date, '+', $quarters, DateIntervalUnit::QUARTER); |
| 538 | } |
| 539 | public function getDateSubQuartersExpression($date, $quarters) |
| 540 | { |
| 541 | if (is_int($quarters)) { |
| 542 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/3498', 'Passing $quarters as an integer is deprecated. Pass it as a numeric string instead.'); |
| 543 | } |
| 544 | return $this->getDateArithmeticIntervalExpression($date, '-', $quarters, DateIntervalUnit::QUARTER); |
| 545 | } |
| 546 | public function getDateAddYearsExpression($date, $years) |
| 547 | { |
| 548 | if (is_int($years)) { |
| 549 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/3498', 'Passing $years as an integer is deprecated. Pass it as a numeric string instead.'); |
| 550 | } |
| 551 | return $this->getDateArithmeticIntervalExpression($date, '+', $years, DateIntervalUnit::YEAR); |
| 552 | } |
| 553 | public function getDateSubYearsExpression($date, $years) |
| 554 | { |
| 555 | if (is_int($years)) { |
| 556 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/3498', 'Passing $years as an integer is deprecated. Pass it as a numeric string instead.'); |
| 557 | } |
| 558 | return $this->getDateArithmeticIntervalExpression($date, '-', $years, DateIntervalUnit::YEAR); |
| 559 | } |
| 560 | protected function getDateArithmeticIntervalExpression($date, $operator, $interval, $unit) |
| 561 | { |
| 562 | throw Exception::notSupported(__METHOD__); |
| 563 | } |
| 564 | protected function multiplyInterval(string $interval, int $multiplier) : string |
| 565 | { |
| 566 | return sprintf('(%s * %d)', $interval, $multiplier); |
| 567 | } |
| 568 | public function getBitAndComparisonExpression($value1, $value2) |
| 569 | { |
| 570 | return '(' . $value1 . ' & ' . $value2 . ')'; |
| 571 | } |
| 572 | public function getBitOrComparisonExpression($value1, $value2) |
| 573 | { |
| 574 | return '(' . $value1 . ' | ' . $value2 . ')'; |
| 575 | } |
| 576 | public abstract function getCurrentDatabaseExpression() : string; |
| 577 | public function getForUpdateSQL() |
| 578 | { |
| 579 | Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/6191', '%s is deprecated as non-portable.', __METHOD__); |
| 580 | return 'FOR UPDATE'; |
| 581 | } |
| 582 | public function appendLockHint(string $fromClause, int $lockMode) : string |
| 583 | { |
| 584 | switch ($lockMode) { |
| 585 | case LockMode::NONE: |
| 586 | case LockMode::OPTIMISTIC: |
| 587 | case LockMode::PESSIMISTIC_READ: |
| 588 | case LockMode::PESSIMISTIC_WRITE: |
| 589 | return $fromClause; |
| 590 | default: |
| 591 | throw InvalidLockMode::fromLockMode($lockMode); |
| 592 | } |
| 593 | } |
| 594 | public function getReadLockSQL() |
| 595 | { |
| 596 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/6191', '%s is deprecated as non-portable.', __METHOD__); |
| 597 | return $this->getForUpdateSQL(); |
| 598 | } |
| 599 | public function getWriteLockSQL() |
| 600 | { |
| 601 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/6191', '%s is deprecated as non-portable.', __METHOD__); |
| 602 | return $this->getForUpdateSQL(); |
| 603 | } |
| 604 | public function getDropTableSQL($table) |
| 605 | { |
| 606 | $tableArg = $table; |
| 607 | if ($table instanceof Table) { |
| 608 | 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__); |
| 609 | $table = $table->getQuotedName($this); |
| 610 | } |
| 611 | if (!is_string($table)) { |
| 612 | throw new InvalidArgumentException(__METHOD__ . '() expects $table parameter to be string or ' . Table::class . '.'); |
| 613 | } |
| 614 | if ($this->_eventManager !== null && $this->_eventManager->hasListeners(Events::onSchemaDropTable)) { |
| 615 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/issues/5784', 'Subscribing to %s events is deprecated.', Events::onSchemaDropTable); |
| 616 | $eventArgs = new SchemaDropTableEventArgs($tableArg, $this); |
| 617 | $this->_eventManager->dispatchEvent(Events::onSchemaDropTable, $eventArgs); |
| 618 | if ($eventArgs->isDefaultPrevented()) { |
| 619 | $sql = $eventArgs->getSql(); |
| 620 | if ($sql === null) { |
| 621 | throw new UnexpectedValueException('Default implementation of DROP TABLE was overridden with NULL'); |
| 622 | } |
| 623 | return $sql; |
| 624 | } |
| 625 | } |
| 626 | return 'DROP TABLE ' . $table; |
| 627 | } |
| 628 | public function getDropTemporaryTableSQL($table) |
| 629 | { |
| 630 | if ($table instanceof Table) { |
| 631 | 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__); |
| 632 | $table = $table->getQuotedName($this); |
| 633 | } |
| 634 | return $this->getDropTableSQL($table); |
| 635 | } |
| 636 | public function getDropIndexSQL($index, $table = null) |
| 637 | { |
| 638 | if ($index instanceof Index) { |
| 639 | 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__); |
| 640 | $index = $index->getQuotedName($this); |
| 641 | } elseif (!is_string($index)) { |
| 642 | throw new InvalidArgumentException(__METHOD__ . '() expects $index parameter to be string or ' . Index::class . '.'); |
| 643 | } |
| 644 | return 'DROP INDEX ' . $index; |
| 645 | } |
| 646 | public function getDropConstraintSQL($constraint, $table) |
| 647 | { |
| 648 | if ($constraint instanceof Constraint) { |
| 649 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/issues/4798', 'Passing $constraint as a Constraint object to %s is deprecated. Pass it as a quoted name instead.', __METHOD__); |
| 650 | } else { |
| 651 | $constraint = new Identifier($constraint); |
| 652 | } |
| 653 | if ($table instanceof Table) { |
| 654 | 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__); |
| 655 | } else { |
| 656 | $table = new Identifier($table); |
| 657 | } |
| 658 | $constraint = $constraint->getQuotedName($this); |
| 659 | $table = $table->getQuotedName($this); |
| 660 | return 'ALTER TABLE ' . $table . ' DROP CONSTRAINT ' . $constraint; |
| 661 | } |
| 662 | public function getDropForeignKeySQL($foreignKey, $table) |
| 663 | { |
| 664 | if ($foreignKey instanceof ForeignKeyConstraint) { |
| 665 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/issues/4798', 'Passing $foreignKey as a ForeignKeyConstraint object to %s is deprecated.' . ' Pass it as a quoted name instead.', __METHOD__); |
| 666 | } else { |
| 667 | $foreignKey = new Identifier($foreignKey); |
| 668 | } |
| 669 | if ($table instanceof Table) { |
| 670 | 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__); |
| 671 | } else { |
| 672 | $table = new Identifier($table); |
| 673 | } |
| 674 | $foreignKey = $foreignKey->getQuotedName($this); |
| 675 | $table = $table->getQuotedName($this); |
| 676 | return 'ALTER TABLE ' . $table . ' DROP FOREIGN KEY ' . $foreignKey; |
| 677 | } |
| 678 | public function getDropUniqueConstraintSQL(string $name, string $tableName) : string |
| 679 | { |
| 680 | return $this->getDropConstraintSQL($name, $tableName); |
| 681 | } |
| 682 | public function getCreateTableSQL(Table $table, $createFlags = self::CREATE_INDEXES) |
| 683 | { |
| 684 | if (!is_int($createFlags)) { |
| 685 | throw new InvalidArgumentException('Second argument of AbstractPlatform::getCreateTableSQL() has to be integer.'); |
| 686 | } |
| 687 | if (($createFlags & self::CREATE_INDEXES) === 0) { |
| 688 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5416', 'Unsetting the CREATE_INDEXES flag in AbstractPlatform::getCreateTableSQL() is deprecated.'); |
| 689 | } |
| 690 | if (($createFlags & self::CREATE_FOREIGNKEYS) === 0) { |
| 691 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5416', 'Not setting the CREATE_FOREIGNKEYS flag in AbstractPlatform::getCreateTableSQL()' . ' is deprecated. In order to build the statements that create multiple tables' . ' referencing each other via foreign keys, use AbstractPlatform::getCreateTablesSQL().'); |
| 692 | } |
| 693 | return $this->buildCreateTableSQL($table, ($createFlags & self::CREATE_INDEXES) > 0, ($createFlags & self::CREATE_FOREIGNKEYS) > 0); |
| 694 | } |
| 695 | public function createSelectSQLBuilder() : SelectSQLBuilder |
| 696 | { |
| 697 | return new DefaultSelectSQLBuilder($this, 'FOR UPDATE', 'SKIP LOCKED'); |
| 698 | } |
| 699 | protected final function getCreateTableWithoutForeignKeysSQL(Table $table) : array |
| 700 | { |
| 701 | return $this->buildCreateTableSQL($table, \true, \false); |
| 702 | } |
| 703 | private function buildCreateTableSQL(Table $table, bool $createIndexes, bool $createForeignKeys) : array |
| 704 | { |
| 705 | if (count($table->getColumns()) === 0) { |
| 706 | throw Exception::noColumnsSpecifiedForTable($table->getName()); |
| 707 | } |
| 708 | $tableName = $table->getQuotedName($this); |
| 709 | $options = $table->getOptions(); |
| 710 | $options['uniqueConstraints'] = []; |
| 711 | $options['indexes'] = []; |
| 712 | $options['primary'] = []; |
| 713 | if ($createIndexes) { |
| 714 | foreach ($table->getIndexes() as $index) { |
| 715 | if (!$index->isPrimary()) { |
| 716 | $options['indexes'][$index->getQuotedName($this)] = $index; |
| 717 | continue; |
| 718 | } |
| 719 | $options['primary'] = $index->getQuotedColumns($this); |
| 720 | $options['primary_index'] = $index; |
| 721 | } |
| 722 | foreach ($table->getUniqueConstraints() as $uniqueConstraint) { |
| 723 | $options['uniqueConstraints'][$uniqueConstraint->getQuotedName($this)] = $uniqueConstraint; |
| 724 | } |
| 725 | } |
| 726 | if ($createForeignKeys) { |
| 727 | $options['foreignKeys'] = []; |
| 728 | foreach ($table->getForeignKeys() as $fkConstraint) { |
| 729 | $options['foreignKeys'][] = $fkConstraint; |
| 730 | } |
| 731 | } |
| 732 | $columnSql = []; |
| 733 | $columns = []; |
| 734 | foreach ($table->getColumns() as $column) { |
| 735 | if ($this->_eventManager !== null && $this->_eventManager->hasListeners(Events::onSchemaCreateTableColumn)) { |
| 736 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/issues/5784', 'Subscribing to %s events is deprecated.', Events::onSchemaCreateTableColumn); |
| 737 | $eventArgs = new SchemaCreateTableColumnEventArgs($column, $table, $this); |
| 738 | $this->_eventManager->dispatchEvent(Events::onSchemaCreateTableColumn, $eventArgs); |
| 739 | $columnSql = array_merge($columnSql, $eventArgs->getSql()); |
| 740 | if ($eventArgs->isDefaultPrevented()) { |
| 741 | continue; |
| 742 | } |
| 743 | } |
| 744 | $columnData = $this->columnToArray($column); |
| 745 | if (in_array($column->getName(), $options['primary'], \true)) { |
| 746 | $columnData['primary'] = \true; |
| 747 | } |
| 748 | $columns[$columnData['name']] = $columnData; |
| 749 | } |
| 750 | if ($this->_eventManager !== null && $this->_eventManager->hasListeners(Events::onSchemaCreateTable)) { |
| 751 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/issues/5784', 'Subscribing to %s events is deprecated.', Events::onSchemaCreateTable); |
| 752 | $eventArgs = new SchemaCreateTableEventArgs($table, $columns, $options, $this); |
| 753 | $this->_eventManager->dispatchEvent(Events::onSchemaCreateTable, $eventArgs); |
| 754 | if ($eventArgs->isDefaultPrevented()) { |
| 755 | return array_merge($eventArgs->getSql(), $columnSql); |
| 756 | } |
| 757 | } |
| 758 | $sql = $this->_getCreateTableSQL($tableName, $columns, $options); |
| 759 | if ($this->supportsCommentOnStatement()) { |
| 760 | if ($table->hasOption('comment')) { |
| 761 | $sql[] = $this->getCommentOnTableSQL($tableName, $table->getOption('comment')); |
| 762 | } |
| 763 | foreach ($table->getColumns() as $column) { |
| 764 | $comment = $this->getColumnComment($column); |
| 765 | if ($comment === null || $comment === '') { |
| 766 | continue; |
| 767 | } |
| 768 | $sql[] = $this->getCommentOnColumnSQL($tableName, $column->getQuotedName($this), $comment); |
| 769 | } |
| 770 | } |
| 771 | return array_merge($sql, $columnSql); |
| 772 | } |
| 773 | public function getCreateTablesSQL(array $tables) : array |
| 774 | { |
| 775 | $sql = []; |
| 776 | foreach ($tables as $table) { |
| 777 | $sql = array_merge($sql, $this->getCreateTableWithoutForeignKeysSQL($table)); |
| 778 | } |
| 779 | foreach ($tables as $table) { |
| 780 | foreach ($table->getForeignKeys() as $foreignKey) { |
| 781 | $sql[] = $this->getCreateForeignKeySQL($foreignKey, $table->getQuotedName($this)); |
| 782 | } |
| 783 | } |
| 784 | return $sql; |
| 785 | } |
| 786 | public function getDropTablesSQL(array $tables) : array |
| 787 | { |
| 788 | $sql = []; |
| 789 | foreach ($tables as $table) { |
| 790 | foreach ($table->getForeignKeys() as $foreignKey) { |
| 791 | $sql[] = $this->getDropForeignKeySQL($foreignKey->getQuotedName($this), $table->getQuotedName($this)); |
| 792 | } |
| 793 | } |
| 794 | foreach ($tables as $table) { |
| 795 | $sql[] = $this->getDropTableSQL($table->getQuotedName($this)); |
| 796 | } |
| 797 | return $sql; |
| 798 | } |
| 799 | protected function getCommentOnTableSQL(string $tableName, ?string $comment) : string |
| 800 | { |
| 801 | $tableName = new Identifier($tableName); |
| 802 | return sprintf('COMMENT ON TABLE %s IS %s', $tableName->getQuotedName($this), $this->quoteStringLiteral((string) $comment)); |
| 803 | } |
| 804 | public function getCommentOnColumnSQL($tableName, $columnName, $comment) |
| 805 | { |
| 806 | $tableName = new Identifier($tableName); |
| 807 | $columnName = new Identifier($columnName); |
| 808 | return sprintf('COMMENT ON COLUMN %s.%s IS %s', $tableName->getQuotedName($this), $columnName->getQuotedName($this), $this->quoteStringLiteral((string) $comment)); |
| 809 | } |
| 810 | public function getInlineColumnCommentSQL($comment) |
| 811 | { |
| 812 | if (!$this->supportsInlineColumnComments()) { |
| 813 | throw Exception::notSupported(__METHOD__); |
| 814 | } |
| 815 | return 'COMMENT ' . $this->quoteStringLiteral($comment); |
| 816 | } |
| 817 | protected function _getCreateTableSQL($name, array $columns, array $options = []) |
| 818 | { |
| 819 | $columnListSql = $this->getColumnDeclarationListSQL($columns); |
| 820 | if (isset($options['uniqueConstraints']) && !empty($options['uniqueConstraints'])) { |
| 821 | foreach ($options['uniqueConstraints'] as $index => $definition) { |
| 822 | $columnListSql .= ', ' . $this->getUniqueConstraintDeclarationSQL($index, $definition); |
| 823 | } |
| 824 | } |
| 825 | if (isset($options['primary']) && !empty($options['primary'])) { |
| 826 | $columnListSql .= ', PRIMARY KEY(' . implode(', ', array_unique(array_values($options['primary']))) . ')'; |
| 827 | } |
| 828 | if (isset($options['indexes']) && !empty($options['indexes'])) { |
| 829 | foreach ($options['indexes'] as $index => $definition) { |
| 830 | $columnListSql .= ', ' . $this->getIndexDeclarationSQL($index, $definition); |
| 831 | } |
| 832 | } |
| 833 | $query = 'CREATE TABLE ' . $name . ' (' . $columnListSql; |
| 834 | $check = $this->getCheckDeclarationSQL($columns); |
| 835 | if (!empty($check)) { |
| 836 | $query .= ', ' . $check; |
| 837 | } |
| 838 | $query .= ')'; |
| 839 | $sql = [$query]; |
| 840 | if (isset($options['foreignKeys'])) { |
| 841 | foreach ($options['foreignKeys'] as $definition) { |
| 842 | $sql[] = $this->getCreateForeignKeySQL($definition, $name); |
| 843 | } |
| 844 | } |
| 845 | return $sql; |
| 846 | } |
| 847 | public function getCreateTemporaryTableSnippetSQL() |
| 848 | { |
| 849 | return 'CREATE TEMPORARY TABLE'; |
| 850 | } |
| 851 | public function getAlterSchemaSQL(SchemaDiff $diff) : array |
| 852 | { |
| 853 | return $diff->toSql($this); |
| 854 | } |
| 855 | public function getCreateSequenceSQL(Sequence $sequence) |
| 856 | { |
| 857 | throw Exception::notSupported(__METHOD__); |
| 858 | } |
| 859 | public function getAlterSequenceSQL(Sequence $sequence) |
| 860 | { |
| 861 | throw Exception::notSupported(__METHOD__); |
| 862 | } |
| 863 | public function getDropSequenceSQL($sequence) |
| 864 | { |
| 865 | if (!$this->supportsSequences()) { |
| 866 | throw Exception::notSupported(__METHOD__); |
| 867 | } |
| 868 | if ($sequence instanceof Sequence) { |
| 869 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/issues/4798', 'Passing $sequence as a Sequence object to %s is deprecated. Pass it as a quoted name instead.', __METHOD__); |
| 870 | $sequence = $sequence->getQuotedName($this); |
| 871 | } |
| 872 | return 'DROP SEQUENCE ' . $sequence; |
| 873 | } |
| 874 | public function getCreateConstraintSQL(Constraint $constraint, $table) |
| 875 | { |
| 876 | if ($table instanceof Table) { |
| 877 | 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__); |
| 878 | $table = $table->getQuotedName($this); |
| 879 | } |
| 880 | $query = 'ALTER TABLE ' . $table . ' ADD CONSTRAINT ' . $constraint->getQuotedName($this); |
| 881 | $columnList = '(' . implode(', ', $constraint->getQuotedColumns($this)) . ')'; |
| 882 | $referencesClause = ''; |
| 883 | if ($constraint instanceof Index) { |
| 884 | if ($constraint->isPrimary()) { |
| 885 | $query .= ' PRIMARY KEY'; |
| 886 | } elseif ($constraint->isUnique()) { |
| 887 | $query .= ' UNIQUE'; |
| 888 | } else { |
| 889 | throw new InvalidArgumentException('Can only create primary or unique constraints, no common indexes with getCreateConstraintSQL().'); |
| 890 | } |
| 891 | } elseif ($constraint instanceof UniqueConstraint) { |
| 892 | $query .= ' UNIQUE'; |
| 893 | } elseif ($constraint instanceof ForeignKeyConstraint) { |
| 894 | $query .= ' FOREIGN KEY'; |
| 895 | $referencesClause = ' REFERENCES ' . $constraint->getQuotedForeignTableName($this) . ' (' . implode(', ', $constraint->getQuotedForeignColumns($this)) . ')'; |
| 896 | } |
| 897 | $query .= ' ' . $columnList . $referencesClause; |
| 898 | return $query; |
| 899 | } |
| 900 | public function getCreateIndexSQL(Index $index, $table) |
| 901 | { |
| 902 | if ($table instanceof Table) { |
| 903 | 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__); |
| 904 | $table = $table->getQuotedName($this); |
| 905 | } |
| 906 | $name = $index->getQuotedName($this); |
| 907 | $columns = $index->getColumns(); |
| 908 | if (count($columns) === 0) { |
| 909 | throw new InvalidArgumentException(sprintf('Incomplete or invalid index definition %s on table %s', $name, $table)); |
| 910 | } |
| 911 | if ($index->isPrimary()) { |
| 912 | return $this->getCreatePrimaryKeySQL($index, $table); |
| 913 | } |
| 914 | $query = 'CREATE ' . $this->getCreateIndexSQLFlags($index) . 'INDEX ' . $name . ' ON ' . $table; |
| 915 | $query .= ' (' . $this->getIndexFieldDeclarationListSQL($index) . ')' . $this->getPartialIndexSQL($index); |
| 916 | return $query; |
| 917 | } |
| 918 | protected function getPartialIndexSQL(Index $index) |
| 919 | { |
| 920 | if ($this->supportsPartialIndexes() && $index->hasOption('where')) { |
| 921 | return ' WHERE ' . $index->getOption('where'); |
| 922 | } |
| 923 | return ''; |
| 924 | } |
| 925 | protected function getCreateIndexSQLFlags(Index $index) |
| 926 | { |
| 927 | return $index->isUnique() ? 'UNIQUE ' : ''; |
| 928 | } |
| 929 | public function getCreatePrimaryKeySQL(Index $index, $table) |
| 930 | { |
| 931 | if ($table instanceof Table) { |
| 932 | 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__); |
| 933 | $table = $table->getQuotedName($this); |
| 934 | } |
| 935 | return 'ALTER TABLE ' . $table . ' ADD PRIMARY KEY (' . $this->getIndexFieldDeclarationListSQL($index) . ')'; |
| 936 | } |
| 937 | public function getCreateSchemaSQL($schemaName) |
| 938 | { |
| 939 | if (!$this->supportsSchemas()) { |
| 940 | throw Exception::notSupported(__METHOD__); |
| 941 | } |
| 942 | return 'CREATE SCHEMA ' . $schemaName; |
| 943 | } |
| 944 | public function getCreateUniqueConstraintSQL(UniqueConstraint $constraint, string $tableName) : string |
| 945 | { |
| 946 | return $this->getCreateConstraintSQL($constraint, $tableName); |
| 947 | } |
| 948 | public function getDropSchemaSQL(string $schemaName) : string |
| 949 | { |
| 950 | if (!$this->supportsSchemas()) { |
| 951 | throw Exception::notSupported(__METHOD__); |
| 952 | } |
| 953 | return 'DROP SCHEMA ' . $schemaName; |
| 954 | } |
| 955 | public function quoteIdentifier($str) |
| 956 | { |
| 957 | if (strpos($str, '.') !== \false) { |
| 958 | $parts = array_map([$this, 'quoteSingleIdentifier'], explode('.', $str)); |
| 959 | return implode('.', $parts); |
| 960 | } |
| 961 | return $this->quoteSingleIdentifier($str); |
| 962 | } |
| 963 | public function quoteSingleIdentifier($str) |
| 964 | { |
| 965 | $c = $this->getIdentifierQuoteCharacter(); |
| 966 | return $c . str_replace($c, $c . $c, $str) . $c; |
| 967 | } |
| 968 | public function getCreateForeignKeySQL(ForeignKeyConstraint $foreignKey, $table) |
| 969 | { |
| 970 | if ($table instanceof Table) { |
| 971 | 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__); |
| 972 | $table = $table->getQuotedName($this); |
| 973 | } |
| 974 | return 'ALTER TABLE ' . $table . ' ADD ' . $this->getForeignKeyDeclarationSQL($foreignKey); |
| 975 | } |
| 976 | public function getAlterTableSQL(TableDiff $diff) |
| 977 | { |
| 978 | throw Exception::notSupported(__METHOD__); |
| 979 | } |
| 980 | public function getRenameTableSQL(string $oldName, string $newName) : array |
| 981 | { |
| 982 | return [sprintf('ALTER TABLE %s RENAME TO %s', $oldName, $newName)]; |
| 983 | } |
| 984 | protected function onSchemaAlterTableAddColumn(Column $column, TableDiff $diff, &$columnSql) |
| 985 | { |
| 986 | if ($this->_eventManager === null) { |
| 987 | return \false; |
| 988 | } |
| 989 | if (!$this->_eventManager->hasListeners(Events::onSchemaAlterTableAddColumn)) { |
| 990 | return \false; |
| 991 | } |
| 992 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/issues/5784', 'Subscribing to %s events is deprecated.', Events::onSchemaAlterTableAddColumn); |
| 993 | $eventArgs = new SchemaAlterTableAddColumnEventArgs($column, $diff, $this); |
| 994 | $this->_eventManager->dispatchEvent(Events::onSchemaAlterTableAddColumn, $eventArgs); |
| 995 | $columnSql = array_merge($columnSql, $eventArgs->getSql()); |
| 996 | return $eventArgs->isDefaultPrevented(); |
| 997 | } |
| 998 | protected function onSchemaAlterTableRemoveColumn(Column $column, TableDiff $diff, &$columnSql) |
| 999 | { |
| 1000 | if ($this->_eventManager === null) { |
| 1001 | return \false; |
| 1002 | } |
| 1003 | if (!$this->_eventManager->hasListeners(Events::onSchemaAlterTableRemoveColumn)) { |
| 1004 | return \false; |
| 1005 | } |
| 1006 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/issues/5784', 'Subscribing to %s events is deprecated.', Events::onSchemaAlterTableRemoveColumn); |
| 1007 | $eventArgs = new SchemaAlterTableRemoveColumnEventArgs($column, $diff, $this); |
| 1008 | $this->_eventManager->dispatchEvent(Events::onSchemaAlterTableRemoveColumn, $eventArgs); |
| 1009 | $columnSql = array_merge($columnSql, $eventArgs->getSql()); |
| 1010 | return $eventArgs->isDefaultPrevented(); |
| 1011 | } |
| 1012 | protected function onSchemaAlterTableChangeColumn(ColumnDiff $columnDiff, TableDiff $diff, &$columnSql) |
| 1013 | { |
| 1014 | if ($this->_eventManager === null) { |
| 1015 | return \false; |
| 1016 | } |
| 1017 | if (!$this->_eventManager->hasListeners(Events::onSchemaAlterTableChangeColumn)) { |
| 1018 | return \false; |
| 1019 | } |
| 1020 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/issues/5784', 'Subscribing to %s events is deprecated.', Events::onSchemaAlterTableChangeColumn); |
| 1021 | $eventArgs = new SchemaAlterTableChangeColumnEventArgs($columnDiff, $diff, $this); |
| 1022 | $this->_eventManager->dispatchEvent(Events::onSchemaAlterTableChangeColumn, $eventArgs); |
| 1023 | $columnSql = array_merge($columnSql, $eventArgs->getSql()); |
| 1024 | return $eventArgs->isDefaultPrevented(); |
| 1025 | } |
| 1026 | protected function onSchemaAlterTableRenameColumn($oldColumnName, Column $column, TableDiff $diff, &$columnSql) |
| 1027 | { |
| 1028 | if ($this->_eventManager === null) { |
| 1029 | return \false; |
| 1030 | } |
| 1031 | if (!$this->_eventManager->hasListeners(Events::onSchemaAlterTableRenameColumn)) { |
| 1032 | return \false; |
| 1033 | } |
| 1034 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/issues/5784', 'Subscribing to %s events is deprecated.', Events::onSchemaAlterTableRenameColumn); |
| 1035 | $eventArgs = new SchemaAlterTableRenameColumnEventArgs($oldColumnName, $column, $diff, $this); |
| 1036 | $this->_eventManager->dispatchEvent(Events::onSchemaAlterTableRenameColumn, $eventArgs); |
| 1037 | $columnSql = array_merge($columnSql, $eventArgs->getSql()); |
| 1038 | return $eventArgs->isDefaultPrevented(); |
| 1039 | } |
| 1040 | protected function onSchemaAlterTable(TableDiff $diff, &$sql) |
| 1041 | { |
| 1042 | if ($this->_eventManager === null) { |
| 1043 | return \false; |
| 1044 | } |
| 1045 | if (!$this->_eventManager->hasListeners(Events::onSchemaAlterTable)) { |
| 1046 | return \false; |
| 1047 | } |
| 1048 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/issues/5784', 'Subscribing to %s events is deprecated.', Events::onSchemaAlterTable); |
| 1049 | $eventArgs = new SchemaAlterTableEventArgs($diff, $this); |
| 1050 | $this->_eventManager->dispatchEvent(Events::onSchemaAlterTable, $eventArgs); |
| 1051 | $sql = array_merge($sql, $eventArgs->getSql()); |
| 1052 | return $eventArgs->isDefaultPrevented(); |
| 1053 | } |
| 1054 | protected function getPreAlterTableIndexForeignKeySQL(TableDiff $diff) |
| 1055 | { |
| 1056 | $tableNameSQL = ($diff->getOldTable() ?? $diff->getName($this))->getQuotedName($this); |
| 1057 | $sql = []; |
| 1058 | if ($this->supportsForeignKeyConstraints()) { |
| 1059 | foreach ($diff->getDroppedForeignKeys() as $foreignKey) { |
| 1060 | if ($foreignKey instanceof ForeignKeyConstraint) { |
| 1061 | $foreignKey = $foreignKey->getQuotedName($this); |
| 1062 | } |
| 1063 | $sql[] = $this->getDropForeignKeySQL($foreignKey, $tableNameSQL); |
| 1064 | } |
| 1065 | foreach ($diff->getModifiedForeignKeys() as $foreignKey) { |
| 1066 | $sql[] = $this->getDropForeignKeySQL($foreignKey->getQuotedName($this), $tableNameSQL); |
| 1067 | } |
| 1068 | } |
| 1069 | foreach ($diff->getDroppedIndexes() as $index) { |
| 1070 | $sql[] = $this->getDropIndexSQL($index->getQuotedName($this), $tableNameSQL); |
| 1071 | } |
| 1072 | foreach ($diff->getModifiedIndexes() as $index) { |
| 1073 | $sql[] = $this->getDropIndexSQL($index->getQuotedName($this), $tableNameSQL); |
| 1074 | } |
| 1075 | return $sql; |
| 1076 | } |
| 1077 | protected function getPostAlterTableIndexForeignKeySQL(TableDiff $diff) |
| 1078 | { |
| 1079 | $sql = []; |
| 1080 | $newName = $diff->getNewName(); |
| 1081 | if ($newName !== \false) { |
| 1082 | $tableNameSQL = $newName->getQuotedName($this); |
| 1083 | } else { |
| 1084 | $tableNameSQL = ($diff->getOldTable() ?? $diff->getName($this))->getQuotedName($this); |
| 1085 | } |
| 1086 | if ($this->supportsForeignKeyConstraints()) { |
| 1087 | foreach ($diff->getAddedForeignKeys() as $foreignKey) { |
| 1088 | $sql[] = $this->getCreateForeignKeySQL($foreignKey, $tableNameSQL); |
| 1089 | } |
| 1090 | foreach ($diff->getModifiedForeignKeys() as $foreignKey) { |
| 1091 | $sql[] = $this->getCreateForeignKeySQL($foreignKey, $tableNameSQL); |
| 1092 | } |
| 1093 | } |
| 1094 | foreach ($diff->getAddedIndexes() as $index) { |
| 1095 | $sql[] = $this->getCreateIndexSQL($index, $tableNameSQL); |
| 1096 | } |
| 1097 | foreach ($diff->getModifiedIndexes() as $index) { |
| 1098 | $sql[] = $this->getCreateIndexSQL($index, $tableNameSQL); |
| 1099 | } |
| 1100 | foreach ($diff->getRenamedIndexes() as $oldIndexName => $index) { |
| 1101 | $oldIndexName = new Identifier($oldIndexName); |
| 1102 | $sql = array_merge($sql, $this->getRenameIndexSQL($oldIndexName->getQuotedName($this), $index, $tableNameSQL)); |
| 1103 | } |
| 1104 | return $sql; |
| 1105 | } |
| 1106 | protected function getRenameIndexSQL($oldIndexName, Index $index, $tableName) |
| 1107 | { |
| 1108 | return [$this->getDropIndexSQL($oldIndexName, $tableName), $this->getCreateIndexSQL($index, $tableName)]; |
| 1109 | } |
| 1110 | public function getColumnDeclarationListSQL(array $columns) |
| 1111 | { |
| 1112 | $declarations = []; |
| 1113 | foreach ($columns as $name => $column) { |
| 1114 | $declarations[] = $this->getColumnDeclarationSQL($name, $column); |
| 1115 | } |
| 1116 | return implode(', ', $declarations); |
| 1117 | } |
| 1118 | public function getColumnDeclarationSQL($name, array $column) |
| 1119 | { |
| 1120 | if (isset($column['columnDefinition'])) { |
| 1121 | $declaration = $this->getCustomTypeDeclarationSQL($column); |
| 1122 | } else { |
| 1123 | $default = $this->getDefaultValueDeclarationSQL($column); |
| 1124 | $charset = !empty($column['charset']) ? ' ' . $this->getColumnCharsetDeclarationSQL($column['charset']) : ''; |
| 1125 | $collation = !empty($column['collation']) ? ' ' . $this->getColumnCollationDeclarationSQL($column['collation']) : ''; |
| 1126 | $notnull = !empty($column['notnull']) ? ' NOT NULL' : ''; |
| 1127 | if (!empty($column['unique'])) { |
| 1128 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5656', 'The usage of the "unique" column property is deprecated. Use unique constraints instead.'); |
| 1129 | $unique = ' ' . $this->getUniqueFieldDeclarationSQL(); |
| 1130 | } else { |
| 1131 | $unique = ''; |
| 1132 | } |
| 1133 | if (!empty($column['check'])) { |
| 1134 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5656', 'The usage of the "check" column property is deprecated.'); |
| 1135 | $check = ' ' . $column['check']; |
| 1136 | } else { |
| 1137 | $check = ''; |
| 1138 | } |
| 1139 | $typeDecl = $column['type']->getSQLDeclaration($column, $this); |
| 1140 | $declaration = $typeDecl . $charset . $default . $notnull . $unique . $check . $collation; |
| 1141 | if ($this->supportsInlineColumnComments() && isset($column['comment']) && $column['comment'] !== '') { |
| 1142 | $declaration .= ' ' . $this->getInlineColumnCommentSQL($column['comment']); |
| 1143 | } |
| 1144 | } |
| 1145 | return $name . ' ' . $declaration; |
| 1146 | } |
| 1147 | public function getDecimalTypeDeclarationSQL(array $column) |
| 1148 | { |
| 1149 | if (empty($column['precision'])) { |
| 1150 | if (!isset($column['precision'])) { |
| 1151 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5637', 'Relying on the default decimal column precision is deprecated' . ', specify the precision explicitly.'); |
| 1152 | } |
| 1153 | $precision = 10; |
| 1154 | } else { |
| 1155 | $precision = $column['precision']; |
| 1156 | } |
| 1157 | if (empty($column['scale'])) { |
| 1158 | if (!isset($column['scale'])) { |
| 1159 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5637', 'Relying on the default decimal column scale is deprecated' . ', specify the scale explicitly.'); |
| 1160 | } |
| 1161 | $scale = 0; |
| 1162 | } else { |
| 1163 | $scale = $column['scale']; |
| 1164 | } |
| 1165 | return 'NUMERIC(' . $precision . ', ' . $scale . ')'; |
| 1166 | } |
| 1167 | public function getDefaultValueDeclarationSQL($column) |
| 1168 | { |
| 1169 | if (!isset($column['default'])) { |
| 1170 | return empty($column['notnull']) ? ' DEFAULT NULL' : ''; |
| 1171 | } |
| 1172 | $default = $column['default']; |
| 1173 | if (!isset($column['type'])) { |
| 1174 | return " DEFAULT '" . $default . "'"; |
| 1175 | } |
| 1176 | $type = $column['type']; |
| 1177 | if ($type instanceof Types\PhpIntegerMappingType) { |
| 1178 | return ' DEFAULT ' . $default; |
| 1179 | } |
| 1180 | if ($type instanceof Types\PhpDateTimeMappingType && $default === $this->getCurrentTimestampSQL()) { |
| 1181 | return ' DEFAULT ' . $this->getCurrentTimestampSQL(); |
| 1182 | } |
| 1183 | if ($type instanceof Types\TimeType && $default === $this->getCurrentTimeSQL()) { |
| 1184 | return ' DEFAULT ' . $this->getCurrentTimeSQL(); |
| 1185 | } |
| 1186 | if ($type instanceof Types\DateType && $default === $this->getCurrentDateSQL()) { |
| 1187 | return ' DEFAULT ' . $this->getCurrentDateSQL(); |
| 1188 | } |
| 1189 | if ($type instanceof Types\BooleanType) { |
| 1190 | return ' DEFAULT ' . $this->convertBooleans($default); |
| 1191 | } |
| 1192 | return ' DEFAULT ' . $this->quoteStringLiteral($default); |
| 1193 | } |
| 1194 | public function getCheckDeclarationSQL(array $definition) |
| 1195 | { |
| 1196 | $constraints = []; |
| 1197 | foreach ($definition as $column => $def) { |
| 1198 | if (is_string($def)) { |
| 1199 | $constraints[] = 'CHECK (' . $def . ')'; |
| 1200 | } else { |
| 1201 | if (isset($def['min'])) { |
| 1202 | $constraints[] = 'CHECK (' . $column . ' >= ' . $def['min'] . ')'; |
| 1203 | } |
| 1204 | if (isset($def['max'])) { |
| 1205 | $constraints[] = 'CHECK (' . $column . ' <= ' . $def['max'] . ')'; |
| 1206 | } |
| 1207 | } |
| 1208 | } |
| 1209 | return implode(', ', $constraints); |
| 1210 | } |
| 1211 | public function getUniqueConstraintDeclarationSQL($name, UniqueConstraint $constraint) |
| 1212 | { |
| 1213 | $columns = $constraint->getQuotedColumns($this); |
| 1214 | $name = new Identifier($name); |
| 1215 | if (count($columns) === 0) { |
| 1216 | throw new InvalidArgumentException("Incomplete definition. 'columns' required."); |
| 1217 | } |
| 1218 | $constraintFlags = array_merge(['UNIQUE'], array_map('strtoupper', $constraint->getFlags())); |
| 1219 | $constraintName = $name->getQuotedName($this); |
| 1220 | $columnListNames = $this->getColumnsFieldDeclarationListSQL($columns); |
| 1221 | return sprintf('CONSTRAINT %s %s (%s)', $constraintName, implode(' ', $constraintFlags), $columnListNames); |
| 1222 | } |
| 1223 | public function getIndexDeclarationSQL($name, Index $index) |
| 1224 | { |
| 1225 | $columns = $index->getColumns(); |
| 1226 | $name = new Identifier($name); |
| 1227 | if (count($columns) === 0) { |
| 1228 | throw new InvalidArgumentException("Incomplete definition. 'columns' required."); |
| 1229 | } |
| 1230 | return $this->getCreateIndexSQLFlags($index) . 'INDEX ' . $name->getQuotedName($this) . ' (' . $this->getIndexFieldDeclarationListSQL($index) . ')' . $this->getPartialIndexSQL($index); |
| 1231 | } |
| 1232 | public function getCustomTypeDeclarationSQL(array $column) |
| 1233 | { |
| 1234 | Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5527', '%s is deprecated.', __METHOD__); |
| 1235 | return $column['columnDefinition']; |
| 1236 | } |
| 1237 | public function getIndexFieldDeclarationListSQL(Index $index) : string |
| 1238 | { |
| 1239 | Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5527', '%s is deprecated.', __METHOD__); |
| 1240 | return implode(', ', $index->getQuotedColumns($this)); |
| 1241 | } |
| 1242 | public function getColumnsFieldDeclarationListSQL(array $columns) : string |
| 1243 | { |
| 1244 | Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5527', '%s is deprecated.', __METHOD__); |
| 1245 | $ret = []; |
| 1246 | foreach ($columns as $column => $definition) { |
| 1247 | if (is_array($definition)) { |
| 1248 | $ret[] = $column; |
| 1249 | } else { |
| 1250 | $ret[] = $definition; |
| 1251 | } |
| 1252 | } |
| 1253 | return implode(', ', $ret); |
| 1254 | } |
| 1255 | public function getTemporaryTableSQL() |
| 1256 | { |
| 1257 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4724', 'AbstractPlatform::getTemporaryTableSQL() is deprecated.'); |
| 1258 | return 'TEMPORARY'; |
| 1259 | } |
| 1260 | public function getTemporaryTableName($tableName) |
| 1261 | { |
| 1262 | return $tableName; |
| 1263 | } |
| 1264 | public function getForeignKeyDeclarationSQL(ForeignKeyConstraint $foreignKey) |
| 1265 | { |
| 1266 | $sql = $this->getForeignKeyBaseDeclarationSQL($foreignKey); |
| 1267 | $sql .= $this->getAdvancedForeignKeyOptionsSQL($foreignKey); |
| 1268 | return $sql; |
| 1269 | } |
| 1270 | public function getAdvancedForeignKeyOptionsSQL(ForeignKeyConstraint $foreignKey) |
| 1271 | { |
| 1272 | $query = ''; |
| 1273 | if ($foreignKey->hasOption('onUpdate')) { |
| 1274 | $query .= ' ON UPDATE ' . $this->getForeignKeyReferentialActionSQL($foreignKey->getOption('onUpdate')); |
| 1275 | } |
| 1276 | if ($foreignKey->hasOption('onDelete')) { |
| 1277 | $query .= ' ON DELETE ' . $this->getForeignKeyReferentialActionSQL($foreignKey->getOption('onDelete')); |
| 1278 | } |
| 1279 | return $query; |
| 1280 | } |
| 1281 | public function getForeignKeyReferentialActionSQL($action) |
| 1282 | { |
| 1283 | $upper = strtoupper($action); |
| 1284 | switch ($upper) { |
| 1285 | case 'CASCADE': |
| 1286 | case 'SET NULL': |
| 1287 | case 'NO ACTION': |
| 1288 | case 'RESTRICT': |
| 1289 | case 'SET DEFAULT': |
| 1290 | return $upper; |
| 1291 | default: |
| 1292 | throw new InvalidArgumentException('Invalid foreign key action: ' . $upper); |
| 1293 | } |
| 1294 | } |
| 1295 | public function getForeignKeyBaseDeclarationSQL(ForeignKeyConstraint $foreignKey) |
| 1296 | { |
| 1297 | $sql = ''; |
| 1298 | if (strlen($foreignKey->getName()) > 0) { |
| 1299 | $sql .= 'CONSTRAINT ' . $foreignKey->getQuotedName($this) . ' '; |
| 1300 | } |
| 1301 | $sql .= 'FOREIGN KEY ('; |
| 1302 | if (count($foreignKey->getLocalColumns()) === 0) { |
| 1303 | throw new InvalidArgumentException("Incomplete definition. 'local' required."); |
| 1304 | } |
| 1305 | if (count($foreignKey->getForeignColumns()) === 0) { |
| 1306 | throw new InvalidArgumentException("Incomplete definition. 'foreign' required."); |
| 1307 | } |
| 1308 | if (strlen($foreignKey->getForeignTableName()) === 0) { |
| 1309 | throw new InvalidArgumentException("Incomplete definition. 'foreignTable' required."); |
| 1310 | } |
| 1311 | return $sql . implode(', ', $foreignKey->getQuotedLocalColumns($this)) . ') REFERENCES ' . $foreignKey->getQuotedForeignTableName($this) . ' (' . implode(', ', $foreignKey->getQuotedForeignColumns($this)) . ')'; |
| 1312 | } |
| 1313 | public function getUniqueFieldDeclarationSQL() |
| 1314 | { |
| 1315 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4724', 'AbstractPlatform::getUniqueFieldDeclarationSQL() is deprecated. Use UNIQUE in SQL instead.'); |
| 1316 | return 'UNIQUE'; |
| 1317 | } |
| 1318 | public function getColumnCharsetDeclarationSQL($charset) |
| 1319 | { |
| 1320 | return ''; |
| 1321 | } |
| 1322 | public function getColumnCollationDeclarationSQL($collation) |
| 1323 | { |
| 1324 | return $this->supportsColumnCollation() ? 'COLLATE ' . $this->quoteSingleIdentifier($collation) : ''; |
| 1325 | } |
| 1326 | public function prefersIdentityColumns() |
| 1327 | { |
| 1328 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/1519', 'AbstractPlatform::prefersIdentityColumns() is deprecated.'); |
| 1329 | return \false; |
| 1330 | } |
| 1331 | public function convertBooleans($item) |
| 1332 | { |
| 1333 | if (is_array($item)) { |
| 1334 | foreach ($item as $k => $value) { |
| 1335 | if (!is_bool($value)) { |
| 1336 | continue; |
| 1337 | } |
| 1338 | $item[$k] = (int) $value; |
| 1339 | } |
| 1340 | } elseif (is_bool($item)) { |
| 1341 | $item = (int) $item; |
| 1342 | } |
| 1343 | return $item; |
| 1344 | } |
| 1345 | public function convertFromBoolean($item) |
| 1346 | { |
| 1347 | return $item === null ? null : (bool) $item; |
| 1348 | } |
| 1349 | public function convertBooleansToDatabaseValue($item) |
| 1350 | { |
| 1351 | return $this->convertBooleans($item); |
| 1352 | } |
| 1353 | public function getCurrentDateSQL() |
| 1354 | { |
| 1355 | return 'CURRENT_DATE'; |
| 1356 | } |
| 1357 | public function getCurrentTimeSQL() |
| 1358 | { |
| 1359 | return 'CURRENT_TIME'; |
| 1360 | } |
| 1361 | public function getCurrentTimestampSQL() |
| 1362 | { |
| 1363 | return 'CURRENT_TIMESTAMP'; |
| 1364 | } |
| 1365 | protected function _getTransactionIsolationLevelSQL($level) |
| 1366 | { |
| 1367 | switch ($level) { |
| 1368 | case TransactionIsolationLevel::READ_UNCOMMITTED: |
| 1369 | return 'READ UNCOMMITTED'; |
| 1370 | case TransactionIsolationLevel::READ_COMMITTED: |
| 1371 | return 'READ COMMITTED'; |
| 1372 | case TransactionIsolationLevel::REPEATABLE_READ: |
| 1373 | return 'REPEATABLE READ'; |
| 1374 | case TransactionIsolationLevel::SERIALIZABLE: |
| 1375 | return 'SERIALIZABLE'; |
| 1376 | default: |
| 1377 | throw new InvalidArgumentException('Invalid isolation level:' . $level); |
| 1378 | } |
| 1379 | } |
| 1380 | public function getListDatabasesSQL() |
| 1381 | { |
| 1382 | throw Exception::notSupported(__METHOD__); |
| 1383 | } |
| 1384 | public function getListNamespacesSQL() |
| 1385 | { |
| 1386 | Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/issues/4503', 'AbstractPlatform::getListNamespacesSQL() is deprecated,' . ' use AbstractSchemaManager::listSchemaNames() instead.'); |
| 1387 | throw Exception::notSupported(__METHOD__); |
| 1388 | } |
| 1389 | public function getListSequencesSQL($database) |
| 1390 | { |
| 1391 | throw Exception::notSupported(__METHOD__); |
| 1392 | } |
| 1393 | public function getListTableConstraintsSQL($table) |
| 1394 | { |
| 1395 | throw Exception::notSupported(__METHOD__); |
| 1396 | } |
| 1397 | public function getListTableColumnsSQL($table, $database = null) |
| 1398 | { |
| 1399 | throw Exception::notSupported(__METHOD__); |
| 1400 | } |
| 1401 | public function getListTablesSQL() |
| 1402 | { |
| 1403 | throw Exception::notSupported(__METHOD__); |
| 1404 | } |
| 1405 | public function getListUsersSQL() |
| 1406 | { |
| 1407 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4724', 'AbstractPlatform::getListUsersSQL() is deprecated.'); |
| 1408 | throw Exception::notSupported(__METHOD__); |
| 1409 | } |
| 1410 | public function getListViewsSQL($database) |
| 1411 | { |
| 1412 | throw Exception::notSupported(__METHOD__); |
| 1413 | } |
| 1414 | public function getListTableIndexesSQL($table, $database = null) |
| 1415 | { |
| 1416 | throw Exception::notSupported(__METHOD__); |
| 1417 | } |
| 1418 | public function getListTableForeignKeysSQL($table) |
| 1419 | { |
| 1420 | throw Exception::notSupported(__METHOD__); |
| 1421 | } |
| 1422 | public function getCreateViewSQL($name, $sql) |
| 1423 | { |
| 1424 | return 'CREATE VIEW ' . $name . ' AS ' . $sql; |
| 1425 | } |
| 1426 | public function getDropViewSQL($name) |
| 1427 | { |
| 1428 | return 'DROP VIEW ' . $name; |
| 1429 | } |
| 1430 | public function getSequenceNextValSQL($sequence) |
| 1431 | { |
| 1432 | throw Exception::notSupported(__METHOD__); |
| 1433 | } |
| 1434 | public function getCreateDatabaseSQL($name) |
| 1435 | { |
| 1436 | if (!$this->supportsCreateDropDatabase()) { |
| 1437 | throw Exception::notSupported(__METHOD__); |
| 1438 | } |
| 1439 | return 'CREATE DATABASE ' . $name; |
| 1440 | } |
| 1441 | public function getDropDatabaseSQL($name) |
| 1442 | { |
| 1443 | if (!$this->supportsCreateDropDatabase()) { |
| 1444 | throw Exception::notSupported(__METHOD__); |
| 1445 | } |
| 1446 | return 'DROP DATABASE ' . $name; |
| 1447 | } |
| 1448 | public function getSetTransactionIsolationSQL($level) |
| 1449 | { |
| 1450 | throw Exception::notSupported(__METHOD__); |
| 1451 | } |
| 1452 | public function getDateTimeTypeDeclarationSQL(array $column) |
| 1453 | { |
| 1454 | throw Exception::notSupported(__METHOD__); |
| 1455 | } |
| 1456 | public function getDateTimeTzTypeDeclarationSQL(array $column) |
| 1457 | { |
| 1458 | return $this->getDateTimeTypeDeclarationSQL($column); |
| 1459 | } |
| 1460 | public function getDateTypeDeclarationSQL(array $column) |
| 1461 | { |
| 1462 | throw Exception::notSupported(__METHOD__); |
| 1463 | } |
| 1464 | public function getTimeTypeDeclarationSQL(array $column) |
| 1465 | { |
| 1466 | throw Exception::notSupported(__METHOD__); |
| 1467 | } |
| 1468 | public function getFloatDeclarationSQL(array $column) |
| 1469 | { |
| 1470 | return 'DOUBLE PRECISION'; |
| 1471 | } |
| 1472 | public function getDefaultTransactionIsolationLevel() |
| 1473 | { |
| 1474 | return TransactionIsolationLevel::READ_COMMITTED; |
| 1475 | } |
| 1476 | public function supportsSequences() |
| 1477 | { |
| 1478 | return \false; |
| 1479 | } |
| 1480 | public function supportsIdentityColumns() |
| 1481 | { |
| 1482 | return \false; |
| 1483 | } |
| 1484 | public function usesSequenceEmulatedIdentityColumns() |
| 1485 | { |
| 1486 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5513', '%s is deprecated.', __METHOD__); |
| 1487 | return \false; |
| 1488 | } |
| 1489 | public function getIdentitySequenceName($tableName, $columnName) |
| 1490 | { |
| 1491 | throw Exception::notSupported(__METHOD__); |
| 1492 | } |
| 1493 | public function supportsIndexes() |
| 1494 | { |
| 1495 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4724', 'AbstractPlatform::supportsIndexes() is deprecated.'); |
| 1496 | return \true; |
| 1497 | } |
| 1498 | public function supportsPartialIndexes() |
| 1499 | { |
| 1500 | return \false; |
| 1501 | } |
| 1502 | public function supportsColumnLengthIndexes() : bool |
| 1503 | { |
| 1504 | return \false; |
| 1505 | } |
| 1506 | public function supportsAlterTable() |
| 1507 | { |
| 1508 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4724', 'AbstractPlatform::supportsAlterTable() is deprecated. All platforms must implement altering tables.'); |
| 1509 | return \true; |
| 1510 | } |
| 1511 | public function supportsTransactions() |
| 1512 | { |
| 1513 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4724', 'AbstractPlatform::supportsTransactions() is deprecated.'); |
| 1514 | return \true; |
| 1515 | } |
| 1516 | public function supportsSavepoints() |
| 1517 | { |
| 1518 | return \true; |
| 1519 | } |
| 1520 | public function supportsReleaseSavepoints() |
| 1521 | { |
| 1522 | return $this->supportsSavepoints(); |
| 1523 | } |
| 1524 | public function supportsPrimaryConstraints() |
| 1525 | { |
| 1526 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4724', 'AbstractPlatform::supportsPrimaryConstraints() is deprecated.'); |
| 1527 | return \true; |
| 1528 | } |
| 1529 | public function supportsForeignKeyConstraints() |
| 1530 | { |
| 1531 | Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5409', 'AbstractPlatform::supportsForeignKeyConstraints() is deprecated.'); |
| 1532 | return \true; |
| 1533 | } |
| 1534 | public function supportsSchemas() |
| 1535 | { |
| 1536 | return \false; |
| 1537 | } |
| 1538 | public function canEmulateSchemas() |
| 1539 | { |
| 1540 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4805', 'AbstractPlatform::canEmulateSchemas() is deprecated.'); |
| 1541 | return \false; |
| 1542 | } |
| 1543 | public function getDefaultSchemaName() |
| 1544 | { |
| 1545 | throw Exception::notSupported(__METHOD__); |
| 1546 | } |
| 1547 | public function supportsCreateDropDatabase() |
| 1548 | { |
| 1549 | Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5513', '%s is deprecated.', __METHOD__); |
| 1550 | return \true; |
| 1551 | } |
| 1552 | public function supportsGettingAffectedRows() |
| 1553 | { |
| 1554 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4724', 'AbstractPlatform::supportsGettingAffectedRows() is deprecated.'); |
| 1555 | return \true; |
| 1556 | } |
| 1557 | public function supportsInlineColumnComments() |
| 1558 | { |
| 1559 | return \false; |
| 1560 | } |
| 1561 | public function supportsCommentOnStatement() |
| 1562 | { |
| 1563 | return \false; |
| 1564 | } |
| 1565 | public function hasNativeGuidType() |
| 1566 | { |
| 1567 | Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5509', '%s is deprecated.', __METHOD__); |
| 1568 | return \false; |
| 1569 | } |
| 1570 | public function hasNativeJsonType() |
| 1571 | { |
| 1572 | Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5509', '%s is deprecated.', __METHOD__); |
| 1573 | return \false; |
| 1574 | } |
| 1575 | public function supportsViews() |
| 1576 | { |
| 1577 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4724', 'AbstractPlatform::supportsViews() is deprecated. All platforms must implement support for views.'); |
| 1578 | return \true; |
| 1579 | } |
| 1580 | public function supportsColumnCollation() |
| 1581 | { |
| 1582 | return \false; |
| 1583 | } |
| 1584 | public function getDateTimeFormatString() |
| 1585 | { |
| 1586 | return 'Y-m-d H:i:s'; |
| 1587 | } |
| 1588 | public function getDateTimeTzFormatString() |
| 1589 | { |
| 1590 | return 'Y-m-d H:i:s'; |
| 1591 | } |
| 1592 | public function getDateFormatString() |
| 1593 | { |
| 1594 | return 'Y-m-d'; |
| 1595 | } |
| 1596 | public function getTimeFormatString() |
| 1597 | { |
| 1598 | return 'H:i:s'; |
| 1599 | } |
| 1600 | public final function modifyLimitQuery($query, $limit, $offset = 0) : string |
| 1601 | { |
| 1602 | if ($offset < 0) { |
| 1603 | throw new Exception(sprintf('Offset must be a positive integer or zero, %d given', $offset)); |
| 1604 | } |
| 1605 | if ($offset > 0 && !$this->supportsLimitOffset()) { |
| 1606 | throw new Exception(sprintf('Platform %s does not support offset values in limit queries.', $this->getName())); |
| 1607 | } |
| 1608 | if ($limit !== null) { |
| 1609 | $limit = (int) $limit; |
| 1610 | } |
| 1611 | return $this->doModifyLimitQuery($query, $limit, (int) $offset); |
| 1612 | } |
| 1613 | protected function doModifyLimitQuery($query, $limit, $offset) |
| 1614 | { |
| 1615 | if ($limit !== null) { |
| 1616 | $query .= sprintf(' LIMIT %d', $limit); |
| 1617 | } |
| 1618 | if ($offset > 0) { |
| 1619 | $query .= sprintf(' OFFSET %d', $offset); |
| 1620 | } |
| 1621 | return $query; |
| 1622 | } |
| 1623 | public function supportsLimitOffset() |
| 1624 | { |
| 1625 | Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4724', 'AbstractPlatform::supportsViews() is deprecated.' . ' All platforms must implement support for offsets in modify limit clauses.'); |
| 1626 | return \true; |
| 1627 | } |
| 1628 | public function getMaxIdentifierLength() |
| 1629 | { |
| 1630 | return 63; |
| 1631 | } |
| 1632 | public function getEmptyIdentityInsertSQL($quotedTableName, $quotedIdentifierColumnName) |
| 1633 | { |
| 1634 | return 'INSERT INTO ' . $quotedTableName . ' (' . $quotedIdentifierColumnName . ') VALUES (null)'; |
| 1635 | } |
| 1636 | public function getTruncateTableSQL($tableName, $cascade = \false) |
| 1637 | { |
| 1638 | $tableIdentifier = new Identifier($tableName); |
| 1639 | return 'TRUNCATE ' . $tableIdentifier->getQuotedName($this); |
| 1640 | } |
| 1641 | public function getDummySelectSQL() |
| 1642 | { |
| 1643 | $expression = func_num_args() > 0 ? func_get_arg(0) : '1'; |
| 1644 | return sprintf('SELECT %s', $expression); |
| 1645 | } |
| 1646 | public function createSavePoint($savepoint) |
| 1647 | { |
| 1648 | return 'SAVEPOINT ' . $savepoint; |
| 1649 | } |
| 1650 | public function releaseSavePoint($savepoint) |
| 1651 | { |
| 1652 | return 'RELEASE SAVEPOINT ' . $savepoint; |
| 1653 | } |
| 1654 | public function rollbackSavePoint($savepoint) |
| 1655 | { |
| 1656 | return 'ROLLBACK TO SAVEPOINT ' . $savepoint; |
| 1657 | } |
| 1658 | public final function getReservedKeywordsList() : KeywordList |
| 1659 | { |
| 1660 | // Store the instance so it doesn't need to be generated on every request. |
| 1661 | return $this->_keywords ??= $this->createReservedKeywordsList(); |
| 1662 | } |
| 1663 | protected function createReservedKeywordsList() : KeywordList |
| 1664 | { |
| 1665 | $class = $this->getReservedKeywordsClass(); |
| 1666 | $keywords = new $class(); |
| 1667 | if (!$keywords instanceof KeywordList) { |
| 1668 | throw Exception::notSupported(__METHOD__); |
| 1669 | } |
| 1670 | return $keywords; |
| 1671 | } |
| 1672 | protected function getReservedKeywordsClass() |
| 1673 | { |
| 1674 | Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/issues/4510', 'AbstractPlatform::getReservedKeywordsClass() is deprecated,' . ' use AbstractPlatform::createReservedKeywordsList() instead.'); |
| 1675 | throw Exception::notSupported(__METHOD__); |
| 1676 | } |
| 1677 | public function quoteStringLiteral($str) |
| 1678 | { |
| 1679 | $c = $this->getStringLiteralQuoteCharacter(); |
| 1680 | return $c . str_replace($c, $c . $c, $str) . $c; |
| 1681 | } |
| 1682 | public function getStringLiteralQuoteCharacter() |
| 1683 | { |
| 1684 | Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5388', 'AbstractPlatform::getStringLiteralQuoteCharacter() is deprecated.' . ' Use quoteStringLiteral() instead.'); |
| 1685 | return "'"; |
| 1686 | } |
| 1687 | public final function escapeStringForLike(string $inputString, string $escapeChar) : string |
| 1688 | { |
| 1689 | return preg_replace('~([' . preg_quote($this->getLikeWildcardCharacters() . $escapeChar, '~') . '])~u', addcslashes($escapeChar, '\\') . '$1', $inputString); |
| 1690 | } |
| 1691 | private function columnToArray(Column $column) : array |
| 1692 | { |
| 1693 | $name = $column->getQuotedName($this); |
| 1694 | return array_merge($column->toArray(), ['name' => $name, 'version' => $column->hasPlatformOption('version') ? $column->getPlatformOption('version') : \false, 'comment' => $this->getColumnComment($column)]); |
| 1695 | } |
| 1696 | public function createSQLParser() : Parser |
| 1697 | { |
| 1698 | return new Parser(\false); |
| 1699 | } |
| 1700 | protected function getLikeWildcardCharacters() : string |
| 1701 | { |
| 1702 | return '%_'; |
| 1703 | } |
| 1704 | public function columnsEqual(Column $column1, Column $column2) : bool |
| 1705 | { |
| 1706 | $column1Array = $this->columnToArray($column1); |
| 1707 | $column2Array = $this->columnToArray($column2); |
| 1708 | // ignore explicit columnDefinition since it's not set on the Column generated by the SchemaManager |
| 1709 | unset($column1Array['columnDefinition']); |
| 1710 | unset($column2Array['columnDefinition']); |
| 1711 | if ($this->getColumnDeclarationSQL('', $column1Array) !== $this->getColumnDeclarationSQL('', $column2Array)) { |
| 1712 | return \false; |
| 1713 | } |
| 1714 | if (!$this->columnDeclarationsMatch($column1, $column2)) { |
| 1715 | return \false; |
| 1716 | } |
| 1717 | // If the platform supports inline comments, all comparison is already done above |
| 1718 | if ($this->supportsInlineColumnComments()) { |
| 1719 | return \true; |
| 1720 | } |
| 1721 | if ($column1->getComment() !== $column2->getComment()) { |
| 1722 | return \false; |
| 1723 | } |
| 1724 | // If disableTypeComments is true, we do not need to check types, all comparison is already done above |
| 1725 | if ($this->disableTypeComments) { |
| 1726 | return \true; |
| 1727 | } |
| 1728 | return $column1->getType() === $column2->getType(); |
| 1729 | } |
| 1730 | private function columnDeclarationsMatch(Column $column1, Column $column2) : bool |
| 1731 | { |
| 1732 | return !($column1->hasPlatformOption('declarationMismatch') || $column2->hasPlatformOption('declarationMismatch')); |
| 1733 | } |
| 1734 | public function createSchemaManager(Connection $connection) : AbstractSchemaManager |
| 1735 | { |
| 1736 | throw Exception::notSupported(__METHOD__); |
| 1737 | } |
| 1738 | } |
| 1739 |