[ticket/12710] Prepare get_existing_indexes() for other DBMS

PHPBB3-12710
This commit is contained in:
Joas Schilling 2014-08-07 18:43:48 +02:00
parent 9b36b5283c
commit 339bf90ec2

View file

@ -2289,12 +2289,14 @@ class tools
$old_return_statements = $this->return_statements;
$this->return_statements = true;
$indexes = $this->mssql_get_existing_indexes($table_name, $column_name);
$indexes = $this->get_existing_indexes($table_name, $column_name);
$unique_indexes = $this->get_existing_indexes($table_name, $column_name, true);
// Drop any indexes
if (!empty($indexes))
if (!empty($indexes) || !empty($unique_indexes))
{
foreach ($indexes as $index_name => $index_data)
$drop_indexes = array_merge(array_keys($indexes), array_keys($unique_indexes));
foreach ($drop_indexes as $index_name)
{
$result = $this->sql_index_drop($table_name, $index_name);
$statements = array_merge($statements, $result);
@ -2324,6 +2326,16 @@ class tools
}
}
if (!empty($unique_indexes))
{
// Recreate unique indexes after we changed the column
foreach ($unique_indexes as $index_name => $index_data)
{
$result = $this->sql_create_unique_index($table_name, $index_name, $index_data);
$statements = array_merge($statements, $result);
}
}
$this->return_statements = $old_return_statements;
break;
@ -2517,11 +2529,23 @@ class tools
*
* @param string $table_name
* @param string $column_name
* @param bool $unique Should we get unique indexes or normal ones
* @return array Array with Index name => columns
*/
protected function mssql_get_existing_indexes($table_name, $column_name)
public function get_existing_indexes($table_name, $column_name, $unique = false)
{
$existing_indexes = array();
switch ($this->sql_layer)
{
case 'mssql':
case 'mssqlnative':
if ($unique)
{
// TODO fix me
throw new \Exception('FIX ME mssql treats unique and normal indexes the same');
}
if ($this->mssql_is_sql_server_2000())
{
// http://msdn.microsoft.com/en-us/library/aa175912%28v=sql.80%29.aspx
@ -2598,6 +2622,21 @@ class tools
$existing_indexes[$row['phpbb_index_name']][] = $row['phpbb_column_name'];
}
$this->db->sql_freeresult($result);
break;
case 'oracle':
throw new \Exception('Needs implementing');
break;
case 'mysql_40':
case 'mysql_41':
case 'postgres':
case 'sqlite':
case 'sqlite3':
// Not supported
throw new \Exception('DBMS is not supported');
break;
}
return $existing_indexes;
}