|
From: Meik S. <acy...@ph...> - 2009-09-21 18:00:00
|
Author: acydburn
Date: Mon Sep 21 18:59:39 2009
New Revision: 10174
Log:
Ok, the oracle database backup never actually worked at all. We used the wrong delimiter, did not preserve correct sequence order, did not merge primary keys and uniques... i think no one ever tried to actually restore an oracle backup.
Fix all of this.
Modified:
branches/phpBB-3_0_0/phpBB/includes/acp/acp_database.php
Modified: branches/phpBB-3_0_0/phpBB/includes/acp/acp_database.php
==============================================================================
*** branches/phpBB-3_0_0/phpBB/includes/acp/acp_database.php (original)
--- branches/phpBB-3_0_0/phpBB/includes/acp/acp_database.php Mon Sep 21 18:59:39 2009
***************
*** 142,148 ****
break;
case 'oracle':
! $extractor->flush('TRUNCATE TABLE ' . $table_name . "\\\n");
break;
default:
--- 142,148 ----
break;
case 'oracle':
! $extractor->flush('TRUNCATE TABLE ' . $table_name . "/\n");
break;
default:
***************
*** 1716,1723 ****
{
global $db;
$sql_data = '-- Table: ' . $table_name . "\n";
! $sql_data .= "DROP TABLE $table_name;\n";
! $sql_data .= '\\' . "\n";
$sql_data .= "\nCREATE TABLE $table_name (\n";
$sql = "SELECT COLUMN_NAME, DATA_TYPE, DATA_PRECISION, DATA_LENGTH, NULLABLE, DATA_DEFAULT
--- 1716,1722 ----
{
global $db;
$sql_data = '-- Table: ' . $table_name . "\n";
! $sql_data .= "DROP TABLE $table_name\n/\n";
$sql_data .= "\nCREATE TABLE $table_name (\n";
$sql = "SELECT COLUMN_NAME, DATA_TYPE, DATA_PRECISION, DATA_LENGTH, NULLABLE, DATA_DEFAULT
***************
*** 1732,1738 ****
if ($row['data_type'] !== 'CLOB')
{
! if ($row['data_type'] !== 'VARCHAR2')
{
$line .= '(' . $row['data_precision'] . ')';
}
--- 1731,1737 ----
if ($row['data_type'] !== 'CLOB')
{
! if ($row['data_type'] !== 'VARCHAR2' && $row['data_type'] !== 'CHAR')
{
$line .= '(' . $row['data_precision'] . ')';
}
***************
*** 1762,1773 ****
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
--- 1761,1780 ----
AND A.TABLE_NAME = '{$table_name}'";
$result = $db->sql_query($sql);
+ $primary_key = array();
+ $contraint_name = '';
while ($row = $db->sql_fetchrow($result))
{
! $constraint_name = '"' . $row['constraint_name'] . '"';
! $primary_key[] = '"' . $row['column_name'] . '"';
}
$db->sql_freeresult($result);
+ if (sizeof($primary_key))
+ {
+ $rows[] = " CONSTRAINT {$constraint_name} PRIMARY KEY (" . implode(', ', $primary_key) . ')';
+ }
+
$sql = "SELECT A.CONSTRAINT_NAME, A.COLUMN_NAME
FROM USER_CONS_COLUMNS A, USER_CONSTRAINTS B
WHERE A.CONSTRAINT_NAME = B.CONSTRAINT_NAME
***************
*** 1775,1798 ****
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);
--- 1782,1825 ----
AND A.TABLE_NAME = '{$table_name}'";
$result = $db->sql_query($sql);
+ $unique = array();
+ $contraint_name = '';
while ($row = $db->sql_fetchrow($result))
{
! $constraint_name = '"' . $row['constraint_name'] . '"';
! $unique[] = '"' . $row['column_name'] . '"';
}
$db->sql_freeresult($result);
+ if (sizeof($unique))
+ {
+ $rows[] = " CONSTRAINT {$constraint_name} UNIQUE (" . implode(', ', $unique) . ')';
+ }
+
$sql_data .= implode(",\n", $rows);
! $sql_data .= "\n)\n/\n";
! $sql = "SELECT A.REFERENCED_NAME, C.*
! FROM USER_DEPENDENCIES A, USER_TRIGGERS B, USER_SEQUENCES C
WHERE A.REFERENCED_TYPE = 'SEQUENCE'
AND A.NAME = B.TRIGGER_NAME
! AND B.TABLE_NAME = '{$table_name}'
! AND C.SEQUENCE_NAME = A.REFERENCED_NAME";
$result = $db->sql_query($sql);
+
+ $type = request_var('type', '');
+
while ($row = $db->sql_fetchrow($result))
{
! $sql_data .= "\nDROP SEQUENCE \"{$row['referenced_name']}\"\n/\n";
! $sql_data .= "\nCREATE SEQUENCE \"{$row['referenced_name']}\"";
!
! if ($type == 'full')
! {
! $sql_data .= ' START WITH ' . $row['last_number'];
! }
!
! $sql_data .= "\n/\n";
}
$db->sql_freeresult($result);
***************
*** 1802,1808 ****
$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);
--- 1829,1835 ----
$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']}\n/\n";
}
$db->sql_freeresult($result);
***************
*** 1822,1828 ****
foreach ($index as $index_name => $column_names)
{
! $sql_data .= "\nCREATE INDEX $index_name ON $table_name(" . implode(', ', $column_names) . ")\n\\";
}
$db->sql_freeresult($result);
$this->flush($sql_data);
--- 1849,1855 ----
foreach ($index as $index_name => $column_names)
{
! $sql_data .= "\nCREATE INDEX $index_name ON $table_name(" . implode(', ', $column_names) . ")\n/\n";
}
$db->sql_freeresult($result);
$this->flush($sql_data);
***************
*** 1858,1864 ****
// Oracle uses uppercase - we use lowercase
$str_val = $row[strtolower($ary_name[$i])];
! if (preg_match('#char|text|bool|raw#i', $ary_type[$i]))
{
$str_quote = '';
$str_empty = "''";
--- 1885,1891 ----
// Oracle uses uppercase - we use lowercase
$str_val = $row[strtolower($ary_name[$i])];
! if (preg_match('#char|text|bool|raw|clob#i', $ary_type[$i]))
{
$str_quote = '';
$str_empty = "''";
***************
*** 1892,1898 ****
// 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";
$this->flush($sql_data);
}
--- 1919,1925 ----
// 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/\n";
$this->flush($sql_data);
}
***************
*** 2211,2218 ****
function sanitize_data_oracle($text)
{
! $data = preg_split('/[\0\n\t\r\b\f\'"\\\]/', $text);
! preg_match_all('/[\0\n\t\r\b\f\'"\\\]/', $text, $matches);
$val = array();
--- 2238,2247 ----
function sanitize_data_oracle($text)
{
! // $data = preg_split('/[\0\n\t\r\b\f\'"\/\\\]/', $text);
! // preg_match_all('/[\0\n\t\r\b\f\'"\/\\\]/', $text, $matches);
! $data = preg_split('/[\0\b\f\'\/]/', $text);
! preg_match_all('/[\0\r\b\f\'\/]/', $text, $matches);
$val = array();
|