diff options
author | Sajaki <sajaki9@gmail.com> | 2012-04-28 10:43:43 +0200 |
---|---|---|
committer | Sajaki <sajaki9@gmail.com> | 2012-04-28 10:43:43 +0200 |
commit | a9cf558af7fc08539e15ceca1e889e087c815c8d (patch) | |
tree | 9f66762e73288458c4192116412bd8410696d846 /phpBB | |
parent | 3a67604900a5301c133bfb0bf8f2d998306c3827 (diff) | |
download | forums-a9cf558af7fc08539e15ceca1e889e087c815c8d.tar forums-a9cf558af7fc08539e15ceca1e889e087c815c8d.tar.gz forums-a9cf558af7fc08539e15ceca1e889e087c815c8d.tar.bz2 forums-a9cf558af7fc08539e15ceca1e889e087c815c8d.tar.xz forums-a9cf558af7fc08539e15ceca1e889e087c815c8d.zip |
[ticket/10854] sql server drop default constraint when dropping column
drops default columns with T-SQL before attempting drop column to
avoids sql exception. This is a huge annoyance in UMIL scripts running
under sql server.
Diffstat (limited to 'phpBB')
-rw-r--r-- | phpBB/includes/db/db_tools.php | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/phpBB/includes/db/db_tools.php b/phpBB/includes/db/db_tools.php index c6dd23e6bd..f63ff18cbe 100644 --- a/phpBB/includes/db/db_tools.php +++ b/phpBB/includes/db/db_tools.php @@ -1819,6 +1819,22 @@ class phpbb_db_tools case 'mssql': case 'mssqlnative': + // remove default cosntraints first + // http://msdn.microsoft.com/en-us/library/aa175912%28v=sql.80%29.aspx + $statements[] = "DECLARE @drop_default_name VARCHAR(100), @cmd VARCHAR(1000) + SET @drop_default_name = + (SELECT so.name FROM sysobjects so + JOIN sysconstraints sc ON so.id = sc.constid + WHERE object_name(so.parent_obj) = '{$table_name}' + AND so.xtype = 'D' + AND sc.colid = (SELECT colid FROM syscolumns + WHERE id = object_id('{$table_name}') + AND name = '{$column_name}')) + IF @drop_default_name <> '' + BEGIN + SET @cmd = 'ALTER TABLE [{$table_name}] DROP CONSTRAINT [' + @drop_default_name + ']' + EXEC(@cmd) + END"; $statements[] = 'ALTER TABLE [' . $table_name . '] DROP COLUMN [' . $column_name . ']'; break; |