Translated using Weblate (Dutch)
[phpmyadmin.git] / libraries / parse_analyze.inc.php
blob2a0c465fea2e3cd64bb66078d7d24bd03dd878e4
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Parse and analyse a SQL query
6 * @package PhpMyAdmin
7 */
8 if (! defined('PHPMYADMIN')) {
9 exit;
12 /**
15 $GLOBALS['unparsed_sql'] = $sql_query;
16 $parsed_sql = PMA_SQP_parse($sql_query);
17 $analyzed_sql = PMA_SQP_analyze($parsed_sql);
19 // for bug 780516: now that we use case insensitive preg_match
20 // or flags from the analyser, do not put back the reformatted query
21 // into $sql_query, to make this kind of query work without
22 // capitalizing keywords:
24 // CREATE TABLE SG_Persons (
25 // id int(10) unsigned NOT NULL auto_increment,
26 // first varchar(64) NOT NULL default '',
27 // PRIMARY KEY (`id`)
28 // )
30 // Fills some variables from the analysed SQL
31 // A table has to be created, renamed, dropped:
32 // the navigation panel should be reloaded
33 $reload = isset($analyzed_sql[0]['queryflags']['reload']);
35 // check for drop database
36 $drop_database = isset($analyzed_sql[0]['queryflags']['drop_database']);
38 // for the presence of EXPLAIN
39 $is_explain = isset($analyzed_sql[0]['queryflags']['is_explain']);
41 // for the presence of DELETE
42 $is_delete = isset($analyzed_sql[0]['queryflags']['is_delete']);
44 // for the presence of UPDATE, DELETE or INSERT|LOAD DATA|REPLACE
45 $is_affected = isset($analyzed_sql[0]['queryflags']['is_affected']);
47 // for the presence of REPLACE
48 $is_replace = isset($analyzed_sql[0]['queryflags']['is_replace']);
50 // for the presence of INSERT
51 $is_insert = isset($analyzed_sql[0]['queryflags']['is_insert']);
53 // for the presence of CHECK|ANALYZE|REPAIR|OPTIMIZE TABLE
54 $is_maint = isset($analyzed_sql[0]['queryflags']['is_maint']);
56 // for the presence of SHOW
57 $is_show = isset($analyzed_sql[0]['queryflags']['is_show']);
59 // for the presence of PROCEDURE ANALYSE
60 $is_analyse = isset($analyzed_sql[0]['queryflags']['is_analyse']);
62 // for the presence of INTO OUTFILE
63 $is_export = isset($analyzed_sql[0]['queryflags']['is_export']);
65 // for the presence of GROUP BY|HAVING|SELECT DISTINCT
66 $is_group = isset($analyzed_sql[0]['queryflags']['is_group']);
68 // for the presence of SUM|AVG|STD|STDDEV|MIN|MAX|BIT_OR|BIT_AND
69 $is_func = isset($analyzed_sql[0]['queryflags']['is_func']);
71 // for the presence of SELECT COUNT
72 $is_count = isset($analyzed_sql[0]['queryflags']['is_count']);
74 // check for a real SELECT ... FROM
75 $is_select = isset($analyzed_sql[0]['queryflags']['select_from']);
77 // check for CALL
78 // Since multiple query execution is anyway handled,
79 // ignore the WHERE clause of the first sql statement
80 // which might contain a phrase like 'call '
81 if (isset($analyzed_sql[0]['queryflags']['is_procedure'])
82 && empty($analyzed_sql[0]['where_clause'])
83 ) {
84 $is_procedure = true;
85 } else {
86 $is_procedure = false;
89 // aggregates all the results into one array
90 $analyzed_sql_results = array(
91 "parsed_sql" => $parsed_sql,
92 "analyzed_sql" => $analyzed_sql,
93 "reload" => $reload,
94 "drop_database" => $drop_database,
95 "is_explain" => $is_explain,
96 "is_delete" => $is_delete,
97 "is_affected" => $is_affected,
98 "is_replace" => $is_replace,
99 "is_insert" => $is_insert,
100 "is_maint" => $is_maint,
101 "is_show" => $is_show,
102 "is_analyse" => $is_analyse,
103 "is_export" => $is_export,
104 "is_group" => $is_group,
105 "is_func" => $is_func,
106 "is_count" => $is_count,
107 "is_select" => $is_select,
108 "is_procedure" => $is_procedure
112 // If the query is a Select, extract the db and table names and modify
113 // $db and $table, to have correct page headers, links and left frame.
114 // db and table name may be enclosed with backquotes, db is optionnal,
115 // query may contain aliases.
118 * @todo if there are more than one table name in the Select:
119 * - do not extract the first table name
120 * - do not show a table name in the page header
121 * - do not display the sub-pages links)
123 if ($is_select) {
124 $prev_db = $db;
125 if (isset($analyzed_sql[0]['table_ref'][0]['table_true_name'])) {
126 $table = $analyzed_sql[0]['table_ref'][0]['table_true_name'];
128 if (isset($analyzed_sql[0]['table_ref'][0]['db'])
129 && strlen($analyzed_sql[0]['table_ref'][0]['db'])
131 $db = $analyzed_sql[0]['table_ref'][0]['db'];
132 } else {
133 $db = $prev_db;
135 // Don't change reload, if we already decided to reload in import
136 if (empty($reload) && empty($GLOBALS['is_ajax_request'])) {
137 $reload = ($db == $prev_db) ? 0 : 1;