diff options
Diffstat (limited to 'phpBB/includes/acp/acp_database.php')
-rw-r--r-- | phpBB/includes/acp/acp_database.php | 502 |
1 files changed, 151 insertions, 351 deletions
diff --git a/phpBB/includes/acp/acp_database.php b/phpBB/includes/acp/acp_database.php index 758cd10434..0c52f82459 100644 --- a/phpBB/includes/acp/acp_database.php +++ b/phpBB/includes/acp/acp_database.php @@ -1,10 +1,13 @@ <?php /** * -* @package acp -* @version $Id$ -* @copyright (c) 2005 phpBB Group -* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ @@ -16,9 +19,6 @@ if (!defined('IN_PHPBB')) exit; } -/** -* @package acp -*/ class acp_database { var $db_tools; @@ -29,11 +29,7 @@ class acp_database global $cache, $db, $user, $auth, $template, $table_prefix; global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx; - if (!class_exists('phpbb_db_tools')) - { - require($phpbb_root_path . 'includes/db/db_tools.' . $phpEx); - } - $this->db_tools = new phpbb_db_tools($db); + $this->db_tools = new \phpbb\db\tools($db); $user->add_lang('acp/database'); @@ -94,34 +90,34 @@ class acp_database $time = time(); $filename = 'backup_' . $time . '_' . unique_id(); - switch ($db->sql_layer) + switch ($db->get_sql_layer()) { case 'mysqli': case 'mysql4': case 'mysql': - $extractor = new mysql_extractor($download, $store, $format, $filename, $time); + $extractor = new mysql_extractor($format, $filename, $time, $download, $store); break; case 'sqlite': - $extractor = new sqlite_extractor($download, $store, $format, $filename, $time); + $extractor = new sqlite_extractor($format, $filename, $time, $download, $store); + break; + + case 'sqlite3': + $extractor = new sqlite3_extractor($format, $filename, $time, $download, $store); break; case 'postgres': - $extractor = new postgres_extractor($download, $store, $format, $filename, $time); + $extractor = new postgres_extractor($format, $filename, $time, $download, $store); break; case 'oracle': - $extractor = new oracle_extractor($download, $store, $format, $filename, $time); + $extractor = new oracle_extractor($format, $filename, $time, $download, $store); break; case 'mssql': case 'mssql_odbc': case 'mssqlnative': - $extractor = new mssql_extractor($download, $store, $format, $filename, $time); - break; - - case 'firebird': - $extractor = new firebird_extractor($download, $store, $format, $filename, $time); + $extractor = new mssql_extractor($format, $filename, $time, $download, $store); break; } @@ -137,10 +133,10 @@ class acp_database else { // We might wanna empty out all that junk :D - switch ($db->sql_layer) + switch ($db->get_sql_layer()) { case 'sqlite': - case 'firebird': + case 'sqlite3': $extractor->flush('DELETE FROM ' . $table_name . ";\n"); break; @@ -273,7 +269,7 @@ class acp_database break; } - header('Pragma: no-cache'); + header('Cache-Control: private, no-cache'); header("Content-Type: $mimetype; name=\"$name\""); header("Content-disposition: attachment; filename=$name"); @@ -324,32 +320,19 @@ class acp_database break; } - switch ($db->sql_layer) + switch ($db->get_sql_layer()) { case 'mysql': case 'mysql4': case 'mysqli': case 'sqlite': + case 'sqlite3': while (($sql = $fgetd($fp, ";\n", $read, $seek, $eof)) !== false) { $db->sql_query($sql); } break; - case 'firebird': - $delim = ";\n"; - while (($sql = $fgetd($fp, $delim, $read, $seek, $eof)) !== false) - { - $query = trim($sql); - if (substr($query, 0, 8) === 'SET TERM') - { - $delim = $query[9] . "\n"; - continue; - } - $db->sql_query($query); - } - break; - case 'postgres': $delim = ";\n"; while (($sql = $fgetd($fp, $delim, $read, $seek, $eof)) !== false) @@ -382,10 +365,10 @@ class acp_database { trigger_error($user->lang['RESTORE_FAILURE'] . adm_back_link($this->u_action), E_USER_WARNING); } - pg_put_line($db->db_connect_id, $sub . "\n"); + pg_put_line($db->get_db_connect_id(), $sub . "\n"); } - pg_put_line($db->db_connect_id, "\\.\n"); - pg_end_copy($db->db_connect_id); + pg_put_line($db->get_db_connect_id(), "\\.\n"); + pg_end_copy($db->get_db_connect_id()); } } break; @@ -478,9 +461,6 @@ class acp_database } } -/** -* @package acp -*/ class base_extractor { var $fh; @@ -493,8 +473,10 @@ class base_extractor var $format; var $run_comp = false; - function base_extractor($download = false, $store = false, $format, $filename, $time) + function base_extractor($format, $filename, $time, $download = false, $store = false) { + global $request; + $this->download = $download; $this->store = $store; $this->time = $time; @@ -528,7 +510,7 @@ class base_extractor if ($download == true) { $name = $filename . $ext; - header('Pragma: no-cache'); + header('Cache-Control: private, no-cache'); header("Content-Type: $mimetype; name=\"$name\""); header("Content-disposition: attachment; filename=$name"); @@ -539,7 +521,7 @@ class base_extractor break; case 'gzip': - if ((isset($_SERVER['HTTP_ACCEPT_ENCODING']) && strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false) && strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'msie') === false) + if (strpos($request->header('Accept-Encoding'), 'gzip') !== false && strpos(strtolower($request->header('User-Agent')), 'msie') === false) { ob_start('ob_gzhandler'); } @@ -622,9 +604,6 @@ class base_extractor } } -/** -* @package acp -*/ class mysql_extractor extends base_extractor { function write_start($table_prefix) @@ -644,7 +623,7 @@ class mysql_extractor extends base_extractor if ($new_extract === null) { - if ($db->sql_layer === 'mysqli' || version_compare($db->sql_server_info(true), '3.23.20', '>=')) + if ($db->get_sql_layer() === 'mysqli' || version_compare($db->sql_server_info(true), '3.23.20', '>=')) { $new_extract = true; } @@ -667,7 +646,7 @@ class mysql_extractor extends base_extractor function write_data($table_name) { global $db; - if ($db->sql_layer === 'mysqli') + if ($db->get_sql_layer() === 'mysqli') { $this->write_data_mysqli($table_name); } @@ -682,7 +661,7 @@ class mysql_extractor extends base_extractor global $db; $sql = "SELECT * FROM $table_name"; - $result = mysqli_query($db->db_connect_id, $sql, MYSQLI_USE_RESULT); + $result = mysqli_query($db->get_db_connect_id(), $sql, MYSQLI_USE_RESULT); if ($result != false) { $fields_cnt = mysqli_num_fields($result); @@ -761,7 +740,7 @@ class mysql_extractor extends base_extractor global $db; $sql = "SELECT * FROM $table_name"; - $result = mysql_unbuffered_query($sql, $db->db_connect_id); + $result = mysql_unbuffered_query($sql, $db->get_db_connect_id()); if ($result != false) { @@ -948,9 +927,6 @@ class mysql_extractor extends base_extractor } } -/** -* @package acp -*/ class sqlite_extractor extends base_extractor { function write_start($prefix) @@ -1016,50 +992,118 @@ class sqlite_extractor extends base_extractor function write_data($table_name) { global $db; - static $proper; - if (is_null($proper)) - { - $proper = version_compare(PHP_VERSION, '5.1.3', '>='); - } + $col_types = sqlite_fetch_column_types($db->get_db_connect_id(), $table_name); - if ($proper) + $sql = "SELECT * + FROM $table_name"; + $result = sqlite_unbuffered_query($db->get_db_connect_id(), $sql); + $rows = sqlite_fetch_all($result, SQLITE_ASSOC); + $sql_insert = 'INSERT INTO ' . $table_name . ' (' . implode(', ', array_keys($col_types)) . ') VALUES ('; + foreach ($rows as $row) { - $col_types = sqlite_fetch_column_types($db->db_connect_id, $table_name); + foreach ($row as $column_name => $column_data) + { + if (is_null($column_data)) + { + $row[$column_name] = 'NULL'; + } + else if ($column_data == '') + { + $row[$column_name] = "''"; + } + else if (strpos($col_types[$column_name], 'text') !== false || strpos($col_types[$column_name], 'char') !== false || strpos($col_types[$column_name], 'blob') !== false) + { + $row[$column_name] = sanitize_data_generic(str_replace("'", "''", $column_data)); + } + } + $this->flush($sql_insert . implode(', ', $row) . ");\n"); } - else - { - $sql = "SELECT sql - FROM sqlite_master - WHERE type = 'table' - AND name = '" . $table_name . "'"; - $table_data = sqlite_single_query($db->db_connect_id, $sql); - $table_data = preg_replace('#CREATE\s+TABLE\s+"?' . $table_name . '"?#i', '', $table_data); - $table_data = trim($table_data); + } + + function write_end() + { + $this->flush("COMMIT;\n"); + parent::write_end(); + } +} - preg_match('#\((.*)\)#s', $table_data, $matches); +class sqlite3_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"; + $sql_data .= "BEGIN TRANSACTION;\n"; + $this->flush($sql_data); + } - $table_cols = explode(',', trim($matches[1])); - foreach ($table_cols as $declaration) + function write_table($table_name) + { + global $db; + $sql_data = '-- Table: ' . $table_name . "\n"; + $sql_data .= "DROP TABLE $table_name;\n"; + + $sql = "SELECT sql + FROM sqlite_master + WHERE type = 'table' + AND name = '" . $db->sql_escape($table_name) . "' + ORDER BY name ASC;"; + $result = $db->sql_query($sql); + $row = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + + // Create Table + $sql_data .= $row['sql'] . ";\n"; + + $result = $db->sql_query("PRAGMA index_list('" . $db->sql_escape($table_name) . "');"); + + while ($row = $db->sql_fetchrow($result)) + { + if (strpos($row['name'], 'autoindex') !== false) { - $entities = preg_split('#\s+#', trim($declaration)); - $column_name = preg_replace('/"?([^"]+)"?/', '\1', $entities[0]); + continue; + } - // Hit a primary key, those are not what we need :D - if (empty($entities[1]) || (strtolower($entities[0]) === 'primary' && strtolower($entities[1]) === 'key')) - { - continue; - } - $col_types[$column_name] = $entities[1]; + $result2 = $db->sql_query("PRAGMA index_info('" . $db->sql_escape($row['name']) . "');"); + + $fields = array(); + while ($row2 = $db->sql_fetchrow($result2)) + { + $fields[] = $row2['name']; } + $db->sql_freeresult($result2); + + $sql_data .= 'CREATE ' . ($row['unique'] ? 'UNIQUE ' : '') . 'INDEX ' . $row['name'] . ' ON ' . $table_name . ' (' . implode(', ', $fields) . ");\n"; + } + $db->sql_freeresult($result); + + $this->flush($sql_data . "\n"); + } + + function write_data($table_name) + { + global $db; + + $result = $db->sql_query("PRAGMA table_info('" . $db->sql_escape($table_name) . "');"); + + $col_types = array(); + while ($row = $db->sql_fetchrow($result)) + { + $col_types[$row['name']] = $row['type']; } + $db->sql_freeresult($result); + + $sql_insert = 'INSERT INTO ' . $table_name . ' (' . implode(', ', array_keys($col_types)) . ') VALUES ('; $sql = "SELECT * FROM $table_name"; - $result = sqlite_unbuffered_query($db->db_connect_id, $sql); - $rows = sqlite_fetch_all($result, SQLITE_ASSOC); - $sql_insert = 'INSERT INTO ' . $table_name . ' (' . implode(', ', array_keys($col_types)) . ') VALUES ('; - foreach ($rows as $row) + $result = $db->sql_query($sql); + + while ($row = $db->sql_fetchrow($result)) { foreach ($row as $column_name => $column_data) { @@ -1067,11 +1111,11 @@ class sqlite_extractor extends base_extractor { $row[$column_name] = 'NULL'; } - else if ($column_data == '') + else if ($column_data === '') { $row[$column_name] = "''"; } - else if (strpos($col_types[$column_name], 'text') !== false || strpos($col_types[$column_name], 'char') !== false || strpos($col_types[$column_name], 'blob') !== false) + else if (stripos($col_types[$column_name], 'text') !== false || stripos($col_types[$column_name], 'char') !== false || stripos($col_types[$column_name], 'blob') !== false) { $row[$column_name] = sanitize_data_generic(str_replace("'", "''", $column_data)); } @@ -1087,9 +1131,6 @@ class sqlite_extractor extends base_extractor } } -/** -* @package acp -*/ class postgres_extractor extends base_extractor { function write_start($prefix) @@ -1218,7 +1259,6 @@ class postgres_extractor extends base_extractor } $db->sql_freeresult($result); - // Get the listing of primary keys. $sql_pri_keys = "SELECT ic.relname as index_name, bc.relname as tab_name, ta.attname as column_name, i.indisunique as unique_key, i.indisprimary as primary_key FROM pg_class bc, pg_class ic, pg_index i, pg_attribute ta, pg_attribute ia @@ -1318,7 +1358,6 @@ class postgres_extractor extends base_extractor $ary_type[] = pg_field_type($result, $i); $ary_name[] = pg_field_name($result, $i); - $sql = "SELECT pg_get_expr(d.adbin, d.adrelid) as rowdefault FROM pg_attrdef d, pg_class c WHERE (c.relname = '{$table_name}') @@ -1381,9 +1420,6 @@ class postgres_extractor extends base_extractor } } -/** -* @package acp -*/ class mssql_extractor extends base_extractor { function write_end() @@ -1517,11 +1553,11 @@ class mssql_extractor extends base_extractor { global $db; - if ($db->sql_layer === 'mssql') + if ($db->get_sql_layer() === 'mssql') { $this->write_data_mssql($table_name); } - else if($db->sql_layer === 'mssqlnative') + else if($db->get_sql_layer() === 'mssqlnative') { $this->write_data_mssqlnative($table_name); } @@ -1624,7 +1660,7 @@ class mssql_extractor extends base_extractor } $this->flush($sql_data); } - + function write_data_mssqlnative($table_name) { global $db; @@ -1645,16 +1681,17 @@ class mssql_extractor extends base_extractor return; } - $sql = "SELECT * FROM $table_name"; - $result_fields = $db->sql_query_limit($sql, 1); + $sql = "SELECT COLUMN_NAME, DATA_TYPE + FROM INFORMATION_SCHEMA.COLUMNS + WHERE INFORMATION_SCHEMA.COLUMNS.TABLE_NAME = '" . $db->sql_escape($table_name) . "'"; + $result_fields = $db->sql_query($sql); - $row = new result_mssqlnative($result_fields); - $i_num_fields = $row->num_fields(); - - for ($i = 0; $i < $i_num_fields; $i++) + $i_num_fields = 0; + while ($row = $db->sql_fetchrow($result_fields)) { - $ary_type[$i] = $row->field_type($i); - $ary_name[$i] = $row->field_name($i); + $ary_type[$i_num_fields] = $row['DATA_TYPE']; + $ary_name[$i_num_fields] = $row['COLUMN_NAME']; + $i_num_fields++; } $db->sql_freeresult($result_fields); @@ -1663,7 +1700,7 @@ class mssql_extractor extends base_extractor WHERE COLUMNPROPERTY(object_id('$table_name'), COLUMN_NAME, 'IsIdentity') = 1"; $result2 = $db->sql_query($sql); $row2 = $db->sql_fetchrow($result2); - + if (!empty($row2['has_identity'])) { $sql_data .= "\nSET IDENTITY_INSERT $table_name ON\nGO\n"; @@ -1727,8 +1764,8 @@ class mssql_extractor extends base_extractor $sql_data .= "\nSET IDENTITY_INSERT $table_name OFF\nGO\n"; } $this->flush($sql_data); - } - + } + function write_data_odbc($table_name) { global $db; @@ -1827,9 +1864,6 @@ class mssql_extractor extends base_extractor } -/** -* @package acp -*/ class oracle_extractor extends base_extractor { function write_table($table_name) @@ -2057,238 +2091,6 @@ class oracle_extractor extends base_extractor } } -/** -* @package acp -*/ -class firebird_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_data($table_name) - { - global $db; - $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 = ibase_num_fields($result); - - for ($i = 0; $i < $i_num_fields; $i++) - { - $info = ibase_field_info($result, $i); - $ary_type[$i] = $info['type']; - $ary_name[$i] = $info['name']; - } - - 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[strtolower($ary_name[$i])]; - - if (preg_match('#char|text|bool|varbinary|blob#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); - } - - function write_table($table_name) - { - global $db; - - $sql_data = '-- Table: ' . $table_name . "\n"; - $sql_data .= "DROP TABLE $table_name;\n"; - - $data_types = array(7 => 'SMALLINT', 8 => 'INTEGER', 10 => 'FLOAT', 12 => 'DATE', 13 => 'TIME', 14 => 'CHARACTER', 27 => 'DOUBLE PRECISION', 35 => 'TIMESTAMP', 37 => 'VARCHAR', 40 => 'CSTRING', 261 => 'BLOB', 701 => 'DECIMAL', 702 => 'NUMERIC'); - - $sql_data .= "\nCREATE TABLE $table_name (\n"; - - $sql = 'SELECT DISTINCT R.RDB$FIELD_NAME as FNAME, R.RDB$NULL_FLAG as NFLAG, R.RDB$DEFAULT_SOURCE as DSOURCE, F.RDB$FIELD_TYPE as FTYPE, F.RDB$FIELD_SUB_TYPE as STYPE, F.RDB$FIELD_LENGTH as FLEN - FROM RDB$RELATION_FIELDS R - JOIN RDB$FIELDS F ON R.RDB$FIELD_SOURCE=F.RDB$FIELD_NAME - LEFT JOIN RDB$FIELD_DIMENSIONS D ON R.RDB$FIELD_SOURCE = D.RDB$FIELD_NAME - WHERE F.RDB$SYSTEM_FLAG = 0 - AND R.RDB$RELATION_NAME = \''. $table_name . '\' - ORDER BY R.RDB$FIELD_POSITION'; - $result = $db->sql_query($sql); - - $rows = array(); - while ($row = $db->sql_fetchrow($result)) - { - $line = "\t" . '"' . $row['fname'] . '" ' . $data_types[$row['ftype']]; - - if ($row['ftype'] == 261 && $row['stype'] == 1) - { - $line .= ' SUB_TYPE TEXT'; - } - - if ($row['ftype'] == 37 || $row['ftype'] == 14) - { - $line .= ' (' . $row['flen'] . ')'; - } - - if (!empty($row['dsource'])) - { - $line .= ' ' . $row['dsource']; - } - - if (!empty($row['nflag'])) - { - $line .= ' NOT NULL'; - } - $rows[] = $line; - } - $db->sql_freeresult($result); - - $sql_data .= implode(",\n", $rows); - $sql_data .= "\n);\n"; - $keys = array(); - - $sql = 'SELECT I.RDB$FIELD_NAME as NAME - FROM RDB$RELATION_CONSTRAINTS RC, RDB$INDEX_SEGMENTS I, RDB$INDICES IDX - WHERE (I.RDB$INDEX_NAME = RC.RDB$INDEX_NAME) - AND (IDX.RDB$INDEX_NAME = RC.RDB$INDEX_NAME) - AND (RC.RDB$RELATION_NAME = \''. $table_name . '\') - ORDER BY I.RDB$FIELD_POSITION'; - $result = $db->sql_query($sql); - - while ($row = $db->sql_fetchrow($result)) - { - $keys[] = $row['name']; - } - - if (sizeof($keys)) - { - $sql_data .= "\nALTER TABLE $table_name ADD PRIMARY KEY (" . implode(', ', $keys) . ');'; - } - - $db->sql_freeresult($result); - - $sql = 'SELECT I.RDB$INDEX_NAME as INAME, I.RDB$UNIQUE_FLAG as UFLAG, S.RDB$FIELD_NAME as FNAME - FROM RDB$INDICES I JOIN RDB$INDEX_SEGMENTS S ON S.RDB$INDEX_NAME=I.RDB$INDEX_NAME - WHERE (I.RDB$SYSTEM_FLAG IS NULL OR I.RDB$SYSTEM_FLAG=0) - AND I.RDB$FOREIGN_KEY IS NULL - AND I.RDB$RELATION_NAME = \''. $table_name . '\' - AND I.RDB$INDEX_NAME NOT STARTING WITH \'RDB$\' - ORDER BY S.RDB$FIELD_POSITION'; - $result = $db->sql_query($sql); - - $index = array(); - while ($row = $db->sql_fetchrow($result)) - { - $index[$row['iname']]['unique'] = !empty($row['uflag']); - $index[$row['iname']]['values'][] = $row['fname']; - } - - foreach ($index as $index_name => $data) - { - $sql_data .= "\nCREATE "; - if ($data['unique']) - { - $sql_data .= 'UNIQUE '; - } - $sql_data .= "INDEX $index_name ON $table_name(" . implode(', ', $data['values']) . ");"; - } - $sql_data .= "\n"; - - $db->sql_freeresult($result); - - $sql = 'SELECT D1.RDB$DEPENDENT_NAME as DNAME, D1.RDB$FIELD_NAME as FNAME, D1.RDB$DEPENDENT_TYPE, R1.RDB$RELATION_NAME - FROM RDB$DEPENDENCIES D1 - LEFT JOIN RDB$RELATIONS R1 ON ((D1.RDB$DEPENDENT_NAME = R1.RDB$RELATION_NAME) AND (NOT (R1.RDB$VIEW_BLR IS NULL))) - WHERE (D1.RDB$DEPENDED_ON_TYPE = 0) - AND (D1.RDB$DEPENDENT_TYPE <> 3) - AND (D1.RDB$DEPENDED_ON_NAME = \'' . $table_name . '\') - UNION SELECT DISTINCT F2.RDB$RELATION_NAME, D2.RDB$FIELD_NAME, D2.RDB$DEPENDENT_TYPE, R2.RDB$RELATION_NAME FROM RDB$DEPENDENCIES D2, RDB$RELATION_FIELDS F2 - LEFT JOIN RDB$RELATIONS R2 ON ((F2.RDB$RELATION_NAME = R2.RDB$RELATION_NAME) AND (NOT (R2.RDB$VIEW_BLR IS NULL))) - WHERE (D2.RDB$DEPENDENT_TYPE = 3) - AND (D2.RDB$DEPENDENT_NAME = F2.RDB$FIELD_SOURCE) - AND (D2.RDB$DEPENDED_ON_NAME = \'' . $table_name . '\') - ORDER BY 1, 2'; - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) - { - $sql = 'SELECT T1.RDB$DEPENDED_ON_NAME as GEN, T1.RDB$FIELD_NAME, T1.RDB$DEPENDED_ON_TYPE - FROM RDB$DEPENDENCIES T1 - WHERE (T1.RDB$DEPENDENT_NAME = \'' . $row['dname'] . '\') - AND (T1.RDB$DEPENDENT_TYPE = 2 AND T1.RDB$DEPENDED_ON_TYPE = 14) - UNION ALL SELECT DISTINCT D.RDB$DEPENDED_ON_NAME, D.RDB$FIELD_NAME, D.RDB$DEPENDED_ON_TYPE - FROM RDB$DEPENDENCIES D, RDB$RELATION_FIELDS F - WHERE (D.RDB$DEPENDENT_TYPE = 3) - AND (D.RDB$DEPENDENT_NAME = F.RDB$FIELD_SOURCE) - AND (F.RDB$RELATION_NAME = \'' . $row['dname'] . '\') - ORDER BY 1,2'; - $result2 = $db->sql_query($sql); - $row2 = $db->sql_fetchrow($result2); - $db->sql_freeresult($result2); - $gen_name = $row2['gen']; - - $sql_data .= "\nDROP GENERATOR " . $gen_name . ";"; - $sql_data .= "\nSET TERM ^ ;"; - $sql_data .= "\nCREATE GENERATOR " . $gen_name . "^"; - $sql_data .= "\nSET GENERATOR " . $gen_name . " TO 0^\n"; - $sql_data .= "\nCREATE TRIGGER {$row['dname']} FOR $table_name"; - $sql_data .= "\nBEFORE INSERT\nAS\nBEGIN"; - $sql_data .= "\n NEW.{$row['fname']} = GEN_ID(" . $gen_name . ", 1);"; - $sql_data .= "\nEND^\n"; - $sql_data .= "\nSET TERM ; ^\n"; - } - - $this->flush($sql_data); - - $db->sql_freeresult($result); - } -} - // get how much space we allow for a chunk of data, very similar to phpMyAdmin's way of doing things ;-) (hey, we only do this for MySQL anyway :P) function get_usable_memory() { @@ -2464,5 +2266,3 @@ function fgetd_seekless(&$fp, $delim, $read, $seek, $eof, $buffer = 8192) return false; } - -?>
\ No newline at end of file |