Merge pull request #446 from scnakandala/gsoc_2013
Refactoring SQL executor
This commit is contained in:
commit
70dd46ecf0
@ -73,29 +73,26 @@ $is_count = isset($analyzed_sql[0]['queryflags']['is_count']);
|
||||
// check for a real SELECT ... FROM
|
||||
$is_select = isset($analyzed_sql[0]['queryflags']['select_from']);
|
||||
|
||||
// checks whether the sorting order should be remembered
|
||||
if ($GLOBALS['cfg']['RememberSorting']
|
||||
&& ! ($is_count || $is_export || $is_func || $is_analyse)
|
||||
&& isset($analyzed_sql[0]['select_expr'])
|
||||
&& (count($analyzed_sql[0]['select_expr']) == 0)
|
||||
&& isset($analyzed_sql[0]['queryflags']['select_from'])
|
||||
&& count($analyzed_sql[0]['table_ref']) == 1
|
||||
) {
|
||||
$is_remember_sorting_order = true;
|
||||
} else {
|
||||
$is_remember_sorting_order = false;
|
||||
}
|
||||
// aggregates all the results in to one array
|
||||
$analyzed_sql_results = array(
|
||||
"analyzed_sql" => $analyzed_sql,
|
||||
"reload" => $reload,
|
||||
"drop_database" => $drop_database,
|
||||
"is_explain" => $is_explain,
|
||||
"is_delete" => $is_delete,
|
||||
"is_affected" => $is_affected,
|
||||
"is_replace" => $is_replace,
|
||||
"is_insert" => $is_insert,
|
||||
"is_maint" => $is_maint,
|
||||
"is_show" => $is_show,
|
||||
"is_analyse" => $is_analyse,
|
||||
"is_export" => $is_export,
|
||||
"is_group" => $is_group,
|
||||
"is_func" => $is_func,
|
||||
"is_count" => $is_count,
|
||||
"is_select" => $is_select
|
||||
);
|
||||
|
||||
// checks whether a LIMIT clause should be added to the query
|
||||
if (! ($is_count || $is_export || $is_func || $is_analyse)
|
||||
&& isset($analyzed_sql[0]['queryflags']['select_from'])
|
||||
&& ! isset($analyzed_sql[0]['queryflags']['offset'])
|
||||
&& empty($analyzed_sql[0]['limit_clause'])
|
||||
) {
|
||||
$is_append_limit_clause = true;
|
||||
} else {
|
||||
$is_append_limit_clause = false;
|
||||
}
|
||||
|
||||
// If the query is a Select, extract the db and table names and modify
|
||||
// $db and $table, to have correct page headers, links and left frame.
|
||||
|
||||
@ -700,4 +700,133 @@ function PMA_getHtmlForBookmark($db, $goto, $bkm_sql_query, $bkm_user)
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to check whether to remeber the sorting order or not
|
||||
*
|
||||
* @param array $analyzed_sql_results the analyzed qyery and other varibles set
|
||||
* after analyzing the query
|
||||
* @return boolean
|
||||
*/
|
||||
function PMA_isRememberSortingOrder($analyzed_sql_results)
|
||||
{
|
||||
if ($GLOBALS['cfg']['RememberSorting']
|
||||
&& ! ($analyzed_sql_results['is_count']
|
||||
|| $analyzed_sql_results['is_export']
|
||||
|| $analyzed_sql_results['is_func']
|
||||
|| $analyzed_sql_results['is_analyse']
|
||||
)
|
||||
&& isset($analyzed_sql_results['analyzed_sql'][0]['select_expr'])
|
||||
&& (count($analyzed_sql_results['analyzed_sql'][0]['select_expr']) == 0)
|
||||
&& isset(
|
||||
$analyzed_sql_results['analyzed_sql'][0]['queryflags']['select_from']
|
||||
)
|
||||
&& count($analyzed_sql_results['analyzed_sql'][0]['table_ref']) == 1
|
||||
) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to check whether the LIMIT clause should be appended or not
|
||||
*
|
||||
* @param array $analyzed_sql_results the analyzed qyery and other varibles set
|
||||
* after analyzing the query
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function PMA_isAppendLimitClause($analyzed_sql_results)
|
||||
{
|
||||
if (($_SESSION['tmp_user_values']['max_rows'] != 'all')
|
||||
&& ! ($analyzed_sql_results['is_count']
|
||||
|| $analyzed_sql_results['is_export']
|
||||
|| $analyzed_sql_results['is_func']
|
||||
|| $analyzed_sql_results['is_analyse']
|
||||
)
|
||||
&& isset(
|
||||
$analyzed_sql_results['analyzed_sql'][0]['queryflags']['select_from']
|
||||
)
|
||||
&& ! isset($analyzed_sql_results['analyzed_sql'][0]['queryflags']['offset'])
|
||||
&& empty($analyzed_sql_results['analyzed_sql'][0]['limit_clause'])
|
||||
) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to check whether this query is for just browsing
|
||||
*
|
||||
* @param array $analyzed_sql_results the analyzed qyery and other varibles set
|
||||
* after analyzing the query
|
||||
* @param boolean $find_real_end whether the real end should be found
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function PMA_isJustBrowsing($analyzed_sql_results, $find_real_end)
|
||||
{
|
||||
if (! $analyzed_sql_results['is_group']
|
||||
&& ! isset($analyzed_sql_results['analyzed_sql'][0]['queryflags']['union'])
|
||||
&& ! isset(
|
||||
$analyzed_sql_results['analyzed_sql'][0]['queryflags']['distinct']
|
||||
)
|
||||
&& ! isset(
|
||||
$analyzed_sql_results['analyzed_sql'][0]['table_ref'][1]['table_name']
|
||||
)
|
||||
&& (empty($analyzed_sql_results['analyzed_sql'][0]['where_clause'])
|
||||
|| $analyzed_sql_results['analyzed_sql'][0]['where_clause'] == '1 ')
|
||||
&& ! isset($find_real_end)
|
||||
) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to check whether the reated transformation information shoul be deleted
|
||||
*
|
||||
* @param array $analyzed_sql_results the analyzed qyery and other varibles set
|
||||
* after analyzing the query
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function PMA_isDeleteTransformationInfo($analyzed_sql_results)
|
||||
{
|
||||
if (!empty($analyzed_sql_results['analyzed_sql'][0]['querytype'])
|
||||
&& (($analyzed_sql_results['analyzed_sql'][0]['querytype'] == 'ALTER')
|
||||
|| ($analyzed_sql_results['analyzed_sql'][0]['querytype'] == 'DROP'))
|
||||
) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to check whether the user has rights to drop the database
|
||||
*
|
||||
* @param array $analyzed_sql_results the analyzed qyery and other varibles set
|
||||
* after analyzing the query
|
||||
* @param boolean $allowUserDropDatabase whether the user is allowed to drop db
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function PMA_hasNoRightsToDropDatabase($analyzed_sql_results,
|
||||
$allowUserDropDatabase
|
||||
) {
|
||||
if (! defined('PMA_CHK_DROP')
|
||||
&& ! $allowUserDropDatabase
|
||||
&& isset ($analyzed_sql_results['drop_database'])
|
||||
&& $analyzed_sql_results['drop_database'] == 1
|
||||
&& ! $analyzed_sql_results['is_superuser']
|
||||
) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
42
sql.php
42
sql.php
@ -212,11 +212,8 @@ require_once 'libraries/parse_analyze.inc.php';
|
||||
* but since a malicious user may pass this variable by url/form, we don't take
|
||||
* into account this case.
|
||||
*/
|
||||
if (! defined('PMA_CHK_DROP')
|
||||
&& ! $cfg['AllowUserDropDatabase']
|
||||
&& isset ($drop_database)
|
||||
&& $drop_database == 1
|
||||
&& ! $is_superuser
|
||||
if (PMA_hasNoRightsToDropDatabase(
|
||||
$analyzed_sql_results, $cfg['AllowUserDropDatabase'])
|
||||
) {
|
||||
PMA_Util::mysqlDie(
|
||||
__('"DROP DATABASE" statements are disabled.'),
|
||||
@ -254,7 +251,9 @@ if (isset($find_real_end) && $find_real_end) {
|
||||
if (isset($_POST['store_bkm'])) {
|
||||
$result = PMA_Bookmark_save(
|
||||
$_POST['bkm_fields'],
|
||||
(isset($_POST['bkm_all_users']) && $_POST['bkm_all_users'] == 'true' ? true : false)
|
||||
(isset($_POST['bkm_all_users'])
|
||||
&& $_POST['bkm_all_users'] == 'true' ? true : false
|
||||
)
|
||||
);
|
||||
$response = PMA_Response::getInstance();
|
||||
if ($response->isAjax()) {
|
||||
@ -271,7 +270,8 @@ if (isset($_POST['store_bkm'])) {
|
||||
} else {
|
||||
// go back to sql.php to redisplay query; do not use & in this case:
|
||||
PMA_sendHeaderLocation(
|
||||
$cfg['PmaAbsoluteUri'] . $goto . '&label=' . $_POST['bkm_fields']['bkm_label']
|
||||
$cfg['PmaAbsoluteUri'] . $goto
|
||||
. '&label=' . $_POST['bkm_fields']['bkm_label']
|
||||
);
|
||||
}
|
||||
} // end if
|
||||
@ -313,15 +313,13 @@ if (isset($_REQUEST['btnDrop']) && $_REQUEST['btnDrop'] == __('No')) {
|
||||
$full_sql_query = $sql_query;
|
||||
|
||||
// Handle remembered sorting order, only for single table query
|
||||
if ($is_remember_sorting_order) {
|
||||
if (PMA_isRememberSortingOrder($analyzed_sql_results)) {
|
||||
PMA_handleSortOrder($db, $table, $analyzed_sql, $full_sql_query);
|
||||
}
|
||||
|
||||
$sql_limit_to_append = '';
|
||||
// Do append a "LIMIT" clause?
|
||||
if (($_SESSION['tmp_user_values']['max_rows'] != 'all')
|
||||
&& $is_append_limit_clause
|
||||
) {
|
||||
if (PMA_isAppendLimitClause($analyzed_sql_results)) {
|
||||
$sql_limit_to_append = ' LIMIT ' . $_SESSION['tmp_user_values']['pos']
|
||||
. ', ' . $_SESSION['tmp_user_values']['max_rows'] . " ";
|
||||
$full_sql_query = PMA_getSqlWithLimitClause(
|
||||
@ -506,13 +504,8 @@ if (isset($GLOBALS['show_as_php']) || ! empty($GLOBALS['validatequery'])) {
|
||||
|
||||
// However, do not count again if we did it previously
|
||||
// due to $find_real_end == true
|
||||
if (! $is_group
|
||||
&& ! isset($analyzed_sql[0]['queryflags']['union'])
|
||||
&& ! isset($analyzed_sql[0]['queryflags']['distinct'])
|
||||
&& ! isset($analyzed_sql[0]['table_ref'][1]['table_name'])
|
||||
&& (empty($analyzed_sql[0]['where_clause'])
|
||||
|| $analyzed_sql[0]['where_clause'] == '1 ')
|
||||
&& ! isset($find_real_end)
|
||||
if (PMA_isJustBrowsing(
|
||||
$analyzed_sql_results,isset($find_real_end) ? $find_real_end : null)
|
||||
) {
|
||||
// "j u s t b r o w s i n g"
|
||||
$justBrowsing = true;
|
||||
@ -616,10 +609,7 @@ if (isset($GLOBALS['show_as_php']) || ! empty($GLOBALS['validatequery'])) {
|
||||
// No rows returned -> move back to the calling page
|
||||
if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) {
|
||||
// Delete related tranformation information
|
||||
if (!empty($analyzed_sql[0]['querytype'])
|
||||
&& (($analyzed_sql[0]['querytype'] == 'ALTER')
|
||||
|| ($analyzed_sql[0]['querytype'] == 'DROP'))
|
||||
) {
|
||||
if (PMA_isDeleteTransformationInfo($analyzed_sql_results)) {
|
||||
include_once 'libraries/transformations.lib.php';
|
||||
if ($analyzed_sql[0]['querytype'] == 'ALTER') {
|
||||
if (stripos($analyzed_sql[0]['unsorted_query'], 'DROP') !== false) {
|
||||
@ -1004,7 +994,9 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) {
|
||||
$bkm_sql_query = urlencode(
|
||||
isset($complete_query) ? $complete_query : $sql_query
|
||||
);
|
||||
$html_output .= PMA_getHtmlForBookmark($db, $goto, $bkm_sql_query, $cfg['Bookmark']['user']);
|
||||
$html_output .= PMA_getHtmlForBookmark(
|
||||
$db, $goto, $bkm_sql_query, $cfg['Bookmark']['user']
|
||||
);
|
||||
} // end bookmark support
|
||||
|
||||
// Do print the page if required
|
||||
@ -1018,9 +1010,7 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) {
|
||||
|
||||
$_SESSION['is_multi_query'] = false;
|
||||
|
||||
/**
|
||||
* Displays the footer
|
||||
*/
|
||||
|
||||
if (! isset($_REQUEST['table_maintenance'])) {
|
||||
exit;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user