Translated using Weblate (German)
[phpmyadmin.git] / tbl_export.php
blob98ced269e6ed3ffb1501ee8b093f13b404eadbd6
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Table export
6 * @package PhpMyAdmin
7 */
8 declare(strict_types=1);
10 use PhpMyAdmin\Config\PageSettings;
11 use PhpMyAdmin\Display\Export;
12 use PhpMyAdmin\Relation;
13 use PhpMyAdmin\Response;
15 /**
18 require_once 'libraries/common.inc.php';
20 PageSettings::showGroup('Export');
22 $response = Response::getInstance();
23 $header = $response->getHeader();
24 $scripts = $header->getScripts();
25 $scripts->addFile('export.js');
27 // Get the relation settings
28 $relation = new Relation($GLOBALS['dbi']);
29 $cfgRelation = $relation->getRelationsParam();
31 $displayExport = new Export();
33 // handling export template actions
34 if (isset($_REQUEST['templateAction']) && $cfgRelation['exporttemplateswork']) {
35 $displayExport->handleTemplateActions($cfgRelation);
36 exit;
39 /**
40 * Gets tables information and displays top links
42 require_once 'libraries/tbl_common.inc.php';
43 $url_query .= '&amp;goto=tbl_export.php&amp;back=tbl_export.php';
45 // Dump of a table
47 $export_page_title = __('View dump (schema) of table');
49 // When we have some query, we need to remove LIMIT from that and possibly
50 // generate WHERE clause (if we are asked to export specific rows)
52 if (! empty($sql_query)) {
53 $parser = new PhpMyAdmin\SqlParser\Parser($sql_query);
55 if ((!empty($parser->statements[0]))
56 && ($parser->statements[0] instanceof PhpMyAdmin\SqlParser\Statements\SelectStatement)
57 ) {
58 // Finding aliases and removing them, but we keep track of them to be
59 // able to replace them in select expression too.
60 $aliases = [];
61 foreach ($parser->statements[0]->from as $from) {
62 if ((!empty($from->table)) && (!empty($from->alias))) {
63 $aliases[$from->alias] = $from->table;
64 // We remove the alias of the table because they are going to
65 // be replaced anyway.
66 $from->alias = null;
67 $from->expr = null; // Force rebuild.
71 // Rebuilding the SELECT and FROM clauses.
72 if (count($parser->statements[0]->from) > 0
73 && count($parser->statements[0]->union) === 0
74 ) {
75 $replaces = [
77 'FROM', 'FROM ' . PhpMyAdmin\SqlParser\Components\ExpressionArray::build(
78 $parser->statements[0]->from
84 // Checking if the WHERE clause has to be replaced.
85 if ((!empty($where_clause)) && (is_array($where_clause))) {
86 $replaces[] = [
87 'WHERE', 'WHERE (' . implode(') OR (', $where_clause) . ')'
91 // Preparing to remove the LIMIT clause.
92 $replaces[] = ['LIMIT', ''];
94 // Replacing the clauses.
95 $sql_query = PhpMyAdmin\SqlParser\Utils\Query::replaceClauses(
96 $parser->statements[0],
97 $parser->list,
98 $replaces
101 // Removing the aliases by finding the alias followed by a dot.
102 $tokens = PhpMyAdmin\SqlParser\Lexer::getTokens($sql_query);
103 foreach ($aliases as $alias => $table) {
104 $tokens = PhpMyAdmin\SqlParser\Utils\Tokens::replaceTokens(
105 $tokens,
108 'value_str' => $alias,
111 'type' => PhpMyAdmin\SqlParser\Token::TYPE_OPERATOR,
112 'value_str' => '.',
116 new PhpMyAdmin\SqlParser\Token($table),
117 new PhpMyAdmin\SqlParser\Token('.', PhpMyAdmin\SqlParser\Token::TYPE_OPERATOR)
121 $sql_query = PhpMyAdmin\SqlParser\TokensList::build($tokens);
124 echo PhpMyAdmin\Util::getMessage(PhpMyAdmin\Message::success());
127 if (! isset($sql_query)) {
128 $sql_query = '';
130 if (! isset($num_tables)) {
131 $num_tables = 0;
133 if (! isset($unlim_num_rows)) {
134 $unlim_num_rows = 0;
136 if (! isset($multi_values)) {
137 $multi_values = '';
139 $response = Response::getInstance();
140 $response->addHTML(
141 $displayExport->getDisplay(
142 'table',
143 $db,
144 $table,
145 $sql_query,
146 $num_tables,
147 $unlim_num_rows,
148 $multi_values