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 require_once ROOT_PATH
. 'libraries/common.inc.php';
23 $container = Container
::getDefaultContainer();
24 $container->set(Response
::class, Response
::getInstance());
26 /** @var Response $response */
27 $response = $container->get(Response
::class);
29 /** @var DatabaseInterface $dbi */
30 $dbi = $container->get(DatabaseInterface
::class);
32 PageSettings
::showGroup('Export');
34 $header = $response->getHeader();
35 $scripts = $header->getScripts();
36 $scripts->addFile('export.js');
38 // Get the relation settings
39 $relation = new Relation($dbi);
40 $cfgRelation = $relation->getRelationsParam();
42 $displayExport = new Export();
44 // handling export template actions
45 if (isset($_POST['templateAction']) && $cfgRelation['exporttemplateswork']) {
46 $displayExport->handleTemplateActions($cfgRelation);
51 * Gets tables information and displays top links
53 require_once ROOT_PATH
. 'libraries/tbl_common.inc.php';
54 $url_query .= '&goto=tbl_export.php&back=tbl_export.php';
58 $export_page_title = __('View dump (schema) of table');
60 // When we have some query, we need to remove LIMIT from that and possibly
61 // generate WHERE clause (if we are asked to export specific rows)
63 if (! empty($sql_query)) {
64 $parser = new PhpMyAdmin\SqlParser\
Parser($sql_query);
66 if (! empty($parser->statements
[0])
67 && ($parser->statements
[0] instanceof PhpMyAdmin\SqlParser\Statements\SelectStatement
)
69 // Finding aliases and removing them, but we keep track of them to be
70 // able to replace them in select expression too.
72 foreach ($parser->statements
[0]->from
as $from) {
73 if (! empty($from->table
) && ! empty($from->alias
)) {
74 $aliases[$from->alias
] = $from->table
;
75 // We remove the alias of the table because they are going to
76 // be replaced anyway.
78 $from->expr
= null; // Force rebuild.
82 // Rebuilding the SELECT and FROM clauses.
83 if (count($parser->statements
[0]->from
) > 0
84 && count($parser->statements
[0]->union
) === 0
89 'FROM ' . PhpMyAdmin\SqlParser\Components\ExpressionArray
::build(
90 $parser->statements
[0]->from
96 // Checking if the WHERE clause has to be replaced.
97 if (! empty($where_clause) && is_array($where_clause)) {
100 'WHERE (' . implode(') OR (', $where_clause) . ')',
104 // Preparing to remove the LIMIT clause.
110 // Replacing the clauses.
111 $sql_query = PhpMyAdmin\SqlParser\Utils\Query
::replaceClauses(
112 $parser->statements
[0],
117 // Removing the aliases by finding the alias followed by a dot.
118 $tokens = PhpMyAdmin\SqlParser\Lexer
::getTokens($sql_query);
119 foreach ($aliases as $alias => $table) {
120 $tokens = PhpMyAdmin\SqlParser\Utils\Tokens
::replaceTokens(
124 'value_str' => $alias,
127 'type' => PhpMyAdmin\SqlParser\Token
::TYPE_OPERATOR
,
132 new PhpMyAdmin\SqlParser\
Token($table),
133 new PhpMyAdmin\SqlParser\
Token('.', PhpMyAdmin\SqlParser\Token
::TYPE_OPERATOR
),
137 $sql_query = PhpMyAdmin\SqlParser\TokensList
::build($tokens);
140 echo PhpMyAdmin\Util
::getMessage(PhpMyAdmin\Message
::success());
143 if (! isset($sql_query)) {
146 if (! isset($num_tables)) {
149 if (! isset($unlim_num_rows)) {
152 if (! isset($multi_values)) {
155 $response = Response
::getInstance();
157 $displayExport->getDisplay(