diff options
| author | Andreas Fischer <bantu@phpbb.com> | 2011-06-12 19:24:00 +0200 |
|---|---|---|
| committer | Andreas Fischer <bantu@phpbb.com> | 2011-06-12 19:24:00 +0200 |
| commit | 4adfa4685096f05e989ba7168bfaa4146e0d7cb4 (patch) | |
| tree | 6214747ede2c140fe2df1612cd297f209ac4843e /phpBB/install/database_update.php | |
| parent | bf2125f0f7c2b3d2f270ae4f3117941dd108f35a (diff) | |
| parent | 4e0717b4d7da58469c795191236ad4256a20c72a (diff) | |
| download | forums-4adfa4685096f05e989ba7168bfaa4146e0d7cb4.tar forums-4adfa4685096f05e989ba7168bfaa4146e0d7cb4.tar.gz forums-4adfa4685096f05e989ba7168bfaa4146e0d7cb4.tar.bz2 forums-4adfa4685096f05e989ba7168bfaa4146e0d7cb4.tar.xz forums-4adfa4685096f05e989ba7168bfaa4146e0d7cb4.zip | |
Merge remote-tracking branch 'naderman/ticket/9892' into develop-olympus
* naderman/ticket/9892:
[ticket/9892] Correct copyright year
[ticket/9892] Remove incorrect use of camel case
[ticket/9892] Removing closing php tag from create_schema_files
[ticket/9892] Transaction support for database update sql execution function
[ticket/9892] count is a keyword in firebird, so renaming this alias
[ticket/9892] Q&A CAPTCHA did not work on firebird, so no need to change config
[ticket/9892] Shorten login_attempt key names to avoid firebird length problems
[ticket/9892] Drop Q&A CAPTCHA tables if left in inconsistent state
[ticket/9892] Adding a number of tests for db_tools
[ticket/9892] Table prefix lengths influence index lengths in db_tools
[ticket/9892] Shorten the index names on the q&a captcha
[ticket/9892] column & index name limits, firebird auto increment in db_tools
Diffstat (limited to 'phpBB/install/database_update.php')
| -rw-r--r-- | phpBB/install/database_update.php | 80 |
1 files changed, 71 insertions, 9 deletions
diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 24a69ab99b..5bc856250b 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -534,12 +534,23 @@ function _sql($sql, &$errored, &$error_ary, $echo_dot = true) $db->sql_return_on_error(true); - $result = $db->sql_query($sql); - if ($db->sql_error_triggered) + if ($sql === 'begin') + { + $db->sql_transaction('begin'); + } + else if ($sql === 'commit') { - $errored = true; - $error_ary['sql'][] = $db->sql_error_sql; - $error_ary['error_code'][] = $db->sql_error_returned; + $db->sql_transaction('commit'); + } + else + { + $result = $db->sql_query($sql); + if ($db->sql_error_triggered) + { + $errored = true; + $error_ary['sql'][] = $db->sql_error_sql; + $error_ary['error_code'][] = $db->sql_error_returned; + } } $db->sql_return_on_error(false); @@ -932,9 +943,9 @@ function database_update_info() ), 'PRIMARY_KEY' => 'attempt_id', 'KEYS' => array( - 'attempt_ip' => array('INDEX', array('attempt_ip', 'attempt_time')), - 'attempt_forwarded_for' => array('INDEX', array('attempt_forwarded_for', 'attempt_time')), - 'attempt_time' => array('INDEX', array('attempt_time')), + 'att_ip' => array('INDEX', array('attempt_ip', 'attempt_time')), + 'att_for' => array('INDEX', array('attempt_forwarded_for', 'attempt_time')), + 'att_time' => array('INDEX', array('attempt_time')), 'user_id' => array('INDEX', 'user_id'), ), ), @@ -1913,6 +1924,27 @@ function change_database_data(&$no_updates, $version) } $db->sql_freeresult($result); + global $db_tools, $table_prefix; + + // Recover from potentially broken Q&A CAPTCHA table on firebird + // Q&A CAPTCHA was uninstallable, so it's safe to remove these + // without data loss + if ($db_tools->sql_layer == 'firebird') + { + $tables = array( + $table_prefix . 'captcha_questions', + $table_prefix . 'captcha_answers', + $table_prefix . 'qa_confirm', + ); + foreach ($tables as $table) + { + if ($db_tools->sql_table_exists($table)) + { + $db_tools->sql_table_drop($table); + } + } + } + $no_updates = false; break; } @@ -2319,6 +2351,11 @@ class updater_db_tools // here lies an array, filled with information compiled on the column's data $prepared_column = $this->sql_prepare_column_data($table_name, $column_name, $column_data); + if (isset($prepared_column['auto_increment']) && strlen($column_name) > 26) // "${column_name}_gen" + { + trigger_error("Index name '${column_name}_gen' on table '$table_name' is too long. The maximum auto increment column length is 26 characters.", E_USER_ERROR); + } + // here we add the definition of the new column to the list of columns switch ($this->sql_layer) { @@ -2468,7 +2505,13 @@ class updater_db_tools case 'firebird': if ($create_sequence) { - $statements[] = "CREATE SEQUENCE {$table_name}_seq;"; + $statements[] = "CREATE GENERATOR {$table_name}_gen;"; + $statements[] = "SET GENERATOR {$table_name}_gen TO 0;"; + + $trigger = "CREATE TRIGGER t_$table_name FOR $table_name\n"; + $trigger .= "BEFORE INSERT\nAS\nBEGIN\n"; + $trigger .= "\tNEW.{$create_sequence} = GEN_ID({$table_name}_gen, 1);\nEND;"; + $statements[] = $trigger; } break; } @@ -3302,6 +3345,11 @@ class updater_db_tools */ function sql_prepare_column_data($table_name, $column_name, $column_data) { + if (strlen($column_name) > 30) + { + trigger_error("Column name '$column_name' on table '$table_name' is too long. The maximum is 30 characters.", E_USER_ERROR); + } + // Get type if (strpos($column_data[0], ':') !== false) { @@ -3875,6 +3923,13 @@ class updater_db_tools { $statements = array(); + $table_prefix = substr(CONFIG_TABLE, 0, -6); // strlen(config) + if (strlen($table_name . $index_name) - strlen($table_prefix) > 24) + { + $max_length = $table_prefix + 24; + trigger_error("Index name '{$table_name}_$index_name' on table '$table_name' is too long. The maximum is $max_length characters.", E_USER_ERROR); + } + switch ($this->sql_layer) { case 'firebird': @@ -3905,6 +3960,13 @@ class updater_db_tools { $statements = array(); + $table_prefix = substr(CONFIG_TABLE, 0, -6); // strlen(config) + if (strlen($table_name . $index_name) - strlen($table_prefix) > 24) + { + $max_length = $table_prefix + 24; + trigger_error("Index name '{$table_name}_$index_name' on table '$table_name' is too long. The maximum is $max_length characters.", E_USER_ERROR); + } + // remove index length unless MySQL4 if ('mysql_40' != $this->sql_layer) { |
