Commit e48d65df authored by Semih Serhat Karakaya's avatar Semih Serhat Karakaya

respect to platform restrictions when creating an identfier name for oracle

parent 9daede40
...@@ -586,6 +586,22 @@ END;'; ...@@ -586,6 +586,22 @@ END;';
return $identifier->isQuoted() ? $identifier : new Identifier(strtoupper($name)); return $identifier->isQuoted() ? $identifier : new Identifier(strtoupper($name));
} }
/**
* Adds suffix to identifier,
*
* if the new string exceeds max identifier length,
* keeps $suffix, cuts from $identifier as much as the part exceeding.
*/
private function addSuffix(string $identifier, string $suffix) : string
{
$maxPossibleLengthWithoutSuffix = $this->getMaxIdentifierLength() - strlen($suffix);
if (strlen($identifier) > $maxPossibleLengthWithoutSuffix) {
$identifier = substr($identifier, 0, $maxPossibleLengthWithoutSuffix);
}
return $identifier . $suffix;
}
/** /**
* Returns the autoincrement primary key identifier name for the given table identifier. * Returns the autoincrement primary key identifier name for the given table identifier.
* *
...@@ -598,7 +614,7 @@ END;'; ...@@ -598,7 +614,7 @@ END;';
*/ */
private function getAutoincrementIdentifierName(Identifier $table) private function getAutoincrementIdentifierName(Identifier $table)
{ {
$identifierName = $table->getName() . '_AI_PK'; $identifierName = $this->addSuffix($table->getName(), '_AI_PK');
return $table->isQuoted() return $table->isQuoted()
? $this->quoteSingleIdentifier($identifierName) ? $this->quoteSingleIdentifier($identifierName)
...@@ -966,7 +982,7 @@ SQL ...@@ -966,7 +982,7 @@ SQL
$table = new Identifier($tableName); $table = new Identifier($tableName);
// No usage of column name to preserve BC compatibility with <2.5 // No usage of column name to preserve BC compatibility with <2.5
$identitySequenceName = $table->getName() . '_SEQ'; $identitySequenceName = $this->addSuffix($table->getName(), '_SEQ');
if ($table->isQuoted()) { if ($table->isQuoted()) {
$identitySequenceName = '"' . $identitySequenceName . '"'; $identitySequenceName = '"' . $identitySequenceName . '"';
......
<?php
namespace Doctrine\Tests\DBAL\Functional\Platform;
use Doctrine\DBAL\Schema\Table;
use Doctrine\Tests\DbalFunctionalTestCase;
use function str_repeat;
/**
* This class holds tests that make sure generated SQL statements respect to platform restrictions
* like maximum element name length
*/
class PlatformRestrictionsTest extends DbalFunctionalTestCase
{
/**
* Tests element names that are at the boundary of the identifier length limit.
* Ensures generated auto-increment identifier name respects to platform restrictions.
*/
public function testMaxIdentifierLengthLimitWithAutoIncrement() : void
{
$platform = $this->connection->getDatabasePlatform();
$tableName = str_repeat('x', $platform->getMaxIdentifierLength());
$columnName = str_repeat('y', $platform->getMaxIdentifierLength());
$table = new Table($tableName);
$table->addColumn($columnName, 'integer', ['autoincrement' => true]);
$table->setPrimaryKey([$columnName]);
$this->connection->getSchemaManager()->dropAndCreateTable($table);
$createdTable = $this->connection->getSchemaManager()->listTableDetails($tableName);
$this->assertTrue($createdTable->hasColumn($columnName));
$this->assertTrue($createdTable->hasPrimaryKey());
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment