mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 14:18:52 +00:00
[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
This commit is contained in:
parent
bf2125f0f7
commit
418c3d546a
3 changed files with 69 additions and 3 deletions
|
@ -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';
|
||||
|
||||
?>
|
||||
?>
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue