aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Alexander <admin@m-a-styles.de>2017-07-16 17:33:52 +0200
committerMarc Alexander <admin@m-a-styles.de>2017-07-16 17:33:52 +0200
commitd490190a99a137ab2a4c33f9ced4945614319855 (patch)
tree287548fcd4679198ada1d3c0016a0061c9d49ddc
parent337c8451e750fe89b9a8eb0b461db1a5699ca005 (diff)
parent24bde10028a1a7d8d479e2a381bec047485b4273 (diff)
downloadforums-d490190a99a137ab2a4c33f9ced4945614319855.tar
forums-d490190a99a137ab2a4c33f9ced4945614319855.tar.gz
forums-d490190a99a137ab2a4c33f9ced4945614319855.tar.bz2
forums-d490190a99a137ab2a4c33f9ced4945614319855.tar.xz
forums-d490190a99a137ab2a4c33f9ced4945614319855.zip
Merge pull request #4864 from lavigor/ticket/15259
[ticket/15259] Fatal error on SQLite/Oracle database update
-rw-r--r--phpBB/phpbb/db/tools/tools.php36
-rw-r--r--tests/dbal/db_tools_test.php37
2 files changed, 51 insertions, 22 deletions
diff --git a/phpBB/phpbb/db/tools/tools.php b/phpBB/phpbb/db/tools/tools.php
index 76036554d2..2f891e43d5 100644
--- a/phpBB/phpbb/db/tools/tools.php
+++ b/phpBB/phpbb/db/tools/tools.php
@@ -941,29 +941,19 @@ class tools implements tools_interface
continue;
}
- // These DBMS prefix index name with the table name
switch ($this->sql_layer)
{
+ // These DBMS prefix index name with the table name
case 'oracle':
case 'sqlite3':
- $index_name = $this->check_index_name_length($table_name, $table_name . '_' . $index_name, false);
- $table_prefix = substr(CONFIG_TABLE, 0, -6); // strlen(config)
-
- if (strpos($index_name , $table_name) === false)
- {
- if (strpos($index_name, $table_prefix) !== false)
- {
- $row[$col] = substr($row[$col], strlen($table_prefix) + 1);
- }
- else
- {
- $row[$col] = substr($row[$col], strlen($table_name) + 1);
- }
- }
+ $new_index_name = $this->check_index_name_length($table_name, $table_name . '_' . $index_name, false);
+ break;
+ default:
+ $new_index_name = $this->check_index_name_length($table_name, $index_name, false);
break;
}
- if (strtolower($row[$col]) == strtolower($index_name))
+ if (strtolower($row[$col]) == strtolower($new_index_name))
{
$this->db->sql_freeresult($result);
return true;
@@ -1577,15 +1567,17 @@ class tools implements tools_interface
$table_prefix = substr(CONFIG_TABLE, 0, -6); // strlen(config)
if (strpos($index_name, $table_prefix) === 0)
{
- $index_name = substr($index_name, strlen($table_prefix) + 1);
- return $this->check_index_name_length($table_name, $index_name);
+ $index_name = substr($index_name, strlen($table_prefix));
+ return $this->check_index_name_length($table_name, $index_name, $throw_error);
}
- // Try removing the table name then
- if (strpos($index_name, $table_name) === 0)
+ // Try removing the remaining suffix part of table name then
+ $table_suffix = substr($table_name, strlen($table_prefix));
+ if (strpos($index_name, $table_suffix) === 0)
{
- $index_name = substr($index_name, strlen($table_name) + 1);
- return $this->check_index_name_length($table_name, $index_name);
+ // Remove the suffix and underscore separator between table_name and index_name
+ $index_name = substr($index_name, strlen($table_suffix) + 1);
+ return $this->check_index_name_length($table_name, $index_name, $throw_error);
}
if ($throw_error)
diff --git a/tests/dbal/db_tools_test.php b/tests/dbal/db_tools_test.php
index b884b4ab95..f9243e7266 100644
--- a/tests/dbal/db_tools_test.php
+++ b/tests/dbal/db_tools_test.php
@@ -421,4 +421,41 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case
$this->assertTrue($this->tools->sql_column_add('prefix_table_name', 'c_bug_13282', array('TINT:2')));
$this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_bug_13282'));
}
+
+ public function test_create_index_with_long_name()
+ {
+ // This constant is being used for checking table prefix.
+ $table_prefix = substr(CONFIG_TABLE, 0, -6); // strlen(config)
+
+ if (strlen($table_prefix) > 20)
+ {
+ $this->markTestIncomplete('The table prefix length is too long for proper testing of index shortening function.');
+ }
+
+ $table_suffix = str_repeat('a', 25 - strlen($table_prefix));
+ $table_name = $table_prefix . $table_suffix;
+
+ $this->tools->sql_create_table($table_name, $this->table_data);
+
+ // Index name and table suffix and table prefix have > 30 chars in total.
+ // Index name and table suffix have <= 30 chars in total.
+ $long_index_name = str_repeat('i', 30 - strlen($table_suffix));
+ $this->assertFalse($this->tools->sql_index_exists($table_name, $long_index_name));
+ $this->assertTrue($this->tools->sql_create_index($table_name, $long_index_name, array('c_timestamp')));
+ $this->assertTrue($this->tools->sql_index_exists($table_name, $long_index_name));
+
+ // Index name and table suffix have > 30 chars in total.
+ $very_long_index_name = str_repeat('i', 30);
+ $this->assertFalse($this->tools->sql_index_exists($table_name, $very_long_index_name));
+ $this->assertTrue($this->tools->sql_create_index($table_name, $very_long_index_name, array('c_timestamp')));
+ $this->assertTrue($this->tools->sql_index_exists($table_name, $very_long_index_name));
+
+ $this->tools->sql_table_drop($table_name);
+
+ // Index name has > 30 chars - that should not be possible.
+ $too_long_index_name = str_repeat('i', 31);
+ $this->assertFalse($this->tools->sql_index_exists('prefix_table_name', $too_long_index_name));
+ $this->setExpectedTriggerError(E_USER_ERROR);
+ $this->tools->sql_create_index('prefix_table_name', $too_long_index_name, array('c_timestamp'));
+ }
}