2 /* vim: set expandtab sw=4 ts=4 sts=4: */
8 use PhpMyAdmin\Config\PageSettings
;
9 use PhpMyAdmin\Display\Export
;
10 use PhpMyAdmin\Relation
;
11 use PhpMyAdmin\Response
;
16 require_once 'libraries/common.inc.php';
18 PageSettings
::showGroup('Export');
20 $response = Response
::getInstance();
21 $header = $response->getHeader();
22 $scripts = $header->getScripts();
23 $scripts->addFile('export.js');
25 // Get the relation settings
26 $cfgRelation = Relation
::getRelationsParam();
28 // handling export template actions
29 if (isset($_REQUEST['templateAction']) && $cfgRelation['exporttemplateswork']) {
30 Export
::handleExportTemplateActions($cfgRelation);
35 * Gets tables information and displays top links
37 require_once 'libraries/tbl_common.inc.php';
38 $url_query .= '&goto=tbl_export.php&back=tbl_export.php';
42 $export_page_title = __('View dump (schema) of table');
44 // When we have some query, we need to remove LIMIT from that and possibly
45 // generate WHERE clause (if we are asked to export specific rows)
47 if (! empty($sql_query)) {
48 $parser = new PhpMyAdmin\SqlParser\
Parser($sql_query);
50 if ((!empty($parser->statements
[0]))
51 && ($parser->statements
[0] instanceof PhpMyAdmin\SqlParser\Statements\SelectStatement
)
54 // Finding aliases and removing them, but we keep track of them to be
55 // able to replace them in select expression too.
57 foreach ($parser->statements
[0]->from
as $from) {
58 if ((!empty($from->table
)) && (!empty($from->alias
))) {
59 $aliases[$from->alias
] = $from->table
;
60 // We remove the alias of the table because they are going to
61 // be replaced anyway.
63 $from->expr
= null; // Force rebuild.
67 // Rebuilding the SELECT and FROM clauses.
68 if (count($parser->statements
[0]->from
) > 0
69 && count($parser->statements
[0]->union
) === 0
73 'FROM', 'FROM ' . PhpMyAdmin\SqlParser\Components\ExpressionArray
::build(
74 $parser->statements
[0]->from
80 // Checking if the WHERE clause has to be replaced.
81 if ((!empty($where_clause)) && (is_array($where_clause))) {
83 'WHERE', 'WHERE (' . implode(') OR (', $where_clause) . ')'
87 // Preparing to remove the LIMIT clause.
88 $replaces[] = array('LIMIT', '');
90 // Replacing the clauses.
91 $sql_query = PhpMyAdmin\SqlParser\Utils\Query
::replaceClauses(
92 $parser->statements
[0],
97 // Removing the aliases by finding the alias followed by a dot.
98 $tokens = PhpMyAdmin\SqlParser\Lexer
::getTokens($sql_query);
99 foreach ($aliases as $alias => $table) {
100 $tokens = PhpMyAdmin\SqlParser\Utils\Tokens
::replaceTokens(
104 'value_str' => $alias,
107 'type' => PhpMyAdmin\SqlParser\Token
::TYPE_OPERATOR
,
112 new PhpMyAdmin\SqlParser\
Token($table),
113 new PhpMyAdmin\SqlParser\
Token('.',PhpMyAdmin\SqlParser\Token
::TYPE_OPERATOR
)
117 $sql_query = PhpMyAdmin\SqlParser\TokensList
::build($tokens);
120 echo PhpMyAdmin\Util
::getMessage(PhpMyAdmin\Message
::success());
123 if (! isset($sql_query)) {
126 if (! isset($num_tables)) {
129 if (! isset($unlim_num_rows)) {
132 if (! isset($multi_values)) {
135 $response = Response
::getInstance();
137 Export
::getExportDisplay(
138 'table', $db, $table, $sql_query, $num_tables,
139 $unlim_num_rows, $multi_values