Remove composer.lock
[phpmyadmin.git] / tbl_export.php
blobee22273070204a49c1d654f74a51218cd0ef524b
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Table export
6 * @package PhpMyAdmin
7 */
8 use PhpMyAdmin\Config\PageSettings;
9 use PhpMyAdmin\Relation;
10 use PhpMyAdmin\Response;
12 /**
15 require_once 'libraries/common.inc.php';
16 require_once 'libraries/display_export.lib.php';
17 require_once 'libraries/config/user_preferences.forms.php';
18 require_once 'libraries/config/page_settings.forms.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 $cfgRelation = Relation::getRelationsParam();
30 // handling export template actions
31 if (isset($_REQUEST['templateAction']) && $cfgRelation['exporttemplateswork']) {
32 PMA_handleExportTemplateActions($cfgRelation);
33 exit;
36 /**
37 * Gets tables information and displays top links
39 require_once 'libraries/tbl_common.inc.php';
40 $url_query .= '&amp;goto=tbl_export.php&amp;back=tbl_export.php';
42 // Dump of a table
44 $export_page_title = __('View dump (schema) of table');
46 // When we have some query, we need to remove LIMIT from that and possibly
47 // generate WHERE clause (if we are asked to export specific rows)
49 if (! empty($sql_query)) {
50 $parser = new PhpMyAdmin\SqlParser\Parser($sql_query);
52 if ((!empty($parser->statements[0]))
53 && ($parser->statements[0] instanceof PhpMyAdmin\SqlParser\Statements\SelectStatement)
54 ) {
56 // Finding aliases and removing them, but we keep track of them to be
57 // able to replace them in select expression too.
58 $aliases = array();
59 foreach ($parser->statements[0]->from as $from) {
60 if ((!empty($from->table)) && (!empty($from->alias))) {
61 $aliases[$from->alias] = $from->table;
62 // We remove the alias of the table because they are going to
63 // be replaced anyway.
64 $from->alias = null;
65 $from->expr = null; // Force rebuild.
69 // Rebuilding the SELECT and FROM clauses.
70 if (count($parser->statements[0]->from) > 0
71 && count($parser->statements[0]->union) === 0
72 ) {
73 $replaces = array(
74 array(
75 'FROM', 'FROM ' . PhpMyAdmin\SqlParser\Components\ExpressionArray::build(
76 $parser->statements[0]->from
82 // Checking if the WHERE clause has to be replaced.
83 if ((!empty($where_clause)) && (is_array($where_clause))) {
84 $replaces[] = array(
85 'WHERE', 'WHERE (' . implode(') OR (', $where_clause) . ')'
89 // Preparing to remove the LIMIT clause.
90 $replaces[] = array('LIMIT', '');
92 // Replacing the clauses.
93 $sql_query = PhpMyAdmin\SqlParser\Utils\Query::replaceClauses(
94 $parser->statements[0],
95 $parser->list,
96 $replaces
99 // Removing the aliases by finding the alias followed by a dot.
100 $tokens = PhpMyAdmin\SqlParser\Lexer::getTokens($sql_query);
101 foreach ($aliases as $alias => $table) {
102 $tokens = PhpMyAdmin\SqlParser\Utils\Tokens::replaceTokens(
103 $tokens,
104 array(
105 array(
106 'value_str' => $alias,
108 array(
109 'type' => PhpMyAdmin\SqlParser\Token::TYPE_OPERATOR,
110 'value_str' => '.',
113 array(
114 new PhpMyAdmin\SqlParser\Token($table),
115 new PhpMyAdmin\SqlParser\Token('.',PhpMyAdmin\SqlParser\Token::TYPE_OPERATOR)
119 $sql_query = PhpMyAdmin\SqlParser\TokensList::build($tokens);
122 echo PhpMyAdmin\Util::getMessage(PhpMyAdmin\Message::success());
125 require_once 'libraries/display_export.lib.php';
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 PMA_getExportDisplay(
142 'table', $db, $table, $sql_query, $num_tables,
143 $unlim_num_rows, $multi_values