From 41ef41ac63af83f04d0e82cd1891c12060e90227 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Tue, 10 Apr 2012 00:46:24 +0200 Subject: [PATCH 1/2] [ticket/10774] Add unit tests for UNIQUE index existence and creation. PHPBB3-10774 --- tests/dbal/db_tools_test.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/dbal/db_tools_test.php b/tests/dbal/db_tools_test.php index fbde636b58..c7ddb88ce8 100644 --- a/tests/dbal/db_tools_test.php +++ b/tests/dbal/db_tools_test.php @@ -354,9 +354,20 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case $this->assertTrue($this->tools->sql_index_exists('prefix_table_name', 'i_simple')); } + public function test_unique_index_exists() + { + $this->assertTrue($this->tools->sql_unique_index_exists('prefix_table_name', 'i_uniq')); + } + public function test_create_index_against_index_exists() { $this->tools->sql_create_index('prefix_table_name', 'fookey', array('c_timestamp', 'c_decimal')); $this->assertTrue($this->tools->sql_index_exists('prefix_table_name', 'fookey')); } + + public function test_create_unique_index_against_unique_index_exists() + { + $this->tools->sql_create_unique_index('prefix_table_name', 'i_uniq_ts_id', array('c_timestamp', 'c_id')); + $this->assertTrue($this->tools->sql_unique_index_exists('prefix_table_name', 'i_uniq_ts_id')); + } } From ef8160e8a2a1dbb51cd2603eefcd9309d2daece8 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Tue, 10 Apr 2012 00:53:27 +0200 Subject: [PATCH 2/2] [ticket/10774] Correctly specify index name when creating unique index on MySQL. PHPBB3-10774 --- phpBB/includes/db/db_tools.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/db/db_tools.php b/phpBB/includes/db/db_tools.php index 2cba11133a..c6dd23e6bd 100644 --- a/phpBB/includes/db/db_tools.php +++ b/phpBB/includes/db/db_tools.php @@ -2115,7 +2115,7 @@ class phpbb_db_tools case 'mysql_40': case 'mysql_41': - $statements[] = 'ALTER TABLE ' . $table_name . ' ADD UNIQUE INDEX (' . implode(', ', $column) . ')'; + $statements[] = 'ALTER TABLE ' . $table_name . ' ADD UNIQUE INDEX ' . $index_name . '(' . implode(', ', $column) . ')'; break; case 'mssql':