phpBB

Code Changes

File: phpbb/db/tools/tools.php

  Unmodified   Added   Modified   Removed
Line 941Line 941
				continue;
}


				continue;
}


			// These DBMS prefix index name with the table name

 
			switch ($this->sql_layer)
{

			switch ($this->sql_layer)
{

 
				// These DBMS prefix index name with the table name

				case 'oracle':
case 'sqlite3':

				case 'oracle':
case 'sqlite3':

					$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;
}


				break;
}


			if (strtolower($row[$col]) == strtolower($index_name))

			if (strtolower($row[$col]) == strtolower($new_index_name))

			{
$this->db->sql_freeresult($result);
return true;

			{
$this->db->sql_freeresult($result);
return true;

Line 1359Line 1362
		{
case 'mysql_40':
case 'mysql_41':

		{
case 'mysql_40':
case 'mysql_41':

 
				$index_name = $this->check_index_name_length($table_name, $index_name, false);

				$statements[] = 'DROP INDEX ' . $index_name . ' ON ' . $table_name;
break;

case 'oracle':
case 'sqlite3':

				$statements[] = 'DROP INDEX ' . $index_name . ' ON ' . $table_name;
break;

case 'oracle':
case 'sqlite3':

				$statements[] = 'DROP INDEX ' . $table_name . '_' . $index_name;


				$index_name = $this->check_index_name_length($table_name, $table_name . '_' . $index_name, false);
$statements[] = 'DROP INDEX ' . $index_name;

			break;
}


			break;
}


Line 1486Line 1491
	function sql_create_unique_index($table_name, $index_name, $column)
{
$statements = array();

	function sql_create_unique_index($table_name, $index_name, $column)
{
$statements = array();


$this->check_index_name_length($table_name, $index_name);

 

switch ($this->sql_layer)
{
case 'oracle':
case 'sqlite3':


switch ($this->sql_layer)
{
case 'oracle':
case 'sqlite3':

				$statements[] = 'CREATE UNIQUE INDEX ' . $table_name . '_' . $index_name . ' ON ' . $table_name . '(' . implode(', ', $column) . ')';


				$index_name = $this->check_index_name_length($table_name, $table_name . '_' . $index_name);
$statements[] = 'CREATE UNIQUE INDEX ' . $index_name . ' ON ' . $table_name . '(' . implode(', ', $column) . ')';

			break;

case 'mysql_40':
case 'mysql_41':

			break;

case 'mysql_40':
case 'mysql_41':

 
				$index_name = $this->check_index_name_length($table_name, $index_name);

				$statements[] = 'ALTER TABLE ' . $table_name . ' ADD UNIQUE INDEX ' . $index_name . '(' . implode(', ', $column) . ')';
break;
}

				$statements[] = 'ALTER TABLE ' . $table_name . ' ADD UNIQUE INDEX ' . $index_name . '(' . implode(', ', $column) . ')';
break;
}

Line 1511Line 1516
	function sql_create_index($table_name, $index_name, $column)
{
$statements = array();

	function sql_create_index($table_name, $index_name, $column)
{
$statements = array();


$this->check_index_name_length($table_name, $index_name);

 

// remove index length unless MySQL4
if ('mysql_40' != $this->sql_layer)


// remove index length unless MySQL4
if ('mysql_40' != $this->sql_layer)

Line 1524Line 1527
		{
case 'oracle':
case 'sqlite3':

		{
case 'oracle':
case 'sqlite3':

				$statements[] = 'CREATE INDEX ' . $table_name . '_' . $index_name . ' ON ' . $table_name . '(' . implode(', ', $column) . ')';


				$index_name = $this->check_index_name_length($table_name, $table_name . '_' . $index_name);
$statements[] = 'CREATE INDEX ' . $index_name . ' ON ' . $table_name . '(' . implode(', ', $column) . ')';

			break;

case 'mysql_40':

			break;

case 'mysql_40':

Line 1539Line 1543
				}
// no break
case 'mysql_41':

				}
// no break
case 'mysql_41':

 
				$index_name = $this->check_index_name_length($table_name, $index_name);

				$statements[] = 'ALTER TABLE ' . $table_name . ' ADD INDEX ' . $index_name . ' (' . implode(', ', $column) . ')';
break;
}

				$statements[] = 'ALTER TABLE ' . $table_name . ' ADD INDEX ' . $index_name . ' (' . implode(', ', $column) . ')';
break;
}

Line 1551Line 1556
	 *
* @param string $table_name
* @param string $index_name

	 *
* @param string $table_name
* @param string $index_name

 
	 * @param bool $throw_error
* @return string The index name, shortened if too long

	 */

	 */

	protected function check_index_name_length($table_name, $index_name)

	protected function check_index_name_length($table_name, $index_name, $throw_error = true)

	{

	{

 
		if (strlen($index_name) > 30)
{
// Try removing the table prefix if it's at the beginning

		$table_prefix = substr(CONFIG_TABLE, 0, -6); // strlen(config)

		$table_prefix = substr(CONFIG_TABLE, 0, -6); // strlen(config)

		if (strlen($table_name . $index_name) - strlen($table_prefix) > 24)

			if (strpos($index_name, $table_prefix) === 0)

		{

		{

			$max_length = strlen($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);

				$index_name = substr($index_name, strlen($table_prefix));
return $this->check_index_name_length($table_name, $index_name, $throw_error);

		}

		}

 

// 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)
{
// 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)
{
trigger_error("Index name '$index_name' on table '$table_name' is too long. The maximum is 30 characters.", E_USER_ERROR);
}
}

return $index_name;

	}

/**

	}

/**