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_properties_common.php');
11 $url_query .= '&goto=tbl_properties_export.php&back=tbl_properties_export.php';
12 require_once('./libraries/tbl_properties_table_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'];
42 if (isset($primary_key) && is_array($primary_key)) {
43 $sql_query .= ' WHERE ';
45 foreach ($primary_key AS $i => $key) {
46 $sql_query .= $conj . '( ' . $key . ' ) ';
49 } elseif (!empty($analyzed_sql[0]['where_clause'])) {
50 $sql_query .= ' WHERE ' . $analyzed_sql[0]['where_clause'];
52 if (!empty($analyzed_sql[0]['group_by_clause'])) {
53 $sql_query .= ' GROUP BY ' . $analyzed_sql[0]['group_by_clause'];
55 if (!empty($analyzed_sql[0]['having_clause'])) {
56 $sql_query .= ' HAVING ' . $analyzed_sql[0]['having_clause'];
58 if (!empty($analyzed_sql[0]['order_by_clause'])) {
59 $sql_query .= ' ORDER BY ' . $analyzed_sql[0]['order_by_clause'];
62 // Just crop LIMIT clause
63 $inside_bracket = FALSE;
64 for ($i = $parsed_sql['len'] - 1; $i >= 0; $i--) {
65 if ($parsed_sql[$i]['type'] == 'punct_bracket_close_round') {
66 $inside_bracket = TRUE;
69 if ($parsed_sql[$i]['type'] == 'punct_bracket_open_round') {
70 $inside_bracket = FALSE;
73 if (!$inside_bracket && $parsed_sql[$i]['type'] == 'alpha_reservedWord' && strtoupper($parsed_sql[$i]['data']) == 'LIMIT') {
74 // We found LIMIT to remove
78 // Concatenate parts before
79 for ($j = 0; $j < $i; $j++
) {
80 $sql_query .= $parsed_sql[$j]['data'] . ' ';
85 while ($i < $parsed_sql['len'] &&
86 ($parsed_sql[$i]['type'] != 'alpha_reservedWord' ||
87 ($parsed_sql[$i]['type'] == 'alpha_reservedWord' && $parsed_sql[$i]['data'] == 'OFFSET'))) {
91 // Add remaining parts
92 while ($i < $parsed_sql['len']) {
93 $sql_query .= $parsed_sql[$i]['data'] . ' ';
100 $message = $GLOBALS['strSuccess'];
104 * Displays top menu links
106 require('./libraries/tbl_properties_links.inc.php');
108 $export_type = 'table';
109 require_once('./libraries/display_export.lib.php');
113 * Displays the footer
115 require_once('./libraries/footer.inc.php');