/**
  * Test PMA_isRememberSortingOrder
  *
  * @return void
  */
 public function testIsRememberSortingOrder()
 {
     // Test environment.
     $GLOBALS['cfg']['RememberSorting'] = true;
     $GLOBALS['db'] = 'db';
     $this->assertTrue(PMA_isRememberSortingOrder(PMA_parseAndAnalyze('SELECT * FROM tbl')));
     $this->assertFalse(PMA_isRememberSortingOrder(PMA_parseAndAnalyze('SELECT col FROM tbl')));
     $this->assertFalse(PMA_isRememberSortingOrder(PMA_parseAndAnalyze('SELECT 1')));
     $this->assertFalse(PMA_isRememberSortingOrder(PMA_parseAndAnalyze('SELECT col1, col2 FROM tbl')));
     $this->assertFalse(PMA_isRememberSortingOrder(PMA_parseAndAnalyze('SELECT COUNT(*) from tbl')));
 }
Пример #2
0
/**
 * Function to execute the query and send the response
 *
 * @param array      $analyzed_sql_results   analysed sql results
 * @param bool       $is_gotofile            whether goto file or not
 * @param string     $db                     current database
 * @param string     $table                  current table
 * @param bool|null  $find_real_end          whether to find real end or not
 * @param string     $sql_query_for_bookmark the sql query to be stored as bookmark
 * @param array|null $extra_data             extra data
 * @param bool       $is_affected            whether affected or not
 * @param string     $message_to_show        message to show
 * @param string     $disp_mode              display mode
 * @param string     $message                message
 * @param array|null $sql_data               sql data
 * @param string     $goto                   goto page url
 * @param string     $pmaThemeImage          uri of the PMA theme image
 * @param string     $disp_query             display query
 * @param string     $disp_message           display message
 * @param string     $query_type             query type
 * @param string     $sql_query              sql query
 * @param array      $selectedTables         array of table names selected from the
 *                                           database structure page, for an action
 *                                           like check table, optimize table,
 *                                           analyze table or repair table
 * @param string     $complete_query         complete query
 *
 * @return void
 */
function PMA_executeQueryAndSendQueryResponse($analyzed_sql_results, $is_gotofile, $db, $table, $find_real_end, $sql_query_for_bookmark, $extra_data, $is_affected, $message_to_show, $disp_mode, $message, $sql_data, $goto, $pmaThemeImage, $disp_query, $disp_message, $query_type, $sql_query, $selectedTables, $complete_query)
{
    // Include PMA_Index class for use in PMA_DisplayResults class
    include_once './libraries/Index.class.php';
    include 'libraries/DisplayResults.class.php';
    // Handle remembered sorting order, only for single table query
    // Handling is not required when it's a union query
    // (the parser never sets the 'union' key to 0)
    if (PMA_isRememberSortingOrder($analyzed_sql_results) && !isset($analyzed_sql_results['analyzed_sql'][0]['queryflags']['union'])) {
        PMA_handleSortOrder($db, $table, $analyzed_sql_results, $sql_query);
    }
    $displayResultsObject = new PMA_DisplayResults($GLOBALS['db'], $GLOBALS['table'], $GLOBALS['goto'], $sql_query);
    $displayResultsObject->setConfigParamsForDisplayTable();
    // assign default full_sql_query
    $full_sql_query = $sql_query;
    // Do append a "LIMIT" clause?
    if (PMA_isAppendLimitClause($analyzed_sql_results)) {
        list($sql_limit_to_append, $full_sql_query) = PMA_appendLimitClause($analyzed_sql_results['analyzed_sql']);
    } else {
        $sql_limit_to_append = '';
    }
    $GLOBALS['reload'] = PMA_hasCurrentDbChanged($db);
    $GLOBALS['dbi']->selectDb($db);
    // Execute the query
    list($result, $num_rows, $unlim_num_rows, $profiling_results, $extra_data) = PMA_executeTheQuery($analyzed_sql_results, $full_sql_query, $is_gotofile, $db, $table, isset($find_real_end) ? $find_real_end : null, isset($sql_query_for_bookmark) ? $sql_query_for_bookmark : null, isset($extra_data) ? $extra_data : null);
    PMA_sendQueryResponse($num_rows, $unlim_num_rows, $is_affected, $db, $table, isset($message_to_show) ? $message_to_show : null, $analyzed_sql_results, $displayResultsObject, $extra_data, isset($result) ? $result : null, isset($disp_mode) ? $disp_mode : null, isset($message) ? $message : null, isset($sql_data) ? $sql_data : null, $goto, $pmaThemeImage, $sql_limit_to_append, $full_sql_query, isset($disp_query) ? $disp_query : null, isset($disp_message) ? $disp_message : null, $profiling_results, isset($query_type) ? $query_type : null, isset($selectedTables) ? $selectedTables : null, $sql_query, isset($complete_query) ? $complete_query : null);
}
Пример #3
0
/**
 * Function to execute the query and send the response
 *
 * @param array      $analyzed_sql_results   analysed sql results
 * @param bool       $is_gotofile            whether goto file or not
 * @param string     $db                     current database
 * @param string     $table                  current table
 * @param bool|null  $find_real_end          whether to find real end or not
 * @param string     $sql_query_for_bookmark the sql query to be stored as bookmark
 * @param array|null $extra_data             extra data
 * @param string     $message_to_show        message to show
 * @param string     $message                message
 * @param array|null $sql_data               sql data
 * @param string     $goto                   goto page url
 * @param string     $pmaThemeImage          uri of the PMA theme image
 * @param string     $disp_query             display query
 * @param string     $disp_message           display message
 * @param string     $query_type             query type
 * @param string     $sql_query              sql query
 * @param array|null $selectedTables         array of table names selected from the
 *                                           database structure page, for an action
 *                                           like check table, optimize table,
 *                                           analyze table or repair table
 * @param string     $complete_query         complete query
 *
 * @return string html
 */
