aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb/db/tools.php
diff options
context:
space:
mode:
Diffstat (limited to 'phpBB/phpbb/db/tools.php')
-rw-r--r--phpBB/phpbb/db/tools.php203
1 files changed, 36 insertions, 167 deletions
diff --git a/phpBB/phpbb/db/tools.php b/phpBB/phpbb/db/tools.php
index 2ee842eace..ae0c695aa2 100644
--- a/phpBB/phpbb/db/tools.php
+++ b/phpBB/phpbb/db/tools.php
@@ -109,36 +109,6 @@ class tools
'VARBINARY' => 'varbinary(255)',
),
- 'firebird' => array(
- 'INT:' => 'INTEGER',
- 'BINT' => 'DOUBLE PRECISION',
- 'UINT' => 'INTEGER',
- 'UINT:' => 'INTEGER',
- 'TINT:' => 'INTEGER',
- 'USINT' => 'INTEGER',
- 'BOOL' => 'INTEGER',
- 'VCHAR' => 'VARCHAR(255) CHARACTER SET NONE',
- 'VCHAR:' => 'VARCHAR(%d) CHARACTER SET NONE',
- 'CHAR:' => 'CHAR(%d) CHARACTER SET NONE',
- 'XSTEXT' => 'BLOB SUB_TYPE TEXT CHARACTER SET NONE',
- 'STEXT' => 'BLOB SUB_TYPE TEXT CHARACTER SET NONE',
- 'TEXT' => 'BLOB SUB_TYPE TEXT CHARACTER SET NONE',
- 'MTEXT' => 'BLOB SUB_TYPE TEXT CHARACTER SET NONE',
- 'XSTEXT_UNI'=> 'VARCHAR(100) CHARACTER SET UTF8',
- 'STEXT_UNI' => 'VARCHAR(255) CHARACTER SET UTF8',
- 'TEXT_UNI' => 'BLOB SUB_TYPE TEXT CHARACTER SET UTF8',
- 'MTEXT_UNI' => 'BLOB SUB_TYPE TEXT CHARACTER SET UTF8',
- 'TIMESTAMP' => 'INTEGER',
- 'DECIMAL' => 'DOUBLE PRECISION',
- 'DECIMAL:' => 'DOUBLE PRECISION',
- 'PDECIMAL' => 'DOUBLE PRECISION',
- 'PDECIMAL:' => 'DOUBLE PRECISION',
- 'VCHAR_UNI' => 'VARCHAR(255) CHARACTER SET UTF8',
- 'VCHAR_UNI:'=> 'VARCHAR(%d) CHARACTER SET UTF8',
- 'VCHAR_CI' => 'VARCHAR(255) CHARACTER SET UTF8',
- 'VARBINARY' => 'CHAR(255) CHARACTER SET NONE',
- ),
-
'mssql' => array(
'INT:' => '[int]',
'BINT' => '[float]',
@@ -331,7 +301,7 @@ class tools
* A list of supported DBMS. We change this class to support more DBMS, the DBMS itself only need to follow some rules.
* @var array
*/
- var $supported_dbms = array('firebird', 'mssql', 'mssqlnative', 'mysql_40', 'mysql_41', 'oracle', 'postgres', 'sqlite', 'sqlite3');
+ var $supported_dbms = array('mssql', 'mssqlnative', 'mysql_40', 'mysql_41', 'oracle', 'postgres', 'sqlite', 'sqlite3');
/**
* This is set to true if user only wants to return the 'to-be-executed' SQL statement(s) (as an array).
@@ -353,7 +323,7 @@ class tools
$this->dbms_type_map = self::get_dbms_type_map();
// Determine mapping database type
- switch ($this->db->sql_layer)
+ switch ($this->db->get_sql_layer())
{
case 'mysql':
$this->sql_layer = 'mysql_40';
@@ -384,7 +354,7 @@ class tools
break;
default:
- $this->sql_layer = $this->db->sql_layer;
+ $this->sql_layer = $this->db->get_sql_layer();
break;
}
}
@@ -407,7 +377,7 @@ class tools
*/
function sql_list_tables()
{
- switch ($this->db->sql_layer)
+ switch ($this->db->get_sql_layer())
{
case 'mysql':
case 'mysql4':
@@ -441,13 +411,6 @@ class tools
FROM pg_stat_user_tables';
break;
- case 'firebird':
- $sql = 'SELECT rdb$relation_name
- FROM rdb$relations
- WHERE rdb$view_source is null
- AND rdb$system_flag = 0';
- break;
-
case 'oracle':
$sql = 'SELECT table_name
FROM USER_TABLES';
@@ -580,7 +543,6 @@ class tools
// Close the table for two DBMS and add to the statements
switch ($this->sql_layer)
{
- case 'firebird':
case 'mssql':
case 'mssqlnative':
$table_sql .= "\n);";
@@ -610,7 +572,6 @@ class tools
$table_sql .= ",\n\t PRIMARY KEY (" . implode(', ', $table_data['PRIMARY_KEY']) . ')';
break;
- case 'firebird':
case 'mssql':
case 'mssqlnative':
// We need the data here
@@ -685,19 +646,6 @@ class tools
$statements[] = $trigger;
}
break;
-
- case 'firebird':
- if ($create_sequence)
- {
- $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;
}
// Write Keys
@@ -763,7 +711,7 @@ class tools
$sqlite = false;
// For SQLite we need to perform the schema changes in a much more different way
- if (($this->db->sql_layer == 'sqlite' || $this->db->sql_layer == 'sqlite3') && $this->return_statements)
+ if (($this->db->get_sql_layer() == 'sqlite' || $this->db->get_sql_layer() == 'sqlite3') && $this->return_statements)
{
$sqlite_data = array();
$sqlite = true;
@@ -1174,12 +1122,6 @@ class tools
WHERE LOWER(table_name) = '" . strtolower($table) . "'";
break;
- case 'firebird':
- $sql = "SELECT RDB\$FIELD_NAME as FNAME
- FROM RDB\$RELATION_FIELDS
- WHERE RDB\$RELATION_NAME = '" . strtoupper($table) . "'";
- break;
-
case 'sqlite':
case 'sqlite3':
$sql = "SELECT sql
@@ -1278,15 +1220,6 @@ class tools
switch ($this->sql_layer)
{
- case 'firebird':
- $sql = "SELECT LOWER(RDB\$INDEX_NAME) as index_name
- FROM RDB\$INDICES
- WHERE RDB\$RELATION_NAME = '" . strtoupper($table_name) . "'
- AND RDB\$UNIQUE_FLAG IS NULL
- AND RDB\$FOREIGN_KEY IS NULL";
- $col = 'index_name';
- break;
-
case 'postgres':
$sql = "SELECT ic.relname as index_name
FROM pg_class bc, pg_class ic, pg_index i
@@ -1332,7 +1265,6 @@ class tools
// These DBMS prefix index name with the table name
switch ($this->sql_layer)
{
- case 'firebird':
case 'oracle':
case 'postgres':
case 'sqlite':
@@ -1385,15 +1317,6 @@ class tools
switch ($this->sql_layer)
{
- case 'firebird':
- $sql = "SELECT LOWER(RDB\$INDEX_NAME) as index_name
- FROM RDB\$INDICES
- WHERE RDB\$RELATION_NAME = '" . strtoupper($table_name) . "'
- AND RDB\$UNIQUE_FLAG IS NOT NULL
- AND RDB\$FOREIGN_KEY IS NULL";
- $col = 'index_name';
- break;
-
case 'postgres':
$sql = "SELECT ic.relname as index_name, i.indisunique
FROM pg_class bc, pg_class ic, pg_index i
@@ -1460,7 +1383,6 @@ class tools
}
break;
- case 'firebird':
case 'postgres':
case 'sqlite':
case 'sqlite3':
@@ -1536,32 +1458,6 @@ class tools
switch ($this->sql_layer)
{
- case 'firebird':
- $sql .= " {$column_type} ";
- $return_array['column_type_sql_type'] = " {$column_type} ";
-
- if (!is_null($column_data[1]))
- {
- $sql .= 'DEFAULT ' . ((is_numeric($column_data[1])) ? $column_data[1] : "'{$column_data[1]}'") . ' ';
- $return_array['column_type_sql_default'] = ((is_numeric($column_data[1])) ? $column_data[1] : "'{$column_data[1]}'") . ' ';
- }
-
- $sql .= 'NOT NULL';
-
- // This is a UNICODE column and thus should be given it's fair share
- if (preg_match('/^X?STEXT_UNI|VCHAR_(CI|UNI:?)/', $column_data[0]))
- {
- $sql .= ' COLLATE UNICODE';
- }
-
- $return_array['auto_increment'] = false;
- if (isset($column_data[2]) && $column_data[2] == 'auto_increment')
- {
- $return_array['auto_increment'] = true;
- }
-
- break;
-
case 'mssql':
case 'mssqlnative':
$sql .= " {$column_type} ";
@@ -1591,8 +1487,16 @@ class tools
$return_array['textimage'] = $column_type === '[text]';
- $sql .= 'NOT NULL';
- $sql_default .= 'NOT NULL';
+ if (!is_null($column_data[1]) || (isset($column_data[2]) && $column_data[2] == 'auto_increment'))
+ {
+ $sql .= 'NOT NULL';
+ $sql_default .= 'NOT NULL';
+ }
+ else
+ {
+ $sql .= 'NULL';
+ $sql_default .= 'NULL';
+ }
$return_array['column_type_sql_default'] = $sql_default;
@@ -1607,7 +1511,15 @@ class tools
{
$sql .= (strpos($column_data[1], '0x') === 0) ? "DEFAULT {$column_data[1]} " : "DEFAULT '{$column_data[1]}' ";
}
- $sql .= 'NOT NULL';
+
+ if (!is_null($column_data[1]))
+ {
+ $sql .= 'NOT NULL';
+ }
+ else
+ {
+ $sql .= 'NULL';
+ }
if (isset($column_data[2]))
{
@@ -1632,7 +1544,7 @@ class tools
// Oracle does not like setting NOT NULL on a column that is already NOT NULL (this happens only on number fields)
if (!preg_match('/number/i', $column_type))
{
- $sql .= ($column_data[1] === '') ? '' : 'NOT NULL';
+ $sql .= ($column_data[1] === '' || $column_data[1] === null) ? '' : 'NOT NULL';
}
$return_array['auto_increment'] = false;
@@ -1660,6 +1572,12 @@ class tools
$return_array['null'] = 'NOT NULL';
$sql .= 'NOT NULL ';
}
+ else
+ {
+ $default_val = "'" . $column_data[1] . "'";
+ $return_array['null'] = 'NULL';
+ $sql .= 'NULL ';
+ }
$return_array['default'] = $default_val;
@@ -1692,8 +1610,11 @@ class tools
$sql .= ' ' . $column_type;
}
- $sql .= ' NOT NULL ';
- $sql .= (!is_null($column_data[1])) ? "DEFAULT '{$column_data[1]}'" : '';
+ if (!is_null($column_data[1]))
+ {
+ $sql .= ' NOT NULL ';
+ $sql .= "DEFAULT '{$column_data[1]}'";
+ }
break;
}
@@ -1772,11 +1693,6 @@ class tools
switch ($this->sql_layer)
{
- case 'firebird':
- // Does not support AFTER statement, only POSITION (and there you need the column position)
- $statements[] = 'ALTER TABLE ' . $table_name . ' ADD "' . strtoupper($column_name) . '" ' . $column_data['column_type_sql'];
- break;
-
case 'mssql':
case 'mssqlnative':
// Does not support AFTER, only through temporary table
@@ -1894,10 +1810,6 @@ class tools
switch ($this->sql_layer)
{
- case 'firebird':
- $statements[] = 'ALTER TABLE ' . $table_name . ' DROP "' . strtoupper($column_name) . '"';
- break;
-
case 'mssql':
case 'mssqlnative':
// We need the data here
@@ -2036,7 +1948,6 @@ class tools
$statements[] = 'DROP INDEX ' . $index_name . ' ON ' . $table_name;
break;
- case 'firebird':
case 'oracle':
case 'postgres':
case 'sqlite':
@@ -2065,21 +1976,6 @@ class tools
switch ($this->sql_layer)
{
- case 'firebird':
- $sql = 'SELECT RDB$GENERATOR_NAME as gen
- FROM RDB$GENERATORS
- WHERE RDB$SYSTEM_FLAG = 0
- AND RDB$GENERATOR_NAME = \'' . strtoupper($table_name) . "_GEN'";
- $result = $this->db->sql_query($sql);
-
- // does a generator exist?
- if ($row = $this->db->sql_fetchrow($result))
- {
- $statements[] = "DROP GENERATOR {$row['gen']};";
- }
- $this->db->sql_freeresult($result);
- break;
-
case 'oracle':
$sql = 'SELECT A.REFERENCED_NAME
FROM USER_DEPENDENCIES A, USER_TRIGGERS B
@@ -2125,7 +2021,6 @@ class tools
switch ($this->sql_layer)
{
- case 'firebird':
case 'postgres':
case 'mysql_40':
case 'mysql_41':
@@ -2217,7 +2112,6 @@ class tools
switch ($this->sql_layer)
{
- case 'firebird':
case 'postgres':
case 'oracle':
case 'sqlite':
@@ -2261,7 +2155,6 @@ class tools
switch ($this->sql_layer)
{
- case 'firebird':
case 'postgres':
case 'oracle':
case 'sqlite':
@@ -2320,15 +2213,6 @@ class tools
{
switch ($this->sql_layer)
{
- case 'firebird':
- $sql = "SELECT LOWER(RDB\$INDEX_NAME) as index_name
- FROM RDB\$INDICES
- WHERE RDB\$RELATION_NAME = '" . strtoupper($table_name) . "'
- AND RDB\$UNIQUE_FLAG IS NULL
- AND RDB\$FOREIGN_KEY IS NULL";
- $col = 'index_name';
- break;
-
case 'postgres':
$sql = "SELECT ic.relname as index_name
FROM pg_class bc, pg_class ic, pg_index i
@@ -2373,7 +2257,6 @@ class tools
switch ($this->sql_layer)
{
- case 'firebird':
case 'oracle':
case 'postgres':
case 'sqlite':
@@ -2400,20 +2283,6 @@ class tools
switch ($this->sql_layer)
{
- case 'firebird':
- // Change type...
- if (!empty($column_data['column_type_sql_default']))
- {
- $statements[] = 'ALTER TABLE ' . $table_name . ' ALTER COLUMN "' . strtoupper($column_name) . '" TYPE ' . ' ' . $column_data['column_type_sql_type'];
- $statements[] = 'ALTER TABLE ' . $table_name . ' ALTER COLUMN "' . strtoupper($column_name) . '" SET DEFAULT ' . ' ' . $column_data['column_type_sql_default'];
- }
- else
- {
- // TODO: try to change pkey without removing trigger, generator or constraints. ATM this query may fail.
- $statements[] = 'ALTER TABLE ' . $table_name . ' ALTER COLUMN "' . strtoupper($column_name) . '" TYPE ' . ' ' . $column_data['column_type_sql_type'];
- }
- break;
-
case 'mssql':
case 'mssqlnative':
// We need the data here