Ejemplo n.º 1
0
/**
 * Generate table html when SQL statement have multiple queries
 * which return displayable results
 *
 * @param object $displayResultsObject PMA_DisplayResults object
 * @param string $db                   database name
 * @param array  $sql_data             information about SQL statement
 * @param string $goto                 URL to go back in case of errors
 * @param string $pmaThemeImage        path for theme images  directory
 * @param string $printview            whether printview is enabled
 * @param string $url_query            URL query
 * @param array  $disp_mode            the display mode
 * @param string $sql_limit_to_append  limit clause
 * @param bool   $editable             whether editable or not
 *
 * @return string   $table_html   html content
 */
function PMA_getTableHtmlForMultipleQueries($displayResultsObject, $db, $sql_data, $goto, $pmaThemeImage, $printview, $url_query, $disp_mode, $sql_limit_to_append, $editable)
{
    $table_html = '';
    $tables_array = $GLOBALS['dbi']->getTables($db);
    $databases_array = $GLOBALS['dbi']->getDatabasesFull();
    $multi_sql = implode(";", $sql_data['valid_sql']);
    $querytime_before = array_sum(explode(' ', microtime()));
    // Assignment for variable is not needed since the results are
    // looping using the connection
    @$GLOBALS['dbi']->tryMultiQuery($multi_sql);
    $querytime_after = array_sum(explode(' ', microtime()));
    $querytime = $querytime_after - $querytime_before;
    $sql_no = 0;
    do {
        $analyzed_sql = array();
        $is_affected = false;
        $showtable = array();
        $result = $GLOBALS['dbi']->storeResult();
        $fields_meta = $result !== false ? $GLOBALS['dbi']->getFieldsMeta($result) : array();
        $fields_cnt = count($fields_meta);
        // Initialize needed params related to each query in multiquery statement
        if (isset($sql_data['valid_sql'][$sql_no])) {
            // 'Use' query can change the database
            if (mb_stripos($sql_data['valid_sql'][$sql_no], "use ")) {
                $db = PMA_getNewDatabase($sql_data['valid_sql'][$sql_no], $databases_array);
            }
            $table = PMA_getTableNameBySQL($sql_data['valid_sql'][$sql_no], $tables_array);
            // for the use of the parse_analyze.inc.php
            $sql_query = $sql_data['valid_sql'][$sql_no];
            // Parse and analyze the query
            include 'libraries/parse_analyze.inc.php';
            $unlim_num_rows = PMA_Table::countRecords($db, $table, true);
            $showtable = PMA_Table::sGetStatusInfo($db, $table, null, true);
            $url_query = PMA_URL_getCommon(array('db' => $db, 'table' => $table));
            // Handle remembered sorting order, only for single table query
            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) {
                PMA_handleSortOrder($db, $table, $analyzed_sql, $sql_data['valid_sql'][$sql_no]);
            }
            // Do append a "LIMIT" clause?
            if ($_SESSION['tmpval']['max_rows'] != 'all' && !($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'])) {
                $sql_limit_to_append = ' LIMIT ' . $_SESSION['tmpval']['pos'] . ', ' . $_SESSION['tmpval']['max_rows'] . " ";
                $sql_data['valid_sql'][$sql_no] = PMA_getSqlWithLimitClause($analyzed_sql, $sql_limit_to_append);
            }
            // Set the needed properties related to executing sql query
            $displayResultsObject->__set('db', $db);
            $displayResultsObject->__set('table', $table);
            $displayResultsObject->__set('goto', $goto);
        }
        if (!$is_affected) {
            $num_rows = $result ? @$GLOBALS['dbi']->numRows($result) : 0;
        } elseif (!isset($num_rows)) {
            $num_rows = @$GLOBALS['dbi']->affectedRows();
        }
        if (isset($sql_data['valid_sql'][$sql_no])) {
            $displayResultsObject->__set('sql_query', $sql_data['valid_sql'][$sql_no]);
            $displayResultsObject->setProperties($unlim_num_rows, $fields_meta, $is_count, $is_export, $is_func, $is_analyse, $num_rows, $fields_cnt, $querytime, $pmaThemeImage, $GLOBALS['text_dir'], $is_maint, $is_explain, $is_show, $showtable, $printview, $url_query, $editable);
        }
        if ($num_rows == 0) {
            continue;
        }
        // With multiple results, operations are limited
        $disp_mode = 'nnnn000000';
        $is_limited_display = true;
        // Collect the tables
        $table_html .= $displayResultsObject->getTable($result, $disp_mode, $analyzed_sql, $is_limited_display);
        // Free the result to save the memory
        $GLOBALS['dbi']->freeResult($result);
        $sql_no++;
    } while ($GLOBALS['dbi']->moreResults() && $GLOBALS['dbi']->nextResult());
    return $table_html;
}
Ejemplo n.º 2
0
/**
 * Generate table html when SQL statement have multiple queries
 * which return displayable results
 *
 * @param PMA_DisplayResults $displayResultsObject object
 * @param string             $db                   database name
 * @param array              $sql_data             information about SQL statement
 * @param string             $goto                 the URL to go back in case of errors
 * @param string             $pmaThemeImage        path for theme images directory
 * @param string             $text_dir             
 * @param string             $printview            
 * @param string             $url_query            URL query
 * @param array              $disp_mode            the display mode
 *
 * @return string   $table_html   html content
 */
