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('tbl_change.js');
27 $scripts->addFile('indexes.js');
28 $scripts->addFile('gis_data_editor.js');
31 * Set ajax_reload in the response if it was already set
33 if (isset($ajax_reload) && $ajax_reload['reload'] === true) {
34 $response->addJSON('ajax_reload', $ajax_reload);
39 * Defines the url to return to in case of error in a sql statement
43 $is_gotofile = preg_replace('@^([^?]+).*$@s', '\\1', $goto);
44 if (! @file_exists
('' . $is_gotofile)) {
47 $is_gotofile = ($is_gotofile == $goto);
51 $goto = $cfg['DefaultTabDatabase'];
53 $goto = $cfg['DefaultTabTable'];
58 if (! isset($err_url)) {
59 $err_url = (! empty($back) ?
$back : $goto)
60 . '?' . PMA_URL_getCommon($db)
61 . ((strpos(' ' . $goto, 'db_') != 1 && strlen($table))
62 ?
'&table=' . urlencode($table)
67 // Coming from a bookmark dialog
68 if (isset($_POST['bkm_fields']['bkm_sql_query'])) {
69 $sql_query = $_POST['bkm_fields']['bkm_sql_query'];
70 } elseif (isset($_GET['sql_query'])) {
71 $sql_query = $_GET['sql_query'];
74 // This one is just to fill $db
75 if (isset($_POST['bkm_fields']['bkm_database'])) {
76 $db = $_POST['bkm_fields']['bkm_database'];
80 // During grid edit, if we have a relational field, show the dropdown for it.
81 if (isset($_REQUEST['get_relational_values'])
82 && $_REQUEST['get_relational_values'] == true
84 PMA_getRelationalValues($db, $table, $display_field);
85 // script has exited at this point
88 // Just like above, find possible values for enum fields during grid edit.
89 if (isset($_REQUEST['get_enum_values']) && $_REQUEST['get_enum_values'] == true) {
90 PMA_getEnumOrSetValues($db, $table, "enum");
91 // script has exited at this point
95 // Find possible values for set fields during grid edit.
96 if (isset($_REQUEST['get_set_values']) && $_REQUEST['get_set_values'] == true) {
97 PMA_getEnumOrSetValues($db, $table, "set");
98 // script has exited at this point
102 * Check ajax request to set the column order and visibility
104 if (isset($_REQUEST['set_col_prefs']) && $_REQUEST['set_col_prefs'] == true) {
105 PMA_setColumnOrderOrVisibility($table, $db);
106 // script has exited at this point
109 // Default to browse if no query set and we have table
110 // (needed for browsing from DefaultTabTable)
111 if (empty($sql_query) && strlen($table) && strlen($db)) {
112 $sql_query = PMA_getDefaultSqlQueryForBrowse($db, $table);
114 // set $goto to what will be displayed if query returns 0 rows
117 // Now we can check the parameters
118 PMA_Util
::checkParameters(array('sql_query'));
122 * Parse and analyze the query
124 require_once 'libraries/parse_analyze.inc.php';
128 * Check rights in case of DROP DATABASE
130 * This test may be bypassed if $is_js_confirmed = 1 (already checked with js)
131 * but since a malicious user may pass this variable by url/form, we don't take
132 * into account this case.
134 if (PMA_hasNoRightsToDropDatabase(
135 $analyzed_sql_results, $cfg['AllowUserDropDatabase'], $is_superuser
138 __('"DROP DATABASE" statements are disabled.'),
146 * Need to find the real end of rows?
148 if (isset($find_real_end) && $find_real_end) {
149 $unlim_num_rows = PMA_findRealEndOfRows($db, $table);
156 if (isset($_POST['store_bkm'])) {
157 PMA_addBookmark($cfg['PmaAbsoluteUri'], $goto);
158 // script has exited at this point
163 * Sets or modifies the $goto variable if required
165 if ($goto == 'sql.php') {
166 $is_gotofile = false;
167 $goto = 'sql.php' . PMA_URL_getCommon(
171 'sql_query' => $sql_query
176 PMA_executeQueryAndSendQueryResponse(
177 $analyzed_sql_results,
181 isset($find_real_end) ?
$find_real_end : null,
182 isset($import_text) ?
$import_text : null,
183 isset($extra_data) ?
$extra_data : null,
185 isset($message_to_show) ?
$message_to_show : null,
186 isset($disp_mode) ?
$disp_mode : null,
187 isset($message) ?
$message : null,
188 isset($sql_data) ?
$sql_data : null,
191 isset($disp_query) ?
$display_query : null,
192 isset($disp_message) ?
$disp_message : null,
193 isset($query_type) ?
$query_type : null,
195 isset($selected) ?
$selected : null,
196 isset($complete_query) ?
$complete_query : null