parse_analyze.lib.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Parse and analyse a SQL query
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. if (! defined('PHPMYADMIN')) {
  9. exit;
  10. }
  11. /**
  12. *
  13. */
  14. $GLOBALS['unparsed_sql'] = $sql_query;
  15. $parsed_sql = PMA_SQP_parse($sql_query);
  16. $analyzed_sql = PMA_SQP_analyze($parsed_sql);
  17. // for bug 780516: now that we use case insensitive preg_match
  18. // or flags from the analyser, do not put back the reformatted query
  19. // into $sql_query, to make this kind of query work without
  20. // capitalizing keywords:
  21. //
  22. // CREATE TABLE SG_Persons (
  23. // id int(10) unsigned NOT NULL auto_increment,
  24. // first varchar(64) NOT NULL default '',
  25. // PRIMARY KEY (`id`)
  26. // )
  27. // check for a real SELECT ... FROM
  28. $is_select = isset($analyzed_sql[0]['queryflags']['select_from']);
  29. // If the query is a Select, extract the db and table names and modify
  30. // $db and $table, to have correct page headers, links and left frame.
  31. // db and table name may be enclosed with backquotes, db is optionnal,
  32. // query may contain aliases.
  33. /**
  34. * @todo if there are more than one table name in the Select:
  35. * - do not extract the first table name
  36. * - do not show a table name in the page header
  37. * - do not display the sub-pages links)
  38. */
  39. if ($is_select) {
  40. $prev_db = $db;
  41. if (isset($analyzed_sql[0]['table_ref'][0]['table_true_name'])) {
  42. $table = $analyzed_sql[0]['table_ref'][0]['table_true_name'];
  43. }
  44. if (isset($analyzed_sql[0]['table_ref'][0]['db'])
  45. && strlen($analyzed_sql[0]['table_ref'][0]['db'])
  46. ) {
  47. $db = $analyzed_sql[0]['table_ref'][0]['db'];
  48. } else {
  49. $db = $prev_db;
  50. }
  51. // Nijel: don't change reload, if we already decided to reload in import
  52. if (empty($reload) && empty($GLOBALS['is_ajax_request'])) {
  53. $reload = ($db == $prev_db) ? 0 : 1;
  54. }
  55. }
  56. ?>