doctrine / dbal

Doctrine Database Abstraction Layer
https://www.doctrine-project.org/projects/dbal.html
MIT License
9.48k stars 1.34k forks source link

SQLServer renameTable() problem #6566

Open aimeos opened 4 weeks ago

aimeos commented 4 weeks ago

Bug Report

Q A
Version 3.9/4.2

Summary

SQL Server uses sp_rename function for renaming tables but using quotes for target table name results in wrong table name.

How to reproduce

$schemaManager->renameTable('[test]', '[dbo.test2]');
// -> sp_rename '[test]', '[dbo.test2]'

The new table is now named "[dbo.test2]" instead of "test2". This does only occur in SQLServer platform, all other platforms use quoting as expected so this is inconsistent between SQLServer platform and all other platforms.

Expected behaviour

Quotes for the target table name should be automatically removed by the SQLServer platform here to get consistent results: https://github.com/doctrine/dbal/blob/dadd35300837a3a2184bd47d403333b15d0a9bd0/src/Platforms/SQLServerPlatform.php#L498

$schemaManager->renameTable('[test]', '[dbo.test2]');
// -> sp_rename '[test]', 'test2'
morozov commented 2 days ago

Can sp_rename move the table to a different schema? See the details in https://github.com/doctrine/dbal/pull/6602.

As currently designed, the behavior of renameTable() isn't portable across supported platforms. Unlike other platforms where the second parameter is a SQL expression representing the new name, the SQL Server platform (due to the implementation details) accepts a literal.

aimeos commented 1 day ago

No, sp_rename can't move tables to a different schema and only accepts a literal as new name.