From a9cf558af7fc08539e15ceca1e889e087c815c8d Mon Sep 17 00:00:00 2001 From: Sajaki Date: Sat, 28 Apr 2012 10:43:43 +0200 Subject: [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. --- phpBB/includes/db/db_tools.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'phpBB/includes/db/db_tools.php') 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; -- cgit v1.2.1 From 6c44dadecbf50d6550f98dd1e1694519f39be680 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 8 Jan 2013 22:07:26 -0600 Subject: [feature/migrations] Move migrator to service container Version numbers 3.1 updates Restore database_update.php file to what it was in develop Get first forum to place global announcements in PHPBB3-9737 --- phpBB/includes/db/db_tools.php | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'phpBB/includes/db/db_tools.php') diff --git a/phpBB/includes/db/db_tools.php b/phpBB/includes/db/db_tools.php index 2bb016cebd..5329d871c8 100644 --- a/phpBB/includes/db/db_tools.php +++ b/phpBB/includes/db/db_tools.php @@ -345,6 +345,16 @@ class phpbb_db_tools } } + /** + * Setter for {@link $return_statements return_statements}. + * + * @param bool $return_statements True if SQL should not be executed but returned as strings + */ + public function set_return_statements($return_statements) + { + $this->return_statements = $return_statements; + } + /** * Gets a list of tables in the database. * -- cgit v1.2.1 From e3737978f76a962385a26de910959607d0ae0d30 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Wed, 9 Jan 2013 14:27:01 -0600 Subject: [feature/migrations] Fixing returns of callables and handling data state Lots of comments and some other miscellaneous fixes. PHPBB3-9737 --- phpBB/includes/db/db_tools.php | 1 + 1 file changed, 1 insertion(+) (limited to 'phpBB/includes/db/db_tools.php') diff --git a/phpBB/includes/db/db_tools.php b/phpBB/includes/db/db_tools.php index 5329d871c8..1d6823d37a 100644 --- a/phpBB/includes/db/db_tools.php +++ b/phpBB/includes/db/db_tools.php @@ -349,6 +349,7 @@ class phpbb_db_tools * Setter for {@link $return_statements return_statements}. * * @param bool $return_statements True if SQL should not be executed but returned as strings + * @return null */ public function set_return_statements($return_statements) { -- cgit v1.2.1 From 595246f9bf17f1bef69c285ba8e78534cd91054a Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Wed, 9 Jan 2013 18:55:55 -0600 Subject: [feature/migrations] Some comments in db_tools PHPBB3-9737 --- phpBB/includes/db/db_tools.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'phpBB/includes/db/db_tools.php') diff --git a/phpBB/includes/db/db_tools.php b/phpBB/includes/db/db_tools.php index 1d6823d37a..b13d4fe978 100644 --- a/phpBB/includes/db/db_tools.php +++ b/phpBB/includes/db/db_tools.php @@ -685,6 +685,8 @@ class phpbb_db_tools * Handle passed database update array. * Expected structure... * Key being one of the following + * drop_tables: Drop tables + * add_tables: Add tables * change_columns: Column changes (only type, not name) * add_columns: Add columns to a table * drop_keys: Dropping keys -- cgit v1.2.1 From daf243026a1c6bcd369381433b556732674c41f6 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Wed, 6 Feb 2013 13:08:35 -0600 Subject: [ticket/11350] Do not pass $db by reference; typehint phpbb_db_driver PHPBB3-11350 --- phpBB/includes/db/db_tools.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/db/db_tools.php') diff --git a/phpBB/includes/db/db_tools.php b/phpBB/includes/db/db_tools.php index a4bf40fcd7..9235317958 100644 --- a/phpBB/includes/db/db_tools.php +++ b/phpBB/includes/db/db_tools.php @@ -303,7 +303,7 @@ class phpbb_db_tools * @param phpbb_db_driver $db Database connection * @param bool $return_statements True if only statements should be returned and no SQL being executed */ - function phpbb_db_tools(&$db, $return_statements = false) + function phpbb_db_tools(phpbb_db_driver $db, $return_statements = false) { $this->db = $db; $this->return_statements = $return_statements; -- cgit v1.2.1