mirror of
https://github.com/phpbb/phpbb.git
synced 2025-07-30 21:40:43 +02:00
- add DB2 support
/me takes a nap git-svn-id: file:///svn/phpbb/trunk@8308 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
@@ -113,6 +113,10 @@ class acp_database
|
||||
case 'firebird':
|
||||
$extractor = new firebird_extractor($download, $store, $format, $filename, $time);
|
||||
break;
|
||||
|
||||
case 'db2':
|
||||
$extractor = new db2_extractor($download, $store, $format, $filename, $time);
|
||||
break;
|
||||
}
|
||||
|
||||
$extractor->write_start($table_prefix);
|
||||
@@ -131,6 +135,7 @@ class acp_database
|
||||
{
|
||||
case 'sqlite':
|
||||
case 'firebird':
|
||||
case 'db2':
|
||||
$extractor->flush('DELETE FROM ' . $table_name . ";\n");
|
||||
break;
|
||||
|
||||
@@ -1549,6 +1554,175 @@ class mssql_extractor extends base_extractor
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @package acp
|
||||
*/
|
||||
class db2_extractor extends base_extractor
|
||||
{
|
||||
function write_start($prefix)
|
||||
{
|
||||
$sql_data = "--\n";
|
||||
$sql_data .= "-- phpBB Backup Script\n";
|
||||
$sql_data .= "-- Dump of tables for $prefix\n";
|
||||
$sql_data .= "-- DATE : " . gmdate("d-m-Y H:i:s", $this->time) . " GMT\n";
|
||||
$sql_data .= "--\n";
|
||||
$this->flush($sql_data);
|
||||
}
|
||||
|
||||
function write_table($table_name)
|
||||
{
|
||||
global $db;
|
||||
$sql_data = '-- Table: ' . $table_name . "\n";
|
||||
$sql_data .= "\nCREATE TABLE $table_name (\n";
|
||||
$rows = array();
|
||||
|
||||
// switch to db2_columns()?
|
||||
$sql = "SELECT colname, typename, length, default, identity, nulls
|
||||
FROM syscat.columns
|
||||
WHERE tabname = '$table_name'";
|
||||
$result = $db->sql_query($sql);
|
||||
|
||||
while ($row = $db->sql_fetchrow($result))
|
||||
{
|
||||
$line = "\t{$row['colname']} {$row['typename']}";
|
||||
|
||||
if ($row['identity'] == 'Y')
|
||||
{
|
||||
$line .= ' GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1)';
|
||||
}
|
||||
|
||||
if ($row['typename'] == 'VARCHAR' || $row['typename'] == 'CHARACTER' || $row['typename'] == 'CLOB')
|
||||
{
|
||||
$line .= ' (' . $row['length'] . ')';
|
||||
}
|
||||
|
||||
if ($row['nulls'] == 'N')
|
||||
{
|
||||
$line .= ' NOT NULL';
|
||||
}
|
||||
else
|
||||
{
|
||||
$line .= ' NULL';
|
||||
}
|
||||
|
||||
if ($row['default'] !== null)
|
||||
{
|
||||
$line .= ' DEFAULT ' . $row['default'];
|
||||
}
|
||||
|
||||
$rows[] = $line;
|
||||
}
|
||||
$db->sql_freeresult($result);
|
||||
|
||||
// switch to db2_columns()?
|
||||
$sql = "SELECT colname
|
||||
FROM SYSCAT.KEYCOLUSE
|
||||
WHERE tabname = '$table_name'";
|
||||
$result = $db->sql_query($sql);
|
||||
$prim_cols = array();
|
||||
while ($row = $db->sql_fetchrow($result))
|
||||
{
|
||||
$prim_cols[] = $row['colname'];
|
||||
}
|
||||
$db->sql_freeresult($result);
|
||||
if (sizeof($prim_cols))
|
||||
{
|
||||
$rows[] = "\tPRIMARY KEY (" . implode($prim_cols) . ')';
|
||||
}
|
||||
|
||||
$sql_data .= implode(",\n", $rows);
|
||||
$sql_data .= "\n);\n\n";
|
||||
$rows = array();
|
||||
|
||||
$sql = "SELECT colnames, indname
|
||||
FROM SYSCAT.INDEXES
|
||||
WHERE TABNAME = '$table_name'
|
||||
AND UNIQUERULE <> 'P'";
|
||||
$result = $db->sql_query($sql);
|
||||
$index = array();
|
||||
while ($row = $db->sql_fetchrow($result))
|
||||
{
|
||||
$inds = explode('+', $row['colnames']);
|
||||
unset($inds[0]);
|
||||
$sql_data .= 'CREATE INDEX ' . $row['indname'] . ' ON ' . $table_name . ' (' . implode(', ', $inds) . ") PCTFREE 10 MINPCTUSED 10 ALLOW REVERSE SCANS PAGE SPLIT SYMMETRIC COLLECT SAMPLED DETAILED STATISTICS;\n";
|
||||
}
|
||||
$db->sql_freeresult($result);
|
||||
|
||||
$this->flush($sql_data);
|
||||
}
|
||||
|
||||
function write_data($table_name)
|
||||
{
|
||||
global $db;
|
||||
$ary_type = $ary_name = array();
|
||||
$result = db2_columns($db->db_connect_id, '', '%', $table_name);
|
||||
$i = 0;
|
||||
while ($row = $db->sql_fetchrow($result))
|
||||
{
|
||||
$ary_type[$i] = $row['type_name'];
|
||||
$ary_name[$i++] = strtolower($row['column_name']);
|
||||
}
|
||||
$db->sql_freeresult($result);
|
||||
|
||||
// Grab all of the data from current table.
|
||||
$sql = "SELECT *
|
||||
FROM $table_name";
|
||||
$result = $db->sql_query($sql);
|
||||
|
||||
$sql_data = '';
|
||||
$i_num_fields = $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|clob#i', $ary_type[$i]))
|
||||
{
|
||||
$str_quote = "'";
|
||||
$str_empty = '';
|
||||
$str_val = sanitize_data_generic(str_replace("'", "''", $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[$i] = $str_quote . $str_val . $str_quote;
|
||||
$schema_fields[$i] = '"' . $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";
|
||||
|
||||
$this->flush($sql_data);
|
||||
}
|
||||
$db->sql_freeresult($result);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @package acp
|
||||
*/
|
||||
|
Reference in New Issue
Block a user