function getTableHtmlForMultipleQueries(
    $displayResultsObject, $db, $sql_data, $goto, $pmaThemeImage,
    $text_dir, $printview, $url_query, $disp_mode, $sql_limit_to_append
) {
    
    $table_html = '';
        
    $tables_array = PMA_DBI_get_tables($db);
    $databases_array = PMA_DBI_get_databases_full();
    $multi_sql = implode(";", $sql_data['valid_sql']);    
    $querytime_before = array_sum(explode(' ', microtime()));

    // Assignment for variable is not needed since the results are
    // looiping using the connection
    @PMA_DBI_try_multi_query($multi_sql);

    $querytime_after = array_sum(explode(' ', microtime()));
    $querytime = $querytime_after - $querytime_before;        
    $sql_no = 0;

    do {

        $analyzed_sql = array();
        $is_affected = false;
        
        $result = PMA_DBI_store_result();
        $fields_meta = ($result !== false) ? PMA_DBI_get_fields_meta($result) : array();
        $fields_cnt  = count($fields_meta);
        
        // Initialize needed params related to each query in multiquery statement
        if (isset($sql_data['valid_sql'][$sql_no])) {
            
            // 'Use' query can change the database
            if (stripos($sql_data['valid_sql'][$sql_no], "use ")) {
                $db = PMA_getNewDatabase($sql_data['valid_sql'][$sql_no], $databases_array);
            }
            $parsed_sql = PMA_SQP_parse($sql_data['valid_sql'][$sql_no]);
            $table = PMA_getTableNameBySQL($sql_data['valid_sql'][$sql_no], $tables_array);            
            
            $analyzed_sql = PMA_SQP_analyze($parsed_sql);
            $is_select = isset($analyzed_sql[0]['queryflags']['select_from']);        
            $unlim_num_rows = PMA_Table::countRecords($db, $table, $force_exact = true);
            $showtable = PMA_Table::sGetStatusInfo($db, $table, null, true);
            $url_query = PMA_generate_common_url($db, $table);
            
            list($is_group, $is_func, $is_count, $is_export, $is_analyse,
                $is_explain, $is_delete, $is_affected, $is_insert, $is_replace,
                $is_show, $is_maint)
                    = PMA_getDisplayPropertyParams(
                        $sql_data['valid_sql'][$sql_no], $is_select
                    );
            
            // Handle remembered sorting order, only for single table query
            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
            ) {
                PMA_handleSortOrder($db, $table, $analyzed_sql, $sql_data['valid_sql'][$sql_no]);
            }

            // Do append a "LIMIT" clause?
            if (($_SESSION['tmp_user_values']['max_rows'] != 'all')
                && ! ($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'])
            ) {            
                $sql_data['valid_sql'][$sql_no] = PMA_getSqlWithLimitClause(
                    $sql_data['valid_sql'][$sql_no], $analyzed_sql, $sql_limit_to_append
                );            
            }
            
            // Set the needed properties related to executing sql query
            $displayResultsObject->__set('_db', $db);
            $displayResultsObject->__set('_table', $table);
            $displayResultsObject->__set('_goto', $goto);
            
        }
        
        if (! $is_affected) {
            $num_rows = ($result) ? @PMA_DBI_num_rows($result) : 0;
        } elseif (! isset($num_rows)) {
            $num_rows = @PMA_DBI_affected_rows();
        }

        if (isset($sql_data['valid_sql'][$sql_no])) {
            
            $displayResultsObject->__set('_sql_query', $sql_data['valid_sql'][$sql_no]);
            $displayResultsObject->setProperties(
                $unlim_num_rows, $fields_meta, $is_count, $is_export, $is_func,
                $is_analyse, $num_rows, $fields_cnt, $querytime, $pmaThemeImage, $text_dir,
                $is_maint, $is_explain, $is_show, $showtable, $printview, $url_query
            );
            
        }

        if ($num_rows == 0) {
            continue;
        }

        // With multiple results, operations are limied
        $disp_mode = 'nnnn000000';
        $is_limited_display = true;

        // Collect the tables
        $table_html .= $displayResultsObject->getTable(
            $result, $disp_mode, $analyzed_sql, $is_limited_display
        );

        // Free the result to save the memory
        PMA_DBI_free_result($result);
        
        $sql_no++;
        
    } while (PMA_DBI_more_results() && PMA_DBI_next_result());

    return $table_html;
    
}