function PMA_executeQueryAndGetQueryResponse($analyzed_sql_results, $is_gotofile, $db, $table, $find_real_end, $sql_query_for_bookmark, $extra_data, $message_to_show, $message, $sql_data, $goto, $pmaThemeImage, $disp_query, $disp_message, $query_type, $sql_query, $selectedTables, $complete_query)
{
    // Handle disable/enable foreign key checks
    $default_fk_check = PMA\libraries\Util::handleDisableFKCheckInit();
    // Handle remembered sorting order, only for single table query.
    // Handling is not required when it's a union query
    // (the parser never sets the 'union' key to 0).
    // Handling is also not required if we came from the "Sort by key"
    // drop-down.
    if (PMA_isRememberSortingOrder($analyzed_sql_results) && empty($analyzed_sql_results['union']) && !isset($_REQUEST['sort_by_key'])) {
        if (!isset($_SESSION['sql_from_query_box'])) {
            PMA_handleSortOrder($db, $table, $analyzed_sql_results, $sql_query);
        } else {
            unset($_SESSION['sql_from_query_box']);
        }
    }
    $displayResultsObject = new PMA\libraries\DisplayResults($GLOBALS['db'], $GLOBALS['table'], $goto, $sql_query);
    $displayResultsObject->setConfigParamsForDisplayTable();
    // assign default full_sql_query
    $full_sql_query = $sql_query;
    // Do append a "LIMIT" clause?
    if (PMA_isAppendLimitClause($analyzed_sql_results)) {
        $full_sql_query = PMA_getSqlWithLimitClause($analyzed_sql_results);
    }
    $GLOBALS['reload'] = PMA_hasCurrentDbChanged($db);
    $GLOBALS['dbi']->selectDb($db);
    // Execute the query
    list($result, $num_rows, $unlim_num_rows, $profiling_results, $extra_data) = PMA_executeTheQuery($analyzed_sql_results, $full_sql_query, $is_gotofile, $db, $table, isset($find_real_end) ? $find_real_end : null, isset($sql_query_for_bookmark) ? $sql_query_for_bookmark : null, isset($extra_data) ? $extra_data : null);
    // No rows returned -> move back to the calling page
    if (0 == $num_rows && 0 == $unlim_num_rows || $analyzed_sql_results['is_affected']) {
        $html_output = PMA_getQueryResponseForNoResultsReturned($analyzed_sql_results, $db, $table, isset($message_to_show) ? $message_to_show : null, $num_rows, $displayResultsObject, $extra_data, $pmaThemeImage, isset($result) ? $result : null, $sql_query, isset($complete_query) ? $complete_query : null);
    } else {
        // At least one row is returned -> displays a table with results
        $html_output = PMA_getQueryResponseForResultsReturned(isset($result) ? $result : null, $analyzed_sql_results, $db, $table, isset($message) ? $message : null, isset($sql_data) ? $sql_data : null, $displayResultsObject, $pmaThemeImage, $unlim_num_rows, $num_rows, isset($disp_query) ? $disp_query : null, isset($disp_message) ? $disp_message : null, $profiling_results, isset($query_type) ? $query_type : null, isset($selectedTables) ? $selectedTables : null, $sql_query, isset($complete_query) ? $complete_query : null);
    }
    // Handle disable/enable foreign key checks
    PMA\libraries\Util::handleDisableFKCheckCleanup($default_fk_check);
    return $html_output;
}
Пример #4
0
/**
 * Function to execute the query and send the response
 *
 * @param array      $analyzed_sql_results   analysed sql results
 * @param bool       $is_gotofile            whether goto file or not
 * @param string     $db                     current database
 * @param string     $table                  current table
 * @param bool|null  $find_real_end          whether to find real end or not
 * @param string     $sql_query_for_bookmark the sql query to be stored as bookmark
 * @param array|null $extra_data             extra data
 * @param bool       $is_affected            whether affected or not
 * @param string     $message_to_show        message to show
 * @param string     $message                message
 * @param array|null $sql_data               sql data
 * @param string     $goto                   goto page url
 * @param string     $pmaThemeImage          uri of the PMA theme image
 * @param string     $disp_query             display query
 * @param string     $disp_message           display message
 * @param string     $query_type             query type
 * @param string     $sql_query              sql query
 * @param array      $selectedTables         array of table names selected from the
 *                                           database structure page, for an action
 *                                           like check table, optimize table,
 *                                           analyze table or repair table
 * @param string     $complete_query         complete query
 *
 * @return string html
 */
