diff options
author | Derky <derky@phpbb.com> | 2018-01-05 22:44:34 +0100 |
---|---|---|
committer | Derky <derky@phpbb.com> | 2018-01-05 22:44:34 +0100 |
commit | 182a96f2738316adcb292816a9ac8af0e0cb5866 (patch) | |
tree | 0b6a0fb40a2ea201fdf4cfc5e4cc5ebfb4cb46db /phpBB/phpbb/db/tools | |
parent | 2fcb8ab87fb30c57b106695859c2661fc3cc2837 (diff) | |
parent | 98c50695003652fba171e25dd2e171ddffbd72e1 (diff) | |
download | forums-182a96f2738316adcb292816a9ac8af0e0cb5866.tar forums-182a96f2738316adcb292816a9ac8af0e0cb5866.tar.gz forums-182a96f2738316adcb292816a9ac8af0e0cb5866.tar.bz2 forums-182a96f2738316adcb292816a9ac8af0e0cb5866.tar.xz forums-182a96f2738316adcb292816a9ac8af0e0cb5866.zip |
Merge pull request #4680 from marc1706/ticket/15055
[ticket/15055] Add appveyor file to allow running tests on appveyor as well
Diffstat (limited to 'phpBB/phpbb/db/tools')
-rw-r--r-- | phpBB/phpbb/db/tools/mssql.php | 84 | ||||
-rw-r--r-- | phpBB/phpbb/db/tools/tools.php | 15 |
2 files changed, 79 insertions, 20 deletions
diff --git a/phpBB/phpbb/db/tools/mssql.php b/phpBB/phpbb/db/tools/mssql.php index 8b95b7070e..cbedf9a5c4 100644 --- a/phpBB/phpbb/db/tools/mssql.php +++ b/phpBB/phpbb/db/tools/mssql.php @@ -49,18 +49,18 @@ class mssql extends tools 'STEXT' => '[varchar] (3000)', 'TEXT' => '[varchar] (8000)', 'MTEXT' => '[text]', - 'XSTEXT_UNI'=> '[varchar] (100)', - 'STEXT_UNI' => '[varchar] (255)', - 'TEXT_UNI' => '[varchar] (4000)', - 'MTEXT_UNI' => '[text]', + 'XSTEXT_UNI'=> '[nvarchar] (100)', + 'STEXT_UNI' => '[nvarchar] (255)', + 'TEXT_UNI' => '[nvarchar] (4000)', + 'MTEXT_UNI' => '[ntext]', 'TIMESTAMP' => '[int]', 'DECIMAL' => '[float]', 'DECIMAL:' => '[float]', 'PDECIMAL' => '[float]', 'PDECIMAL:' => '[float]', - 'VCHAR_UNI' => '[varchar] (255)', - 'VCHAR_UNI:'=> '[varchar] (%d)', - 'VCHAR_CI' => '[varchar] (255)', + 'VCHAR_UNI' => '[nvarchar] (255)', + 'VCHAR_UNI:'=> '[nvarchar] (%d)', + 'VCHAR_CI' => '[nvarchar] (255)', 'VARBINARY' => '[varchar] (255)', ), @@ -80,18 +80,18 @@ class mssql extends tools 'STEXT' => '[varchar] (3000)', 'TEXT' => '[varchar] (8000)', 'MTEXT' => '[text]', - 'XSTEXT_UNI'=> '[varchar] (100)', - 'STEXT_UNI' => '[varchar] (255)', - 'TEXT_UNI' => '[varchar] (4000)', - 'MTEXT_UNI' => '[text]', + 'XSTEXT_UNI'=> '[nvarchar] (100)', + 'STEXT_UNI' => '[nvarchar] (255)', + 'TEXT_UNI' => '[nvarchar] (4000)', + 'MTEXT_UNI' => '[ntext]', 'TIMESTAMP' => '[int]', 'DECIMAL' => '[float]', 'DECIMAL:' => '[float]', 'PDECIMAL' => '[float]', 'PDECIMAL:' => '[float]', - 'VCHAR_UNI' => '[varchar] (255)', - 'VCHAR_UNI:'=> '[varchar] (%d)', - 'VCHAR_CI' => '[varchar] (255)', + 'VCHAR_UNI' => '[nvarchar] (255)', + 'VCHAR_UNI:'=> '[nvarchar] (%d)', + 'VCHAR_CI' => '[nvarchar] (255)', 'VARBINARY' => '[varchar] (255)', ), ); @@ -448,6 +448,10 @@ class mssql extends tools } } + // Drop primary keys depending on this column + $result = $this->mssql_get_drop_default_primary_key_queries($table_name, $column_name); + $statements = array_merge($statements, $result); + // Drop default value constraint $result = $this->mssql_get_drop_default_constraints_queries($table_name, $column_name); $statements = array_merge($statements, $result); @@ -541,10 +545,7 @@ class mssql extends tools { $statements = array(); - if ($this->mssql_is_sql_server_2000()) - { - $this->check_index_name_length($table_name, $index_name); - } + $this->check_index_name_length($table_name, $index_name); // remove index length $column = preg_replace('#:.*$#', '', $column); @@ -555,6 +556,21 @@ class mssql extends tools } /** + * {@inheritdoc} + */ + protected function get_max_index_name_length() + { + if ($this->mssql_is_sql_server_2000()) + { + return parent::get_max_index_name_length(); + } + else + { + return 128; + } + } + + /** * {@inheritDoc} */ function sql_list_index($table_name) @@ -685,6 +701,38 @@ class mssql extends tools } /** + * Get queries to drop the primary keys depending on the specified column + * + * We need to drop primary keys depending on this column before being able + * to delete them. + * + * @param string $table_name + * @param string $column_name + * @return array Array with SQL statements + */ + protected function mssql_get_drop_default_primary_key_queries($table_name, $column_name) + { + $statements = array(); + + $sql = "SELECT ccu.CONSTRAINT_NAME, ccu.COLUMN_NAME + FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc + JOIN INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE ccu ON tc.CONSTRAINT_NAME = ccu.Constraint_name + WHERE tc.TABLE_NAME = '{$table_name}' + AND tc.CONSTRAINT_TYPE = 'Primary Key' + AND ccu.COLUMN_NAME = '{$column_name}'"; + + $result = $this->db->sql_query($sql); + + while ($primary_key = $this->db->sql_fetchrow($result)) + { + $statements[] = 'ALTER TABLE [' . $table_name . '] DROP CONSTRAINT [' . $primary_key['CONSTRAINT_NAME'] . ']'; + } + $this->db->sql_freeresult($result); + + return $statements; + } + + /** * Checks to see if column is an identity column * * Identity columns cannot have defaults set for them. diff --git a/phpBB/phpbb/db/tools/tools.php b/phpBB/phpbb/db/tools/tools.php index 2f891e43d5..d21d34b8a9 100644 --- a/phpBB/phpbb/db/tools/tools.php +++ b/phpBB/phpbb/db/tools/tools.php @@ -1561,7 +1561,8 @@ class tools implements tools_interface */ protected function check_index_name_length($table_name, $index_name, $throw_error = true) { - if (strlen($index_name) > 30) + $max_index_name_length = $this->get_max_index_name_length(); + if (strlen($index_name) > $max_index_name_length) { // Try removing the table prefix if it's at the beginning $table_prefix = substr(CONFIG_TABLE, 0, -6); // strlen(config) @@ -1582,7 +1583,7 @@ class tools implements tools_interface if ($throw_error) { - trigger_error("Index name '$index_name' on table '$table_name' is too long. The maximum is 30 characters.", E_USER_ERROR); + trigger_error("Index name '$index_name' on table '$table_name' is too long. The maximum is $max_index_name_length characters.", E_USER_ERROR); } } @@ -1590,6 +1591,16 @@ class tools implements tools_interface } /** + * Get maximum index name length. Might vary depending on db type + * + * @return int Maximum index name length + */ + protected function get_max_index_name_length() + { + return 30; + } + + /** * {@inheritDoc} */ function sql_list_index($table_name) |