From cfa1afadaa5f348b450b76eab5cebb6ddb2f2ada Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Mon, 18 Jul 2022 16:59:05 +0200 Subject: [PATCH] make platform configureable --- src/Platforms/SqlitePlatform.php | 35 ++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/src/Platforms/SqlitePlatform.php b/src/Platforms/SqlitePlatform.php index 9ab23d50b00..561735d0081 100644 --- a/src/Platforms/SqlitePlatform.php +++ b/src/Platforms/SqlitePlatform.php @@ -39,6 +39,9 @@ */ class SqlitePlatform extends AbstractPlatform { + /** @var bool True for BC reasons, option to be removed in DBAL 4.0 */ + private $replaceDotInTableName = true; + /** * {@inheritDoc} */ @@ -329,14 +332,20 @@ protected function _getCommonIntegerTypeDeclarationSQL(array $column) } /** - * To backport https://github.com/doctrine/dbal/pull/4804 override - * this method to return unchanged $tableName. + * To backport https://github.com/doctrine/dbal/pull/4804 set $replaceDotInTableName to false. * - * Removed in DBAL v4.0. + * Removed in DBAL 4.0. */ - protected function emulateSchemaInTableName(string $tableName): string + public function setReplaceDotInTableName(bool $replaceDotInTableName): void + { + $this->replaceDotInTableName = $replaceDotInTableName; + } + + private function replaceDotInTableName(string $tableName): string { - return str_replace('.', '__', $tableName); + return $this->replaceDotInTableName + ? str_replace('.', '__', $tableName) + : $tableName; } /** @@ -346,7 +355,7 @@ public function getForeignKeyDeclarationSQL(ForeignKeyConstraint $foreignKey) { return parent::getForeignKeyDeclarationSQL(new ForeignKeyConstraint( $foreignKey->getQuotedLocalColumns($this), - $this->emulateSchemaInTableName($foreignKey->getQuotedForeignTableName($this)), + $this->replaceDotInTableName($foreignKey->getQuotedForeignTableName($this)), $foreignKey->getQuotedForeignColumns($this), $foreignKey->getName(), $foreignKey->getOptions() @@ -358,7 +367,7 @@ public function getForeignKeyDeclarationSQL(ForeignKeyConstraint $foreignKey) */ protected function _getCreateTableSQL($name, array $columns, array $options = []) { - $name = $this->emulateSchemaInTableName($name); + $name = $this->replaceDotInTableName($name); $queryFields = $this->getColumnDeclarationListSQL($columns); if (isset($options['uniqueConstraints']) && ! empty($options['uniqueConstraints'])) { @@ -472,7 +481,7 @@ public function getClobTypeDeclarationSQL(array $column) */ public function getListTableConstraintsSQL($table) { - $table = $this->emulateSchemaInTableName($table); + $table = $this->replaceDotInTableName($table); return sprintf( "SELECT sql FROM sqlite_master WHERE type='index' AND tbl_name = %s AND sql NOT NULL ORDER BY name", @@ -485,7 +494,7 @@ public function getListTableConstraintsSQL($table) */ public function getListTableColumnsSQL($table, $database = null) { - $table = $this->emulateSchemaInTableName($table); + $table = $this->replaceDotInTableName($table); return sprintf('PRAGMA table_info(%s)', $this->quoteStringLiteral($table)); } @@ -495,7 +504,7 @@ public function getListTableColumnsSQL($table, $database = null) */ public function getListTableIndexesSQL($table, $database = null) { - $table = $this->emulateSchemaInTableName($table); + $table = $this->replaceDotInTableName($table); return sprintf('PRAGMA index_list(%s)', $this->quoteStringLiteral($table)); } @@ -597,7 +606,7 @@ public function getName() public function getTruncateTableSQL($tableName, $cascade = false) { $tableIdentifier = new Identifier($tableName); - $tableName = $this->emulateSchemaInTableName($tableIdentifier->getQuotedName($this)); + $tableName = $this->replaceDotInTableName($tableIdentifier->getQuotedName($this)); return 'DELETE FROM ' . $tableName; } @@ -803,7 +812,7 @@ public function getBlobTypeDeclarationSQL(array $column) */ public function getTemporaryTableName($tableName) { - $tableName = $this->emulateSchemaInTableName($tableName); + $tableName = $this->replaceDotInTableName($tableName); return $tableName; } @@ -892,7 +901,7 @@ public function getCreateTableSQL(Table $table, $createFlags = null) */ public function getListTableForeignKeysSQL($table, $database = null) { - $table = $this->emulateSchemaInTableName($table); + $table = $this->replaceDotInTableName($table); return sprintf('PRAGMA foreign_key_list(%s)', $this->quoteStringLiteral($table)); }