Skip to content

Commit

Permalink
make platform configureable
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Jul 18, 2022
1 parent 583d56a commit cfa1afa
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions src/Platforms/SqlitePlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}
*/
Expand Down Expand Up @@ -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;
}

/**
Expand All @@ -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()
Expand All @@ -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'])) {
Expand Down Expand Up @@ -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",
Expand All @@ -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));
}
Expand All @@ -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));
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -803,7 +812,7 @@ public function getBlobTypeDeclarationSQL(array $column)
*/
public function getTemporaryTableName($tableName)
{
$tableName = $this->emulateSchemaInTableName($tableName);
$tableName = $this->replaceDotInTableName($tableName);

return $tableName;
}
Expand Down Expand Up @@ -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));
}
Expand Down

0 comments on commit cfa1afa

Please sign in to comment.