Translated using Weblate (Italian)
[phpmyadmin.git] / sql.php
blob5e73353519b719b2c1f8c777df3e6efd08a82831
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * SQL executor
6 * @todo we must handle the case if sql.php is called directly with a query
7 * that returns 0 rows - to prevent cyclic redirects or includes
8 * @package PhpMyAdmin
9 */
10 use PhpMyAdmin\Config\PageSettings;
11 use PhpMyAdmin\ParseAnalyze;
12 use PhpMyAdmin\Response;
13 use PhpMyAdmin\Sql;
14 use PhpMyAdmin\Url;
15 use PhpMyAdmin\Util;
17 /**
18 * Gets some core libraries
20 require_once 'libraries/common.inc.php';
21 require_once 'libraries/check_user_privileges.inc.php';
23 PageSettings::showGroup('Browse');
25 $response = Response::getInstance();
26 $header = $response->getHeader();
27 $scripts = $header->getScripts();
28 $scripts->addFile('vendor/jquery/jquery.uitablefilter.js');
29 $scripts->addFile('tbl_change.js');
30 $scripts->addFile('indexes.js');
31 $scripts->addFile('gis_data_editor.js');
32 $scripts->addFile('multi_column_sort.js');
34 $sql = new Sql();
36 /**
37 * Set ajax_reload in the response if it was already set
39 if (isset($ajax_reload) && $ajax_reload['reload'] === true) {
40 $response->addJSON('ajax_reload', $ajax_reload);
43 /**
44 * Defines the url to return to in case of error in a sql statement
46 $is_gotofile = true;
47 if (empty($goto)) {
48 if (empty($table)) {
49 $goto = Util::getScriptNameForOption(
50 $GLOBALS['cfg']['DefaultTabDatabase'], 'database'
52 } else {
53 $goto = Util::getScriptNameForOption(
54 $GLOBALS['cfg']['DefaultTabTable'], 'table'
57 } // end if
59 if (! isset($err_url)) {
60 $err_url = (! empty($back) ? $back : $goto)
61 . '?' . Url::getCommon(array('db' => $GLOBALS['db']))
62 . ((mb_strpos(' ' . $goto, 'db_') != 1
63 && strlen($table) > 0)
64 ? '&amp;table=' . urlencode($table)
65 : ''
67 } // end if
69 // Coming from a bookmark dialog
70 if (isset($_POST['bkm_fields']['bkm_sql_query'])) {
71 $sql_query = $_POST['bkm_fields']['bkm_sql_query'];
72 } elseif (isset($_POST['sql_query'])) {
73 $sql_query = $_POST['sql_query'];
76 // This one is just to fill $db
77 if (isset($_POST['bkm_fields']['bkm_database'])) {
78 $db = $_POST['bkm_fields']['bkm_database'];
81 // During grid edit, if we have a relational field, show the dropdown for it.
82 if (isset($_POST['get_relational_values'])
83 && $_POST['get_relational_values'] == true
84 ) {
85 $sql->getRelationalValues($db, $table);
86 // script has exited at this point
89 // Just like above, find possible values for enum fields during grid edit.
90 if (isset($_POST['get_enum_values']) && $_POST['get_enum_values'] == true) {
91 $sql->getEnumOrSetValues($db, $table, "enum");
92 // script has exited at this point
96 // Find possible values for set fields during grid edit.
97 if (isset($_POST['get_set_values']) && $_POST['get_set_values'] == true) {
98 $sql->getEnumOrSetValues($db, $table, "set");
99 // script has exited at this point
102 if (isset($_GET['get_default_fk_check_value'])
103 && $_GET['get_default_fk_check_value'] == true
105 $response = Response::getInstance();
106 $response->addJSON(
107 'default_fk_check_value', Util::isForeignKeyCheck()
109 exit;
113 * Check ajax request to set the column order and visibility
115 if (isset($_POST['set_col_prefs']) && $_POST['set_col_prefs'] == true) {
116 $sql->setColumnOrderOrVisibility($table, $db);
117 // script has exited at this point
120 // Default to browse if no query set and we have table
121 // (needed for browsing from DefaultTabTable)
122 if (empty($sql_query) && strlen($table) > 0 && strlen($db) > 0) {
123 $sql_query = $sql->getDefaultSqlQueryForBrowse($db, $table);
125 // set $goto to what will be displayed if query returns 0 rows
126 $goto = '';
127 } else {
128 // Now we can check the parameters
129 Util::checkParameters(array('sql_query'));
133 * Parse and analyze the query
135 list(
136 $analyzed_sql_results,
137 $db,
138 $table_from_sql
139 ) = ParseAnalyze::sqlQuery($sql_query, $db);
140 // @todo: possibly refactor
141 extract($analyzed_sql_results);
143 if ($table != $table_from_sql && !empty($table_from_sql)) {
144 $table = $table_from_sql;
149 * Check rights in case of DROP DATABASE
151 * This test may be bypassed if $is_js_confirmed = 1 (already checked with js)
152 * but since a malicious user may pass this variable by url/form, we don't take
153 * into account this case.
155 if ($sql->hasNoRightsToDropDatabase(
156 $analyzed_sql_results, $cfg['AllowUserDropDatabase'], $GLOBALS['dbi']->isSuperuser()
157 )) {
158 Util::mysqlDie(
159 __('"DROP DATABASE" statements are disabled.'),
161 false,
162 $err_url
164 } // end if
167 * Need to find the real end of rows?
169 if (isset($find_real_end) && $find_real_end) {
170 $unlim_num_rows = $sql->findRealEndOfRows($db, $table);
175 * Bookmark add
177 if (isset($_POST['store_bkm'])) {
178 $sql->addBookmark($goto);
179 // script has exited at this point
180 } // end if
184 * Sets or modifies the $goto variable if required
186 if ($goto == 'sql.php') {
187 $is_gotofile = false;
188 $goto = 'sql.php' . Url::getCommon(
189 array(
190 'db' => $db,
191 'table' => $table,
192 'sql_query' => $sql_query
195 } // end if
197 $sql->executeQueryAndSendQueryResponse(
198 $analyzed_sql_results, // analyzed_sql_results
199 $is_gotofile, // is_gotofile
200 $db, // db
201 $table, // table
202 isset($find_real_end) ? $find_real_end : null, // find_real_end
203 isset($import_text) ? $import_text : null, // sql_query_for_bookmark
204 isset($extra_data) ? $extra_data : null, // extra_data
205 isset($message_to_show) ? $message_to_show : null, // message_to_show
206 isset($message) ? $message : null, // message
207 isset($sql_data) ? $sql_data : null, // sql_data
208 $goto, // goto
209 $pmaThemeImage, // pmaThemeImage
210 isset($disp_query) ? $display_query : null, // disp_query
211 isset($disp_message) ? $disp_message : null, // disp_message
212 isset($query_type) ? $query_type : null, // query_type
213 $sql_query, // sql_query
214 isset($selected) ? $selected : null, // selectedTables
215 isset($complete_query) ? $complete_query : null // complete_query