Translated using Weblate (Slovenian)
[phpmyadmin.git] / sql.php
blob2b0cb77484e45275a6d386226e0cdf53d90eed8e
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 PMA\libraries\config\PageSettings;
11 use PMA\libraries\Response;
12 use PMA\libraries\Util;
13 use PMA\libraries\URL;
15 /**
16 * Gets some core libraries
18 require_once 'libraries/common.inc.php';
19 require_once 'libraries/check_user_privileges.lib.php';
20 require_once 'libraries/bookmark.lib.php';
21 require_once 'libraries/sql.lib.php';
22 require_once 'libraries/config/user_preferences.forms.php';
23 require_once 'libraries/config/page_settings.forms.php';
25 PageSettings::showGroup('Browse');
28 $response = Response::getInstance();
29 $header = $response->getHeader();
30 $scripts = $header->getScripts();
31 $scripts->addFile('jquery/jquery-ui-timepicker-addon.js');
32 $scripts->addFile('jquery/jquery.uitablefilter.js');
33 $scripts->addFile('tbl_change.js');
34 $scripts->addFile('indexes.js');
35 $scripts->addFile('gis_data_editor.js');
36 $scripts->addFile('multi_column_sort.js');
38 /**
39 * Set ajax_reload in the response if it was already set
41 if (isset($ajax_reload) && $ajax_reload['reload'] === true) {
42 $response->addJSON('ajax_reload', $ajax_reload);
46 /**
47 * Defines the url to return to in case of error in a sql statement
49 $is_gotofile = true;
50 if (empty($goto)) {
51 if (empty($table)) {
52 $goto = Util::getScriptNameForOption(
53 $GLOBALS['cfg']['DefaultTabDatabase'], 'database'
55 } else {
56 $goto = Util::getScriptNameForOption(
57 $GLOBALS['cfg']['DefaultTabTable'], 'table'
60 } // end if
62 if (! isset($err_url)) {
63 $err_url = (! empty($back) ? $back : $goto)
64 . '?' . URL::getCommon(array('db' => $GLOBALS['db']))
65 . ((mb_strpos(' ' . $goto, 'db_') != 1
66 && mb_strlen($table))
67 ? '&amp;table=' . urlencode($table)
68 : ''
70 } // end if
72 // Coming from a bookmark dialog
73 if (isset($_POST['bkm_fields']['bkm_sql_query'])) {
74 $sql_query = $_POST['bkm_fields']['bkm_sql_query'];
75 } elseif (isset($_GET['sql_query'])) {
76 $sql_query = $_GET['sql_query'];
79 // This one is just to fill $db
80 if (isset($_POST['bkm_fields']['bkm_database'])) {
81 $db = $_POST['bkm_fields']['bkm_database'];
85 // During grid edit, if we have a relational field, show the dropdown for it.
86 if (isset($_REQUEST['get_relational_values'])
87 && $_REQUEST['get_relational_values'] == true
88 ) {
89 PMA_getRelationalValues($db, $table);
90 // script has exited at this point
93 // Just like above, find possible values for enum fields during grid edit.
94 if (isset($_REQUEST['get_enum_values']) && $_REQUEST['get_enum_values'] == true) {
95 PMA_getEnumOrSetValues($db, $table, "enum");
96 // script has exited at this point
100 // Find possible values for set fields during grid edit.
101 if (isset($_REQUEST['get_set_values']) && $_REQUEST['get_set_values'] == true) {
102 PMA_getEnumOrSetValues($db, $table, "set");
103 // script has exited at this point
106 if (isset($_REQUEST['get_default_fk_check_value'])
107 && $_REQUEST['get_default_fk_check_value'] == true
109 $response = Response::getInstance();
110 $response->addJSON(
111 'default_fk_check_value', Util::isForeignKeyCheck()
113 exit;
117 * Check ajax request to set the column order and visibility
119 if (isset($_REQUEST['set_col_prefs']) && $_REQUEST['set_col_prefs'] == true) {
120 PMA_setColumnOrderOrVisibility($table, $db);
121 // script has exited at this point
124 // Default to browse if no query set and we have table
125 // (needed for browsing from DefaultTabTable)
126 $tableLength = mb_strlen($table);
127 $dbLength = mb_strlen($db);
128 if (empty($sql_query) && $tableLength && $dbLength) {
129 $sql_query = PMA_getDefaultSqlQueryForBrowse($db, $table);
131 // set $goto to what will be displayed if query returns 0 rows
132 $goto = '';
133 } else {
134 // Now we can check the parameters
135 Util::checkParameters(array('sql_query'));
139 * Parse and analyze the query
141 require_once 'libraries/parse_analyze.lib.php';
142 list(
143 $analyzed_sql_results,
144 $db,
145 $table
146 ) = PMA_parseAnalyze($sql_query, $db);
147 // @todo: possibly refactor
148 extract($analyzed_sql_results);
152 * Check rights in case of DROP DATABASE
154 * This test may be bypassed if $is_js_confirmed = 1 (already checked with js)
155 * but since a malicious user may pass this variable by url/form, we don't take
156 * into account this case.
158 if (PMA_hasNoRightsToDropDatabase(
159 $analyzed_sql_results, $cfg['AllowUserDropDatabase'], $is_superuser
160 )) {
161 Util::mysqlDie(
162 __('"DROP DATABASE" statements are disabled.'),
164 false,
165 $err_url
167 } // end if
170 * Need to find the real end of rows?
172 if (isset($find_real_end) && $find_real_end) {
173 $unlim_num_rows = PMA_findRealEndOfRows($db, $table);
178 * Bookmark add
180 if (isset($_POST['store_bkm'])) {
181 PMA_addBookmark($goto);
182 // script has exited at this point
183 } // end if
187 * Sets or modifies the $goto variable if required
189 if ($goto == 'sql.php') {
190 $is_gotofile = false;
191 $goto = 'sql.php' . URL::getCommon(
192 array(
193 'db' => $db,
194 'table' => $table,
195 'sql_query' => $sql_query
198 } // end if
200 PMA_executeQueryAndSendQueryResponse(
201 $analyzed_sql_results, // analyzed_sql_results
202 $is_gotofile, // is_gotofile
203 $db, // db
204 $table, // table
205 isset($find_real_end) ? $find_real_end : null, // find_real_end
206 isset($import_text) ? $import_text : null, // sql_query_for_bookmark
207 isset($extra_data) ? $extra_data : null, // extra_data
208 isset($message_to_show) ? $message_to_show : null, // message_to_show
209 isset($message) ? $message : null, // message
210 isset($sql_data) ? $sql_data : null, // sql_data
211 $goto, // goto
212 $pmaThemeImage, // pmaThemeImage
213 isset($disp_query) ? $display_query : null, // disp_query
214 isset($disp_message) ? $disp_message : null, // disp_message
215 isset($query_type) ? $query_type : null, // query_type
216 $sql_query, // sql_query
217 isset($selected) ? $selected : null, // selectedTables
218 isset($complete_query) ? $complete_query : null // complete_query