aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Webster <noxwizard@phpbb.com>2014-06-15 14:52:05 -0500
committerPatrick Webster <noxwizard@phpbb.com>2014-06-15 19:07:32 -0500
commit754e36e378e9d5d744fcfd6d447bd1e48d2052c3 (patch)
tree297de5bfd2d0b2fbf2a21ab5bf81864b928c8a4f
parente6a8df7f7ea2036ae9943368ad1ea2cee7cd5655 (diff)
downloadforums-754e36e378e9d5d744fcfd6d447bd1e48d2052c3.tar
forums-754e36e378e9d5d744fcfd6d447bd1e48d2052c3.tar.gz
forums-754e36e378e9d5d744fcfd6d447bd1e48d2052c3.tar.bz2
forums-754e36e378e9d5d744fcfd6d447bd1e48d2052c3.tar.xz
forums-754e36e378e9d5d744fcfd6d447bd1e48d2052c3.zip
[ticket/12643] Properly handle changing columns on tables with constraints
PHPBB3-12643
-rw-r--r--phpBB/phpbb/db/tools.php13
-rw-r--r--tests/dbal/db_tools_test.php18
2 files changed, 30 insertions, 1 deletions
diff --git a/phpBB/phpbb/db/tools.php b/phpBB/phpbb/db/tools.php
index 3b329b47bc..2ee842eace 100644
--- a/phpBB/phpbb/db/tools.php
+++ b/phpBB/phpbb/db/tools.php
@@ -2561,7 +2561,18 @@ class tools
foreach ($old_table_cols as $key => $declaration)
{
- $entities = preg_split('#\s+#', trim($declaration));
+ $declaration = trim($declaration);
+
+ // Check for the beginning of the constraint section and stop
+ if (preg_match('/[^\(]*\s*PRIMARY KEY\s+\(/', $declaration) ||
+ preg_match('/[^\(]*\s*UNIQUE\s+\(/', $declaration) ||
+ preg_match('/[^\(]*\s*FOREIGN KEY\s+\(/', $declaration) ||
+ preg_match('/[^\(]*\s*CHECK\s+\(/', $declaration))
+ {
+ break;
+ }
+
+ $entities = preg_split('#\s+#', $declaration);
$column_list[] = $entities[0];
if ($entities[0] == $column_name)
{
diff --git a/tests/dbal/db_tools_test.php b/tests/dbal/db_tools_test.php
index 7cf05a34d4..f3c6888c8d 100644
--- a/tests/dbal/db_tools_test.php
+++ b/tests/dbal/db_tools_test.php
@@ -239,6 +239,24 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case
$this->assertFalse($this->tools->sql_column_exists('prefix_table_name', 'c_bug_12012'));
}
+ public function test_column_change_with_composite_primary()
+ {
+ // Remove the old primary key
+ $this->assertTrue($this->tools->sql_column_remove('prefix_table_name', 'c_id'));
+ $this->assertTrue($this->tools->sql_column_add('prefix_table_name', 'c_id', array('UINT', 0)));
+
+ // Create a composite key
+ $this->assertTrue($this->tools->sql_create_primary_key('prefix_table_name', array('c_id', 'c_uint')));
+
+ // Create column
+ $this->assertFalse($this->tools->sql_column_exists('prefix_table_name', 'c_bug_12643'));
+ $this->assertTrue($this->tools->sql_column_add('prefix_table_name', 'c_bug_12643', array('DECIMAL', 0)));
+ $this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_bug_12643'));
+
+ // Change type from int to string
+ $this->assertTrue($this->tools->sql_column_change('prefix_table_name', 'c_bug_12643', array('VCHAR:100', '')));
+ }
+
public function test_column_remove()
{
$this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_int_size'));