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
MariaDb1043Platform.php
75 lines
| 1 | <?php |
| 2 | namespace MailPoetVendor\Doctrine\DBAL\Platforms; |
| 3 | if (!defined('ABSPATH')) exit; |
| 4 | use MailPoetVendor\Doctrine\DBAL\Types\JsonType; |
| 5 | use MailPoetVendor\Doctrine\Deprecations\Deprecation; |
| 6 | use function sprintf; |
| 7 | class MariaDb1043Platform extends MariaDb1027Platform |
| 8 | { |
| 9 | public function getJsonTypeDeclarationSQL(array $column) : string |
| 10 | { |
| 11 | return 'JSON'; |
| 12 | } |
| 13 | public function getListTableColumnsSQL($table, $database = null) : string |
| 14 | { |
| 15 | // @todo 4.0 - call getColumnTypeSQLSnippet() instead |
| 16 | [$columnTypeSQL, $joinCheckConstraintSQL] = $this->getColumnTypeSQLSnippets('c', $database); |
| 17 | return sprintf(<<<SQL |
| 18 | SELECT c.COLUMN_NAME AS Field, |
| 19 | {$columnTypeSQL} AS Type, |
| 20 | c.IS_NULLABLE AS `Null`, |
| 21 | c.COLUMN_KEY AS `Key`, |
| 22 | c.COLUMN_DEFAULT AS `Default`, |
| 23 | c.EXTRA AS Extra, |
| 24 | c.COLUMN_COMMENT AS Comment, |
| 25 | c.CHARACTER_SET_NAME AS CharacterSet, |
| 26 | c.COLLATION_NAME AS Collation |
| 27 | FROM information_schema.COLUMNS c |
| 28 | {$joinCheckConstraintSQL} |
| 29 | WHERE c.TABLE_SCHEMA = %s |
| 30 | AND c.TABLE_NAME = %s |
| 31 | ORDER BY ORDINAL_POSITION ASC; |
| 32 | SQL |
| 33 | , $this->getDatabaseNameSQL($database), $this->quoteStringLiteral($table)); |
| 34 | } |
| 35 | public function getColumnTypeSQLSnippet(string $tableAlias = 'c', ?string $databaseName = null) : string |
| 36 | { |
| 37 | if ($this->getJsonTypeDeclarationSQL([]) !== 'JSON') { |
| 38 | return parent::getColumnTypeSQLSnippet($tableAlias, $databaseName); |
| 39 | } |
| 40 | if ($databaseName === null) { |
| 41 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/6215', 'Not passing a database name to methods "getColumnTypeSQLSnippet()", ' . '"getColumnTypeSQLSnippets()", and "getListTableColumnsSQL()" of "%s" is deprecated.', self::class); |
| 42 | } |
| 43 | $subQueryAlias = 'i_' . $tableAlias; |
| 44 | $databaseName = $this->getDatabaseNameSQL($databaseName); |
| 45 | // The check for `CONSTRAINT_SCHEMA = $databaseName` is mandatory here to prevent performance issues |
| 46 | return <<<SQL |
| 47 | IF( |
| 48 | {$tableAlias}.COLUMN_TYPE = 'longtext' |
| 49 | AND EXISTS( |
| 50 | SELECT * from information_schema.CHECK_CONSTRAINTS {$subQueryAlias} |
| 51 | WHERE {$subQueryAlias}.CONSTRAINT_SCHEMA = {$databaseName} |
| 52 | AND {$subQueryAlias}.TABLE_NAME = {$tableAlias}.TABLE_NAME |
| 53 | AND {$subQueryAlias}.CHECK_CLAUSE = CONCAT( |
| 54 | 'json_valid(`', |
| 55 | {$tableAlias}.COLUMN_NAME, |
| 56 | '`)' |
| 57 | ) |
| 58 | ), |
| 59 | 'json', |
| 60 | {$tableAlias}.COLUMN_TYPE |
| 61 | ) |
| 62 | SQL; |
| 63 | } |
| 64 | public function getColumnDeclarationSQL($name, array $column) |
| 65 | { |
| 66 | // MariaDb forces column collation to utf8mb4_bin where the column was declared as JSON so ignore |
| 67 | // collation and character set for json columns as attempting to set them can cause an error. |
| 68 | if ($this->getJsonTypeDeclarationSQL([]) === 'JSON' && ($column['type'] ?? null) instanceof JsonType) { |
| 69 | unset($column['collation']); |
| 70 | unset($column['charset']); |
| 71 | } |
| 72 | return parent::getColumnDeclarationSQL($name, $column); |
| 73 | } |
| 74 | } |
| 75 |