mirror of
https://github.com/phpbb/phpbb.git
synced 2025-05-07 16:15:22 +02:00
[ticket/12710] Prepare get_existing_indexes() for other DBMS
PHPBB3-12710
This commit is contained in:
parent
9b36b5283c
commit
339bf90ec2
@ -2289,12 +2289,14 @@ class tools
|
|||||||
$old_return_statements = $this->return_statements;
|
$old_return_statements = $this->return_statements;
|
||||||
$this->return_statements = true;
|
$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
|
// 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);
|
$result = $this->sql_index_drop($table_name, $index_name);
|
||||||
$statements = array_merge($statements, $result);
|
$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;
|
$this->return_statements = $old_return_statements;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -2517,11 +2529,23 @@ class tools
|
|||||||
*
|
*
|
||||||
* @param string $table_name
|
* @param string $table_name
|
||||||
* @param string $column_name
|
* @param string $column_name
|
||||||
|
* @param bool $unique Should we get unique indexes or normal ones
|
||||||
* @return array Array with Index name => columns
|
* @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();
|
$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())
|
if ($this->mssql_is_sql_server_2000())
|
||||||
{
|
{
|
||||||
// http://msdn.microsoft.com/en-us/library/aa175912%28v=sql.80%29.aspx
|
// 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'];
|
$existing_indexes[$row['phpbb_index_name']][] = $row['phpbb_column_name'];
|
||||||
}
|
}
|
||||||
$this->db->sql_freeresult($result);
|
$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;
|
return $existing_indexes;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user