/** * If necessary, prepares trigger information and passes * it to PMA_RTE_handleExport() for the actual export. */ function PMA_TRI_handleExport() { global $_GET, $db, $table; if (!empty($_GET['export_item']) && !empty($_GET['item_name'])) { $item_name = $_GET['item_name']; $triggers = PMA_DBI_get_triggers($db, $table, ''); $export_data = false; foreach ($triggers as $trigger) { if ($trigger['name'] === $item_name) { $export_data = $trigger['create']; break; } } PMA_RTE_handleExport($item_name, $export_data); } }
/** * renames table * * @param string $new_name new table name * @param string $new_db new database name * @param bool $is_view is this for a VIEW rename? * @todo remove the $is_view parameter (also in callers) * * @return bool success */ function rename($new_name, $new_db = null, $is_view = false) { if (null !== $new_db && $new_db !== $this->getDbName()) { // Ensure the target is valid if (!$GLOBALS['pma']->databases->exists($new_db)) { $this->errors[] = __('Invalid database') . ': ' . $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[] = __('Invalid table name') . ': ' . $new_table->getFullName(); return false; } // If the table is moved to a different database drop its triggers first $triggers = PMA_DBI_get_triggers($this->getDbName(), $this->getName(), ''); $handle_triggers = $this->getDbName() != $new_db && $triggers; if ($handle_triggers) { foreach ($triggers as $trigger) { $sql = 'DROP TRIGGER IF EXISTS ' . PMA_backquote($this->getDbName()) . '.' . PMA_backquote($trigger['name']) . ';'; PMA_DBI_query($sql); } } /* * tested also for a view, in MySQL 5.0.92, 5.1.55 and 5.5.13 */ $GLOBALS['sql_query'] = ' RENAME TABLE ' . $this->getFullName(true) . ' TO ' . $new_table->getFullName(true) . ';'; // I don't think a specific error message for views is necessary if (!PMA_DBI_query($GLOBALS['sql_query'])) { // Restore triggers in the old database if ($handle_triggers) { PMA_DBI_select_db($this->getDbName()); foreach ($triggers as $trigger) { PMA_DBI_query($trigger['create']); } } $this->errors[] = sprintf(__('Error renaming table %1$s to %2$s'), $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) */ // Move old entries from comments to new table $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_controluser($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_controluser($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_controluser($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_controluser($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_controluser($table_query); unset($table_query); } if ($GLOBALS['cfgRelation']['designerwork']) { $table_query = ' UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['designer_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_controluser($table_query); unset($table_query); } $this->messages[] = sprintf(__('Table %1$s has been renamed to %2$s.'), htmlspecialchars($old_name), htmlspecialchars($new_name)); return true; }
/** * Outputs table's structure * * @param string $db database name * @param string $table table name * @param string $crlf the end of line sequence * @param string $error_url the url to go back in case of error * @param string $export_mode 'create_table','triggers','create_view', * 'stand_in' * @param string $export_type 'server', 'database', 'table' * @param bool $relation whether to include relation comments * @param bool $comments whether to include the pmadb-style column * comments as comments in the structure; this is * deprecated but the parameter is left here * because export.php calls exportStructure() * also for other export types which use this * parameter * @param bool $mime whether to include mime comments * @param bool $dates whether to include creation/update/check dates * * @return bool Whether it succeeded */ public function exportStructure($db, $table, $crlf, $error_url, $export_mode, $export_type, $relation = false, $comments = false, $mime = false, $dates = false) { if (isset($GLOBALS['sql_compatibility'])) { $compat = $GLOBALS['sql_compatibility']; } else { $compat = 'NONE'; } $formatted_table_name = isset($GLOBALS['sql_backquotes']) ? PMA_Util::backquoteCompat($table, $compat) : '\'' . $table . '\''; $dump = $this->_possibleCRLF() . $this->_exportComment(str_repeat('-', 56)) . $this->_possibleCRLF() . $this->_exportComment(); switch ($export_mode) { case 'create_table': $dump .= $this->_exportComment(__('Table structure for table') . ' ' . $formatted_table_name); $dump .= $this->_exportComment(); $dump .= $this->getTableDef($db, $table, $crlf, $error_url, $dates); $dump .= $this->_getTableComments($db, $table, $crlf, $relation, $mime); break; case 'triggers': $dump = ''; $triggers = PMA_DBI_get_triggers($db, $table); if ($triggers) { $dump .= $this->_possibleCRLF() . $this->_exportComment() . $this->_exportComment(__('Triggers') . ' ' . $formatted_table_name) . $this->_exportComment(); $delimiter = '//'; foreach ($triggers as $trigger) { $dump .= $trigger['drop'] . ';' . $crlf; $dump .= 'DELIMITER ' . $delimiter . $crlf; $dump .= $trigger['create']; $dump .= 'DELIMITER ;' . $crlf; } } break; case 'create_view': $dump .= $this->_exportComment(__('Structure for view') . ' ' . $formatted_table_name) . $this->_exportComment(); // delete the stand-in table previously created (if any) if ($export_type != 'table') { $dump .= 'DROP TABLE IF EXISTS ' . PMA_Util::backquote($table) . ';' . $crlf; } $dump .= $this->getTableDef($db, $table, $crlf, $error_url, $dates, true, true); break; case 'stand_in': $dump .= $this->_exportComment(__('Stand-in structure for view') . ' ' . $formatted_table_name) . $this->_exportComment(); // export a stand-in definition to resolve view dependencies $dump .= $this->getTableDefStandIn($db, $table, $crlf); } // end switch // this one is built by getTableDef() to use in table copy/move // but not in the case of export unset($GLOBALS['sql_constraints_query']); return PMA_exportOutputHandler($dump); }
/** * renames table * * @param string $new_name new table name * @param string $new_db new database name * * @return bool success */ function rename($new_name, $new_db = null) { if (null !== $new_db && $new_db !== $this->getDbName()) { // Ensure the target is valid if (!$GLOBALS['pma']->databases->exists($new_db)) { $this->errors[] = __('Invalid database') . ': ' . $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[] = __('Invalid table name') . ': ' . $new_table->getFullName(); return false; } // If the table is moved to a different database drop its triggers first $triggers = PMA_DBI_get_triggers($this->getDbName(), $this->getName(), ''); $handle_triggers = $this->getDbName() != $new_db && $triggers; if ($handle_triggers) { foreach ($triggers as $trigger) { $sql = 'DROP TRIGGER IF EXISTS ' . PMA_Util::backquote($this->getDbName()) . '.' . PMA_Util::backquote($trigger['name']) . ';'; PMA_DBI_query($sql); } } /* * tested also for a view, in MySQL 5.0.92, 5.1.55 and 5.5.13 */ $GLOBALS['sql_query'] = ' RENAME TABLE ' . $this->getFullName(true) . ' TO ' . $new_table->getFullName(true) . ';'; // I don't think a specific error message for views is necessary if (!PMA_DBI_query($GLOBALS['sql_query'])) { // Restore triggers in the old database if ($handle_triggers) { PMA_DBI_select_db($this->getDbName()); foreach ($triggers as $trigger) { PMA_DBI_query($trigger['create']); } } $this->errors[] = sprintf(__('Error renaming table %1$s to %2$s'), $this->getFullName(), $new_table->getFullName()); return false; } $old_name = $this->getName(); $old_db = $this->getDbName(); $this->setName($new_name); $this->setDbName($new_db); // Renable table in configuration storage PMA_REL_renameTable($old_db, $new_db, $old_name, $new_name); $this->messages[] = sprintf(__('Table %1$s has been renamed to %2$s.'), htmlspecialchars($old_name), htmlspecialchars($new_name)); return true; }
/** * This function will generate the values that are required to complete * the "Edit trigger" form given the name of a trigger. * * @param string $name The name of the trigger. * * @return array Data necessary to create the editor. */ function PMA_TRI_getDataFromName($name) { global $db, $table, $_REQUEST; $temp = array(); $items = PMA_DBI_get_triggers($db, $table, ''); foreach ($items as $value) { if ($value['name'] == $name) { $temp = $value; } } if (empty($temp)) { return false; } else { $retval = array(); $retval['create'] = $temp['create']; $retval['drop'] = $temp['drop']; $retval['item_name'] = $temp['name']; $retval['item_table'] = $temp['table']; $retval['item_action_timing'] = $temp['action_timing']; $retval['item_event_manipulation'] = $temp['event_manipulation']; $retval['item_definition'] = $temp['definition']; $retval['item_definer'] = $temp['definer']; return $retval; } }
$this_what = $what; // do not copy the data from a Merge table // note: on the calling FORM, 'data' means 'structure and data' if ($tables_full[$each_table]['Engine'] == 'MRG_MyISAM') { if ($this_what == 'data') { $this_what = 'structure'; } if ($this_what == 'dataonly') { $this_what = 'nocopy'; } } if ($this_what != 'nocopy') { // keep the triggers from the original db+table // (third param is empty because delimiters are only intended // for importing via the mysql client or our Import feature) $triggers = PMA_DBI_get_triggers($db, $each_table, ''); if (!PMA_Table::moveCopy($db, $each_table, $newname, $each_table, isset($this_what) ? $this_what : 'data', $move, 'db_copy')) { $_error = true; // $sql_query is filled by PMA_Table::moveCopy() $sql_query = $back . $sql_query; break; } // apply the triggers to the destination db+table if ($triggers) { PMA_DBI_select_db($newname); foreach ($triggers as $trigger) { PMA_DBI_query($trigger['create']); } unset($trigger); } unset($triggers);
/** * Outputs table's structure * * @param string $db database name * @param string $table table name * @param string $crlf the end of line sequence * @param string $error_url the url to go back in case of error * @param string $export_mode 'create_table', 'triggers', 'create_view', * 'stand_in' * @param string $export_type 'server', 'database', 'table' * @param bool $do_relation whether to include relation comments * @param bool $do_comments whether to include the pmadb-style column * comments as comments in the structure; * this is deprecated but the parameter is * left here because export.php calls * PMA_exportStructure() also for other * export types which use this parameter * @param bool $do_mime whether to include mime comments * @param bool $dates whether to include creation/update/check dates * * @return bool Whether it succeeded */ public function exportStructure($db, $table, $crlf, $error_url, $export_mode, $export_type, $do_relation = false, $do_comments = false, $do_mime = false, $dates = false) { $dump = ''; switch ($export_mode) { case 'create_table': $dump .= '<h2>' . __('Table structure for table') . ' ' . htmlspecialchars($table) . '</h2>'; $dump .= $this->getTableDef($db, $table, $crlf, $error_url, $do_relation, $do_comments, $do_mime, $dates); break; case 'triggers': $dump = ''; $triggers = PMA_DBI_get_triggers($db, $table); if ($triggers) { $dump .= '<h2>' . __('Triggers') . ' ' . htmlspecialchars($table) . '</h2>'; $dump .= $this->getTriggers($db, $table); } break; case 'create_view': $dump .= '<h2>' . __('Structure for view') . ' ' . htmlspecialchars($table) . '</h2>'; $dump .= $this->getTableDef($db, $table, $crlf, $error_url, $do_relation, $do_comments, $do_mime, $dates, true, true); break; case 'stand_in': $dump .= '<h2>' . __('Stand-in structure for view') . ' ' . htmlspecialchars($table) . '</h2>'; // export a stand-in definition to resolve view dependencies $dump .= $this->getTableDefStandIn($db, $table, $crlf); } // end switch return PMA_exportOutputHandler($dump); }
/** * Outputs table's structure * * @param string $db database name * @param string $table table name * @param string $crlf the end of line sequence * @param string $error_url the url to go back in case of error * @param string $export_mode 'create_table', 'triggers', 'create_view', * 'stand_in' * @param string $export_type 'server', 'database', 'table' * @param bool $do_relation whether to include relation comments * @param bool $do_comments whether to include the pmadb-style column * comments as comments in the structure; * this is deprecated but the parameter is * left here because export.php calls * PMA_exportStructure() also for other * @param bool $do_mime whether to include mime comments * @param bool $dates whether to include creation/update/check dates * * @return bool Whether it succeeded */ public function exportStructure($db, $table, $crlf, $error_url, $export_mode, $export_type, $do_relation = false, $do_comments = false, $do_mime = false, $dates = false) { switch ($export_mode) { case 'create_table': $GLOBALS['odt_buffer'] .= '<text:h text:outline-level="2" text:style-name="Heading_2"' . ' text:is-list-header="true">' . __('Table structure for table') . ' ' . htmlspecialchars($table) . '</text:h>'; $this->getTableDef($db, $table, $crlf, $error_url, $do_relation, $do_comments, $do_mime, $dates); break; case 'triggers': $triggers = PMA_DBI_get_triggers($db, $table); if ($triggers) { $GLOBALS['odt_buffer'] .= '<text:h text:outline-level="2" text:style-name="Heading_2"' . ' text:is-list-header="true">' . __('Triggers') . ' ' . htmlspecialchars($table) . '</text:h>'; $this->getTriggers($db, $table); } break; case 'create_view': $GLOBALS['odt_buffer'] .= '<text:h text:outline-level="2" text:style-name="Heading_2"' . ' text:is-list-header="true">' . __('Structure for view') . ' ' . htmlspecialchars($table) . '</text:h>'; $this->getTableDef($db, $table, $crlf, $error_url, $do_relation, $do_comments, $do_mime, $dates, true, true); break; case 'stand_in': $GLOBALS['odt_buffer'] .= '<text:h text:outline-level="2" text:style-name="Heading_2"' . ' text:is-list-header="true">' . __('Stand-in structure for view') . ' ' . htmlspecialchars($table) . '</text:h>'; // export a stand-in definition to resolve view dependencies $this->getTableDefStandIn($db, $table, $crlf); } // end switch return true; }
/** * Outputs export header * * @return bool Whether it suceeded * * @access public */ function PMA_exportHeader() { global $crlf; global $cfg; global $what; global $db; global $table; global $tables; $export_struct = isset($GLOBALS[$what . '_export_struc']) ? true : false; $export_data = isset($GLOBALS[$what . '_export_contents']) ? true : false; if ($GLOBALS['output_charset_conversion']) { $charset = $GLOBALS['charset_of_file']; } else { $charset = $GLOBALS['charset']; } $head = '<?xml version="1.0" encoding="' . $charset . '"?>' . $crlf . '<!--' . $crlf . '- phpMyAdmin XML Dump' . $crlf . '- version ' . PMA_VERSION . $crlf . '- http://www.phpmyadmin.net' . $crlf . '-' . $crlf . '- ' . $GLOBALS['strHost'] . ': ' . $cfg['Server']['host']; if (!empty($cfg['Server']['port'])) { $head .= ':' . $cfg['Server']['port']; } $head .= $crlf . '- ' . $GLOBALS['strGenTime'] . ': ' . PMA_localisedDate() . $crlf . '- ' . $GLOBALS['strServerVersion'] . ': ' . substr(PMA_MYSQL_INT_VERSION, 0, 1) . '.' . (int) substr(PMA_MYSQL_INT_VERSION, 1, 2) . '.' . (int) substr(PMA_MYSQL_INT_VERSION, 3) . $crlf . '- ' . $GLOBALS['strPHPVersion'] . ': ' . phpversion() . $crlf . '-->' . $crlf . $crlf; $head .= '<pma_xml_export version="1.0"' . ($export_struct ? ' xmlns:pma="http://www.phpmyadmin.net/some_doc_url/"' : '') . '>' . $crlf; if ($export_struct) { $result = PMA_DBI_fetch_result('SELECT `DEFAULT_CHARACTER_SET_NAME`, `DEFAULT_COLLATION_NAME` FROM `information_schema`.`SCHEMATA` WHERE `SCHEMA_NAME` = \'' . $db . '\' LIMIT 1'); $db_collation = $result[0]['DEFAULT_COLLATION_NAME']; $db_charset = $result[0]['DEFAULT_CHARACTER_SET_NAME']; $head .= ' <!--' . $crlf; $head .= ' - Structure schemas' . $crlf; $head .= ' -->' . $crlf; $head .= ' <pma:structure_schemas>' . $crlf; $head .= ' <pma:database name="' . $db . '" collation="' . $db_collation . '" charset="' . $db_charset . '">' . $crlf; if (count($tables) == 0) { $tables[] = $table; } foreach ($tables as $table) { // Export tables and views $result = PMA_DBI_fetch_result('SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table), 0); $tbl = $result[$table][1]; $is_view = PMA_isView($db, $table); if ($is_view) { $type = 'view'; } else { $type = 'table'; } if ($is_view && !isset($GLOBALS[$what . '_export_views'])) { continue; } if (!$is_view && !isset($GLOBALS[$what . '_export_tables'])) { continue; } $head .= ' <pma:' . $type . ' name="' . $table . '">' . $crlf; $tbl = " " . $tbl; $tbl = str_replace("\n", "\n ", $tbl); $head .= $tbl . ';' . $crlf; $head .= ' </pma:' . $type . '>' . $crlf; if (isset($GLOBALS[$what . '_export_triggers']) && $GLOBALS[$what . '_export_triggers']) { // Export triggers $triggers = PMA_DBI_get_triggers($db, $table); if ($triggers) { foreach ($triggers as $trigger) { $code = $trigger['create']; $head .= ' <pma:trigger name="' . $trigger['name'] . '">' . $crlf; // Do some formatting $code = substr(rtrim($code), 0, -3); $code = " " . $code; $code = str_replace("\n", "\n ", $code); $head .= $code . $crlf; $head .= ' </pma:trigger>' . $crlf; } unset($trigger); unset($triggers); } } } if (isset($GLOBALS[$what . '_export_functions']) && $GLOBALS[$what . '_export_functions']) { // Export functions $functions = PMA_DBI_get_procedures_or_functions($db, 'FUNCTION'); if ($functions) { foreach ($functions as $function) { $head .= ' <pma:function name="' . $function . '">' . $crlf; // Do some formatting $sql = PMA_DBI_get_definition($db, 'FUNCTION', $function); $sql = rtrim($sql); $sql = " " . $sql; $sql = str_replace("\n", "\n ", $sql); $head .= $sql . $crlf; $head .= ' </pma:function>' . $crlf; } unset($create_func); unset($function); unset($functions); } } if (isset($GLOBALS[$what . '_export_procedures']) && $GLOBALS[$what . '_export_procedures']) { // Export procedures $procedures = PMA_DBI_get_procedures_or_functions($db, 'PROCEDURE'); if ($procedures) { foreach ($procedures as $procedure) { $head .= ' <pma:procedure name="' . $procedure . '">' . $crlf; // Do some formatting $sql = PMA_DBI_get_definition($db, 'PROCEDURE', $procedure); $sql = rtrim($sql); $sql = " " . $sql; $sql = str_replace("\n", "\n ", $sql); $head .= $sql . $crlf; $head .= ' </pma:procedure>' . $crlf; } unset($create_proc); unset($procedure); unset($procedures); } } unset($result); $head .= ' </pma:database>' . $crlf; $head .= ' </pma:structure_schemas>' . $crlf; if ($export_data) { $head .= $crlf; } } return PMA_exportOutputHandler($head); }
/** * Outputs export header. It is the first method to be called, so all * the required variables are initialized here. * * @return bool Whether it succeeded */ public function exportHeader() { $this->initSpecificVariables(); global $crlf, $cfg, $db; $table = $this->_getTable(); $tables = $this->_getTables(); $export_struct = isset($GLOBALS['xml_export_functions']) || isset($GLOBALS['xml_export_procedures']) || isset($GLOBALS['xml_export_tables']) || isset($GLOBALS['xml_export_triggers']) || isset($GLOBALS['xml_export_views']); $export_data = isset($GLOBALS['xml_export_contents']) ? true : false; if ($GLOBALS['output_charset_conversion']) { $charset = $GLOBALS['charset_of_file']; } else { $charset = 'utf-8'; } $head = '<?xml version="1.0" encoding="' . $charset . '"?>' . $crlf . '<!--' . $crlf . '- phpMyAdmin XML Dump' . $crlf . '- version ' . PMA_VERSION . $crlf . '- http://www.phpmyadmin.net' . $crlf . '-' . $crlf . '- ' . __('Host') . ': ' . $cfg['Server']['host']; if (!empty($cfg['Server']['port'])) { $head .= ':' . $cfg['Server']['port']; } $head .= $crlf . '- ' . __('Generation Time') . ': ' . PMA_Util::localisedDate() . $crlf . '- ' . __('Server version') . ': ' . PMA_MYSQL_STR_VERSION . $crlf . '- ' . __('PHP Version') . ': ' . phpversion() . $crlf . '-->' . $crlf . $crlf; $head .= '<pma_xml_export version="1.0"' . ($export_struct ? ' xmlns:pma="http://www.phpmyadmin.net/some_doc_url/"' : '') . '>' . $crlf; if ($export_struct) { if (PMA_DRIZZLE) { $result = PMA_DBI_fetch_result("SELECT\n 'utf8' AS DEFAULT_CHARACTER_SET_NAME,\n DEFAULT_COLLATION_NAME\n FROM data_dictionary.SCHEMAS\n WHERE SCHEMA_NAME = '" . PMA_Util::sqlAddSlashes($db) . "'"); } else { $result = PMA_DBI_fetch_result('SELECT `DEFAULT_CHARACTER_SET_NAME`, `DEFAULT_COLLATION_NAME`' . ' FROM `information_schema`.`SCHEMATA` WHERE `SCHEMA_NAME`' . ' = \'' . PMA_Util::sqlAddSlashes($db) . '\' LIMIT 1'); } $db_collation = $result[0]['DEFAULT_COLLATION_NAME']; $db_charset = $result[0]['DEFAULT_CHARACTER_SET_NAME']; $head .= ' <!--' . $crlf; $head .= ' - Structure schemas' . $crlf; $head .= ' -->' . $crlf; $head .= ' <pma:structure_schemas>' . $crlf; $head .= ' <pma:database name="' . htmlspecialchars($db) . '" collation="' . $db_collation . '" charset="' . $db_charset . '">' . $crlf; if (count($tables) == 0) { $tables[] = $table; } foreach ($tables as $table) { // Export tables and views $result = PMA_DBI_fetch_result('SHOW CREATE TABLE ' . PMA_Util::backquote($db) . '.' . PMA_Util::backquote($table), 0); $tbl = $result[$table][1]; $is_view = PMA_Table::isView($db, $table); if ($is_view) { $type = 'view'; } else { $type = 'table'; } if ($is_view && !isset($GLOBALS['xml_export_views'])) { continue; } if (!$is_view && !isset($GLOBALS['xml_export_tables'])) { continue; } $head .= ' <pma:' . $type . ' name="' . $table . '">' . $crlf; $tbl = " " . htmlspecialchars($tbl); $tbl = str_replace("\n", "\n ", $tbl); $head .= $tbl . ';' . $crlf; $head .= ' </pma:' . $type . '>' . $crlf; if (isset($GLOBALS['xml_export_triggers']) && $GLOBALS['xml_export_triggers']) { // Export triggers $triggers = PMA_DBI_get_triggers($db, $table); if ($triggers) { foreach ($triggers as $trigger) { $code = $trigger['create']; $head .= ' <pma:trigger name="' . $trigger['name'] . '">' . $crlf; // Do some formatting $code = substr(rtrim($code), 0, -3); $code = " " . htmlspecialchars($code); $code = str_replace("\n", "\n ", $code); $head .= $code . $crlf; $head .= ' </pma:trigger>' . $crlf; } unset($trigger); unset($triggers); } } } if (isset($GLOBALS['xml_export_functions']) && $GLOBALS['xml_export_functions']) { // Export functions $functions = PMA_DBI_get_procedures_or_functions($db, 'FUNCTION'); if ($functions) { foreach ($functions as $function) { $head .= ' <pma:function name="' . $function . '">' . $crlf; // Do some formatting $sql = PMA_DBI_get_definition($db, 'FUNCTION', $function); $sql = rtrim($sql); $sql = " " . htmlspecialchars($sql); $sql = str_replace("\n", "\n ", $sql); $head .= $sql . $crlf; $head .= ' </pma:function>' . $crlf; } unset($function); unset($functions); } } if (isset($GLOBALS['xml_export_procedures']) && $GLOBALS['xml_export_procedures']) { // Export procedures $procedures = PMA_DBI_get_procedures_or_functions($db, 'PROCEDURE'); if ($procedures) { foreach ($procedures as $procedure) { $head .= ' <pma:procedure name="' . $procedure . '">' . $crlf; // Do some formatting $sql = PMA_DBI_get_definition($db, 'PROCEDURE', $procedure); $sql = rtrim($sql); $sql = " " . htmlspecialchars($sql); $sql = str_replace("\n", "\n ", $sql); $head .= $sql . $crlf; $head .= ' </pma:procedure>' . $crlf; } unset($procedure); unset($procedures); } } unset($result); $head .= ' </pma:database>' . $crlf; $head .= ' </pma:structure_schemas>' . $crlf; if ($export_data) { $head .= $crlf; } } return PMA_exportOutputHandler($head); }
<?php /* vim: set expandtab sw=4 ts=4 sts=4: */ /** * * @version $Id: tbl_triggers.lib.php 11994 2008-11-24 11:22:44Z nijel $ * @package phpMyAdmin */ if (!defined('PHPMYADMIN')) { exit; } $url_query .= '&goto=tbl_structure.php'; $triggers = PMA_DBI_get_triggers($db, $table); if ($triggers) { echo '<div id="tabletriggers">' . "\n"; echo '<table class="data">' . "\n"; echo ' <caption class="tblHeaders">' . $strTriggers . '</caption>' . "\n"; echo sprintf('<tr> <th>%s</th> <th> </th> <th> </th> <th>%s</th> <th>%s</th> </tr>', $strName, $strTime, $strEvent); $ct = 0; $delimiter = '//'; foreach ($triggers as $trigger) { $drop_and_create = $trigger['drop'] . $delimiter . "\n" . $trigger['create'] . "\n"; echo sprintf('<tr class="%s"> <td><strong>%s</strong></td> <td>%s</td>
/** * Outputs table's structure * * @param string the database name * @param string the table name * @param string the end of line sequence * @param string the url to go back in case of error * @param boolean whether to include relation comments * @param boolean whether to include column comments * @param boolean whether to include mime comments * @param string 'stand_in', 'create_table', 'create_view' * @param string 'server', 'database', 'table' * * @return bool Whether it suceeded * * @access public */ function PMA_exportStructure($db, $table, $crlf, $error_url, $relation = FALSE, $comments = FALSE, $mime = FALSE, $dates = FALSE, $export_mode, $export_type) { $formatted_table_name = isset($GLOBALS['sql_backquotes']) ? PMA_backquote($table) : '\'' . $table . '\''; $dump = $crlf . PMA_exportComment(str_repeat('-', 56)) . $crlf . PMA_exportComment(); switch ($export_mode) { case 'create_table': $dump .= PMA_exportComment($GLOBALS['strTableStructure'] . ' ' . $formatted_table_name) . PMA_exportComment(); $dump .= PMA_getTableDef($db, $table, $crlf, $error_url, $dates) . ';' . $crlf; $triggers = PMA_DBI_get_triggers($db, $table); if ($triggers) { $dump .= $crlf . PMA_exportComment() . PMA_exportComment($GLOBALS['strTriggers'] . ' ' . $formatted_table_name) . PMA_exportComment(); $delimiter = '//'; foreach ($triggers as $trigger) { $dump .= $trigger['drop'] . ';' . $crlf; $dump .= 'DELIMITER ' . $delimiter . $crlf; $dump .= $trigger['create']; $dump .= 'DELIMITER ;' . $crlf; } } break; case 'create_view': $dump .= PMA_exportComment($GLOBALS['strStructureForView'] . ' ' . $formatted_table_name) . PMA_exportComment(); // delete the stand-in table previously created (if any) if ($export_type != 'table') { $dump .= 'DROP TABLE IF EXISTS ' . PMA_backquote($table) . ';' . $crlf; } $dump .= PMA_getTableDef($db, $table, $crlf, $error_url, $dates) . ';' . $crlf; break; case 'stand_in': $dump .= PMA_exportComment($GLOBALS['strStandInStructureForView'] . ' ' . $formatted_table_name) . PMA_exportComment(); // export a stand-in definition to resolve view dependencies $dump .= PMA_getTableDefStandIn($db, $table, $crlf); } // end switch $dump .= PMA_getTableComments($db, $table, $crlf, $relation, $comments, $mime); // this one is built by PMA_getTableDef() to use in table copy/move // but not in the case of export unset($GLOBALS['sql_constraints_query']); return PMA_exportOutputHandler($dump); }
/** * Get sql query for copy/rename table and boolean for whether copy/rename or not * * @param array $tables_full array of all tables in given db or dbs * @param string $sql_query sql query for all operations * @param boolean $move whether databse name is empty or not * @param string $db database name * * @return array ($sql_query, $error) */ function PMA_getSqlQueryForCopyTable($tables_full, $sql_query, $move, $db) { $error = false; foreach ($tables_full as $each_table => $tmp) { // skip the views; we have creted stand-in definitions if (PMA_Table::isView($db, $each_table)) { continue; } $back = $sql_query; $sql_query = ''; // value of $what for this table only $this_what = $_REQUEST['what']; // do not copy the data from a Merge table // note: on the calling FORM, 'data' means 'structure and data' if (PMA_Table::isMerge($db, $each_table)) { if ($this_what == 'data') { $this_what = 'structure'; } if ($this_what == 'dataonly') { $this_what = 'nocopy'; } } if ($this_what != 'nocopy') { // keep the triggers from the original db+table // (third param is empty because delimiters are only intended // for importing via the mysql client or our Import feature) $triggers = PMA_DBI_get_triggers($db, $each_table, ''); if (!PMA_Table::moveCopy($db, $each_table, $_REQUEST['newname'], $each_table, isset($this_what) ? $this_what : 'data', $move, 'db_copy')) { $error = true; // $sql_query is filled by PMA_Table::moveCopy() $sql_query = $back . $sql_query; break; } // apply the triggers to the destination db+table if ($triggers) { PMA_DBI_select_db($_REQUEST['newname']); foreach ($triggers as $trigger) { PMA_DBI_query($trigger['create']); $GLOBALS['sql_query'] .= "\n" . $trigger['create'] . ';'; } } // this does not apply to a rename operation if (isset($_REQUEST['add_constraints']) && !empty($GLOBALS['sql_constraints_query'])) { $GLOBALS['sql_constraints_query_full_db'][] = $GLOBALS['sql_constraints_query']; unset($GLOBALS['sql_constraints_query']); } } // $sql_query is filled by PMA_Table::moveCopy() $sql_query = $back . $sql_query; } return array($sql_query, $error); }