updated-packages

This commit is contained in:
RafficMohammed
2023-01-08 00:13:22 +05:30
parent 3ff7df7487
commit da241bacb6
12659 changed files with 563377 additions and 510538 deletions

View File

@@ -3,17 +3,20 @@
namespace Doctrine\DBAL\Schema;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver\DriverException;
use Doctrine\DBAL\Driver\Exception;
use Doctrine\DBAL\Platforms\SQLServerPlatform;
use Doctrine\DBAL\Types\Type;
use PDOException;
use Throwable;
use function assert;
use function count;
use function in_array;
use function preg_replace;
use function is_string;
use function preg_match;
use function sprintf;
use function str_replace;
use function strpos;
use function strtok;
use function trim;
/**
* SQL Server Schema Manager.
@@ -29,8 +32,9 @@ class SQLServerSchemaManager extends AbstractSchemaManager
parent::dropDatabase($database);
} catch (DBALException $exception) {
$exception = $exception->getPrevious();
assert($exception instanceof Throwable);
if (! $exception instanceof DriverException) {
if (! $exception instanceof Exception) {
throw $exception;
}
@@ -61,7 +65,9 @@ class SQLServerSchemaManager extends AbstractSchemaManager
*/
protected function _getPortableTableColumnDefinition($tableColumn)
{
$dbType = strtok($tableColumn['type'], '(), ');
$dbType = strtok($tableColumn['type'], '(), ');
assert(is_string($dbType));
$fixed = null;
$length = (int) $tableColumn['length'];
$default = $tableColumn['default'];
@@ -71,15 +77,7 @@ class SQLServerSchemaManager extends AbstractSchemaManager
}
if ($default !== null) {
while ($default !== ($default2 = preg_replace('/^\((.*)\)$/', '$1', $default))) {
$default = trim($default2, "'");
if ($default !== 'getdate()') {
continue;
}
$default = $this->_platform->getCurrentTimestampSQL();
}
$default = $this->parseDefaultExpression($default);
}
switch ($dbType) {
@@ -89,11 +87,13 @@ class SQLServerSchemaManager extends AbstractSchemaManager
// Unicode data requires 2 bytes per character
$length /= 2;
break;
case 'varchar':
// TEXT type is returned as VARCHAR(MAX) with a length of -1
if ($length === -1) {
$dbType = 'text';
}
break;
}
@@ -109,7 +109,7 @@ class SQLServerSchemaManager extends AbstractSchemaManager
'length' => $length === 0 || ! in_array($type, ['text', 'string']) ? null : $length,
'unsigned' => false,
'fixed' => (bool) $fixed,
'default' => $default !== 'NULL' ? $default : null,
'default' => $default,
'notnull' => (bool) $tableColumn['notnull'],
'scale' => $tableColumn['scale'],
'precision' => $tableColumn['precision'],
@@ -126,6 +126,27 @@ class SQLServerSchemaManager extends AbstractSchemaManager
return $column;
}
private function parseDefaultExpression(string $value): ?string
{
while (preg_match('/^\((.*)\)$/s', $value, $matches)) {
$value = $matches[1];
}
if ($value === 'NULL') {
return null;
}
if (preg_match('/^\'(.*)\'$/s', $value, $matches)) {
$value = str_replace("''", "'", $matches[1]);
}
if ($value === 'getdate()') {
return $this->_platform->getCurrentTimestampSQL();
}
return $value;
}
/**
* {@inheritdoc}
*/
@@ -134,20 +155,22 @@ class SQLServerSchemaManager extends AbstractSchemaManager
$foreignKeys = [];
foreach ($tableForeignKeys as $tableForeignKey) {
if (! isset($foreignKeys[$tableForeignKey['ForeignKey']])) {
$foreignKeys[$tableForeignKey['ForeignKey']] = [
$name = $tableForeignKey['ForeignKey'];
if (! isset($foreignKeys[$name])) {
$foreignKeys[$name] = [
'local_columns' => [$tableForeignKey['ColumnName']],
'foreign_table' => $tableForeignKey['ReferenceTableName'],
'foreign_columns' => [$tableForeignKey['ReferenceColumnName']],
'name' => $tableForeignKey['ForeignKey'],
'name' => $name,
'options' => [
'onUpdate' => str_replace('_', ' ', $tableForeignKey['update_referential_action_desc']),
'onDelete' => str_replace('_', ' ', $tableForeignKey['delete_referential_action_desc']),
],
];
} else {
$foreignKeys[$tableForeignKey['ForeignKey']]['local_columns'][] = $tableForeignKey['ColumnName'];
$foreignKeys[$tableForeignKey['ForeignKey']]['foreign_columns'][] = $tableForeignKey['ReferenceColumnName'];
$foreignKeys[$name]['local_columns'][] = $tableForeignKey['ColumnName'];
$foreignKeys[$name]['foreign_columns'][] = $tableForeignKey['ReferenceColumnName'];
}
}
@@ -157,15 +180,15 @@ class SQLServerSchemaManager extends AbstractSchemaManager
/**
* {@inheritdoc}
*/
protected function _getPortableTableIndexesList($tableIndexRows, $tableName = null)
protected function _getPortableTableIndexesList($tableIndexes, $tableName = null)
{
foreach ($tableIndexRows as &$tableIndex) {
foreach ($tableIndexes as &$tableIndex) {
$tableIndex['non_unique'] = (bool) $tableIndex['non_unique'];
$tableIndex['primary'] = (bool) $tableIndex['primary'];
$tableIndex['flags'] = $tableIndex['flags'] ? [$tableIndex['flags']] : null;
}
return parent::_getPortableTableIndexesList($tableIndexRows, $tableName);
return parent::_getPortableTableIndexesList($tableIndexes, $tableName);
}
/**
@@ -216,7 +239,7 @@ class SQLServerSchemaManager extends AbstractSchemaManager
protected function _getPortableViewDefinition($view)
{
// @todo
return new View($view['name'], null);
return new View($view['name'], '');
}
/**
@@ -227,13 +250,7 @@ class SQLServerSchemaManager extends AbstractSchemaManager
$sql = $this->_platform->getListTableIndexesSQL($table, $this->_conn->getDatabase());
try {
$tableIndexes = $this->_conn->fetchAll($sql);
} catch (PDOException $e) {
if ($e->getCode() === 'IMSSP') {
return [];
}
throw $e;
$tableIndexes = $this->_conn->fetchAllAssociative($sql);
} catch (DBALException $e) {
if (strpos($e->getMessage(), 'SQLSTATE [01000, 15472]') === 0) {
return [];
@@ -253,7 +270,7 @@ class SQLServerSchemaManager extends AbstractSchemaManager
if (count($tableDiff->removedColumns) > 0) {
foreach ($tableDiff->removedColumns as $col) {
$columnConstraintSql = $this->getColumnConstraintSQL($tableDiff->name, $col->getName());
foreach ($this->_conn->fetchAll($columnConstraintSql) as $constraint) {
foreach ($this->_conn->fetchAllAssociative($columnConstraintSql) as $constraint) {
$this->_conn->exec(
sprintf(
'ALTER TABLE %s DROP CONSTRAINT %s',
@@ -278,11 +295,11 @@ class SQLServerSchemaManager extends AbstractSchemaManager
*/
private function getColumnConstraintSQL($table, $column)
{
return "SELECT SysObjects.[Name]
FROM SysObjects INNER JOIN (SELECT [Name],[ID] FROM SysObjects WHERE XType = 'U') AS Tab
ON Tab.[ID] = Sysobjects.[Parent_Obj]
INNER JOIN sys.default_constraints DefCons ON DefCons.[object_id] = Sysobjects.[ID]
INNER JOIN SysColumns Col ON Col.[ColID] = DefCons.[parent_column_id] AND Col.[ID] = Tab.[ID]
return "SELECT sysobjects.[Name]
FROM sysobjects INNER JOIN (SELECT [Name],[ID] FROM sysobjects WHERE XType = 'U') AS Tab
ON Tab.[ID] = sysobjects.[Parent_Obj]
INNER JOIN sys.default_constraints DefCons ON DefCons.[object_id] = sysobjects.[ID]
INNER JOIN syscolumns Col ON Col.[ColID] = DefCons.[parent_column_id] AND Col.[ID] = Tab.[ID]
WHERE Col.[Name] = " . $this->_conn->quote($column) . ' AND Tab.[Name] = ' . $this->_conn->quote($table) . '
ORDER BY Col.[Name]';
}
@@ -307,4 +324,24 @@ class SQLServerSchemaManager extends AbstractSchemaManager
)
);
}
/**
* @param string $name
*/
public function listTableDetails($name): Table
{
$table = parent::listTableDetails($name);
$platform = $this->_platform;
assert($platform instanceof SQLServerPlatform);
$sql = $platform->getListTableMetadataSQL($name);
$tableOptions = $this->_conn->fetchAssociative($sql);
if ($tableOptions !== false) {
$table->addOption('comment', $tableOptions['table_comment']);
}
return $table;
}
}