aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--phpBB/includes/acp/acp_database.php202
-rw-r--r--phpBB/includes/db/oracle.php2
-rw-r--r--phpBB/install/schemas/oracle_schema.sql48
3 files changed, 216 insertions, 36 deletions
diff --git a/phpBB/includes/acp/acp_database.php b/phpBB/includes/acp/acp_database.php
index 3dafa54a4b..1572a80c89 100644
--- a/phpBB/includes/acp/acp_database.php
+++ b/phpBB/includes/acp/acp_database.php
@@ -34,8 +34,7 @@ class acp_database
switch ($mode)
{
- // TODO: Firebird creates EVERYTHING in upper case, should this be changed?
- // Oracle support must be written
+ // TODO: Check the cases of Oracle and Firebird ( they generate everything in uppercase )
// The queries are ugly++, they must get some love so that they follow the CS
case 'backup':
@@ -154,6 +153,11 @@ class acp_database
$sql_data .= '# Table: ' . $table_name . "\n";
$sql_data .= "DROP TABLE IF EXISTS $table_name;\n";
break;
+
+ case 'oracle':
+ $sql_data .= '# Table: ' . $table_name . "\n";
+ $sql_data .= "DROP TABLE $table_name;\n\\\n";
+ break;
case 'postgres':
case 'firebird':
@@ -166,10 +170,6 @@ class acp_database
$sql_data .= '# Table: ' . $table_name . "\n";
$sql_data .= "DROP TABLE $table_name;\nGO\n";
break;
-
- default:
- trigger_error('KungFuDeathGrip');
- break;
}
$sql_data .= $this->get_table_structure($table_name);
}
@@ -749,8 +749,88 @@ class acp_database
$db->sql_freeresult($result);
break;
- default:
- trigger_error('KungFuDeathGrip');
+ case 'oracle':
+ $ary_type = $ary_name = array();
+
+ // Grab all of the data from current table.
+ $sql = "SELECT * FROM {$table_name}";
+ $result = $db->sql_query($sql);
+
+ $i_num_fields = ocinumcols($result);
+
+ for ($i = 0; $i < $i_num_fields; $i++)
+ {
+ $ary_type[] = ocicolumntype($result, $i);
+ $ary_name[] = "'" . ocicolumnname($result, $i) . "'";
+ }
+
+ while ($row = $db->sql_fetchrow($result))
+ {
+ $schema_vals = $schema_fields = array();
+
+ // Build the SQL statement to recreate the data.
+ for ($i = 0; $i < $i_num_fields; $i++)
+ {
+ $str_val = $row[$ary_name[$i]];
+
+ if (preg_match('#char|text|bool#i', $ary_type[$i]))
+ {
+ $str_quote = "'";
+ $str_empty = '';
+ $str_val = addslashes($str_val);
+ }
+ else if (preg_match('#date|timestamp#i', $ary_type[$i]))
+ {
+ if (empty($str_val))
+ {
+ $str_quote = '';
+ }
+ else
+ {
+ $str_quote = "'";
+ }
+ }
+ else
+ {
+ $str_quote = '';
+ $str_empty = 'NULL';
+ }
+
+ if (empty($str_val) && $str_val !== '0')
+ {
+ $str_val = $str_empty;
+ }
+
+ $schema_vals[] = $str_quote . $str_val . $str_quote;
+ $schema_fields[] = $ary_name[$i];
+ }
+
+ // Take the ordered fields and their associated data and build it
+ // into a valid sql statement to recreate that field in the data.
+ $sql_data .= "INSERT INTO $table_name (" . implode(', ', $schema_fields) . ') VALUES(' . implode(', ', $schema_vals) . ");\n";
+
+ if ($store == true)
+ {
+ $write($fp, $sql_data);
+ }
+
+ if ($download == true)
+ {
+ if (!empty($oper))
+ {
+ echo $oper($sql_data);
+ }
+ else
+ {
+ echo $sql_data;
+ }
+ }
+
+ $sql_data = '';
+
+ }
+ $db->sql_freeresult($result);
+ break;
}
}
}
@@ -862,8 +942,18 @@ class acp_database
$db->sql_freeresult($result);
break;
- default:
- trigger_error('KungFuDeathGrip');
+ case 'oracle':
+ $sql = 'SELECT TNAME as table_name FROM TAB';
+ $result = $db->sql_query($sql);
+ while ($row = $db->sql_fetchrow($result))
+ {
+ if (stripos($row['table_name'], $table_prefix) === 0)
+ {
+ $tables[] = $row['table_name'];
+ }
+ }
+ $db->sql_freeresult($result);
+ break;
}
foreach ($tables as $table)
@@ -1491,8 +1581,96 @@ class acp_database
$db->sql_freeresult($result);
break;
- default:
- trigger_error('KungFuDeathGrip');
+ case 'oracle':
+ $sql_data .= "\nCREATE TABLE $table_name (\n";
+
+ $sql = "SELECT COLUMN_NAME, DATA_TYPE, DATA_PRECISION, DATA_LENGTH, NULLABLE, DATA_DEFAULT from ALL_TAB_COLS where table_name = '{$table_name}'";
+ $result = $db->sql_query($sql);
+
+ $rows = array();
+ while ($row = $db->sql_fetchrow($result))
+ {
+ $line = ' "' . $row['column_name'] . '" ' . $row['data_type'];
+
+ if ($row['data_type'] !== 'CLOB')
+ {
+ if ($row['data_type'] !== 'VARCHAR2')
+ {
+ $line .= '(' . $row['data_precision'] . ')';
+ }
+ else
+ {
+ $line .= '(' . $row['data_length'] . ')';
+ }
+ }
+
+ if (!empty($row['data_default']))
+ {
+ $line .= ' DEFAULT ' . $row['data_default'];
+ }
+
+ if ($row['nullable'] == 'N')
+ {
+ $line .= ' NOT NULL';
+ }
+ $rows[] = $line;
+ }
+ $db->sql_freeresult($result);
+
+ $sql = "SELECT A.CONSTRAINT_NAME, A.COLUMN_NAME FROM USER_CONS_COLUMNS A, USER_CONSTRAINTS B WHERE A.CONSTRAINT_NAME = B.CONSTRAINT_NAME AND B.CONSTRAINT_TYPE = 'P' AND A.TABLE_NAME = '{$table_name}'";
+ $result = $db->sql_query($sql);
+
+ while ($row = $db->sql_fetchrow($result))
+ {
+ $rows[] = " CONSTRAINT {$row['constraint_name']} PRIMARY KEY ({$row['column_name']})";
+ }
+ $db->sql_freeresult($result);
+
+ $sql = "SELECT A.CONSTRAINT_NAME, A.COLUMN_NAME FROM USER_CONS_COLUMNS A, USER_CONSTRAINTS B WHERE A.CONSTRAINT_NAME = B.CONSTRAINT_NAME AND B.CONSTRAINT_TYPE = 'U' AND A.TABLE_NAME = '{$table_name}'";
+ $result = $db->sql_query($sql);
+
+ while ($row = $db->sql_fetchrow($result))
+ {
+ $rows[] = " CONSTRAINT {$row['constraint_name']} UNIQUE ({$row['column_name']})";
+ }
+ $db->sql_freeresult($result);
+
+ $sql_data .= implode(",\n", $rows);
+ $sql_data .= "\n)\n\\";
+
+ $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 = '{$table_name}'";
+ $result = $db->sql_query($sql);
+ while ($row = $db->sql_fetchrow($result))
+ {
+ $sql_data .= "\nCREATE SEQUENCE {$row['referenced_name']}\\\n";
+ }
+ $db->sql_freeresult($result);
+
+ $sql = "SELECT DESCRIPTION, WHEN_CLAUSE, TRIGGER_BODY FROM USER_TRIGGERS WHERE TABLE_NAME = '{$table_name}'";
+ $result = $db->sql_query($sql);
+ while ($row = $db->sql_fetchrow($result))
+ {
+ $sql_data .= "\nCREATE OR REPLACE TRIGGER {$row['description']}WHEN ({$row['when_clause']})\n{$row['trigger_body']}\\";
+ }
+ $db->sql_freeresult($result);
+
+ $sql = "SELECT A.INDEX_NAME, B.COLUMN_NAME FROM USER_INDEXES A, USER_IND_COLUMNS B WHERE A.UNIQUENESS = 'NONUNIQUE' AND A.INDEX_NAME = B.INDEX_NAME AND B.TABLE_NAME = '{$table_name}'";
+ $result = $db->sql_query($sql);
+
+ $index = array();
+
+ while ($row = $db->sql_fetchrow($result))
+ {
+ $index[$row['index_name']][] = $row['column_name'];
+ }
+
+ foreach ($index as $index_name => $column_names)
+ {
+ $sql_data .= "\nCREATE INDEX $index_name ON $table_name(" . implode(', ', $column_names) . ")\n\\";
+ }
+ $db->sql_freeresult($result);
+
+ break;
}
return $sql_data;
diff --git a/phpBB/includes/db/oracle.php b/phpBB/includes/db/oracle.php
index 1431171f19..2a4898ca0d 100644
--- a/phpBB/includes/db/oracle.php
+++ b/phpBB/includes/db/oracle.php
@@ -90,6 +90,8 @@ class dbal_oracle extends dbal
{
global $cache;
+ $query = preg_replace('#FROM \(([^)]*)\)(,|[\n\r\t ]+(?:WHERE|LEFT JOIN)) #', 'FROM \1\2 ', $query);
+
// EXPLAIN only in extra debug mode
if (defined('DEBUG_EXTRA'))
{
diff --git a/phpBB/install/schemas/oracle_schema.sql b/phpBB/install/schemas/oracle_schema.sql
index c7b9bb60a7..c40df033cc 100644
--- a/phpBB/install/schemas/oracle_schema.sql
+++ b/phpBB/install/schemas/oracle_schema.sql
@@ -51,7 +51,7 @@ CREATE TABLE phpbb_attachments (
physical_filename varchar2(255),
real_filename varchar2(255),
download_count number(8) DEFAULT '0' NOT NULL,
- comment clob,
+ "COMMENT" clob,
extension varchar2(100),
mimetype varchar2(100),
filesize number(20) NOT NULL,
@@ -84,7 +84,7 @@ CREATE INDEX phpbb_attachments_topic_id on phpbb_attachments (topic_id)
/
CREATE INDEX phpbb_attachments_poster_id on phpbb_attachments (poster_id)
/
-CREATE INDEX phpbb_attachments_physical_filename on phpbb_attachments (physical_filename)
+CREATE INDEX phpbb_attachments_phys_fname on phpbb_attachments (physical_filename)
/
CREATE INDEX phpbb_attachments_filesize on phpbb_attachments (filesize)
/
@@ -104,7 +104,7 @@ CREATE TABLE phpbb_auth_groups (
CREATE INDEX phpbb_auth_groups_group_id on phpbb_auth_groups (group_id)
/
-CREATE INDEX phpbb_auth_groups_auth_option_id on phpbb_auth_groups (auth_option_id)
+CREATE INDEX phpbb_auth_groups_auth_opt_id on phpbb_auth_groups (auth_option_id)
/
@@ -182,7 +182,7 @@ CREATE TABLE phpbb_auth_roles_data (
role_id number(8) DEFAULT '0' NOT NULL,
auth_option_id number(8) DEFAULT '0' NOT NULL,
auth_setting number(4) DEFAULT '0' NOT NULL,
- CONSTRAINT pk_phpbb_confirm PRIMARY KEY (role_id, auth_option_id)
+ CONSTRAINT pk_phpbb_auth_roles_data PRIMARY KEY (role_id, auth_option_id)
)
/
@@ -201,7 +201,7 @@ CREATE TABLE phpbb_auth_users (
CREATE INDEX phpbb_auth_users_user_id on phpbb_auth_users (user_id)
/
-CREATE INDEX phpbb_auth_users_auth_option_id on phpbb_auth_users (auth_option_id)
+CREATE INDEX phpbb_auth_users_auth_opt_id on phpbb_auth_users (auth_option_id)
/
@@ -255,7 +255,7 @@ CREATE TABLE phpbb_bbcodes (
)
/
-CREATE INDEX phpbb_bbcodes_display_on_posting on phpbb_bbcodes (display_on_posting)
+CREATE INDEX phpbb_bbcodes_disp_on_posting on phpbb_bbcodes (display_on_posting)
/
@@ -529,7 +529,7 @@ END;
CREATE INDEX phpbb_forums_left_right_id on phpbb_forums (left_id, right_id)
/
-CREATE INDEX phpbb_forums_forum_last_post_id on phpbb_forums (forum_last_post_id)
+CREATE INDEX phpbb_forums_forum_last_pst_id on phpbb_forums (forum_last_post_id)
/
@@ -571,7 +571,7 @@ CREATE INDEX phpbb_forums_watch_forum_id on phpbb_forums_watch (forum_id)
/
CREATE INDEX phpbb_forums_watch_user_id on phpbb_forums_watch (user_id)
/
-CREATE INDEX phpbb_forums_watch_notify_status on phpbb_forums_watch (notify_status)
+CREATE INDEX phpbb_forums_watch_notify_stat on phpbb_forums_watch (notify_status)
/
@@ -738,7 +738,7 @@ CREATE TABLE phpbb_moderator_cache (
)
/
-CREATE INDEX phpbb_moderator_cache_display_on_index on phpbb_moderator_cache (display_on_index)
+CREATE INDEX phpbb_moderator_cache_disp_idx on phpbb_moderator_cache (display_on_index)
/
CREATE INDEX phpbb_moderator_cache_forum_id on phpbb_moderator_cache (forum_id)
/
@@ -751,14 +751,14 @@ CREATE TABLE phpbb_modules (
module_id number(8) NOT NULL,
module_enabled number(1) DEFAULT '1' NOT NULL,
module_display number(1) DEFAULT '1' NOT NULL,
- module_name varchar2(255) DEFAULT '' NOT NULL,
- module_class varchar2(10) DEFAULT '' NOT NULL,
+ module_name varchar2(255) DEFAULT '',
+ module_class varchar2(10) DEFAULT '',
parent_id number(8) DEFAULT '0' NOT NULL,
left_id number(8) DEFAULT '0' NOT NULL,
right_id number(8) DEFAULT '0' NOT NULL,
- module_langname varchar2(255) DEFAULT '' NOT NULL,
- module_mode varchar2(255) DEFAULT '' NOT NULL,
- module_auth varchar2(255) DEFAULT '' NOT NULL,
+ module_langname varchar2(255) DEFAULT '',
+ module_mode varchar2(255) DEFAULT '',
+ module_auth varchar2(255) DEFAULT '',
CONSTRAINT pk_phpbb_modules PRIMARY KEY (module_id)
)
/
@@ -795,7 +795,7 @@ CREATE TABLE phpbb_poll_results (
)
/
-CREATE INDEX phpbb_poll_results_poll_option_id on phpbb_poll_results (poll_option_id)
+CREATE INDEX phpbb_poll_results_poll_opt_id on phpbb_poll_results (poll_option_id)
/
CREATE INDEX phpbb_poll_results_topic_id on phpbb_poll_results (topic_id)
/
@@ -953,7 +953,7 @@ CREATE TABLE phpbb_privmsgs_folder (
CREATE SEQUENCE phpbb_privmsgs_folder_seq
/
-CREATE OR REPLACE TRIGGER ai_phpbb_privmsgs_seq
+CREATE OR REPLACE TRIGGER ai_phpbb_privmsgs_fldr_seq
BEFORE INSERT ON phpbb_privmsgs_folder
FOR EACH ROW WHEN (
new.folder_id IS NULL OR new.folder_id = 0
@@ -1065,9 +1065,9 @@ BEGIN
END;
/
-CREATE INDEX phpbb_profile_fields_field_type on phpbb_profile_fields (field_type)
+CREATE INDEX phpbb_profile_fields_field_typ on phpbb_profile_fields (field_type)
/
-CREATE INDEX phpbb_profile_fields_field_order on phpbb_profile_fields (field_order)
+CREATE INDEX phpbb_profile_fields_fld_order on phpbb_profile_fields (field_order)
/
@@ -1202,7 +1202,7 @@ END;
Table: phpbb_search_results
*/
CREATE TABLE phpbb_search_results (
- session_key varchar2(32) DEFAULT '',
+ search_key varchar2(32) DEFAULT '',
search_time number(11) DEFAULT '0' NOT NULL,
search_keywords clob,
search_authors clob,
@@ -1438,9 +1438,9 @@ CREATE TABLE phpbb_styles_template_data (
)
/
-CREATE INDEX phpbb_styles_template_data_template_id on phpbb_styles_template_data (template_id)
+CREATE INDEX phpbb_sty_tmplt_dt_tmplate_id on phpbb_styles_template_data (template_id)
/
-CREATE INDEX phpbb_styles_template_data_template_filename on phpbb_styles_template_data (template_filename)
+CREATE INDEX phpbb_sty_tmplt_dt_tmplt_fname on phpbb_styles_template_data (template_filename)
/
@@ -1640,7 +1640,7 @@ CREATE INDEX phpbb_topics_forum_id on phpbb_topics (forum_id)
/
CREATE INDEX phpbb_topics_forum_id_type on phpbb_topics (forum_id, topic_type)
/
-CREATE INDEX phpbb_topics_topic_last_post_time on phpbb_topics (topic_last_post_time)
+CREATE INDEX phpbb_topics_last_post_time on phpbb_topics (topic_last_post_time)
/
@@ -1686,7 +1686,7 @@ CREATE INDEX phpbb_topics_watch_topic_id on phpbb_topics_watch (topic_id)
/
CREATE INDEX phpbb_topics_watch_user_id on phpbb_topics_watch (user_id)
/
-CREATE INDEX phpbb_topics_watch_notify_status on phpbb_topics_watch (notify_status)
+CREATE INDEX phpbb_topics_watch_notify_stat on phpbb_topics_watch (notify_status)
/
@@ -1816,7 +1816,7 @@ CREATE TABLE phpbb_warnings (
user_id number(8) DEFAULT '0' NOT NULL,
post_id number(8) DEFAULT '0' NOT NULL,
log_id number(8) DEFAULT '0' NOT NULL,
- warning_time number(11) DEFAULT '0' NOT NULL
+ warning_time number(11) DEFAULT '0' NOT NULL,
CONSTRAINT pk_phpbb_warnings PRIMARY KEY (warning_id)
)
/