mirror of
https://github.com/phpbb/phpbb.git
synced 2025-07-23 18:11:47 +02:00
[ticket/12012] Remove duplicated code (only the $sql are different)
PHPBB3-12012
This commit is contained in:
@@ -2572,12 +2572,6 @@ class tools
|
|||||||
AND sc.colid = (SELECT colid FROM syscolumns
|
AND sc.colid = (SELECT colid FROM syscolumns
|
||||||
WHERE id = object_id('{$table_name}')
|
WHERE id = object_id('{$table_name}')
|
||||||
AND name = '{$column_name}')";
|
AND name = '{$column_name}')";
|
||||||
$result = $this->db->sql_query($sql);
|
|
||||||
while ($row = $this->db->sql_fetchrow($result))
|
|
||||||
{
|
|
||||||
$statements[] = 'ALTER TABLE [' . $table_name . '] DROP CONSTRAINT [' . $row['def_name'] . ']';
|
|
||||||
}
|
|
||||||
$this->db->sql_freeresult($result);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -2587,14 +2581,15 @@ class tools
|
|||||||
WHERE col.object_id = object_id('{$table_name}')
|
WHERE col.object_id = object_id('{$table_name}')
|
||||||
AND col.name = '{$column_name}'
|
AND col.name = '{$column_name}'
|
||||||
AND dobj.name IS NOT NULL";
|
AND dobj.name IS NOT NULL";
|
||||||
$result = $this->db->sql_query($sql);
|
|
||||||
while ($row = $this->db->sql_fetchrow($result))
|
|
||||||
{
|
|
||||||
$statements[] = 'ALTER TABLE [' . $table_name . '] DROP CONSTRAINT [' . $row['def_name'] . ']';
|
|
||||||
}
|
|
||||||
$this->db->sql_freeresult($result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$result = $this->db->sql_query($sql);
|
||||||
|
while ($row = $this->db->sql_fetchrow($result))
|
||||||
|
{
|
||||||
|
$statements[] = 'ALTER TABLE [' . $table_name . '] DROP CONSTRAINT [' . $row['def_name'] . ']';
|
||||||
|
}
|
||||||
|
$this->db->sql_freeresult($result);
|
||||||
|
|
||||||
return $statements;
|
return $statements;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2627,36 +2622,6 @@ class tools
|
|||||||
AND cols.id = ix.id
|
AND cols.id = ix.id
|
||||||
WHERE ix.id = object_id('{$table_name}')
|
WHERE ix.id = object_id('{$table_name}')
|
||||||
AND cols.name = '{$column_name}'";
|
AND cols.name = '{$column_name}'";
|
||||||
$result = $this->db->sql_query($sql);
|
|
||||||
$existing_indexes = array();
|
|
||||||
while ($row = $this->db->sql_fetchrow($result))
|
|
||||||
{
|
|
||||||
$existing_indexes[$row['phpbb_index_name']] = array();
|
|
||||||
}
|
|
||||||
$this->db->sql_freeresult($result);
|
|
||||||
|
|
||||||
if (empty($existing_indexes))
|
|
||||||
{
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
|
|
||||||
$sql = "SELECT DISTINCT ix.name AS phpbb_index_name, cols.name AS phpbb_column_name
|
|
||||||
FROM sysindexes ix
|
|
||||||
INNER JOIN sysindexkeys ixc
|
|
||||||
ON ixc.id = ix.id
|
|
||||||
AND ixc.indid = ix.indid
|
|
||||||
INNER JOIN syscolumns cols
|
|
||||||
ON cols.colid = ixc.colid
|
|
||||||
AND cols.id = ix.id
|
|
||||||
WHERE ix.id = object_id('{$table_name}')
|
|
||||||
AND " . $this->db->sql_in_set('ix.name', array_keys($existing_indexes));
|
|
||||||
$result = $this->db->sql_query($sql);
|
|
||||||
|
|
||||||
while ($row = $this->db->sql_fetchrow($result))
|
|
||||||
{
|
|
||||||
$existing_indexes[$row['phpbb_index_name']][] = $row['phpbb_column_name'];
|
|
||||||
}
|
|
||||||
$this->db->sql_freeresult($result);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -2670,19 +2635,36 @@ class tools
|
|||||||
AND cols.object_id = ix.object_id
|
AND cols.object_id = ix.object_id
|
||||||
WHERE ix.object_id = object_id('{$table_name}')
|
WHERE ix.object_id = object_id('{$table_name}')
|
||||||
AND cols.name = '{$column_name}'";
|
AND cols.name = '{$column_name}'";
|
||||||
$result = $this->db->sql_query($sql);
|
}
|
||||||
$existing_indexes = array();
|
|
||||||
while ($row = $this->db->sql_fetchrow($result))
|
|
||||||
{
|
|
||||||
$existing_indexes[$row['phpbb_index_name']] = array();
|
|
||||||
}
|
|
||||||
$this->db->sql_freeresult($result);
|
|
||||||
|
|
||||||
if (empty($existing_indexes))
|
$result = $this->db->sql_query($sql);
|
||||||
{
|
$existing_indexes = array();
|
||||||
return array();
|
while ($row = $this->db->sql_fetchrow($result))
|
||||||
}
|
{
|
||||||
|
$existing_indexes[$row['phpbb_index_name']] = array();
|
||||||
|
}
|
||||||
|
$this->db->sql_freeresult($result);
|
||||||
|
|
||||||
|
if (empty($existing_indexes))
|
||||||
|
{
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($mssql_server_properties['mssql_version'][0] == '8') // SQL Server 2000
|
||||||
|
{
|
||||||
|
$sql = "SELECT DISTINCT ix.name AS phpbb_index_name, cols.name AS phpbb_column_name
|
||||||
|
FROM sysindexes ix
|
||||||
|
INNER JOIN sysindexkeys ixc
|
||||||
|
ON ixc.id = ix.id
|
||||||
|
AND ixc.indid = ix.indid
|
||||||
|
INNER JOIN syscolumns cols
|
||||||
|
ON cols.colid = ixc.colid
|
||||||
|
AND cols.id = ix.id
|
||||||
|
WHERE ix.id = object_id('{$table_name}')
|
||||||
|
AND " . $this->db->sql_in_set('ix.name', array_keys($existing_indexes));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
$sql = "SELECT DISTINCT ix.name AS phpbb_index_name, cols.name AS phpbb_column_name
|
$sql = "SELECT DISTINCT ix.name AS phpbb_index_name, cols.name AS phpbb_column_name
|
||||||
FROM sys.indexes ix
|
FROM sys.indexes ix
|
||||||
INNER JOIN sys.index_columns ixc
|
INNER JOIN sys.index_columns ixc
|
||||||
@@ -2693,15 +2675,16 @@ class tools
|
|||||||
AND cols.object_id = ix.object_id
|
AND cols.object_id = ix.object_id
|
||||||
WHERE ix.object_id = object_id('{$table_name}')
|
WHERE ix.object_id = object_id('{$table_name}')
|
||||||
AND " . $this->db->sql_in_set('ix.name', array_keys($existing_indexes));
|
AND " . $this->db->sql_in_set('ix.name', array_keys($existing_indexes));
|
||||||
$result = $this->db->sql_query($sql);
|
|
||||||
|
|
||||||
while ($row = $this->db->sql_fetchrow($result))
|
|
||||||
{
|
|
||||||
$existing_indexes[$row['phpbb_index_name']][] = $row['phpbb_column_name'];
|
|
||||||
}
|
|
||||||
$this->db->sql_freeresult($result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$result = $this->db->sql_query($sql);
|
||||||
|
|
||||||
|
while ($row = $this->db->sql_fetchrow($result))
|
||||||
|
{
|
||||||
|
$existing_indexes[$row['phpbb_index_name']][] = $row['phpbb_column_name'];
|
||||||
|
}
|
||||||
|
$this->db->sql_freeresult($result);
|
||||||
|
|
||||||
return $existing_indexes;
|
return $existing_indexes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user