/**
* 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
* @param array $aliases Aliases of db/table/columns
*
* @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, $aliases = array())
{
$db_alias = $db;
$table_alias = $table;
$this->initAlias($aliases, $db_alias, $table_alias);
if (isset($GLOBALS['sql_compatibility'])) {
$compat = $GLOBALS['sql_compatibility'];
} else {
$compat = 'NONE';
}
$formatted_table_name = Util::backquoteCompat($table_alias, $compat, isset($GLOBALS['sql_backquotes']));
$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, true, false, true, $aliases);
$dump .= $this->_getTableComments($db, $table, $crlf, $relation, $mime, $aliases);
break;
case 'triggers':
$dump = '';
$delimiter = '$$';
$triggers = $GLOBALS['dbi']->getTriggers($db, $table, $delimiter);
if ($triggers) {
$dump .= $this->_possibleCRLF() . $this->_exportComment() . $this->_exportComment(__('Triggers') . ' ' . $formatted_table_name) . $this->_exportComment();
$used_alias = false;
$trigger_query = '';
foreach ($triggers as $trigger) {
if (!empty($GLOBALS['sql_drop_table'])) {
$trigger_query .= $trigger['drop'] . ';' . $crlf;
}
$trigger_query .= 'DELIMITER ' . $delimiter . $crlf;
$trigger_query .= $this->replaceWithAliases($trigger['create'], $aliases, $db, $table, $flag);
if ($flag) {
$used_alias = true;
}
$trigger_query .= 'DELIMITER ;' . $crlf;
}
// One warning per table.
if ($used_alias) {
$dump .= $this->_exportComment(__('It appears your table uses triggers;')) . $this->_exportComment(__('alias export may not work reliably in all cases.')) . $this->_exportComment();
}
$dump .= $trigger_query;
}
break;
case 'create_view':
if (empty($GLOBALS['sql_views_as_tables'])) {
$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 ' . Util::backquote($table_alias) . ';' . $crlf;
}
$dump .= $this->getTableDef($db, $table, $crlf, $error_url, $dates, true, true, true, $aliases);
} else {
$dump .= $this->_exportComment(sprintf(__('Structure for view %s exported as a table'), $formatted_table_name)) . $this->_exportComment();
// delete the stand-in table previously created (if any)
if ($export_type != 'table') {
$dump .= 'DROP TABLE IF EXISTS ' . Util::backquote($table_alias) . ';' . $crlf;
}
$dump .= $this->_getTableDefForView($db, $table, $crlf, true, $aliases);
}
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, $aliases);
}
// 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);
}