diff options
Diffstat (limited to 'phpBB/includes/acp')
-rw-r--r-- | phpBB/includes/acp/acp_database.php | 174 | ||||
-rw-r--r-- | phpBB/includes/acp/acp_profile.php | 36 | ||||
-rw-r--r-- | phpBB/includes/acp/acp_users.php | 3 |
3 files changed, 212 insertions, 1 deletions
diff --git a/phpBB/includes/acp/acp_database.php b/phpBB/includes/acp/acp_database.php index d7ce8db8b3..64806eda59 100644 --- a/phpBB/includes/acp/acp_database.php +++ b/phpBB/includes/acp/acp_database.php @@ -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; @@ -1552,6 +1557,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 +*/ class oracle_extractor extends base_extractor { function write_table($table_name) diff --git a/phpBB/includes/acp/acp_profile.php b/phpBB/includes/acp/acp_profile.php index 2a9c0e8c19..bd7d58717b 100644 --- a/phpBB/includes/acp/acp_profile.php +++ b/phpBB/includes/acp/acp_profile.php @@ -1605,6 +1605,42 @@ class acp_profile } break; + + case 'db2': + + // We are defining the biggest common value, because of the possibility to edit the min/max values of each field. + $sql = 'ALTER TABLE ' . PROFILE_FIELDS_DATA_TABLE . " ADD \"$field_ident\" "; + + switch ($field_type) + { + case FIELD_STRING: + $sql .= ' VARCHAR(255) '; + break; + + case FIELD_DATE: + $sql .= 'VARCHAR(10) '; + break; + + case FIELD_TEXT: + $sql .= "varchar(32672)"; + // ADD {$field_ident}_bbcode_uid VARCHAR2(5) NOT NULL, + // ADD {$field_ident}_bbcode_bitfield NUMBER(11) UNSIGNED"; + break; + + case FIELD_BOOL: + $sql .= 'smallint '; + break; + + case FIELD_DROPDOWN: + $sql .= 'integer '; + break; + + case FIELD_INT: + $sql .= 'float '; + break; + } + + break; } return $sql; diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index f87e175301..13612cf363 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -775,7 +775,7 @@ class acp_users { $sql_ary += array( 'user_email' => $update_email, - 'user_email_hash' => crc32($update_email) . strlen($update_email) + 'user_email_hash' => hexdec(crc32($update_email) . strlen($update_email)) ); add_log('user', $user_id, 'LOG_USER_UPDATE_EMAIL', $user_row['username'], $user_row['user_email'], $update_email); @@ -1130,6 +1130,7 @@ class acp_users case 'oracle': case 'firebird': case 'postgres': + case 'db2': $right_delim = $left_delim = '"'; break; |