Rev Author Line No. Line
250 kaklik 1 <?php
2 /* $Id: tbl_properties_export.php,v 2.17 2005/12/08 16:13:51 nijel Exp $ */
3 // vim: expandtab sw=4 ts=4 sts=4:
4  
5 require_once('./libraries/common.lib.php');
6  
7 /**
8 * Gets tables informations and displays top links
9 */
10 require_once('./libraries/tbl_properties_common.php');
11 $url_query .= '&amp;goto=tbl_properties_export.php&amp;back=tbl_properties_export.php';
12 require_once('./libraries/tbl_properties_table_info.inc.php');
13  
14 // Dump of a table
15  
16 $export_page_title = $strViewDump;
17  
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)
20  
21 if (isset($sql_query)) {
22 // Parse query so we can work with tokens
23 $parsed_sql = PMA_SQP_parse($sql_query);
24  
25 // Need to generate WHERE clause?
26 if (isset($primary_key)) {
27 // Yes => rebuild query from scracts, this doesn't work with nested
28 // selects :-(
29 $analyzed_sql = PMA_SQP_analyze($parsed_sql);
30 $sql_query = 'SELECT ';
31  
32 if (isset($analyzed_sql[0]['queryflags']['distinct'])) {
33 $sql_query .= ' DISTINCT ';
34 }
35  
36 $sql_query .= $analyzed_sql[0]['select_expr_clause'];
37  
38 if (!empty($analyzed_sql[0]['from_clause'])) {
39 $sql_query .= ' FROM ' . $analyzed_sql[0]['from_clause'];
40 }
41  
42 if (isset($primary_key) && is_array($primary_key)) {
43 $sql_query .= ' WHERE ';
44 $conj = '';
45 foreach ($primary_key AS $i => $key) {
46 $sql_query .= $conj . '( ' . $key . ' ) ';
47 $conj = 'OR ';
48 }
49 } elseif (!empty($analyzed_sql[0]['where_clause'])) {
50 $sql_query .= ' WHERE ' . $analyzed_sql[0]['where_clause'];
51 }
52 if (!empty($analyzed_sql[0]['group_by_clause'])) {
53 $sql_query .= ' GROUP BY ' . $analyzed_sql[0]['group_by_clause'];
54 }
55 if (!empty($analyzed_sql[0]['having_clause'])) {
56 $sql_query .= ' HAVING ' . $analyzed_sql[0]['having_clause'];
57 }
58 if (!empty($analyzed_sql[0]['order_by_clause'])) {
59 $sql_query .= ' ORDER BY ' . $analyzed_sql[0]['order_by_clause'];
60 }
61 } else {
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;
67 continue;
68 }
69 if ($parsed_sql[$i]['type'] == 'punct_bracket_open_round') {
70 $inside_bracket = FALSE;
71 continue;
72 }
73 if (!$inside_bracket && $parsed_sql[$i]['type'] == 'alpha_reservedWord' && strtoupper($parsed_sql[$i]['data']) == 'LIMIT') {
74 // We found LIMIT to remove
75  
76 $sql_query = '';
77  
78 // Concatenate parts before
79 for ($j = 0; $j < $i; $j++) {
80 $sql_query .= $parsed_sql[$j]['data'] . ' ';
81 }
82  
83 // Skip LIMIT
84 $i++;
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'))) {
88 $i++;
89 }
90  
91 // Add remaining parts
92 while ($i < $parsed_sql['len']) {
93 $sql_query .= $parsed_sql[$i]['data'] . ' ';
94 $i++;
95 }
96 break;
97 }
98 }
99 }
100 $message = $GLOBALS['strSuccess'];
101 }
102  
103 /**
104 * Displays top menu links
105 */
106 require('./libraries/tbl_properties_links.inc.php');
107  
108 $export_type = 'table';
109 require_once('./libraries/display_export.lib.php');
110  
111  
112 /**
113 * Displays the footer
114 */
115 require_once('./libraries/footer.inc.php');
116 ?>