aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--phpBB/includes/acp/acp_database.php2
-rw-r--r--phpBB/includes/db/db_tools.php64
2 files changed, 65 insertions, 1 deletions
diff --git a/phpBB/includes/acp/acp_database.php b/phpBB/includes/acp/acp_database.php
index 980f4fcf48..fa3c3a5dca 100644
--- a/phpBB/includes/acp/acp_database.php
+++ b/phpBB/includes/acp/acp_database.php
@@ -1805,7 +1805,7 @@ class oracle_extractor extends base_extractor
FROM USER_DEPENDENCIES A, USER_TRIGGERS B
WHERE A.REFERENCED_TYPE = 'SEQUENCE'
AND A.NAME = B.TRIGGER_NAME
- AND B. TABLE_NAME = '{$table_name}'";
+ AND B.TABLE_NAME = '{$table_name}'";
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
diff --git a/phpBB/includes/db/db_tools.php b/phpBB/includes/db/db_tools.php
index 734cc05e08..4bb6fb0bff 100644
--- a/phpBB/includes/db/db_tools.php
+++ b/phpBB/includes/db/db_tools.php
@@ -1195,6 +1195,70 @@ class phpbb_db_tools
}
/**
+ * Drop Table
+ */
+ public static function sql_table_drop($table_name, $index_name)
+ {
+ global $db;
+
+ $statements = array();
+
+ // the most basic operation, get rid of the table
+ $statements[] = 'DROP TABLE ' . $table_name;
+
+ switch ($db->dbms_type)
+ {
+ 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 = $db->sql_query($sql);
+
+ // does a generator exist?
+ if ($row = $db->sql_fetchrow($result))
+ {
+ $statements[] = "DROP GENERATOR {$row['gen']};";
+ }
+ $db->sql_freeresult($result);
+ break;
+
+ case 'oracle':
+ $sql = 'SELECT A.REFERENCED_NAME
+ FROM USER_DEPENDENCIES A, USER_TRIGGERS B
+ WHERE A.REFERENCED_TYPE = 'SEQUENCE'
+ AND A.NAME = B.TRIGGER_NAME
+ AND B.TABLE_NAME = \'' . strtoupper($table_name) . "'";
+ $result = $db->sql_query($sql);
+
+ // any sequences ref'd to this table's triggers?
+ while ($row = $db->sql_fetchrow($result))
+ {
+ $statements[] = "DROP SEQUENCE {$row['referenced_name']}";
+ }
+ $db->sql_freeresult($result);
+
+ case 'postgres':
+ // PGSQL does not "tightly" bind sequences and tables, we must guess...
+ $sql = "SELECT relname
+ FROM pg_class
+ WHERE relkind = 'S'
+ AND relname = '{$table_name}_seq'";
+ $result = $db->sql_query($sql);
+
+ // We don't even care about storing the results. We already know the answer if we get rows back.
+ if ($db->sql_fetchrow($result))
+ {
+ $statements[] = "DROP SEQUENCE {$table_name}_seq;\n";
+ }
+ $db->sql_freeresult($result);
+ break;
+ }
+
+ return self::_sql_run_sql($statements);
+ }
+
+ /**
* Add primary key
*/
public static function sql_create_primary_key($table_name, $column)