2 /* vim: set expandtab sw=4 ts=4 sts=4: */
8 declare(strict_types
=1);
10 use PhpMyAdmin\Config\PageSettings
;
11 use PhpMyAdmin\DatabaseInterface
;
12 use PhpMyAdmin\Di\Container
;
13 use PhpMyAdmin\Display\Export
;
14 use PhpMyAdmin\Relation
;
15 use PhpMyAdmin\Response
;
17 if (! defined('ROOT_PATH')) {
18 define('ROOT_PATH', __DIR__
. DIRECTORY_SEPARATOR
);
21 global $db, $url_query;
23 require_once ROOT_PATH
. 'libraries/common.inc.php';
25 $container = Container
::getDefaultContainer();
26 $container->set(Response
::class, Response
::getInstance());
28 /** @var Response $response */
29 $response = $container->get(Response
::class);
31 /** @var DatabaseInterface $dbi */
32 $dbi = $container->get(DatabaseInterface
::class);
34 PageSettings
::showGroup('Export');
36 $header = $response->getHeader();
37 $scripts = $header->getScripts();
38 $scripts->addFile('export.js');
40 // Get the relation settings
41 /** @var Relation $relation */
42 $relation = $containerBuilder->get('relation');
43 $cfgRelation = $relation->getRelationsParam();
45 $displayExport = new Export();
47 // handling export template actions
48 if (isset($_POST['templateAction']) && $cfgRelation['exporttemplateswork']) {
49 $displayExport->handleTemplateActions($cfgRelation);
54 * Gets tables information and displays top links
56 require_once ROOT_PATH
. 'libraries/tbl_common.inc.php';
57 $url_query .= '&goto=tbl_export.php&back=tbl_export.php';
61 $export_page_title = __('View dump (schema) of table');
63 // When we have some query, we need to remove LIMIT from that and possibly
64 // generate WHERE clause (if we are asked to export specific rows)
66 if (! empty($sql_query)) {
67 $parser = new PhpMyAdmin\SqlParser\
Parser($sql_query);
69 if (! empty($parser->statements
[0])
70 && ($parser->statements
[0] instanceof PhpMyAdmin\SqlParser\Statements\SelectStatement
)
72 // Finding aliases and removing them, but we keep track of them to be
73 // able to replace them in select expression too.
75 foreach ($parser->statements
[0]->from
as $from) {
76 if (! empty($from->table
) && ! empty($from->alias
)) {
77 $aliases[$from->alias
] = $from->table
;
78 // We remove the alias of the table because they are going to
79 // be replaced anyway.
81 $from->expr
= null; // Force rebuild.
85 // Rebuilding the SELECT and FROM clauses.
86 if (count($parser->statements
[0]->from
) > 0
87 && count($parser->statements
[0]->union
) === 0
92 'FROM ' . PhpMyAdmin\SqlParser\Components\ExpressionArray
::build(
93 $parser->statements
[0]->from
99 // Checking if the WHERE clause has to be replaced.
100 if (! empty($where_clause) && is_array($where_clause)) {
103 'WHERE (' . implode(') OR (', $where_clause) . ')',
107 // Preparing to remove the LIMIT clause.
113 // Replacing the clauses.
114 $sql_query = PhpMyAdmin\SqlParser\Utils\Query
::replaceClauses(
115 $parser->statements
[0],
120 // Removing the aliases by finding the alias followed by a dot.
121 $tokens = PhpMyAdmin\SqlParser\Lexer
::getTokens($sql_query);
122 foreach ($aliases as $alias => $table) {
123 $tokens = PhpMyAdmin\SqlParser\Utils\Tokens
::replaceTokens(
127 'value_str' => $alias,
130 'type' => PhpMyAdmin\SqlParser\Token
::TYPE_OPERATOR
,
135 new PhpMyAdmin\SqlParser\
Token($table),
136 new PhpMyAdmin\SqlParser\
Token('.', PhpMyAdmin\SqlParser\Token
::TYPE_OPERATOR
),
140 $sql_query = PhpMyAdmin\SqlParser\TokensList
::build($tokens);
143 echo PhpMyAdmin\Util
::getMessage(PhpMyAdmin\Message
::success());
146 if (! isset($sql_query)) {
149 if (! isset($num_tables)) {
152 if (! isset($unlim_num_rows)) {
155 if (! isset($multi_values)) {
158 $response = Response
::getInstance();
160 $displayExport->getDisplay(