function PMA_executeQueryAndGetQueryResponse($analyzed_sql_results, $is_gotofile, $db, $table, $find_real_end, $sql_query_for_bookmark, $extra_data, $is_affected, $message_to_show, $message, $sql_data, $goto, $pmaThemeImage, $disp_query, $disp_message, $query_type, $sql_query, $selectedTables, $complete_query)
{
    // Include PMA_Index class for use in PMA_DisplayResults class
    include_once './libraries/Index.class.php';
    include_once 'libraries/DisplayResults.class.php';
    // Handle remembered sorting order, only for single table query
    // Handling is not required when it's a union query
    // (the parser never sets the 'union' key to 0)
    if (PMA_isRememberSortingOrder($analyzed_sql_results) && !isset($analyzed_sql_results['analyzed_sql'][0]['queryflags']['union'])) {
        if (!isset($_SESSION['sql_from_query_box'])) {
            PMA_handleSortOrder($db, $table, $analyzed_sql_results, $sql_query);
        } else {
            unset($_SESSION['sql_from_query_box']);
        }
    }
    $displayResultsObject = new PMA_DisplayResults($GLOBALS['db'], $GLOBALS['table'], $GLOBALS['goto'], $sql_query);
    $displayResultsObject->setConfigParamsForDisplayTable();
    // assign default full_sql_query
    $full_sql_query = $sql_query;
    // Do append a "LIMIT" clause?
    if (PMA_isAppendLimitClause($analyzed_sql_results)) {
        $full_sql_query = PMA_getSqlWithLimitClause($analyzed_sql_results['analyzed_sql'], ' LIMIT ' . $_SESSION['tmpval']['pos'] . ', ' . $_SESSION['tmpval']['max_rows'] . " ");
    }
    $GLOBALS['reload'] = PMA_hasCurrentDbChanged($db);
    $GLOBALS['dbi']->selectDb($db);
    // Execute the query
    list($result, $num_rows, $unlim_num_rows, $profiling_results, $extra_data) = PMA_executeTheQuery($analyzed_sql_results, $full_sql_query, $is_gotofile, $db, $table, isset($find_real_end) ? $find_real_end : null, isset($sql_query_for_bookmark) ? $sql_query_for_bookmark : null, isset($extra_data) ? $extra_data : null);
    // No rows returned -> move back to the calling page
    if (0 == $num_rows && 0 == $unlim_num_rows || $is_affected) {
        $html_output = PMA_getQueryResponseForNoResultsReturned($analyzed_sql_results, $db, $table, isset($message_to_show) ? $message_to_show : null, $num_rows, $displayResultsObject, $extra_data);
    } else {
        // At least one row is returned -> displays a table with results
        $html_output = PMA_getQueryResponseForResultsReturned(isset($result) ? $result : null, $analyzed_sql_results, $db, $table, isset($message) ? $message : null, isset($sql_data) ? $sql_data : null, $displayResultsObject, $pmaThemeImage, $unlim_num_rows, $num_rows, $full_sql_query, isset($disp_query) ? $disp_query : null, isset($disp_message) ? $disp_message : null, $profiling_results, isset($query_type) ? $query_type : null, isset($selectedTables) ? $selectedTables : null, $sql_query, isset($complete_query) ? $complete_query : null);
    }
    return $html_output;
}