2 /* vim: set expandtab sw=4 ts=4 sts=4: */
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
12 * Gets some core libraries
14 require_once 'libraries/common.inc.php';
15 require_once 'libraries/Table.class.php';
16 require_once 'libraries/Header.class.php';
17 require_once 'libraries/check_user_privileges.lib.php';
18 require_once 'libraries/bookmark.lib.php';
19 require_once 'libraries/sql.lib.php';
20 require_once 'libraries/sqlparser.lib.php';
22 $response = PMA_Response
::getInstance();
23 $header = $response->getHeader();
24 $scripts = $header->getScripts();
25 $scripts->addFile('jquery/jquery-ui-timepicker-addon.js');
26 $scripts->addFile('jquery/jquery.uitablefilter.js');
27 $scripts->addFile('tbl_change.js');
28 $scripts->addFile('indexes.js');
29 $scripts->addFile('gis_data_editor.js');
30 $scripts->addFile('multi_column_sort.js');
33 * Set ajax_reload in the response if it was already set
35 if (isset($ajax_reload) && $ajax_reload['reload'] === true) {
36 $response->addJSON('ajax_reload', $ajax_reload);
41 * Defines the url to return to in case of error in a sql statement
45 $is_gotofile = preg_replace('@^([^?]+).*$@s', '\\1', $goto);
46 if (! @file_exists
('' . $is_gotofile)) {
49 $is_gotofile = ($is_gotofile == $goto);
53 $goto = $cfg['DefaultTabDatabase'];
55 $goto = $cfg['DefaultTabTable'];
60 if (! isset($err_url)) {
61 $err_url = (! empty($back) ?
$back : $goto)
62 . '?' . PMA_URL_getCommon($db)
63 . ((strpos(' ' . $goto, 'db_') != 1 && strlen($table))
64 ?
'&table=' . urlencode($table)
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($_GET['sql_query'])) {
73 $sql_query = $_GET['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'];
82 // During grid edit, if we have a relational field, show the dropdown for it.
83 if (isset($_REQUEST['get_relational_values'])
84 && $_REQUEST['get_relational_values'] == true
86 PMA_getRelationalValues($db, $table);
87 // script has exited at this point
90 // Just like above, find possible values for enum fields during grid edit.
91 if (isset($_REQUEST['get_enum_values']) && $_REQUEST['get_enum_values'] == true) {
92 PMA_getEnumOrSetValues($db, $table, "enum");
93 // script has exited at this point
97 // Find possible values for set fields during grid edit.
98 if (isset($_REQUEST['get_set_values']) && $_REQUEST['get_set_values'] == true) {
99 PMA_getEnumOrSetValues($db, $table, "set");
100 // script has exited at this point
104 * Check ajax request to set the column order and visibility
106 if (isset($_REQUEST['set_col_prefs']) && $_REQUEST['set_col_prefs'] == true) {
107 PMA_setColumnOrderOrVisibility($table, $db);
108 // script has exited at this point
111 // Default to browse if no query set and we have table
112 // (needed for browsing from DefaultTabTable)
113 if (empty($sql_query) && strlen($table) && strlen($db)) {
114 $sql_query = PMA_getDefaultSqlQueryForBrowse($db, $table);
116 // set $goto to what will be displayed if query returns 0 rows
119 // Now we can check the parameters
120 PMA_Util
::checkParameters(array('sql_query'));
124 * Parse and analyze the query
126 require_once 'libraries/parse_analyze.inc.php';
130 * Check rights in case of DROP DATABASE
132 * This test may be bypassed if $is_js_confirmed = 1 (already checked with js)
133 * but since a malicious user may pass this variable by url/form, we don't take
134 * into account this case.
136 if (PMA_hasNoRightsToDropDatabase(
137 $analyzed_sql_results, $cfg['AllowUserDropDatabase'], $is_superuser
140 __('"DROP DATABASE" statements are disabled.'),
148 * Need to find the real end of rows?
150 if (isset($find_real_end) && $find_real_end) {
151 $unlim_num_rows = PMA_findRealEndOfRows($db, $table);
158 if (isset($_POST['store_bkm'])) {
159 PMA_addBookmark($cfg['PmaAbsoluteUri'], $goto);
160 // script has exited at this point
165 * Sets or modifies the $goto variable if required
167 if ($goto == 'sql.php') {
168 $is_gotofile = false;
169 $goto = 'sql.php' . PMA_URL_getCommon(
173 'sql_query' => $sql_query
178 PMA_executeQueryAndSendQueryResponse(
179 $analyzed_sql_results,
183 isset($find_real_end) ?
$find_real_end : null,
184 isset($import_text) ?
$import_text : null,
185 isset($extra_data) ?
$extra_data : null,
187 isset($message_to_show) ?
$message_to_show : null,
188 isset($disp_mode) ?
$disp_mode : null,
189 isset($message) ?
$message : null,
190 isset($sql_data) ?
$sql_data : null,
193 isset($disp_query) ?
$display_query : null,
194 isset($disp_message) ?
$disp_message : null,
195 isset($query_type) ?
$query_type : null,
197 isset($selected) ?
$selected : null,
198 isset($complete_query) ?
$complete_query : null