tbl_export.php 2.8 KB

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