home *** CD-ROM | disk | FTP | other *** search
/ Freelog 70 / Freelog070.iso / Internet / EasyPHP / easyphp1-8_setup.exe / {app} / phpmyadmin / tbl_properties_export.php < prev    next >
Encoding:
PHP Script  |  2004-10-21  |  3.7 KB  |  116 lines

  1. <?php
  2. /* $Id: tbl_properties_export.php,v 2.9 2004/10/21 10:18:12 nijel Exp $ */
  3. // vim: expandtab sw=4 ts=4 sts=4:
  4.  
  5.  
  6. /**
  7.  * Gets tables informations and displays top links
  8.  */
  9. require('./tbl_properties_common.php');
  10. $url_query .= '&goto=tbl_properties_export.php&back=tbl_properties_export.php';
  11. require('./tbl_properties_table_info.php');
  12. ?>
  13.  
  14. <!-- Dump of a table -->
  15. <?php
  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.         if (isset($primary_key)) {
  42.             $sql_query .= ' WHERE ';
  43.             $conj = '';
  44.             foreach ($primary_key AS $i => $key) {
  45.                 $sql_query .= $conj . '( ' . $key . ' ) ';
  46.                 $conj = 'OR ';
  47.             }
  48.         } elseif (!empty($analyzed_sql[0]['where_clause']))  {
  49.             $sql_query .= ' WHERE ' . $analyzed_sql[0]['where_clause'];
  50.         }
  51.         if (!empty($analyzed_sql[0]['group_by_clause'])) {
  52.             $sql_query .= ' GROUP BY ' . $analyzed_sql[0]['group_by_clause'];
  53.         }
  54.         if (!empty($analyzed_sql[0]['having_clause'])) {
  55.             $sql_query .= ' HAVING ' . $analyzed_sql[0]['having_clause'];
  56.         }
  57.         if (!empty($analyzed_sql[0]['order_by_clause'])) {
  58.             $sql_query .= ' ORDER BY ' . $analyzed_sql[0]['order_by_clause'];
  59.         }
  60.     } else {
  61.         // Just crop LIMIT clause
  62.         $inside_bracket = FALSE;
  63.         for ($i = $parsed_sql['len'] - 1; $i >= 0; $i--) {
  64.             if ($parsed_sql[$i]['type'] == 'punct_bracket_close_round') {
  65.                 $inside_bracket = TRUE;
  66.                 continue;
  67.             }
  68.             if ($parsed_sql[$i]['type'] == 'punct_bracket_open_round') {
  69.                 $inside_bracket = FALSE;
  70.                 continue;
  71.             }
  72.             if (!$inside_bracket && $parsed_sql[$i]['type'] == 'alpha_reservedWord' && $parsed_sql[$i]['data'] == 'LIMIT') {
  73.                 // We found LIMIT to remove
  74.                 
  75.                 $sql_query = '';
  76.                 
  77.                 // Concatenate parts before
  78.                 for ($j = 0; $j < $i; $j++) {
  79.                     $sql_query .= $parsed_sql[$j]['data'] . ' ';
  80.                 }
  81.                 
  82.                 // Skip LIMIT
  83.                 $i++;
  84.                 while ($i < $parsed_sql['len'] &&
  85.                     ($parsed_sql[$i]['type'] != 'alpha_reservedWord' || 
  86.                     ($parsed_sql[$i]['type'] == 'alpha_reservedWord' && $parsed_sql[$i]['data'] == 'OFFSET'))) { 
  87.                     $i++; 
  88.                 }
  89.  
  90.                 // Add remaining parts
  91.                 while ($i < $parsed_sql['len']) {
  92.                     $sql_query .= $parsed_sql[$i]['data'] . ' ';
  93.                     $i++;
  94.                 }
  95.                 break;
  96.             }
  97.         }
  98.     }
  99.     $message = $GLOBALS['strSuccess'];
  100. }
  101.  
  102. /**
  103.  * Displays top menu links
  104.  */
  105. require('./tbl_properties_links.php');
  106.  
  107. $export_type = 'table';
  108. require_once('./libraries/display_export.lib.php');
  109.  
  110.  
  111. /**
  112.  * Displays the footer
  113.  */
  114. require_once('./footer.inc.php');
  115. ?>
  116.