1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-07-30 21:40:43 +02:00

remove log_time index (was not used at all)

At the same time the database updater now supports checking for existing indexes. The db tools will not have this in 3.0.6 (the db tools have a function to retrieve all indexes) and i need to test the updater on all DBMS today...

git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10183 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Meik Sievertsen
2009-09-24 08:53:17 +00:00
parent c1b898890b
commit 54c22ae52a
2 changed files with 126 additions and 6 deletions

View File

@@ -8,7 +8,7 @@
*
*/
$updates_to_version = '3.0.6-RC1';
$updates_to_version = '3.0.6-RC2';
// Enter any version to update from to test updates. The version within the db will not be updated.
$debug_from_version = false;
@@ -868,9 +868,6 @@ function database_update_info()
),
),
'add_index' => array(
LOG_TABLE => array(
'log_time' => array('log_time'),
),
REPORTS_TABLE => array(
'post_id' => array('post_id'),
'pm_id' => array('pm_id'),
@@ -880,6 +877,12 @@ function database_update_info()
),
),
),
// Changes from 3.0.6-RC1 to 3.0.6-RC2
'3.0.6-RC1' => array(
'drop_keys' => array(
LOG_TABLE => array('log_time'),
),
),
);
}
@@ -1506,6 +1509,16 @@ function change_database_data(&$no_updates, $version)
$no_updates = false;
break;
// Changes from 3.0.6-RC1 to 3.0.6-RC2
case '3.0.6-RC1':
// We check if there is an index for log_time within the logs table
// If so, we remove it
break;
}
}
@@ -1902,7 +1915,8 @@ class updater_db_tools
{
if ($column_exists)
{
$sqlite_data[$table]['change_columns'][] = $result;
continue;
// $sqlite_data[$table]['change_columns'][] = $result;
}
else
{
@@ -1924,6 +1938,11 @@ class updater_db_tools
{
foreach ($indexes as $index_name)
{
if (!$this->sql_index_exists($table, $index_name))
{
continue;
}
$result = $this->sql_index_drop($table, $index_name);
if ($this->return_statements)
@@ -1984,6 +2003,11 @@ class updater_db_tools
{
foreach ($index_array as $index_name => $column)
{
if ($this->sql_index_exists($table, $index_name))
{
continue;
}
$result = $this->sql_create_unique_index($table, $index_name, $column);
if ($this->return_statements)
@@ -2001,6 +2025,11 @@ class updater_db_tools
{
foreach ($index_array as $index_name => $column)
{
if ($this->sql_index_exists($table, $index_name))
{
continue;
}
$result = $this->sql_create_index($table, $index_name, $column);
if ($this->return_statements)
@@ -2308,6 +2337,98 @@ class updater_db_tools
}
}
/**
* Check if a specified index exists in table
*
* @param string $table_name Table to check the index at
* @param string $index_name The index name to check
*
* @return bool True if index exists, else false
*/
function sql_index_exists($table_name, $index_name)
{
if ($this->sql_layer == 'mssql')
{
$sql = "EXEC sp_statistics '$table_name'";
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
{
if ($row['TYPE'] == 3)
{
if (strtolower($row['INDEX_NAME']) == strtolower($index_name))
{
$this->db->sql_freeresult($result);
return true;
}
}
}
$this->db->sql_freeresult($result);
return false;
}
switch ($this->sql_layer)
{
case 'firebird':
$sql = "SELECT LOWER(RDB\$INDEX_NAME) as index_name
FROM RDB\$INDICES
WHERE RDB\$RELATION_NAME = " . strtoupper($table_name) . "
AND RDB\$UNIQUE_FLAG IS NULL
AND RDB\$FOREIGN_KEY IS NULL";
$col = 'index_name';
break;
case 'postgres':
$sql = "SELECT ic.relname as index_name
FROM pg_class bc, pg_class ic, pg_index i
WHERE (bc.oid = i.indrelid)
AND (ic.oid = i.indexrelid)
AND (bc.relname = '" . $table_name . "')
AND (i.indisunique != 't')
AND (i.indisprimary != 't')";
$col = 'index_name';
break;
case 'mysql_40':
case 'mysql_41':
$sql = 'SHOW KEYS
FROM ' . $table_name;
$col = 'Key_name';
break;
case 'oracle':
$sql = "SELECT index_name
FROM user_indexes
WHERE table_name = '" . $table_name . "'
AND generated = 'N'";
break;
case 'sqlite':
$sql = "PRAGMA index_info('" . $table_name . "');";
$col = 'name';
break;
}
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
{
if (($this->sql_layer == 'mysql_40' || $this->sql_layer == 'mysql_41') && !$row['Non_unique'])
{
continue;
}
if (strtolower($row[$col]) == strtolower($index_name))
{
$this->db->sql_freeresult($result);
return true;
}
}
$this->db->sql_freeresult($result);
return false;
}
/**
* Private method for performing sql statements (either execute them or return them)
* @access private