tbl_export.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Table export
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. /**
  9. *
  10. */
  11. require_once 'libraries/common.inc.php';
  12. $response = PMA_Response::getInstance();
  13. $header = $response->getHeader();
  14. $scripts = $header->getScripts();
  15. $scripts->addFile('export.js');
  16. /**
  17. * Gets tables informations and displays top links
  18. */
  19. require_once 'libraries/tbl_common.inc.php';
  20. $url_query .= '&amp;goto=tbl_export.php&amp;back=tbl_export.php';
  21. require_once 'libraries/tbl_info.inc.php';
  22. // Dump of a table
  23. $export_page_title = __('View dump (schema) of table');
  24. // When we have some query, we need to remove LIMIT from that and possibly
  25. // generate WHERE clause (if we are asked to export specific rows)
  26. if (! empty($sql_query)) {
  27. // Parse query so we can work with tokens
  28. $parsed_sql = PMA_SQP_parse($sql_query);
  29. $analyzed_sql = PMA_SQP_analyze($parsed_sql);
  30. // Need to generate WHERE clause?
  31. if (isset($where_clause)) {
  32. // Regular expressions which can appear in sql query,
  33. // before the sql segment which remains as it is.
  34. $regex_array = array(
  35. '/\bwhere\b/i', '/\bgroup by\b/i', '/\bhaving\b/i', '/\border by\b/i'
  36. );
  37. $first_occurring_regex = PMA_Util::getFirstOccurringRegularExpression(
  38. $regex_array, $sql_query
  39. );
  40. unset($regex_array);
  41. // The part "SELECT `id`, `name` FROM `customers`"
  42. // is not modified by the next code segment, when exporting
  43. // the result set from a query such as
  44. // "SELECT `id`, `name` FROM `customers` WHERE id NOT IN
  45. // ( SELECT id FROM companies WHERE name LIKE '%u%')"
  46. if (! is_null($first_occurring_regex)) {
  47. $temp_sql_array = preg_split($first_occurring_regex, $sql_query);
  48. $sql_query = $temp_sql_array[0];
  49. }
  50. unset($first_occurring_regex, $temp_sql_array);
  51. // Append the where clause using the primary key of each row
  52. if (is_array($where_clause) && (count($where_clause) > 0)) {
  53. $sql_query .= ' WHERE (' . implode(') OR (', $where_clause) . ')';
  54. }
  55. if (!empty($analyzed_sql[0]['group_by_clause'])) {
  56. $sql_query .= ' GROUP BY ' . $analyzed_sql[0]['group_by_clause'];
  57. }
  58. if (!empty($analyzed_sql[0]['having_clause'])) {
  59. $sql_query .= ' HAVING ' . $analyzed_sql[0]['having_clause'];
  60. }
  61. if (!empty($analyzed_sql[0]['order_by_clause'])) {
  62. $sql_query .= ' ORDER BY ' . $analyzed_sql[0]['order_by_clause'];
  63. }
  64. } else {
  65. // Just crop LIMIT clause
  66. $sql_query = $analyzed_sql[0]['section_before_limit']
  67. . $analyzed_sql[0]['section_after_limit'];
  68. }
  69. echo PMA_Util::getMessage(PMA_Message::success());
  70. }
  71. $export_type = 'table';
  72. require_once 'libraries/display_export.inc.php';
  73. ?>