From 5553cfc2ed81ba9eb571804c431def962720b39e Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Fri, 30 Oct 2009 19:19:48 +0000 Subject: [PATCH] Several fixes: Fix Bug #53335 Fix wrong unique index fetch for oracle and sqlite Fix alter column definition for firebird (although the query will fail in these circumstances [primary key] because firebird (again) does not support simple things... although... mssql/oracle having the same "problems", but there you are able to do more advanced queries) git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10248 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/db/db_tools.php | 2 +- phpBB/install/database_update.php | 69 +++++++++++++++++++++++-------- 2 files changed, 52 insertions(+), 19 deletions(-) diff --git a/phpBB/includes/db/db_tools.php b/phpBB/includes/db/db_tools.php index bc9f36b23a..a762b31681 100644 --- a/phpBB/includes/db/db_tools.php +++ b/phpBB/includes/db/db_tools.php @@ -1873,7 +1873,7 @@ class phpbb_db_tools } else { - $statements[] = 'ALTER TABLE ' . $table_name . ' ALTER COLUMN "' . strtoupper($column_name) . '" TYPE ' . ' ' . $column_data['column_type_sql']; + $statements[] = 'ALTER TABLE ' . $table_name . ' ALTER COLUMN "' . strtoupper($column_name) . '" TYPE ' . ' ' . $column_data['column_type_sql_type']; } break; diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index e3667e3f3c..e3511e89a4 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -346,11 +346,15 @@ for ($i = 0; $i < sizeof($versions); $i++) $no_updates = false; - $statements = $db_tools->perform_schema_changes($schema_changes); - - foreach ($statements as $sql) + // We run one index after the other... to be consistent with schema changes... + foreach ($schema_changes as $key => $changes) { - _sql($sql, $errored, $error_ary); + $statements = $db_tools->perform_schema_changes(array($key => $changes)); + + foreach ($statements as $sql) + { + _sql($sql, $errored, $error_ary); + } } } @@ -716,6 +720,9 @@ function database_update_info() 'session_forum_id' => array('UINT', 0), ), ), + 'drop_keys' => array( + GROUPS_TABLE => array('group_legend'), + ), 'add_index' => array( SESSIONS_TABLE => array( 'session_forum_id' => array('session_forum_id'), @@ -724,9 +731,6 @@ function database_update_info() 'group_legend_name' => array('group_legend', 'group_name'), ), ), - 'drop_keys' => array( - GROUPS_TABLE => array('group_legend'), - ), ), // No changes from 3.0.1-RC1 to 3.0.1 '3.0.1-RC1' => array(), @@ -1053,10 +1057,21 @@ function change_database_data(&$no_updates, $version) // Changes from 3.0.3-RC1 to 3.0.3 case '3.0.3-RC1': - $sql = 'UPDATE ' . LOG_TABLE . " - SET log_operation = 'LOG_DELETE_TOPIC' - WHERE log_operation = 'LOG_TOPIC_DELETED'"; - _sql($sql, $errored, $error_ary); + if ($db->sql_layer == 'oracle') + { + // log_operation is CLOB - but we can change this later + $sql = 'UPDATE ' . LOG_TABLE . " + SET log_operation = 'LOG_DELETE_TOPIC' + WHERE log_operation LIKE 'LOG_TOPIC_DELETED'"; + _sql($sql, $errored, $error_ary); + } + else + { + $sql = 'UPDATE ' . LOG_TABLE . " + SET log_operation = 'LOG_DELETE_TOPIC' + WHERE log_operation = 'LOG_TOPIC_DELETED'"; + _sql($sql, $errored, $error_ary); + } $no_updates = false; break; @@ -1199,6 +1214,18 @@ function change_database_data(&$no_updates, $version) 'drop_keys' => array( ACL_OPTIONS_TABLE => array('auth_option'), ), + ); + + global $db_tools; + + $statements = $db_tools->perform_schema_changes($changes); + + foreach ($statements as $sql) + { + _sql($sql, $errored, $error_ary); + } + + $changes = array( 'add_unique_index' => array( ACL_OPTIONS_TABLE => array( 'auth_option' => array('auth_option'), @@ -1206,8 +1233,6 @@ function change_database_data(&$no_updates, $version) ), ); - global $db_tools; - $statements = $db_tools->perform_schema_changes($changes); foreach ($statements as $sql) @@ -2521,13 +2546,12 @@ class updater_db_tools FROM user_indexes WHERE table_name = '" . strtoupper($table_name) . "' AND generated = 'N' - AND uniqueness = 'UNIQUE' - AND index_name LIKE 'U_%'"; + AND uniqueness = 'UNIQUE'"; $col = 'index_name'; break; case 'sqlite': - $sql = "PRAGMA index_list('" . $table_name . "') WHERE unique = 1;"; + $sql = "PRAGMA index_list('" . $table_name . "');"; $col = 'name'; break; } @@ -2554,7 +2578,15 @@ class updater_db_tools switch ($this->sql_layer) { case 'oracle': - $row[$col] = substr($row[$col], strlen('U_' . $row['table_owner']) + 1); + // Two cases here... prefixed with U_[table_owner] and not prefixed with table_name + if (strpos($row[$col], 'U_') === 0) + { + $row[$col] = substr($row[$col], strlen('U_' . $row['table_owner']) + 1); + } + else if (strpos($row[$col], strtoupper($table_name)) === 0) + { + $row[$col] = substr($row[$col], strlen($table_name) + 1); + } break; case 'firebird': @@ -3228,7 +3260,8 @@ class updater_db_tools } else { - $statements[] = 'ALTER TABLE ' . $table_name . ' ALTER COLUMN "' . strtoupper($column_name) . '" TYPE ' . ' ' . $column_data['column_type_sql']; + // TODO: try to change pkey without removing trigger, generator or constraints. ATM this query may fail. + $statements[] = 'ALTER TABLE ' . $table_name . ' ALTER COLUMN "' . strtoupper($column_name) . '" TYPE ' . ' ' . $column_data['column_type_sql_type']; } break;