2
/* $Id: tbl_export.php 10144 2007-03-20 11:22:31Z cybot_tm $ */
3
// vim: expandtab sw=4 ts=4 sts=4:
5
require_once('./libraries/common.lib.php');
8
* Gets tables informations and displays top links
10
require_once('./libraries/tbl_common.php');
11
$url_query .= '&goto=tbl_export.php&back=tbl_export.php';
12
require_once('./libraries/tbl_info.inc.php');
16
$export_page_title = $strViewDump;
18
// When we have some query, we need to remove LIMIT from that and possibly
19
// generate WHERE clause (if we are asked to export specific rows)
21
if (isset($sql_query)) {
22
// Parse query so we can work with tokens
23
$parsed_sql = PMA_SQP_parse($sql_query);
25
// Need to generate WHERE clause?
26
if (isset($primary_key)) {
27
// Yes => rebuild query from scracts, this doesn't work with nested
29
$analyzed_sql = PMA_SQP_analyze($parsed_sql);
30
$sql_query = 'SELECT ';
32
if (isset($analyzed_sql[0]['queryflags']['distinct'])) {
33
$sql_query .= ' DISTINCT ';
36
$sql_query .= $analyzed_sql[0]['select_expr_clause'];
38
if (!empty($analyzed_sql[0]['from_clause'])) {
39
$sql_query .= ' FROM ' . $analyzed_sql[0]['from_clause'];
44
if (isset($primary_key) && is_array($primary_key)
45
&& count($primary_key) > 0) {
46
$wheres[] = '(' . implode(') OR (',$primary_key) . ')';
49
if (!empty($analyzed_sql[0]['where_clause'])) {
50
$wheres[] = $analyzed_sql[0]['where_clause'];
53
if (count($wheres) > 0 ) {
54
$sql_query .= ' WHERE (' . implode(') AND (', $wheres) . ')';
57
if (!empty($analyzed_sql[0]['group_by_clause'])) {
58
$sql_query .= ' GROUP BY ' . $analyzed_sql[0]['group_by_clause'];
60
if (!empty($analyzed_sql[0]['having_clause'])) {
61
$sql_query .= ' HAVING ' . $analyzed_sql[0]['having_clause'];
63
if (!empty($analyzed_sql[0]['order_by_clause'])) {
64
$sql_query .= ' ORDER BY ' . $analyzed_sql[0]['order_by_clause'];
67
// Just crop LIMIT clause
68
$inside_bracket = FALSE;
69
for ($i = $parsed_sql['len'] - 1; $i >= 0; $i--) {
70
if ($parsed_sql[$i]['type'] == 'punct_bracket_close_round') {
71
$inside_bracket = TRUE;
74
if ($parsed_sql[$i]['type'] == 'punct_bracket_open_round') {
75
$inside_bracket = FALSE;
78
if (!$inside_bracket && $parsed_sql[$i]['type'] == 'alpha_reservedWord' && strtoupper($parsed_sql[$i]['data']) == 'LIMIT') {
79
// We found LIMIT to remove
83
// Concatenate parts before
84
for ($j = 0; $j < $i; $j++) {
85
$sql_query .= $parsed_sql[$j]['data'] . ' ';
90
while ($i < $parsed_sql['len'] &&
91
($parsed_sql[$i]['type'] != 'alpha_reservedWord' ||
92
($parsed_sql[$i]['type'] == 'alpha_reservedWord' && $parsed_sql[$i]['data'] == 'OFFSET'))) {
96
// Add remaining parts
97
while ($i < $parsed_sql['len']) {
98
$sql_query .= $parsed_sql[$i]['data'] . ' ';
105
$message = $GLOBALS['strSuccess'];
109
* Displays top menu links
111
require('./libraries/tbl_links.inc.php');
113
$export_type = 'table';
114
require_once('./libraries/display_export.lib.php');
118
* Displays the footer
120
require_once('./libraries/footer.inc.php');