mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-10 21:38:54 +00:00
[ticket/15055] Drop primary keys when necessary and fix test comparisons
PHPBB3-15055
This commit is contained in:
parent
5bb62f5560
commit
635befa00e
2 changed files with 43 additions and 1 deletions
|
@ -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
|
// Drop default value constraint
|
||||||
$result = $this->mssql_get_drop_default_constraints_queries($table_name, $column_name);
|
$result = $this->mssql_get_drop_default_constraints_queries($table_name, $column_name);
|
||||||
$statements = array_merge($statements, $result);
|
$statements = array_merge($statements, $result);
|
||||||
|
@ -684,6 +688,37 @@ class mssql extends tools
|
||||||
return $statements;
|
return $statements;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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'";
|
||||||
|
|
||||||
|
$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
|
* Checks to see if column is an identity column
|
||||||
*
|
*
|
||||||
|
|
|
@ -203,8 +203,15 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case
|
||||||
|
|
||||||
public function test_list_columns()
|
public function test_list_columns()
|
||||||
{
|
{
|
||||||
|
$config = $this->get_database_config();
|
||||||
|
$table_columns = $this->table_data['COLUMNS'];
|
||||||
|
|
||||||
|
if (strpos($config['dbms'], 'mssql') !== false)
|
||||||
|
{
|
||||||
|
ksort($table_columns);
|
||||||
|
}
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
array_keys($this->table_data['COLUMNS']),
|
array_keys($table_columns),
|
||||||
array_values($this->tools->sql_list_columns('prefix_table_name'))
|
array_values($this->tools->sql_list_columns('prefix_table_name'))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue