📄 table.class.php
字号:
} $GLOBALS['sql_query'] .= "\n" . $GLOBALS['sql_constraints_query']; if ($mode == 'one_table') { unset($GLOBALS['sql_constraints_query']); } } } else { $GLOBALS['sql_query'] = ''; } // Copy the data unless this is a VIEW if (($what == 'data' || $what == 'dataonly') && ! PMA_Table::_isView($target_db,$target_table)) { $sql_insert_data = 'INSERT INTO ' . $target . ' SELECT * FROM ' . $source; PMA_DBI_query($sql_insert_data); $GLOBALS['sql_query'] .= "\n\n" . $sql_insert_data . ';'; } require_once './libraries/relation.lib.php'; $GLOBALS['cfgRelation'] = PMA_getRelationsParam(); // Drops old table if the user has requested to move it if ($move) { // This could avoid some problems with replicated databases, when // moving table from replicated one to not replicated one PMA_DBI_select_db($source_db); if (PMA_Table::_isView($source_db,$source_table)) { $sql_drop_query = 'DROP VIEW'; } else { $sql_drop_query = 'DROP TABLE'; } $sql_drop_query .= ' ' . $source; PMA_DBI_query($sql_drop_query); // garvin: Move old entries from PMA-DBs to new table if ($GLOBALS['cfgRelation']['commwork']) { $remove_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['column_info']) . ' SET table_name = \'' . PMA_sqlAddslashes($target_table) . '\', ' . ' db_name = \'' . PMA_sqlAddslashes($target_db) . '\'' . ' WHERE db_name = \'' . PMA_sqlAddslashes($source_db) . '\'' . ' AND table_name = \'' . PMA_sqlAddslashes($source_table) . '\''; PMA_query_as_cu($remove_query); unset($remove_query); } // garvin: updating bookmarks is not possible since only a single table is moved, // and not the whole DB. if ($GLOBALS['cfgRelation']['displaywork']) { $table_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['table_info']) . ' SET db_name = \'' . PMA_sqlAddslashes($target_db) . '\', ' . ' table_name = \'' . PMA_sqlAddslashes($target_table) . '\'' . ' WHERE db_name = \'' . PMA_sqlAddslashes($source_db) . '\'' . ' AND table_name = \'' . PMA_sqlAddslashes($source_table) . '\''; PMA_query_as_cu($table_query); unset($table_query); } if ($GLOBALS['cfgRelation']['relwork']) { $table_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['relation']) . ' SET foreign_table = \'' . PMA_sqlAddslashes($target_table) . '\',' . ' foreign_db = \'' . PMA_sqlAddslashes($target_db) . '\'' . ' WHERE foreign_db = \'' . PMA_sqlAddslashes($source_db) . '\'' . ' AND foreign_table = \'' . PMA_sqlAddslashes($source_table) . '\''; PMA_query_as_cu($table_query); unset($table_query); $table_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['relation']) . ' SET master_table = \'' . PMA_sqlAddslashes($target_table) . '\',' . ' master_db = \'' . PMA_sqlAddslashes($target_db) . '\'' . ' WHERE master_db = \'' . PMA_sqlAddslashes($source_db) . '\'' . ' AND master_table = \'' . PMA_sqlAddslashes($source_table) . '\''; PMA_query_as_cu($table_query); unset($table_query); } // garvin: [TODO] Can't get moving PDFs the right way. The page numbers always // get screwed up independently from duplication because the numbers do not // seem to be stored on a per-database basis. Would the author of pdf support // please have a look at it? if ($GLOBALS['cfgRelation']['pdfwork']) { $table_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['table_coords']) . ' SET table_name = \'' . PMA_sqlAddslashes($target_table) . '\',' . ' db_name = \'' . PMA_sqlAddslashes($target_db) . '\'' . ' WHERE db_name = \'' . PMA_sqlAddslashes($source_db) . '\'' . ' AND table_name = \'' . PMA_sqlAddslashes($source_table) . '\''; PMA_query_as_cu($table_query); unset($table_query); /* $pdf_query = 'SELECT pdf_page_number ' . ' FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['table_coords']) . ' WHERE db_name = \'' . PMA_sqlAddslashes($target_db) . '\'' . ' AND table_name = \'' . PMA_sqlAddslashes($target_table) . '\''; $pdf_rs = PMA_query_as_cu($pdf_query); while ($pdf_copy_row = PMA_DBI_fetch_assoc($pdf_rs)) { $table_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['pdf_pages']) . ' SET db_name = \'' . PMA_sqlAddslashes($target_db) . '\'' . ' WHERE db_name = \'' . PMA_sqlAddslashes($source_db) . '\'' . ' AND page_nr = \'' . PMA_sqlAddslashes($pdf_copy_row['pdf_page_number']) . '\''; $tb_rs = PMA_query_as_cu($table_query); unset($table_query); unset($tb_rs); } */ } $GLOBALS['sql_query'] .= "\n\n" . $sql_drop_query . ';'; } else { // garvin: Create new entries as duplicates from old PMA DBs if ($what != 'dataonly' && !isset($maintain_relations)) { if ($GLOBALS['cfgRelation']['commwork']) { // Get all comments and MIME-Types for current table $comments_copy_query = 'SELECT column_name, ' . PMA_backquote('comment') . ($GLOBALS['cfgRelation']['mimework'] ? ', mimetype, transformation, transformation_options' : '') . ' FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['column_info']) . ' WHERE db_name = \'' . PMA_sqlAddslashes($source_db) . '\' AND table_name = \'' . PMA_sqlAddslashes($source_table) . '\''; $comments_copy_rs = PMA_query_as_cu($comments_copy_query); // Write every comment as new copied entry. [MIME] while ($comments_copy_row = PMA_DBI_fetch_assoc($comments_copy_rs)) { $new_comment_query = 'REPLACE INTO ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['column_info']) . ' (db_name, table_name, column_name, ' . PMA_backquote('comment') . ($GLOBALS['cfgRelation']['mimework'] ? ', mimetype, transformation, transformation_options' : '') . ') ' . ' VALUES(' . '\'' . PMA_sqlAddslashes($target_db) . '\',' . '\'' . PMA_sqlAddslashes($target_table) . '\',' . '\'' . PMA_sqlAddslashes($comments_copy_row['column_name']) . '\'' . ($GLOBALS['cfgRelation']['mimework'] ? ',\'' . PMA_sqlAddslashes($comments_copy_row['comment']) . '\',' . '\'' . PMA_sqlAddslashes($comments_copy_row['mimetype']) . '\',' . '\'' . PMA_sqlAddslashes($comments_copy_row['transformation']) . '\',' . '\'' . PMA_sqlAddslashes($comments_copy_row['transformation_options']) . '\'' : '') . ')'; PMA_query_as_cu($new_comment_query); } // end while PMA_DBI_free_result($comments_copy_rs); unset($comments_copy_rs); } // duplicating the bookmarks must not be done here, but // just once per db $get_fields = array('display_field'); $where_fields = array('db_name' => $source_db, 'table_name' => $source_table); $new_fields = array('db_name' => $target_db, 'table_name' => $target_table); PMA_Table::duplicateInfo('displaywork', 'table_info', $get_fields, $where_fields, $new_fields); $get_fields = array('master_field', 'foreign_db', 'foreign_table', 'foreign_field'); $where_fields = array('master_db' => $source_db, 'master_table' => $source_table); $new_fields = array('master_db' => $target_db, 'master_table' => $target_table); PMA_Table::duplicateInfo('relwork', 'relation', $get_fields, $where_fields, $new_fields); $get_fields = array('foreign_field', 'master_db', 'master_table', 'master_field'); $where_fields = array('foreign_db' => $source_db, 'foreign_table' => $source_table); $new_fields = array('foreign_db' => $target_db, 'foreign_table' => $target_table); PMA_Table::duplicateInfo('relwork', 'relation', $get_fields, $where_fields, $new_fields); // garvin: [TODO] Can't get duplicating PDFs the right way. The page numbers always // get screwed up independently from duplication because the numbers do not // seem to be stored on a per-database basis. Would the author of pdf support // please have a look at it? /* $get_fields = array('page_descr'); $where_fields = array('db_name' => $source_db); $new_fields = array('db_name' => $target_db); $last_id = PMA_Table::duplicateInfo('pdfwork', 'pdf_pages', $get_fields, $where_fields, $new_fields); if (isset($last_id) && $last_id >= 0) { $get_fields = array('x', 'y'); $where_fields = array('db_name' => $source_db, 'table_name' => $source_table); $new_fields = array('db_name' => $target_db, 'table_name' => $target_table, 'pdf_page_number' => $last_id); PMA_Table::duplicateInfo('pdfwork', 'table_coords', $get_fields, $where_fields, $new_fields); } */ } } } /** * checks if given name is a valid table name, * currently if not empty, trailing spaces, '.', '/' and '\' * * @todo add check for valid chars in filename on current system/os * @see http://dev.mysql.com/doc/refman/5.0/en/legal-names.html * @param string $table_name name to check * @return boolean whether the string is valid or not */ function isValidName($table_name) { if ($table_name !== trim($table_name)) { // trailing spaces return false; } if (! strlen($table_name)) { // zero length return false; } if (preg_match('/[.\/\\\\]+/i', $table_name)) { // illegal char . / \ return false; } return true; } /** * renames table * * @param string new table name * @param string new database name * @return boolean success */ function rename($new_name, $new_db = null) { if (null !== $new_db && $new_db !== $this->getDbName()) { // Ensure the target is valid if (count($GLOBALS['dblist']) > 0 && ! in_array($new_db, $GLOBALS['dblist'])) { $this->errors[] = $GLOBALS['strInvalidDatabase'] . ': ' . $new_db; return false; } } else { $new_db = $this->getDbName(); } $new_table = new PMA_Table($new_name, $new_db); if ($this->getFullName() === $new_table->getFullName()) { return true; } if (! PMA_Table::isValidName($new_name)) { $this->errors[] = $GLOBALS['strInvalidTableName'] . ': ' . $new_table->getFullName(); return false; } $GLOBALS['sql_query'] = ' RENAME TABLE ' . $this->getFullName(true) . ' TO ' . $new_table->getFullName(true) . ';'; if (! PMA_DBI_query($GLOBALS['sql_query'])) { $this->errors[] = sprintf($GLOBALS['strErrorRenamingTable'], $this->getFullName(), $new_table->getFullName()); return false; } $old_name = $this->getName(); $old_db = $this->getDbName(); $this->setName($new_name); $this->setDbName($new_db); // TODO move into extra function // PMA_Relation::renameTable($new_name, $old_name, $new_db, $old_db) // garvin: Move old entries from comments to new table require_once './libraries/relation.lib.php'; $GLOBALS['cfgRelation'] = PMA_getRelationsParam(); if ($GLOBALS['cfgRelation']['commwork']) { $remove_query = ' UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['column_info']) . ' SET `db_name` = \'' . PMA_sqlAddslashes($new_db) . '\', `table_name` = \'' . PMA_sqlAddslashes($new_name) . '\' WHERE `db_name` = \'' . PMA_sqlAddslashes($old_db) . '\' AND `table_name` = \'' . PMA_sqlAddslashes($old_name) . '\''; PMA_query_as_cu($remove_query); unset($remove_query); } if ($GLOBALS['cfgRelation']['displaywork']) { $table_query = ' UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['table_info']) . ' SET `db_name` = \'' . PMA_sqlAddslashes($new_db) . '\', `table_name` = \'' . PMA_sqlAddslashes($new_name) . '\' WHERE `db_name` = \'' . PMA_sqlAddslashes($old_db) . '\' AND `table_name` = \'' . PMA_sqlAddslashes($old_name) . '\''; PMA_query_as_cu($table_query); unset($table_query); } if ($GLOBALS['cfgRelation']['relwork']) { $table_query = ' UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['relation']) . ' SET `foreign_db` = \'' . PMA_sqlAddslashes($new_db) . '\', `foreign_table` = \'' . PMA_sqlAddslashes($new_name) . '\' WHERE `foreign_db` = \'' . PMA_sqlAddslashes($old_db) . '\' AND `foreign_table` = \'' . PMA_sqlAddslashes($old_name) . '\''; PMA_query_as_cu($table_query); $table_query = ' UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['relation']) . ' SET `master_db` = \'' . PMA_sqlAddslashes($new_db) . '\', `master_table` = \'' . PMA_sqlAddslashes($new_name) . '\' WHERE `master_db` = \'' . PMA_sqlAddslashes($old_db) . '\' AND `master_table` = \'' . PMA_sqlAddslashes($old_name) . '\''; PMA_query_as_cu($table_query); unset($table_query); } if ($GLOBALS['cfgRelation']['pdfwork']) { $table_query = ' UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['table_coords']) . ' SET `db_name` = \'' . PMA_sqlAddslashes($new_db) . '\', `table_name` = \'' . PMA_sqlAddslashes($new_name) . '\' WHERE `db_name` = \'' . PMA_sqlAddslashes($old_db) . '\' AND `table_name` = \'' . PMA_sqlAddslashes($old_name) . '\''; PMA_query_as_cu($table_query); unset($table_query); } $this->messages[] = sprintf($GLOBALS['strRenameTableOK'], htmlspecialchars($old_name), htmlspecialchars($new_name)); return true; }}?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -