From 418c3d546a5ea29b5ce338e4710e0d3636009733 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Sun, 12 Jun 2011 01:21:55 +0200 Subject: [PATCH 01/12] [ticket/9892] column & index name limits, firebird auto increment in db_tools - Column names are limited to 30 characters - Index names are limited to 31 characters. On some dbms the index name contains both table name and actual index name so the limit applies to the sum of the lenghts of table name and index name. - Auto incremented column names are limited to 26 characters to provide an additional 4 characters for sequence names The code for firebird auto increment support using generators/sequences with triggers was copied from create_schema_files.php PHPBB3-9892 --- phpBB/develop/create_schema_files.php | 16 ++++++++++++++- phpBB/includes/db/db_tools.php | 28 ++++++++++++++++++++++++++- phpBB/install/database_update.php | 28 ++++++++++++++++++++++++++- 3 files changed, 69 insertions(+), 3 deletions(-) diff --git a/phpBB/develop/create_schema_files.php b/phpBB/develop/create_schema_files.php index f1e2858848..e59552f370 100644 --- a/phpBB/develop/create_schema_files.php +++ b/phpBB/develop/create_schema_files.php @@ -329,6 +329,15 @@ foreach ($supported_dbms as $dbms) // Write columns one by one... foreach ($table_data['COLUMNS'] as $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); + } + if (isset($column_data[2]) && $column_data[2] == '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 is 30 characters.", E_USER_ERROR); + } + // Get type if (strpos($column_data[0], ':') !== false) { @@ -632,6 +641,11 @@ foreach ($supported_dbms as $dbms) $key_data[1] = array($key_data[1]); } + if (strlen($table_name . $key_name) > 30) + { + trigger_error("Index name '$key_name' on table '$table_name' is too long. The maximum is 30 characters.", E_USER_ERROR); + } + switch ($dbms) { case 'mysql_40': @@ -2067,4 +2081,4 @@ EOF; echo 'done'; -?> \ No newline at end of file +?> diff --git a/phpBB/includes/db/db_tools.php b/phpBB/includes/db/db_tools.php index fdefda9e26..0e3173c23e 100644 --- a/phpBB/includes/db/db_tools.php +++ b/phpBB/includes/db/db_tools.php @@ -417,6 +417,11 @@ class phpbb_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 is 30 characters.", E_USER_ERROR); + } + // here we add the definition of the new column to the list of columns switch ($this->sql_layer) { @@ -566,7 +571,13 @@ class phpbb_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; } @@ -1400,6 +1411,11 @@ class phpbb_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) { @@ -2040,6 +2056,11 @@ class phpbb_db_tools { $statements = array(); + if (strlen($table_name . $index_name) > 30) + { + trigger_error("Index name '{$table_name}_$index_name' on table '$table_name' is too long. The maximum is 30 characters.", E_USER_ERROR); + } + switch ($this->sql_layer) { case 'firebird': @@ -2070,6 +2091,11 @@ class phpbb_db_tools { $statements = array(); + if (strlen($table_name . $index_name) > 30) + { + trigger_error("Index name '${table_name}_$index_name' on table '$table_name' is too long. The maximum is 30 characters.", E_USER_ERROR); + } + // remove index length unless MySQL4 if ('mysql_40' != $this->sql_layer) { diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 24a69ab99b..1abd91e27f 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -2319,6 +2319,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 is 30 characters.", E_USER_ERROR); + } + // here we add the definition of the new column to the list of columns switch ($this->sql_layer) { @@ -2468,7 +2473,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 +3313,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 +3891,11 @@ class updater_db_tools { $statements = array(); + if (strlen($table_name . $index_name) > 30) + { + trigger_error("Index name '{$table_name}_$index_name' on table '$table_name' is too long. The maximum is 30 characters.", E_USER_ERROR); + } + switch ($this->sql_layer) { case 'firebird': @@ -3905,6 +3926,11 @@ class updater_db_tools { $statements = array(); + if (strlen($table_name . $index_name) > 30) + { + trigger_error("Index name '${table_name}_$index_name' on table '$table_name' is too long. The maximum is 30 characters.", E_USER_ERROR); + } + // remove index length unless MySQL4 if ('mysql_40' != $this->sql_layer) { From 8a5e3781d53e3df379c55166136abd6e71990af4 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Sun, 12 Jun 2011 01:25:15 +0200 Subject: [PATCH 02/12] [ticket/9892] Shorten the index names on the q&a captcha PHPBB3-9892 --- phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php index 49a64b9339..45f76bd676 100644 --- a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php +++ b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php @@ -319,7 +319,7 @@ class phpbb_captcha_qa ), 'PRIMARY_KEY' => 'question_id', 'KEYS' => array( - 'lang_iso' => array('INDEX', 'lang_iso'), + 'lang' => array('INDEX', 'lang_iso'), ), ), CAPTCHA_ANSWERS_TABLE => array ( @@ -328,7 +328,7 @@ class phpbb_captcha_qa 'answer_text' => array('STEXT_UNI', ''), ), 'KEYS' => array( - 'question_id' => array('INDEX', 'question_id'), + 'qid' => array('INDEX', 'question_id'), ), ), CAPTCHA_QA_CONFIRM_TABLE => array ( From ef544ee095f2decde39cc537d3d675642b7c80f2 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Sun, 12 Jun 2011 04:10:51 +0200 Subject: [PATCH 03/12] [ticket/9892] Table prefix lengths influence index lengths in db_tools PHPBB3-9892 --- phpBB/includes/db/db_tools.php | 14 +++++++++----- phpBB/install/database_update.php | 14 +++++++++----- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/phpBB/includes/db/db_tools.php b/phpBB/includes/db/db_tools.php index 0e3173c23e..c1af2782f8 100644 --- a/phpBB/includes/db/db_tools.php +++ b/phpBB/includes/db/db_tools.php @@ -419,7 +419,7 @@ class phpbb_db_tools 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 is 30 characters.", E_USER_ERROR); + 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 @@ -2056,9 +2056,11 @@ class phpbb_db_tools { $statements = array(); - if (strlen($table_name . $index_name) > 30) + $table_prefix = substr(CONFIG_TABLE, 0, -6); // strlen(config) + if (strlen($table_name . $index_name) - strlen($table_prefix) > 24) { - trigger_error("Index name '{$table_name}_$index_name' on table '$table_name' is too long. The maximum is 30 characters.", E_USER_ERROR); + $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) @@ -2091,9 +2093,11 @@ class phpbb_db_tools { $statements = array(); - if (strlen($table_name . $index_name) > 30) + $table_prefix = substr(CONFIG_TABLE, 0, -6); // strlen(config) + if (strlen($table_name . $index_name) - strlen($table_prefix) > 24) { - trigger_error("Index name '${table_name}_$index_name' on table '$table_name' is too long. The maximum is 30 characters.", E_USER_ERROR); + $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 diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 1abd91e27f..7bf41c8450 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -2321,7 +2321,7 @@ class updater_db_tools 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 is 30 characters.", E_USER_ERROR); + 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 @@ -3891,9 +3891,11 @@ class updater_db_tools { $statements = array(); - if (strlen($table_name . $index_name) > 30) + $table_prefix = substr(CONFIG_TABLE, 0, -6); // strlen(config) + if (strlen($table_name . $index_name) - strlen($table_prefix) > 24) { - trigger_error("Index name '{$table_name}_$index_name' on table '$table_name' is too long. The maximum is 30 characters.", E_USER_ERROR); + $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) @@ -3926,9 +3928,11 @@ class updater_db_tools { $statements = array(); - if (strlen($table_name . $index_name) > 30) + $table_prefix = substr(CONFIG_TABLE, 0, -6); // strlen(config) + if (strlen($table_name . $index_name) - strlen($table_prefix) > 24) { - trigger_error("Index name '${table_name}_$index_name' on table '$table_name' is too long. The maximum is 30 characters.", E_USER_ERROR); + $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 From 025649e14cf4a4678f26790fa4328b25a3f040cf Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Sun, 12 Jun 2011 10:34:43 +0200 Subject: [PATCH 04/12] [ticket/9892] Adding a number of tests for db_tools The test creates a table and runs a number of queries on it to judge whether the selected column types can hold the data they are expected to contain. Additional test methods check the auto increment feature and a few of the basic commands of db_tools. This is only a starting point. Plenty more tests need to be added. PHPBB3-9892 --- tests/dbal/db_tools_test.php | 268 +++++++++++++++++++++++++++++++++++ 1 file changed, 268 insertions(+) create mode 100644 tests/dbal/db_tools_test.php diff --git a/tests/dbal/db_tools_test.php b/tests/dbal/db_tools_test.php new file mode 100644 index 0000000000..b9206b622e --- /dev/null +++ b/tests/dbal/db_tools_test.php @@ -0,0 +1,268 @@ +createXMLDataSet(dirname(__FILE__).'/fixtures/config.xml'); + } + + protected function setUp() + { + parent::setUp(); + + $this->db = $this->new_dbal(); + $this->tools = new phpbb_db_tools($this->db); + + $this->table_data = array( + 'COLUMNS' => array( + 'c_id' => array('UINT', NULL, 'auto_increment'), + 'c_int_size' => array('INT:4', 4), + 'c_bint' => array('BINT', 4), + 'c_uint' => array('UINT', 4), + 'c_uint_size' => array('UINT:4', 4), + 'c_tint_size' => array('TINT:2', 4), + 'c_usint' => array('USINT', 4), + 'c_bool' => array('BOOL', 1), + 'c_vchar' => array('VCHAR', 'foo'), + 'c_vchar_size' => array('VCHAR:4', 'foo'), + 'c_char_size' => array('CHAR:4', 'foo'), + 'c_xstext' => array('XSTEXT', 'foo'), + 'c_stext' => array('STEXT', 'foo'), + 'c_text' => array('TEXT', 'foo'), + 'c_mtext' => array('MTEXT', 'foo'), + 'c_xstext_uni' => array('XSTEXT_UNI', 'foo'), + 'c_stext_uni' => array('STEXT_UNI', 'foo'), + 'c_text_uni' => array('TEXT_UNI', 'foo'), + 'c_mtext_uni' => array('MTEXT_UNI', 'foo'), + 'c_timestamp' => array('TIMESTAMP', 4), + 'c_decimal' => array('DECIMAL', 4.2), + 'c_decimal_size' => array('DECIMAL:6', 4.2), + 'c_pdecimal' => array('PDECIMAL', 4.2), + 'c_pdecimal_size' => array('PDECIMAL:7', 4.2), + 'c_vchar_uni' => array('VCHAR_UNI', 'foo'), + 'c_vchar_uni_size' => array('VCHAR_UNI:4', 'foo'), + 'c_vchar_ci' => array('VCHAR_CI', 'foo'), + 'c_varbinary' => array('VARBINARY', 'foo'), + ), + 'PRIMARY_KEY' => 'c_id', + 'KEYS' => array( + 'i_simple' => array('INDEX', 'c_uint'), + 'i_uniq' => array('UNIQUE', 'c_vchar'), + 'i_comp' => array('INDEX', array('c_vchar_uni', 'c_bool')), + 'i_comp_uniq' => array('UNIQUE', array('c_vchar_size', 'c_usint')), + ), + ); + $this->tools->sql_create_table('prefix_table_name', $this->table_data); + $this->table_exists = true; + } + + protected function tearDown() + { + if ($this->table_exists) + { + $this->tools->sql_table_drop('prefix_table_name'); + } + + parent::tearDown(); + } + + public function test_created_and_drop_table() + { + // table is empty after creation and queryable + $sql = 'SELECT * FROM prefix_table_name'; + $result = $this->db->sql_query($sql); + $this->assertTrue(! $this->db->sql_fetchrow($result)); + $this->db->sql_freeresult($result); + + $this->table_exists = false; + $this->tools->sql_table_drop('prefix_table_name'); + } + + static protected function get_default_values() + { + return array( + 'c_int_size' => 0, + 'c_bint' => 0, + 'c_uint' => 0, + 'c_uint_size' => 0, + 'c_tint_size' => 0, + 'c_usint' => 0, + 'c_bool' => 0, + 'c_vchar' => '', + 'c_vchar_size' => '', + 'c_char_size' => '', + 'c_xstext' => '', + 'c_stext' => '', + 'c_text' => '', + 'c_mtext' => '', + 'c_xstext_uni' => '', + 'c_stext_uni' => '', + 'c_text_uni' => '', + 'c_mtext_uni' => '', + 'c_timestamp' => 0, + 'c_decimal' => 0, + 'c_decimal_size' => 0, + 'c_pdecimal' => 0, + 'c_pdecimal_size' => 0, + 'c_vchar_uni' => '', + 'c_vchar_uni_size' => '', + 'c_vchar_ci' => '', + 'c_varbinary' => '', + ); + } + + static public function columnValues() + { + return array( + array('c_int_size', -9999), + array('c_bint', '99999999999999999'), + array('c_uint', 16777215), + array('c_uint_size', 9999), + array('c_tint_size', -99), + array('c_usint', 99), + array('c_bool', 0), + array('c_vchar', str_repeat('a', 255)), + array('c_vchar_size', str_repeat('a', 4)), + array('c_char_size', str_repeat('a', 4)), + array('c_xstext', str_repeat('a', 1000)), + array('c_stext', str_repeat('a', 3000)), + array('c_text', str_repeat('a', 8000)), + array('c_mtext', str_repeat('a', 10000)), + array('c_xstext_uni', str_repeat("\xC3\x84", 100)), + array('c_stext_uni', str_repeat("\xC3\x84", 255)), + array('c_text_uni', str_repeat("\xC3\x84", 4000)), + array('c_mtext_uni', str_repeat("\xC3\x84", 10000)), + array('c_timestamp', 2147483647), + array('c_decimal', 999.99), + array('c_decimal_size', 9999.99), + array('c_pdecimal', 999.999), + array('c_pdecimal_size', 9999.999), + array('c_vchar_uni', str_repeat("\xC3\x84", 255)), + array('c_vchar_uni_size', str_repeat("\xC3\x84", 4)), + array('c_vchar_ci', str_repeat("\xC3\x84", 255)), + array('c_varbinary', str_repeat("\x00\xFF", 127)), + ); + } + + /** + * @dataProvider columnValues + */ + public function test_created_column($column_name, $column_value) + { + $row_insert = self::get_default_values(); + $row_insert[$column_name] = $column_value; + + // empty table + $sql = 'DELETE FROM prefix_table_name'; + $result = $this->db->sql_query($sql); + + $sql = 'INSERT INTO prefix_table_name ' . $this->db->sql_build_array('INSERT', $row_insert); + $result = $this->db->sql_query($sql); + + $sql = "SELECT * + FROM prefix_table_name"; + $result = $this->db->sql_query($sql); + $row_actual = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + $row_expect = $row_insert; + + unset($row_actual['id']); // auto increment id changes, so ignore + + $type = $this->table_data['COLUMNS'][$column_name][0]; + $this->assertEquals($row_expect[$column_name], $row_actual[$column_name], "Column $column_name of type $type should have equal return and input value."); + } + + public function test_auto_increment() + { + $sql = 'DELETE FROM prefix_table_name'; + $result = $this->db->sql_query($sql); + + $row1 = array_merge(self::get_default_values(), array( + 'c_uint' => 1, + 'c_vchar' => '1', // these values are necessary to avoid unique index issues + 'c_vchar_size' => '1', + )); + $row2 = array_merge(self::get_default_values(), array( + 'c_uint' => 2, + 'c_vchar' => '2', + 'c_vchar_size' => '2', + )); + + $sql = 'INSERT INTO prefix_table_name ' . $this->db->sql_build_array('INSERT', $row1); + $result = $this->db->sql_query($sql); + $id1 = $this->db->sql_nextid(); + + $sql = 'INSERT INTO prefix_table_name ' . $this->db->sql_build_array('INSERT', $row2); + $result = $this->db->sql_query($sql); + $id2 = $this->db->sql_nextid(); + + $this->assertGreaterThan($id1, $id2, 'Auto increment should increase the id value'); + + $sql = "SELECT * + FROM prefix_table_name WHERE c_id = $id1"; + $result = $this->db->sql_query($sql); + $row_actual = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + $row1['c_id'] = $id1; + $this->assertEquals($row1, $row_actual); + + $sql = "SELECT * + FROM prefix_table_name WHERE c_id = $id2"; + $result = $this->db->sql_query($sql); + $row_actual = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + $row2['c_id'] = $id2; + $this->assertEquals($row2, $row_actual); + } + + public function test_column_exists() + { + $this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_id')); + $this->assertFalse($this->tools->sql_column_exists('prefix_table_name', 'column_does_not_exist')); + } + + public function test_column_remove() + { + $this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_id')); + + $this->assertTrue($this->tools->sql_column_remove('prefix_table_name', 'c_id')); + + $this->assertFalse($this->tools->sql_column_exists('prefix_table_name', 'c_id')); + } + + public function test_table_exists() + { + $this->assertTrue($this->tools->sql_table_exists('prefix_table_name')); + $this->assertFalse($this->tools->sql_table_exists('prefix_does_not_exist')); + } + + public function test_table_drop() + { + $this->tools->sql_create_table('prefix_test_table', + array('COLUMNS' => array( + 'foo' => array('UINT', 42))) + ); + + $this->tools->sql_table_drop('prefix_test_table'); + } + +} From 32f37bf938efe7a85b72ad2429e715269abc6fee Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Sun, 12 Jun 2011 10:49:48 +0200 Subject: [PATCH 05/12] [ticket/9892] Drop Q&A CAPTCHA tables if left in inconsistent state PHPBB3-9892 --- phpBB/install/database_update.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 7bf41c8450..dce77a67d7 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -1913,6 +1913,30 @@ function change_database_data(&$no_updates, $version) } $db->sql_freeresult($result); + global $db_tools; + + // Recover from potentially broken Q&A CAPTCHA table on firebird + if ($db_tools->sql_layer == 'firebird') + { + if ($config['captcha_plugin'] == 'phpbb_captcha_qa') + { + setconfig('captcha_plugin', 'phpbb_captcha_nogd'); + } + + $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; } From 6cab45b28e5c30571ce6f2961e26d268fb6542e7 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Sun, 12 Jun 2011 11:02:30 +0200 Subject: [PATCH 06/12] [ticket/9892] Shorten login_attempt key names to avoid firebird length problems PHPBB3-9892 --- phpBB/install/database_update.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index dce77a67d7..7cf3b02e9f 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -932,9 +932,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'), ), ), From cd3d23810f844b529f304cb7062ffe65cc17e4e3 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Sun, 12 Jun 2011 11:06:52 +0200 Subject: [PATCH 07/12] [ticket/9892] Q&A CAPTCHA did not work on firebird, so no need to change config PHPBB3-9892 --- phpBB/install/database_update.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 7cf3b02e9f..7d7572b204 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -1913,16 +1913,13 @@ function change_database_data(&$no_updates, $version) } $db->sql_freeresult($result); - global $db_tools; + 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') { - if ($config['captcha_plugin'] == 'phpbb_captcha_qa') - { - setconfig('captcha_plugin', 'phpbb_captcha_nogd'); - } - $tables = array( $table_prefix . 'captcha_questions', $table_prefix . 'captcha_answers', From ef977abe596fdc926e84e10fd994278665d38417 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Sun, 12 Jun 2011 11:33:55 +0200 Subject: [PATCH 08/12] [ticket/9892] count is a keyword in firebird, so renaming this alias PHPBB3-9892 --- phpBB/includes/auth/auth_db.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/auth/auth_db.php b/phpBB/includes/auth/auth_db.php index 02c9386f33..fe3ea30b2a 100644 --- a/phpBB/includes/auth/auth_db.php +++ b/phpBB/includes/auth/auth_db.php @@ -72,7 +72,7 @@ function login_db($username, $password, $ip = '', $browser = '', $forwarded_for if (($ip && !$config['ip_login_limit_use_forwarded']) || ($forwarded_for && $config['ip_login_limit_use_forwarded'])) { - $sql = 'SELECT COUNT(attempt_id) AS count + $sql = 'SELECT COUNT(attempt_id) AS attempts FROM ' . LOGIN_ATTEMPT_TABLE . ' WHERE attempt_time > ' . (time() - (int) $config['ip_login_limit_time']); if ($config['ip_login_limit_use_forwarded']) @@ -85,7 +85,7 @@ function login_db($username, $password, $ip = '', $browser = '', $forwarded_for } $result = $db->sql_query($sql); - $attempts = (int) $db->sql_fetchfield('count'); + $attempts = (int) $db->sql_fetchfield('attempts'); $db->sql_freeresult($result); $attempt_data = array( From 2569d7460ae8ba771b840f437c3846fc1f2c3e07 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Sun, 12 Jun 2011 11:40:57 +0200 Subject: [PATCH 09/12] [ticket/9892] Transaction support for database update sql execution function Updates would fail before because 'begin' as generated by db_tools::sql_create_table would be executed literally. PHPBB3-9892 --- phpBB/install/database_update.php | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 7d7572b204..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') { - $errored = true; - $error_ary['sql'][] = $db->sql_error_sql; - $error_ary['error_code'][] = $db->sql_error_returned; + $db->sql_transaction('begin'); + } + else if ($sql === 'commit') + { + $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); From 76cc7be4d2e388cc59ea297a33fda532ffe853fe Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Sun, 12 Jun 2011 11:46:55 +0200 Subject: [PATCH 10/12] [ticket/9892] Removing closing php tag from create_schema_files PHPBB3-9892 --- phpBB/develop/create_schema_files.php | 1 - 1 file changed, 1 deletion(-) diff --git a/phpBB/develop/create_schema_files.php b/phpBB/develop/create_schema_files.php index e59552f370..c153f3e1e8 100644 --- a/phpBB/develop/create_schema_files.php +++ b/phpBB/develop/create_schema_files.php @@ -2081,4 +2081,3 @@ EOF; echo 'done'; -?> From 11750bdccc168568148de68df2ceca258e5a7da5 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Sun, 12 Jun 2011 12:24:57 +0200 Subject: [PATCH 11/12] [ticket/9892] Remove incorrect use of camel case PHPBB3-9892 --- tests/dbal/db_tools_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/dbal/db_tools_test.php b/tests/dbal/db_tools_test.php index b9206b622e..48406d40a3 100644 --- a/tests/dbal/db_tools_test.php +++ b/tests/dbal/db_tools_test.php @@ -127,7 +127,7 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case ); } - static public function columnValues() + static public function column_values() { return array( array('c_int_size', -9999), @@ -161,7 +161,7 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case } /** - * @dataProvider columnValues + * @dataProvider column_values */ public function test_created_column($column_name, $column_value) { From 4e0717b4d7da58469c795191236ad4256a20c72a Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Sun, 12 Jun 2011 12:26:49 +0200 Subject: [PATCH 12/12] [ticket/9892] Correct copyright year PHPBB3-9892 --- tests/dbal/db_tools_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/dbal/db_tools_test.php b/tests/dbal/db_tools_test.php index 48406d40a3..eb2af4c4cc 100644 --- a/tests/dbal/db_tools_test.php +++ b/tests/dbal/db_tools_test.php @@ -2,7 +2,7 @@ /** * * @package testing -* @copyright (c) 2008 phpBB Group +* @copyright (c) 2011 phpBB Group * @license http://opensource.org/licenses/gpl-license.php GNU Public License * */