Exemplo n.º 1
0
function PMA_transformation_text_plain__sql($buffer, $options = array(), $meta = '')
{
    $result = PMA_SQP_formatHtml(PMA_SQP_parse($buffer));
    // Need to clear error state not to break subsequent queries display.
    PMA_SQP_resetError();
    return $result;
}
Exemplo n.º 2
0
 /**
  * Testing of SQL parser.
  *
  * @param string $sql      SQL query to parse
  * @param array  $expected Expected parse result
  * @param string $error    Expected error message
  *
  * @return void
  *
  * @dataProvider parserData
  * @group medium
  */
 public function testParser($sql, $expected, $error = '')
 {
     PMA_SQP_resetError();
     $parsed_sql = PMA_SQP_parse($sql);
     $this->assertEquals($error, PMA_SQP_getErrorString());
     $this->assertEquals($expected, $parsed_sql);
 }
Exemplo n.º 3
0
function executeQuery($queryOrQueryAndParams)
{
    global $trackDbSpeed, $traceSqlQueries, $sqlQueryDump, $dbPrefix, $dbClasses;
    if (is_array($queryOrQueryAndParams)) {
        $query = array_shift($queryOrQueryAndParams);
        $args = $queryOrQueryAndParams;
    } else {
        $query = $queryOrQueryAndParams;
        $args = func_get_args();
        if (count($args) > 1) {
            array_shift($args);
        } else {
            $args = array();
        }
    }
    $query = preg_replace("/@(" . implode("|", $dbClasses) . ")/", "{$dbPrefix}\$1", $query);
    if (count($args)) {
        $query = preg_replace(array("/'%/", "/%'/"), array("'%%", "%%'"), $query);
        $query = preg_replace(array("/#[^#]+#/", "/`[^`]+`/"), array("'%s'", "`%s`"), $query);
        $query = vsprintf($query, array_map("quoteSQL", $args));
    }
    if (isset($trackDbSpeed) && $trackDbSpeed) {
        $result = speedTrackExecuteQuery($query);
    } else {
        $result = mysql_query($query);
    }
    if ($result == 0) {
        handleErrorSql($query);
    }
    if ($traceSqlQueries) {
        require_once GORUM_DIR . "/sqlparser.php";
        $parsed_sql = PMA_SQP_parse($query);
        $sqlQueryDump .= PMA_SQP_formatHtml($parsed_sql);
        $sqlQueryDump .= "<br><br>";
    }
    return $result;
}
Exemplo n.º 4
0
/**
 * Displays HTML for changing one or more columns
 *
 * @param string $db       database name
 * @param string $table    table name
 * @param array  $selected the selected columns
 * @param string $action   target script to call
 *
 * @return boolean $regenerate true if error occurred
 *
 */
function PMA_displayHtmlForColumnChange($db, $table, $selected, $action)
{
    // $selected comes from multi_submits.inc.php
    if (empty($selected)) {
        $selected[] = $_REQUEST['field'];
        $selected_cnt = 1;
    } else {
        // from a multiple submit
        $selected_cnt = count($selected);
    }
    /**
     * @todo optimize in case of multiple fields to modify
     */
    $fields_meta = array();
    for ($i = 0; $i < $selected_cnt; $i++) {
        $fields_meta[] = $GLOBALS['dbi']->getColumns($db, $table, $selected[$i], true);
    }
    $num_fields = count($fields_meta);
    // set these globals because tbl_columns_definition_form.inc.php
    // verifies them
    // @todo: refactor tbl_columns_definition_form.inc.php so that it uses
    // function params
    $GLOBALS['action'] = 'tbl_structure.php';
    $GLOBALS['num_fields'] = $num_fields;
    // Get more complete field information.
    // For now, this is done to obtain MySQL 4.1.2+ new TIMESTAMP options
    // and to know when there is an empty DEFAULT value.
    // Later, if the analyser returns more information, it
    // could be executed to replace the info given by SHOW FULL COLUMNS FROM.
    /**
     * @todo put this code into a require()
     * or maybe make it part of $GLOBALS['dbi']->getColumns();
     */
    // We also need this to correctly learn if a TIMESTAMP is NOT NULL, since
    // SHOW FULL COLUMNS says NULL and SHOW CREATE TABLE says NOT NULL (tested
    // in MySQL 4.0.25).
    $show_create_table = $GLOBALS['dbi']->fetchValue('SHOW CREATE TABLE ' . PMA_Util::backquote($db) . '.' . PMA_Util::backquote($table), 0, 1);
    $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
    unset($show_create_table);
    /**
     * Form for changing properties.
     */
    include 'libraries/tbl_columns_definition_form.inc.php';
}
Exemplo n.º 5
0
        . ', ' . $_SESSION['tmp_user_values']['max_rows'] . " ";

    $full_sql_query  = $analyzed_sql[0]['section_before_limit'] . "\n"
        . $sql_limit_to_append . $analyzed_sql[0]['section_after_limit'];
    /**
     * @todo pretty printing of this modified query
     */
    if (isset($display_query)) {
        // if the analysis of the original query revealed that we found
        // a section_after_limit, we now have to analyze $display_query
        // to display it correctly

        if (! empty($analyzed_sql[0]['section_after_limit'])
            && trim($analyzed_sql[0]['section_after_limit']) != ';'
        ) {
            $analyzed_display_query = PMA_SQP_analyze(PMA_SQP_parse($display_query));
            $display_query  = $analyzed_display_query[0]['section_before_limit']
                . "\n" . $sql_limit_to_append . $analyzed_display_query[0]['section_after_limit'];
        }
    }

}

if (strlen($db)) {
    PMA_DBI_select_db($db);
}

//  E x e c u t e    t h e    q u e r y

// Only if we didn't ask to see the php code (mikebeck)
if (isset($GLOBALS['show_as_php']) || ! empty($GLOBALS['validatequery'])) {
Exemplo n.º 6
0
/**
 * displays the message and the query
 * usually the message is the result of the query executed
 *
 * @param   string  $message    the message to display
 * @param   string  $sql_query  the query to display
 * @global  array   the configuration array
 * @uses    $cfg
 * @access  public
 */
function PMA_showMessage($message, $sql_query = null)
{
    global $cfg;
    $query_too_big = false;
    if (null === $sql_query) {
        if (!empty($GLOBALS['display_query'])) {
            $sql_query = $GLOBALS['display_query'];
        } elseif ($cfg['SQP']['fmtType'] == 'none' && !empty($GLOBALS['unparsed_sql'])) {
            $sql_query = $GLOBALS['unparsed_sql'];
        } elseif (!empty($GLOBALS['sql_query'])) {
            $sql_query = $GLOBALS['sql_query'];
        } else {
            $sql_query = '';
        }
    }
    // Corrects the tooltip text via JS if required
    // @todo this is REALLY the wrong place to do this - very unexpected here
    if (strlen($GLOBALS['table']) && $cfg['ShowTooltip']) {
        $result = PMA_DBI_try_query('SHOW TABLE STATUS FROM ' . PMA_backquote($GLOBALS['db']) . ' LIKE \'' . PMA_sqlAddslashes($GLOBALS['table'], true) . '\'');
        if ($result) {
            $tbl_status = PMA_DBI_fetch_assoc($result);
            $tooltip = empty($tbl_status['Comment']) ? '' : $tbl_status['Comment'] . ' ';
            $tooltip .= '(' . PMA_formatNumber($tbl_status['Rows'], 0) . ' ' . $GLOBALS['strRows'] . ')';
            PMA_DBI_free_result($result);
            $uni_tbl = PMA_jsFormat($GLOBALS['db'] . '.' . $GLOBALS['table'], false);
            echo "\n";
            echo '<script type="text/javascript">' . "\n";
            echo '//<![CDATA[' . "\n";
            echo "window.parent.updateTableTitle('" . $uni_tbl . "', '" . PMA_jsFormat($tooltip, false) . "');" . "\n";
            echo '//]]>' . "\n";
            echo '</script>' . "\n";
        }
        // end if
    }
    // end if ... elseif
    // Checks if the table needs to be repaired after a TRUNCATE query.
    // @todo what about $GLOBALS['display_query']???
    // @todo this is REALLY the wrong place to do this - very unexpected here
    if (strlen($GLOBALS['table']) && $GLOBALS['sql_query'] == 'TRUNCATE TABLE ' . PMA_backquote($GLOBALS['table'])) {
        if (!isset($tbl_status)) {
            $result = @PMA_DBI_try_query('SHOW TABLE STATUS FROM ' . PMA_backquote($GLOBALS['db']) . ' LIKE \'' . PMA_sqlAddslashes($GLOBALS['table'], true) . '\'');
            if ($result) {
                $tbl_status = PMA_DBI_fetch_assoc($result);
                PMA_DBI_free_result($result);
            }
        }
        if (isset($tbl_status) && (int) $tbl_status['Index_length'] > 1024) {
            PMA_DBI_try_query('REPAIR TABLE ' . PMA_backquote($GLOBALS['table']));
        }
    }
    unset($tbl_status);
    echo '<br />' . "\n";
    echo '<div align="' . $GLOBALS['cell_align_left'] . '">' . "\n";
    if (!empty($GLOBALS['show_error_header'])) {
        echo '<div class="error">' . "\n";
        echo '<h1>' . $GLOBALS['strError'] . '</h1>' . "\n";
    }
    echo '<div class="notice">';
    echo PMA_sanitize($message);
    if (isset($GLOBALS['special_message'])) {
        echo PMA_sanitize($GLOBALS['special_message']);
        unset($GLOBALS['special_message']);
    }
    echo '</div>';
    if (!empty($GLOBALS['show_error_header'])) {
        echo '</div>';
    }
    if ($cfg['ShowSQL'] == true && !empty($sql_query)) {
        // Basic url query part
        $url_qpart = '?' . PMA_generate_common_url($GLOBALS['db'], $GLOBALS['table']);
        // Html format the query to be displayed
        // The nl2br function isn't used because its result isn't a valid
        // xhtml1.0 statement before php4.0.5 ("<br>" and not "<br />")
        // If we want to show some sql code it is easiest to create it here
        /* SQL-Parser-Analyzer */
        if (!empty($GLOBALS['show_as_php'])) {
            $new_line = '\'<br />' . "\n" . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;. \' ';
        }
        if (isset($new_line)) {
            /* SQL-Parser-Analyzer */
            $query_base = PMA_sqlAddslashes(htmlspecialchars($sql_query), false, false, true);
            /* SQL-Parser-Analyzer */
            $query_base = preg_replace("@((\r\n)|(\r)|(\n))+@", $new_line, $query_base);
        } else {
            $query_base = $sql_query;
        }
        if (strlen($query_base) > $cfg['MaxCharactersInDisplayedSQL']) {
            $query_too_big = true;
            $query_base = nl2br(htmlspecialchars($sql_query));
            unset($GLOBALS['parsed_sql']);
        }
        // Parse SQL if needed
        // (here, use "! empty" because when deleting a bookmark,
        // $GLOBALS['parsed_sql'] is set but empty
        if (!empty($GLOBALS['parsed_sql']) && $query_base == $GLOBALS['parsed_sql']['raw']) {
            $parsed_sql = $GLOBALS['parsed_sql'];
        } else {
            // when the query is large (for example an INSERT of binary
            // data), the parser chokes; so avoid parsing the query
            if (!$query_too_big) {
                $parsed_sql = PMA_SQP_parse($query_base);
            }
        }
        // Analyze it
        if (isset($parsed_sql)) {
            $analyzed_display_query = PMA_SQP_analyze($parsed_sql);
        }
        // Here we append the LIMIT added for navigation, to
        // enable its display. Adding it higher in the code
        // to $sql_query would create a problem when
        // using the Refresh or Edit links.
        // Only append it on SELECTs.
        /**
         * @todo what would be the best to do when someone hits Refresh:
         * use the current LIMITs ?
         */
        if (isset($analyzed_display_query[0]['queryflags']['select_from']) && isset($GLOBALS['sql_limit_to_append'])) {
            $query_base = $analyzed_display_query[0]['section_before_limit'] . "\n" . $GLOBALS['sql_limit_to_append'] . $analyzed_display_query[0]['section_after_limit'];
            // Need to reparse query
            $parsed_sql = PMA_SQP_parse($query_base);
        }
        if (!empty($GLOBALS['show_as_php'])) {
            $query_base = '$sql  = \'' . $query_base;
        } elseif (!empty($GLOBALS['validatequery'])) {
            $query_base = PMA_validateSQL($query_base);
        } else {
            if (isset($parsed_sql)) {
                $query_base = PMA_formatSql($parsed_sql, $query_base);
            }
        }
        // Prepares links that may be displayed to edit/explain the query
        // (don't go to default pages, we must go to the page
        // where the query box is available)
        $edit_target = strlen($GLOBALS['db']) ? strlen($GLOBALS['table']) ? 'tbl_sql.php' : 'db_sql.php' : 'server_sql.php';
        if (isset($cfg['SQLQuery']['Edit']) && $cfg['SQLQuery']['Edit'] == true && !empty($edit_target) && !$query_too_big) {
            if ($cfg['EditInWindow'] == true) {
                $onclick = 'window.parent.focus_querywindow(\'' . PMA_jsFormat($sql_query, false) . '\'); return false;';
            } else {
                $onclick = '';
            }
            $edit_link = $edit_target . $url_qpart . '&amp;sql_query=' . urlencode($sql_query) . '&amp;show_query=1#querybox';
            $edit_link = ' [' . PMA_linkOrButton($edit_link, $GLOBALS['strEdit'], array('onclick' => $onclick)) . ']';
        } else {
            $edit_link = '';
        }
        // Want to have the query explained (Mike Beck 2002-05-22)
        // but only explain a SELECT (that has not been explained)
        /* SQL-Parser-Analyzer */
        if (isset($cfg['SQLQuery']['Explain']) && $cfg['SQLQuery']['Explain'] == true && !$query_too_big) {
            // Detect if we are validating as well
            // To preserve the validate uRL data
            if (!empty($GLOBALS['validatequery'])) {
                $explain_link_validate = '&amp;validatequery=1';
            } else {
                $explain_link_validate = '';
            }
            $explain_link = 'import.php' . $url_qpart . $explain_link_validate . '&amp;sql_query=';
            if (preg_match('@^SELECT[[:space:]]+@i', $sql_query)) {
                $explain_link .= urlencode('EXPLAIN ' . $sql_query);
                $message = $GLOBALS['strExplain'];
            } elseif (preg_match('@^EXPLAIN[[:space:]]+SELECT[[:space:]]+@i', $sql_query)) {
                $explain_link .= urlencode(substr($sql_query, 8));
                $message = $GLOBALS['strNoExplain'];
            } else {
                $explain_link = '';
            }
            if (!empty($explain_link)) {
                $explain_link = ' [' . PMA_linkOrButton($explain_link, $message) . ']';
            }
        } else {
            $explain_link = '';
        }
        //show explain
        // Also we would like to get the SQL formed in some nice
        // php-code (Mike Beck 2002-05-22)
        if (isset($cfg['SQLQuery']['ShowAsPHP']) && $cfg['SQLQuery']['ShowAsPHP'] == true && !$query_too_big) {
            $php_link = 'import.php' . $url_qpart . '&amp;show_query=1' . '&amp;sql_query=' . urlencode($sql_query) . '&amp;show_as_php=';
            if (!empty($GLOBALS['show_as_php'])) {
                $php_link .= '0';
                $message = $GLOBALS['strNoPhp'];
            } else {
                $php_link .= '1';
                $message = $GLOBALS['strPhp'];
            }
            $php_link = ' [' . PMA_linkOrButton($php_link, $message) . ']';
            if (isset($GLOBALS['show_as_php'])) {
                $runquery_link = 'import.php' . $url_qpart . '&amp;show_query=1' . '&amp;sql_query=' . urlencode($sql_query);
                $php_link .= ' [' . PMA_linkOrButton($runquery_link, $GLOBALS['strRunQuery']) . ']';
            }
        } else {
            $php_link = '';
        }
        //show as php
        // Refresh query
        if (isset($cfg['SQLQuery']['Refresh']) && $cfg['SQLQuery']['Refresh'] && preg_match('@^(SELECT|SHOW)[[:space:]]+@i', $sql_query)) {
            $refresh_link = 'import.php' . $url_qpart . '&amp;show_query=1' . '&amp;sql_query=' . urlencode($sql_query);
            $refresh_link = ' [' . PMA_linkOrButton($refresh_link, $GLOBALS['strRefresh']) . ']';
        } else {
            $refresh_link = '';
        }
        //show as php
        if (isset($cfg['SQLValidator']['use']) && $cfg['SQLValidator']['use'] == true && isset($cfg['SQLQuery']['Validate']) && $cfg['SQLQuery']['Validate'] == true) {
            $validate_link = 'import.php' . $url_qpart . '&amp;show_query=1' . '&amp;sql_query=' . urlencode($sql_query) . '&amp;validatequery=';
            if (!empty($GLOBALS['validatequery'])) {
                $validate_link .= '0';
                $validate_message = $GLOBALS['strNoValidateSQL'];
            } else {
                $validate_link .= '1';
                $validate_message = $GLOBALS['strValidateSQL'];
            }
            $validate_link = ' [' . PMA_linkOrButton($validate_link, $validate_message) . ']';
        } else {
            $validate_link = '';
        }
        //validator
        // why this?
        //unset($sql_query);
        // Displays the message
        echo '<fieldset class="">' . "\n";
        echo '    <legend>' . $GLOBALS['strSQLQuery'] . ':</legend>';
        echo '    <div>';
        // when uploading a 700 Kio binary file into a LONGBLOB,
        // I get a white page, strlen($query_base) is 2 x 700 Kio
        // so put a hard limit here (let's say 1000)
        if ($query_too_big) {
            echo '    ' . substr($query_base, 0, $cfg['MaxCharactersInDisplayedSQL']) . '[...]';
        } else {
            echo '    ' . $query_base;
        }
        //Clean up the end of the PHP
        if (!empty($GLOBALS['show_as_php'])) {
            echo '\';';
        }
        echo '    </div>';
        echo '</fieldset>' . "\n";
        if (!empty($edit_target)) {
            echo '<fieldset class="tblFooters">';
            // avoid displaying a Profiling checkbox that could
            // be checked, which would reexecute an INSERT, for example
            if (!empty($refresh_link)) {
                PMA_profilingCheckbox($sql_query);
            }
            echo $edit_link . $explain_link . $php_link . $refresh_link . $validate_link;
            echo '</fieldset>';
        }
    }
    echo '</div><br />' . "\n";
}
Exemplo n.º 7
0
 /**
  * Prepare the message and the query
  * usually the message is the result of the query executed
  *
  * @param string  $message   the message to display
  * @param string  $sql_query the query to display
  * @param string  $type      the type (level) of the message
  * @param boolean $is_view   is this a message after a VIEW operation?
  *
  * @return string
  *
  * @access  public
  */
 public static function getMessage($message, $sql_query = null, $type = 'notice', $is_view = false)
 {
     global $cfg;
     $retval = '';
     if (null === $sql_query) {
         if (!empty($GLOBALS['display_query'])) {
             $sql_query = $GLOBALS['display_query'];
         } elseif (!empty($GLOBALS['unparsed_sql'])) {
             $sql_query = $GLOBALS['unparsed_sql'];
         } elseif (!empty($GLOBALS['sql_query'])) {
             $sql_query = $GLOBALS['sql_query'];
         } else {
             $sql_query = '';
         }
     }
     if (isset($GLOBALS['using_bookmark_message'])) {
         $retval .= $GLOBALS['using_bookmark_message']->getDisplay();
         unset($GLOBALS['using_bookmark_message']);
     }
     // In an Ajax request, $GLOBALS['cell_align_left'] may not be defined. Hence,
     // check for it's presence before using it
     $retval .= '<div id="result_query"' . (isset($GLOBALS['cell_align_left']) ? ' style="text-align: ' . $GLOBALS['cell_align_left'] . '"' : '') . '>' . "\n";
     if ($message instanceof PMA_Message) {
         if (isset($GLOBALS['special_message'])) {
             $message->addMessage($GLOBALS['special_message']);
             unset($GLOBALS['special_message']);
         }
         $retval .= $message->getDisplay();
     } else {
         $retval .= '<div class="' . $type . '">';
         $retval .= PMA_sanitize($message);
         if (isset($GLOBALS['special_message'])) {
             $retval .= PMA_sanitize($GLOBALS['special_message']);
             unset($GLOBALS['special_message']);
         }
         $retval .= '</div>';
     }
     if ($cfg['ShowSQL'] == true && !empty($sql_query)) {
         // Html format the query to be displayed
         // If we want to show some sql code it is easiest to create it here
         /* SQL-Parser-Analyzer */
         if (!empty($GLOBALS['show_as_php'])) {
             $new_line = '\\n"<br />' . "\n" . '&nbsp;&nbsp;&nbsp;&nbsp;. "';
             $query_base = htmlspecialchars(addslashes($sql_query));
             $query_base = preg_replace('/((\\015\\012)|(\\015)|(\\012))/', $new_line, $query_base);
         } else {
             $query_base = $sql_query;
         }
         $query_too_big = false;
         if (strlen($query_base) > $cfg['MaxCharactersInDisplayedSQL']) {
             // when the query is large (for example an INSERT of binary
             // data), the parser chokes; so avoid parsing the query
             $query_too_big = true;
             $shortened_query_base = nl2br(htmlspecialchars(substr($sql_query, 0, $cfg['MaxCharactersInDisplayedSQL']) . '[...]'));
         } elseif (!empty($GLOBALS['parsed_sql']) && $query_base == $GLOBALS['parsed_sql']['raw']) {
             // (here, use "! empty" because when deleting a bookmark,
             // $GLOBALS['parsed_sql'] is set but empty
             $parsed_sql = $GLOBALS['parsed_sql'];
         } else {
             // Parse SQL if needed
             $parsed_sql = PMA_SQP_parse($query_base);
         }
         // Analyze it
         if (isset($parsed_sql) && !PMA_SQP_isError()) {
             $analyzed_display_query = PMA_SQP_analyze($parsed_sql);
             // Same as below (append LIMIT), append the remembered ORDER BY
             if ($GLOBALS['cfg']['RememberSorting'] && isset($analyzed_display_query[0]['queryflags']['select_from']) && isset($GLOBALS['sql_order_to_append'])) {
                 $query_base = $analyzed_display_query[0]['section_before_limit'] . "\n" . $GLOBALS['sql_order_to_append'] . $analyzed_display_query[0]['limit_clause'] . ' ' . $analyzed_display_query[0]['section_after_limit'];
                 // Need to reparse query
                 $parsed_sql = PMA_SQP_parse($query_base);
                 // update the $analyzed_display_query
                 $analyzed_display_query[0]['section_before_limit'] .= $GLOBALS['sql_order_to_append'];
                 $analyzed_display_query[0]['order_by_clause'] = $GLOBALS['sorted_col'];
             }
             // Here we append the LIMIT added for navigation, to
             // enable its display. Adding it higher in the code
             // to $sql_query would create a problem when
             // using the Refresh or Edit links.
             // Only append it on SELECTs.
             /**
              * @todo what would be the best to do when someone hits Refresh:
              * use the current LIMITs ?
              */
             if (isset($analyzed_display_query[0]['queryflags']['select_from']) && !empty($GLOBALS['sql_limit_to_append'])) {
                 $query_base = $analyzed_display_query[0]['section_before_limit'] . "\n" . $GLOBALS['sql_limit_to_append'] . $analyzed_display_query[0]['section_after_limit'];
                 // Need to reparse query
                 $parsed_sql = PMA_SQP_parse($query_base);
             }
         }
         if (!empty($GLOBALS['show_as_php'])) {
             $query_base = '$sql  = "' . $query_base;
         } elseif (isset($query_base)) {
             $query_base = self::formatSql($query_base);
         }
         // Prepares links that may be displayed to edit/explain the query
         // (don't go to default pages, we must go to the page
         // where the query box is available)
         // Basic url query part
         $url_params = array();
         if (!isset($GLOBALS['db'])) {
             $GLOBALS['db'] = '';
         }
         if (strlen($GLOBALS['db'])) {
             $url_params['db'] = $GLOBALS['db'];
             if (strlen($GLOBALS['table'])) {
                 $url_params['table'] = $GLOBALS['table'];
                 $edit_link = 'tbl_sql.php';
             } else {
                 $edit_link = 'db_sql.php';
             }
         } else {
             $edit_link = 'server_sql.php';
         }
         // Want to have the query explained
         // but only explain a SELECT (that has not been explained)
         /* SQL-Parser-Analyzer */
         $explain_link = '';
         $is_select = preg_match('@^SELECT[[:space:]]+@i', $sql_query);
         if (!empty($cfg['SQLQuery']['Explain']) && !$query_too_big) {
             $explain_params = $url_params;
             if ($is_select) {
                 $explain_params['sql_query'] = 'EXPLAIN ' . $sql_query;
                 $_message = __('Explain SQL');
             } elseif (preg_match('@^EXPLAIN[[:space:]]+SELECT[[:space:]]+@i', $sql_query)) {
                 $explain_params['sql_query'] = substr($sql_query, 8);
                 $_message = __('Skip Explain SQL');
             }
             if (isset($explain_params['sql_query'])) {
                 $explain_link = 'import.php' . PMA_URL_getCommon($explain_params);
                 $explain_link = ' [' . self::linkOrButton($explain_link, $_message) . ']';
             }
         }
         //show explain
         $url_params['sql_query'] = $sql_query;
         $url_params['show_query'] = 1;
         // even if the query is big and was truncated, offer the chance
         // to edit it (unless it's enormous, see linkOrButton() )
         if (!empty($cfg['SQLQuery']['Edit'])) {
             if ($cfg['EditInWindow'] == true) {
                 $onclick = 'PMA_querywindow.focus(\'' . PMA_jsFormat($sql_query, false) . '\'); return false;';
             } else {
                 $onclick = '';
             }
             $edit_link .= PMA_URL_getCommon($url_params) . '#querybox';
             $edit_link = ' [' . self::linkOrButton($edit_link, __('Edit'), array('onclick' => $onclick, 'class' => 'disableAjax')) . ']';
         } else {
             $edit_link = '';
         }
         // Also we would like to get the SQL formed in some nice
         // php-code
         if (!empty($cfg['SQLQuery']['ShowAsPHP']) && !$query_too_big) {
             $php_params = $url_params;
             if (!empty($GLOBALS['show_as_php'])) {
                 $_message = __('Without PHP Code');
             } else {
                 $php_params['show_as_php'] = 1;
                 $_message = __('Create PHP Code');
             }
             $php_link = 'import.php' . PMA_URL_getCommon($php_params);
             $php_link = ' [' . self::linkOrButton($php_link, $_message) . ']';
             if (isset($GLOBALS['show_as_php'])) {
                 $runquery_link = 'import.php' . PMA_URL_getCommon($url_params);
                 $php_link .= ' [' . self::linkOrButton($runquery_link, __('Submit Query')) . ']';
             }
         } else {
             $php_link = '';
         }
         //show as php
         // Refresh query
         if (!empty($cfg['SQLQuery']['Refresh']) && !isset($GLOBALS['show_as_php']) && preg_match('@^(SELECT|SHOW)[[:space:]]+@i', $sql_query)) {
             $refresh_link = 'import.php' . PMA_URL_getCommon($url_params);
             $refresh_link = ' [' . self::linkOrButton($refresh_link, __('Refresh')) . ']';
         } else {
             $refresh_link = '';
         }
         //refresh
         $retval .= '<div class="sqlOuter">';
         if ($query_too_big) {
             $retval .= $shortened_query_base;
         } else {
             $retval .= $query_base;
         }
         //Clean up the end of the PHP
         if (!empty($GLOBALS['show_as_php'])) {
             $retval .= '";';
         }
         $retval .= '</div>';
         $retval .= '<div class="tools">';
         $retval .= '<form action="sql.php" method="post">';
         $retval .= PMA_URL_getHiddenInputs($GLOBALS['db'], $GLOBALS['table']);
         $retval .= '<input type="hidden" name="sql_query" value="' . htmlspecialchars($sql_query) . '" />';
         // avoid displaying a Profiling checkbox that could
         // be checked, which would reexecute an INSERT, for example
         if (!empty($refresh_link) && self::profilingSupported()) {
             $retval .= '<input type="hidden" name="profiling_form" value="1" />';
             $retval .= self::getCheckbox('profiling', __('Profiling'), isset($_SESSION['profiling']), true);
         }
         $retval .= '</form>';
         /**
          * TODO: Should we have $cfg['SQLQuery']['InlineEdit']?
          */
         if (!empty($cfg['SQLQuery']['Edit']) && !$query_too_big) {
             $inline_edit_link = ' [' . self::linkOrButton('#', _pgettext('Inline edit query', 'Inline'), array('class' => 'inline_edit_sql')) . ']';
         } else {
             $inline_edit_link = '';
         }
         $retval .= $inline_edit_link . $edit_link . $explain_link . $php_link . $refresh_link;
         $retval .= '</div>';
     }
     $retval .= '</div>';
     if ($GLOBALS['is_ajax_request'] === false) {
         $retval .= '<br class="clearfloat" />';
     }
     return $retval;
 }
Exemplo n.º 8
0
    /**
     * Displays a message at the top of the "main" (right) frame
     *
     * @param   string  the message to display
     *
     * @global  array   the configuration array
     *
     * @access  public
     */
    function PMA_showMessage($message)
    {
        global $cfg;
        // Sanitizes $message
        $message = PMA_sanitize($message);
        // Corrects the tooltip text via JS if required
        if (!empty($GLOBALS['table']) && $cfg['ShowTooltip']) {
            $result = PMA_DBI_try_query('SHOW TABLE STATUS FROM ' . PMA_backquote($GLOBALS['db']) . ' LIKE \'' . PMA_sqlAddslashes($GLOBALS['table'], TRUE) . '\'');
            if ($result) {
                $tbl_status = PMA_DBI_fetch_assoc($result);
                $tooltip = empty($tbl_status['Comment']) ? '' : $tbl_status['Comment'] . ' ';
                $tooltip .= '(' . $tbl_status['Rows'] . ' ' . $GLOBALS['strRows'] . ')';
                PMA_DBI_free_result($result);
                $md5_tbl = md5($GLOBALS['table']);
                echo "\n";
                ?>
<script type="text/javascript" language="javascript1.2">
<!--
if (typeof(document.getElementById) != 'undefined'
    && typeof(window.parent.frames['nav']) != 'undefined'
    && typeof(window.parent.frames['nav'].document) != 'undefined' && typeof(window.parent.frames['nav'].document) != 'unknown'
    && (window.parent.frames['nav'].document.getElementById('<?php 
                echo 'tbl_' . $md5_tbl;
                ?>
'))
    && typeof(window.parent.frames['nav'].document.getElementById('<?php 
                echo 'tbl_' . $md5_tbl;
                ?>
')) != 'undefined'
    && typeof(window.parent.frames['nav'].document.getElementById('<?php 
                echo 'tbl_' . $md5_tbl;
                ?>
').title) == 'string') {
    window.parent.frames['nav'].document.getElementById('<?php 
                echo 'tbl_' . $md5_tbl;
                ?>
').title = '<?php 
                echo PMA_jsFormat($tooltip, FALSE);
                ?>
';
}
//-->
</script>
                <?php 
            }
            // end if
        }
        // end if... else if
        // Checks if the table needs to be repaired after a TRUNCATE query.
        if (isset($GLOBALS['table']) && isset($GLOBALS['sql_query']) && $GLOBALS['sql_query'] == 'TRUNCATE TABLE ' . PMA_backquote($GLOBALS['table'])) {
            if (!isset($tbl_status)) {
                $result = @PMA_DBI_try_query('SHOW TABLE STATUS FROM ' . PMA_backquote($GLOBALS['db']) . ' LIKE \'' . PMA_sqlAddslashes($GLOBALS['table'], TRUE) . '\'');
                if ($result) {
                    $tbl_status = PMA_DBI_fetch_assoc($result);
                    PMA_DBI_free_result($result);
                }
            }
            if (isset($tbl_status) && (int) $tbl_status['Index_length'] > 1024) {
                PMA_DBI_try_query('REPAIR TABLE ' . PMA_backquote($GLOBALS['table']));
            }
        }
        unset($tbl_status);
        echo "\n";
        ?>
<br />
<div align="<?php 
        echo $GLOBALS['cell_align_left'];
        ?>
">
    <table border="<?php 
        echo $cfg['Border'];
        ?>
" cellpadding="5" cellspacing="1">
    <tr>
        <th<?php 
        echo $GLOBALS['theme'] != 'original' ? ' class="tblHeaders"' : ' bgcolor="' . $cfg['ThBgcolor'] . '"';
        ?>
>
            <b><?php 
        echo $message;
        ?>
</b>
        </th>
    </tr>
        <?php 
        if ($cfg['ShowSQL'] == TRUE && (!empty($GLOBALS['sql_query']) || !empty($GLOBALS['display_query']))) {
            $local_query = !empty($GLOBALS['display_query']) ? $GLOBALS['display_query'] : ($cfg['SQP']['fmtType'] == 'none' && isset($GLOBALS['unparsed_sql']) && $GLOBALS['unparsed_sql'] != '' ? $GLOBALS['unparsed_sql'] : $GLOBALS['sql_query']);
            // Basic url query part
            $url_qpart = '?' . PMA_generate_common_url(isset($GLOBALS['db']) ? $GLOBALS['db'] : '', isset($GLOBALS['table']) ? $GLOBALS['table'] : '');
            echo "\n";
            ?>
    <tr>
        <td bgcolor="<?php 
            echo $cfg['BgcolorOne'];
            ?>
">
            <?php 
            echo "\n";
            // Html format the query to be displayed
            // The nl2br function isn't used because its result isn't a valid
            // xhtml1.0 statement before php4.0.5 ("<br>" and not "<br />")
            // If we want to show some sql code it is easiest to create it here
            /* SQL-Parser-Analyzer */
            $sqlnr = 1;
            if (!empty($GLOBALS['show_as_php'])) {
                $new_line = '\'<br />' . "\n" . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;. \' ';
            }
            if (isset($new_line)) {
                /* SQL-Parser-Analyzer */
                $query_base = PMA_sqlAddslashes(htmlspecialchars($local_query));
                /* SQL-Parser-Analyzer */
                $query_base = preg_replace("@((\r\n)|(\r)|(\n))+@", $new_line, $query_base);
            } else {
                $query_base = $local_query;
            }
            // Here we append the LIMIT added for navigation, to
            // enable its display. Adding it higher in the code
            // to $local_query would create a problem when
            // using the Refresh or Edit links.
            // Only append it on SELECTs.
            // FIXME: what would be the best to do when someone
            // hits Refresh: use the current LIMITs ?
            // TODO: use the parser instead of preg_match()
            if (preg_match('@^SELECT[[:space:]]+@i', $query_base) && isset($GLOBALS['sql_limit_to_append'])) {
                $query_base .= $GLOBALS['sql_limit_to_append'];
            }
            if (!empty($GLOBALS['show_as_php'])) {
                $query_base = '$sql  = \'' . $query_base;
            } else {
                if (!empty($GLOBALS['validatequery'])) {
                    $query_base = PMA_validateSQL($query_base);
                } else {
                    // avoid reparsing query:
                    if (isset($GLOBALS['parsed_sql']) && $query_base == $GLOBALS['parsed_sql']['raw']) {
                        $parsed_sql = $GLOBALS['parsed_sql'];
                    } else {
                        $parsed_sql = PMA_SQP_parse($query_base);
                    }
                    $query_base = PMA_formatSql($parsed_sql, $query_base);
                }
            }
            // Prepares links that may be displayed to edit/explain the query
            // (don't go to default pages, we must go to the page
            // where the query box is available)
            // (also, I don't see why we should check the goto variable)
            //if (!isset($GLOBALS['goto'])) {
            //$edit_target = (isset($GLOBALS['table'])) ? $cfg['DefaultTabTable'] : $cfg['DefaultTabDatabase'];
            $edit_target = isset($GLOBALS['db']) ? isset($GLOBALS['table']) ? 'tbl_properties.php' : 'db_details.php' : '';
            //} else if ($GLOBALS['goto'] != 'main.php') {
            //    $edit_target = $GLOBALS['goto'];
            //} else {
            //    $edit_target = '';
            //}
            if (isset($cfg['SQLQuery']['Edit']) && $cfg['SQLQuery']['Edit'] == TRUE && !empty($edit_target)) {
                $onclick = '';
                if ($cfg['QueryFrameJS'] && $cfg['QueryFrame']) {
                    $onclick = 'onclick="focus_querywindow(\'' . urlencode($local_query) . '\'); return false;"';
                }
                $edit_link = '&nbsp;[<a href="' . $edit_target . $url_qpart . '&amp;sql_query=' . urlencode($local_query) . '&amp;show_query=1#querybox" ' . $onclick . '>' . $GLOBALS['strEdit'] . '</a>]';
            } else {
                $edit_link = '';
            }
            // Want to have the query explained (Mike Beck 2002-05-22)
            // but only explain a SELECT (that has not been explained)
            /* SQL-Parser-Analyzer */
            if (isset($cfg['SQLQuery']['Explain']) && $cfg['SQLQuery']['Explain'] == TRUE) {
                // Detect if we are validating as well
                // To preserve the validate uRL data
                if (!empty($GLOBALS['validatequery'])) {
                    $explain_link_validate = '&amp;validatequery=1';
                } else {
                    $explain_link_validate = '';
                }
                $explain_link = '&nbsp;[<a href="read_dump.php' . $url_qpart . $explain_link_validate . '&amp;sql_query=';
                if (preg_match('@^SELECT[[:space:]]+@i', $local_query)) {
                    $explain_link .= urlencode('EXPLAIN ' . $local_query) . '">' . $GLOBALS['strExplain'];
                } else {
                    if (preg_match('@^EXPLAIN[[:space:]]+SELECT[[:space:]]+@i', $local_query)) {
                        $explain_link .= urlencode(substr($local_query, 8)) . '">' . $GLOBALS['strNoExplain'];
                    } else {
                        $explain_link = '';
                    }
                }
                if (!empty($explain_link)) {
                    $explain_link .= '</a>]';
                }
            } else {
                $explain_link = '';
            }
            //show explain
            // Also we would like to get the SQL formed in some nice
            // php-code (Mike Beck 2002-05-22)
            if (isset($cfg['SQLQuery']['ShowAsPHP']) && $cfg['SQLQuery']['ShowAsPHP'] == TRUE) {
                $php_link = '&nbsp;[<a href="read_dump.php' . $url_qpart . '&amp;show_query=1' . '&amp;sql_query=' . urlencode($local_query) . '&amp;show_as_php=';
                if (!empty($GLOBALS['show_as_php'])) {
                    $php_link .= '0">' . $GLOBALS['strNoPhp'];
                } else {
                    $php_link .= '1">' . $GLOBALS['strPhp'];
                }
                $php_link .= '</a>]';
                if (isset($GLOBALS['show_as_php']) && $GLOBALS['show_as_php'] == '1') {
                    $php_link .= '&nbsp;[<a href="read_dump.php' . $url_qpart . '&amp;show_query=1' . '&amp;sql_query=' . urlencode($local_query) . '">' . $GLOBALS['strRunQuery'] . '</a>]';
                }
            } else {
                $php_link = '';
            }
            //show as php
            // Refresh query
            if (isset($cfg['SQLQuery']['Refresh']) && $cfg['SQLQuery']['Refresh'] && preg_match('@^(SELECT|SHOW)[[:space:]]+@i', $local_query)) {
                $refresh_link = '&nbsp;[<a href="read_dump.php' . $url_qpart . '&amp;show_query=1' . '&amp;sql_query=' . urlencode($local_query) . '">';
                $refresh_link .= $GLOBALS['strRefresh'];
                $refresh_link .= '</a>]';
            } else {
                $refresh_link = '';
            }
            //show as php
            if (isset($cfg['SQLValidator']['use']) && $cfg['SQLValidator']['use'] == TRUE && isset($cfg['SQLQuery']['Validate']) && $cfg['SQLQuery']['Validate'] == TRUE) {
                $validate_link = '&nbsp;[<a href="read_dump.php' . $url_qpart . '&amp;show_query=1' . '&amp;sql_query=' . urlencode($local_query) . '&amp;validatequery=';
                if (!empty($GLOBALS['validatequery'])) {
                    $validate_link .= '0">' . $GLOBALS['strNoValidateSQL'];
                } else {
                    $validate_link .= '1">' . $GLOBALS['strValidateSQL'];
                }
                $validate_link .= '</a>]';
            } else {
                $validate_link = '';
            }
            //validator
            // Displays the message
            echo '            <b>' . $GLOBALS['strSQLQuery'] . ':</b>&nbsp;';
            echo '<br />' . "\n";
            echo '            ' . $query_base;
            unset($local_query);
            //Clean up the end of the PHP
            if (!empty($GLOBALS['show_as_php'])) {
                echo '\';';
            }
            echo "\n";
            ?>
        </td>
    </tr>
    <?php 
            if (!empty($edit_target)) {
                echo '<tr><td bgcolor="' . $cfg['BgcolorOne'] . '" align="center">';
                echo $edit_link . $explain_link . $php_link . $refresh_link . $validate_link;
                echo '</td></tr>' . "\n";
            }
        }
        echo "\n";
        ?>
    </table>
</div><br />
        <?php 
    }
Exemplo n.º 9
0
 /**
  * Copies or renames table
  * @todo use RENAME for move operations
  *        - would work only if the databases are on the same filesystem,
  *          how can we check that? try the operation and
  *          catch an error?
  *        - for views, only if MYSQL > 50013
  *        - still have to handle pmadb synch.
  *
  * @author          Michal Cihar <*****@*****.**>
  */
 function moveCopy($source_db, $source_table, $target_db, $target_table, $what, $move, $mode)
 {
     global $err_url;
     // set export settings we need
     $GLOBALS['sql_backquotes'] = 1;
     $GLOBALS['asfile'] = 1;
     // Ensure the target is valid
     if (!$GLOBALS['PMA_List_Database']->exists($source_db, $target_db)) {
         /**
          * @todo exit really needed here? or just a return?
          */
         exit;
     }
     $source = PMA_backquote($source_db) . '.' . PMA_backquote($source_table);
     if (!isset($target_db) || !strlen($target_db)) {
         $target_db = $source_db;
     }
     // Doing a select_db could avoid some problems with replicated databases,
     // when moving table from replicated one to not replicated one
     PMA_DBI_select_db($target_db);
     $target = PMA_backquote($target_db) . '.' . PMA_backquote($target_table);
     // do not create the table if dataonly
     if ($what != 'dataonly') {
         require_once './libraries/export/sql.php';
         $no_constraints_comments = true;
         $GLOBALS['sql_constraints_query'] = '';
         $sql_structure = PMA_getTableDef($source_db, $source_table, "\n", $err_url);
         unset($no_constraints_comments);
         $parsed_sql = PMA_SQP_parse($sql_structure);
         $analyzed_sql = PMA_SQP_analyze($parsed_sql);
         $i = 0;
         if (empty($analyzed_sql[0]['create_table_fields'])) {
             // this is not a CREATE TABLE, so find the first VIEW
             $target_for_view = PMA_backquote($target_db);
             while (true) {
                 if ($parsed_sql[$i]['type'] == 'alpha_reservedWord' && $parsed_sql[$i]['data'] == 'VIEW') {
                     break;
                 }
                 $i++;
             }
         }
         unset($analyzed_sql);
         $server_sql_mode = PMA_DBI_fetch_value("SHOW VARIABLES LIKE 'sql_mode'", 0, 1);
         if ('ANSI_QUOTES' == $server_sql_mode) {
             $table_delimiter = 'quote_double';
         } else {
             $table_delimiter = 'quote_backtick';
         }
         unset($server_sql_mode);
         /* nijel: Find table name in query and replace it */
         while ($parsed_sql[$i]['type'] != $table_delimiter) {
             $i++;
         }
         /* no need to PMA_backquote() */
         if (isset($target_for_view)) {
             // this a view definition; we just found the first db name
             // that follows DEFINER VIEW
             // so change it for the new db name
             $parsed_sql[$i]['data'] = $target_for_view;
             // then we have to find all references to the source db
             // and change them to the target db, ensuring we stay into
             // the $parsed_sql limits
             $last = $parsed_sql['len'] - 1;
             $backquoted_source_db = PMA_backquote($source_db);
             for (++$i; $i <= $last; $i++) {
                 if ($parsed_sql[$i]['type'] == $table_delimiter && $parsed_sql[$i]['data'] == $backquoted_source_db) {
                     $parsed_sql[$i]['data'] = $target_for_view;
                 }
             }
             unset($last, $backquoted_source_db);
         } else {
             $parsed_sql[$i]['data'] = $target;
         }
         /* Generate query back */
         $sql_structure = PMA_SQP_formatHtml($parsed_sql, 'query_only');
         // If table exists, and 'add drop table' is selected: Drop it!
         $drop_query = '';
         if (isset($GLOBALS['drop_if_exists']) && $GLOBALS['drop_if_exists'] == 'true') {
             if (PMA_Table::_isView($target_db, $target_table)) {
                 $drop_query = 'DROP VIEW';
             } else {
                 $drop_query = 'DROP TABLE';
             }
             $drop_query .= ' IF EXISTS ' . PMA_backquote($target_db) . '.' . PMA_backquote($target_table);
             PMA_DBI_query($drop_query);
             $GLOBALS['sql_query'] .= "\n" . $drop_query . ';';
             // garvin: If an existing table gets deleted, maintain any
             // entries for the PMA_* tables
             $maintain_relations = true;
         }
         @PMA_DBI_query($sql_structure);
         $GLOBALS['sql_query'] .= "\n" . $sql_structure . ';';
         if (($move || isset($GLOBALS['add_constraints'])) && !empty($GLOBALS['sql_constraints_query'])) {
             $parsed_sql = PMA_SQP_parse($GLOBALS['sql_constraints_query']);
             $i = 0;
             // find the first $table_delimiter, it must be the source table name
             while ($parsed_sql[$i]['type'] != $table_delimiter) {
                 $i++;
                 // maybe someday we should guard against going over limit
                 //if ($i == $parsed_sql['len']) {
                 //    break;
                 //}
             }
             // replace it by the target table name, no need to PMA_backquote()
             $parsed_sql[$i]['data'] = $target;
             // now we must remove all $table_delimiter that follow a CONSTRAINT
             // keyword, because a constraint name must be unique in a db
             $cnt = $parsed_sql['len'] - 1;
             for ($j = $i; $j < $cnt; $j++) {
                 if ($parsed_sql[$j]['type'] == 'alpha_reservedWord' && strtoupper($parsed_sql[$j]['data']) == 'CONSTRAINT') {
                     if ($parsed_sql[$j + 1]['type'] == $table_delimiter) {
                         $parsed_sql[$j + 1]['data'] = '';
                     }
                 }
             }
             // Generate query back
             $GLOBALS['sql_constraints_query'] = PMA_SQP_formatHtml($parsed_sql, 'query_only');
             if ($mode == 'one_table') {
                 PMA_DBI_query($GLOBALS['sql_constraints_query']);
             }
             $GLOBALS['sql_query'] .= "\n" . $GLOBALS['sql_constraints_query'];
             if ($mode == 'one_table') {
                 unset($GLOBALS['sql_constraints_query']);
             }
         }
     } else {
         $GLOBALS['sql_query'] = '';
     }
     // Copy the data unless this is a VIEW
     if (($what == 'data' || $what == 'dataonly') && !PMA_Table::_isView($target_db, $target_table)) {
         $sql_insert_data = 'INSERT INTO ' . $target . ' SELECT * FROM ' . $source;
         PMA_DBI_query($sql_insert_data);
         $GLOBALS['sql_query'] .= "\n\n" . $sql_insert_data . ';';
     }
     require_once './libraries/relation.lib.php';
     $GLOBALS['cfgRelation'] = PMA_getRelationsParam();
     // Drops old table if the user has requested to move it
     if ($move) {
         // This could avoid some problems with replicated databases, when
         // moving table from replicated one to not replicated one
         PMA_DBI_select_db($source_db);
         if (PMA_Table::_isView($source_db, $source_table)) {
             $sql_drop_query = 'DROP VIEW';
         } else {
             $sql_drop_query = 'DROP TABLE';
         }
         $sql_drop_query .= ' ' . $source;
         PMA_DBI_query($sql_drop_query);
         // garvin: Move old entries from PMA-DBs to new table
         if ($GLOBALS['cfgRelation']['commwork']) {
             $remove_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['column_info']) . ' SET     table_name = \'' . PMA_sqlAddslashes($target_table) . '\', ' . '        db_name    = \'' . PMA_sqlAddslashes($target_db) . '\'' . ' WHERE db_name  = \'' . PMA_sqlAddslashes($source_db) . '\'' . ' AND table_name = \'' . PMA_sqlAddslashes($source_table) . '\'';
             PMA_query_as_cu($remove_query);
             unset($remove_query);
         }
         // garvin: updating bookmarks is not possible since only a single table is moved,
         // and not the whole DB.
         if ($GLOBALS['cfgRelation']['displaywork']) {
             $table_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['table_info']) . ' SET     db_name = \'' . PMA_sqlAddslashes($target_db) . '\', ' . '         table_name = \'' . PMA_sqlAddslashes($target_table) . '\'' . ' WHERE db_name  = \'' . PMA_sqlAddslashes($source_db) . '\'' . ' AND table_name = \'' . PMA_sqlAddslashes($source_table) . '\'';
             PMA_query_as_cu($table_query);
             unset($table_query);
         }
         if ($GLOBALS['cfgRelation']['relwork']) {
             $table_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['relation']) . ' SET     foreign_table = \'' . PMA_sqlAddslashes($target_table) . '\',' . '         foreign_db = \'' . PMA_sqlAddslashes($target_db) . '\'' . ' WHERE foreign_db  = \'' . PMA_sqlAddslashes($source_db) . '\'' . ' AND foreign_table = \'' . PMA_sqlAddslashes($source_table) . '\'';
             PMA_query_as_cu($table_query);
             unset($table_query);
             $table_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['relation']) . ' SET     master_table = \'' . PMA_sqlAddslashes($target_table) . '\',' . '         master_db = \'' . PMA_sqlAddslashes($target_db) . '\'' . ' WHERE master_db  = \'' . PMA_sqlAddslashes($source_db) . '\'' . ' AND master_table = \'' . PMA_sqlAddslashes($source_table) . '\'';
             PMA_query_as_cu($table_query);
             unset($table_query);
         }
         /**
          * @todo garvin: Can't get moving PDFs the right way. The page numbers
          * always get screwed up independently from duplication because the
          * numbers do not seem to be stored on a per-database basis. Would
          * the author of pdf support please have a look at it?
          */
         if ($GLOBALS['cfgRelation']['pdfwork']) {
             $table_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['table_coords']) . ' SET     table_name = \'' . PMA_sqlAddslashes($target_table) . '\',' . '         db_name = \'' . PMA_sqlAddslashes($target_db) . '\'' . ' WHERE db_name  = \'' . PMA_sqlAddslashes($source_db) . '\'' . ' AND table_name = \'' . PMA_sqlAddslashes($source_table) . '\'';
             PMA_query_as_cu($table_query);
             unset($table_query);
             /*
             $pdf_query = 'SELECT pdf_page_number '
                        . ' FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['table_coords'])
                        . ' WHERE db_name  = \'' . PMA_sqlAddslashes($target_db) . '\''
                        . ' AND table_name = \'' . PMA_sqlAddslashes($target_table) . '\'';
             $pdf_rs = PMA_query_as_cu($pdf_query);
             
             while ($pdf_copy_row = PMA_DBI_fetch_assoc($pdf_rs)) {
                 $table_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['pdf_pages'])
                                 . ' SET     db_name = \'' . PMA_sqlAddslashes($target_db) . '\''
                                 . ' WHERE db_name  = \'' . PMA_sqlAddslashes($source_db) . '\''
                                 . ' AND page_nr = \'' . PMA_sqlAddslashes($pdf_copy_row['pdf_page_number']) . '\'';
                 $tb_rs    = PMA_query_as_cu($table_query);
                 unset($table_query);
                 unset($tb_rs);
             }
             */
         }
         if ($GLOBALS['cfgRelation']['designerwork']) {
             $table_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['designer_coords']) . ' SET     table_name = \'' . PMA_sqlAddslashes($target_table) . '\',' . '         db_name = \'' . PMA_sqlAddslashes($target_db) . '\'' . ' WHERE db_name  = \'' . PMA_sqlAddslashes($source_db) . '\'' . ' AND table_name = \'' . PMA_sqlAddslashes($source_table) . '\'';
             PMA_query_as_cu($table_query);
             unset($table_query);
         }
         $GLOBALS['sql_query'] .= "\n\n" . $sql_drop_query . ';';
         // end if ($move)
     } else {
         // we are copying
         // garvin: Create new entries as duplicates from old PMA DBs
         if ($what != 'dataonly' && !isset($maintain_relations)) {
             if ($GLOBALS['cfgRelation']['commwork']) {
                 // Get all comments and MIME-Types for current table
                 $comments_copy_query = 'SELECT
                                             column_name, ' . PMA_backquote('comment') . ($GLOBALS['cfgRelation']['mimework'] ? ', mimetype, transformation, transformation_options' : '') . '
                                         FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['column_info']) . '
                                         WHERE
                                             db_name = \'' . PMA_sqlAddslashes($source_db) . '\' AND
                                             table_name = \'' . PMA_sqlAddslashes($source_table) . '\'';
                 $comments_copy_rs = PMA_query_as_cu($comments_copy_query);
                 // Write every comment as new copied entry. [MIME]
                 while ($comments_copy_row = PMA_DBI_fetch_assoc($comments_copy_rs)) {
                     $new_comment_query = 'REPLACE INTO ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['column_info']) . ' (db_name, table_name, column_name, ' . PMA_backquote('comment') . ($GLOBALS['cfgRelation']['mimework'] ? ', mimetype, transformation, transformation_options' : '') . ') ' . ' VALUES(' . '\'' . PMA_sqlAddslashes($target_db) . '\',' . '\'' . PMA_sqlAddslashes($target_table) . '\',' . '\'' . PMA_sqlAddslashes($comments_copy_row['column_name']) . '\'' . ($GLOBALS['cfgRelation']['mimework'] ? ',\'' . PMA_sqlAddslashes($comments_copy_row['comment']) . '\',' . '\'' . PMA_sqlAddslashes($comments_copy_row['mimetype']) . '\',' . '\'' . PMA_sqlAddslashes($comments_copy_row['transformation']) . '\',' . '\'' . PMA_sqlAddslashes($comments_copy_row['transformation_options']) . '\'' : '') . ')';
                     PMA_query_as_cu($new_comment_query);
                 }
                 // end while
                 PMA_DBI_free_result($comments_copy_rs);
                 unset($comments_copy_rs);
             }
             // duplicating the bookmarks must not be done here, but
             // just once per db
             $get_fields = array('display_field');
             $where_fields = array('db_name' => $source_db, 'table_name' => $source_table);
             $new_fields = array('db_name' => $target_db, 'table_name' => $target_table);
             PMA_Table::duplicateInfo('displaywork', 'table_info', $get_fields, $where_fields, $new_fields);
             /**
              * @todo revise this code when we support cross-db relations
              */
             $get_fields = array('master_field', 'foreign_table', 'foreign_field');
             $where_fields = array('master_db' => $source_db, 'master_table' => $source_table);
             $new_fields = array('master_db' => $target_db, 'foreign_db' => $target_db, 'master_table' => $target_table);
             PMA_Table::duplicateInfo('relwork', 'relation', $get_fields, $where_fields, $new_fields);
             $get_fields = array('foreign_field', 'master_table', 'master_field');
             $where_fields = array('foreign_db' => $source_db, 'foreign_table' => $source_table);
             $new_fields = array('master_db' => $target_db, 'foreign_db' => $target_db, 'foreign_table' => $target_table);
             PMA_Table::duplicateInfo('relwork', 'relation', $get_fields, $where_fields, $new_fields);
             $get_fields = array('x', 'y', 'v', 'h');
             $where_fields = array('db_name' => $source_db, 'table_name' => $source_table);
             $new_fields = array('db_name' => $target_db, 'table_name' => $target_table);
             PMA_Table::duplicateInfo('designerwork', 'designer_coords', $get_fields, $where_fields, $new_fields);
             /**
             * @todo garvin: Can't get duplicating PDFs the right way. The
             * page numbers always get screwed up independently from
             * duplication because the numbers do not seem to be stored on a
             * per-database basis. Would the author of pdf support please
             * have a look at it?
             *
                             $get_fields = array('page_descr');
                             $where_fields = array('db_name' => $source_db);
                             $new_fields = array('db_name' => $target_db);
                             $last_id = PMA_Table::duplicateInfo('pdfwork', 'pdf_pages', $get_fields, $where_fields, $new_fields);
             
                             if (isset($last_id) && $last_id >= 0) {
                $get_fields = array('x', 'y');
                $where_fields = array('db_name' => $source_db, 'table_name' => $source_table);
                $new_fields = array('db_name' => $target_db, 'table_name' => $target_table, 'pdf_page_number' => $last_id);
                PMA_Table::duplicateInfo('pdfwork', 'table_coords', $get_fields, $where_fields, $new_fields);
                             }
             */
         }
     }
 }
Exemplo n.º 10
0
 /**
  * Outputs the content of a table in SQL format
  *
  * @param string $db        database name
  * @param string $table     table name
  * @param string $crlf      the end of line sequence
  * @param string $error_url the url to go back in case of error
  * @param string $sql_query SQL query for obtaining data
  *
  * @return bool Whether it succeeded
  */
 public function exportData($db, $table, $crlf, $error_url, $sql_query)
 {
     global $current_row, $sql_backquotes;
     if (isset($GLOBALS['sql_compatibility'])) {
         $compat = $GLOBALS['sql_compatibility'];
     } else {
         $compat = 'NONE';
     }
     $formatted_table_name = isset($GLOBALS['sql_backquotes']) ? PMA_Util::backquoteCompat($table, $compat) : '\'' . $table . '\'';
     // Do not export data for a VIEW
     // (For a VIEW, this is called only when exporting a single VIEW)
     if (PMA_Table::isView($db, $table)) {
         $head = $this->_possibleCRLF() . $this->_exportComment() . $this->_exportComment('VIEW ' . ' ' . $formatted_table_name) . $this->_exportComment(__('Data') . ': ' . __('None')) . $this->_exportComment() . $this->_possibleCRLF();
         if (!PMA_exportOutputHandler($head)) {
             return false;
         }
         return true;
     }
     // analyze the query to get the true column names, not the aliases
     // (this fixes an undefined index, also if Complete inserts
     //  are used, we did not get the true column name in case of aliases)
     $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($sql_query));
     $result = PMA_DBI_try_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED);
     // a possible error: the table has crashed
     $tmp_error = PMA_DBI_getError();
     if ($tmp_error) {
         return PMA_exportOutputHandler($this->_exportComment(__('Error reading data:') . ' (' . $tmp_error . ')'));
     }
     if ($result != false) {
         $fields_cnt = PMA_DBI_num_fields($result);
         // Get field information
         $fields_meta = PMA_DBI_get_fields_meta($result);
         $field_flags = array();
         for ($j = 0; $j < $fields_cnt; $j++) {
             $field_flags[$j] = PMA_DBI_field_flags($result, $j);
         }
         for ($j = 0; $j < $fields_cnt; $j++) {
             if (isset($analyzed_sql[0]['select_expr'][$j]['column'])) {
                 $field_set[$j] = PMA_Util::backquoteCompat($analyzed_sql[0]['select_expr'][$j]['column'], $compat, $sql_backquotes);
             } else {
                 $field_set[$j] = PMA_Util::backquoteCompat($fields_meta[$j]->name, $compat, $sql_backquotes);
             }
         }
         if (isset($GLOBALS['sql_type']) && $GLOBALS['sql_type'] == 'UPDATE') {
             // update
             $schema_insert = 'UPDATE ';
             if (isset($GLOBALS['sql_ignore'])) {
                 $schema_insert .= 'IGNORE ';
             }
             // avoid EOL blank
             $schema_insert .= PMA_Util::backquoteCompat($table, $compat, $sql_backquotes) . ' SET';
         } else {
             // insert or replace
             if (isset($GLOBALS['sql_type']) && $GLOBALS['sql_type'] == 'REPLACE') {
                 $sql_command = 'REPLACE';
             } else {
                 $sql_command = 'INSERT';
             }
             // delayed inserts?
             if (isset($GLOBALS['sql_delayed'])) {
                 $insert_delayed = ' DELAYED';
             } else {
                 $insert_delayed = '';
             }
             // insert ignore?
             if (isset($GLOBALS['sql_type']) && $GLOBALS['sql_type'] == 'INSERT' && isset($GLOBALS['sql_ignore'])) {
                 $insert_delayed .= ' IGNORE';
             }
             //truncate table before insert
             if (isset($GLOBALS['sql_truncate']) && $GLOBALS['sql_truncate'] && $sql_command == 'INSERT') {
                 $truncate = 'TRUNCATE TABLE ' . PMA_Util::backquoteCompat($table, $compat, $sql_backquotes) . ";";
                 $truncatehead = $this->_possibleCRLF() . $this->_exportComment() . $this->_exportComment(__('Truncate table before insert') . ' ' . $formatted_table_name) . $this->_exportComment() . $crlf;
                 PMA_exportOutputHandler($truncatehead);
                 PMA_exportOutputHandler($truncate);
             } else {
                 $truncate = '';
             }
             // scheme for inserting fields
             if ($GLOBALS['sql_insert_syntax'] == 'complete' || $GLOBALS['sql_insert_syntax'] == 'both') {
                 $fields = implode(', ', $field_set);
                 $schema_insert = $sql_command . $insert_delayed . ' INTO ' . PMA_Util::backquoteCompat($table, $compat, $sql_backquotes) . ' (' . $fields . ') VALUES';
             } else {
                 $schema_insert = $sql_command . $insert_delayed . ' INTO ' . PMA_Util::backquoteCompat($table, $compat, $sql_backquotes) . ' VALUES';
             }
         }
         //\x08\\x09, not required
         $search = array("", "\n", "\r", "");
         $replace = array('\\0', '\\n', '\\r', '\\Z');
         $current_row = 0;
         $query_size = 0;
         if (($GLOBALS['sql_insert_syntax'] == 'extended' || $GLOBALS['sql_insert_syntax'] == 'both') && (!isset($GLOBALS['sql_type']) || $GLOBALS['sql_type'] != 'UPDATE')) {
             $separator = ',';
             $schema_insert .= $crlf;
         } else {
             $separator = ';';
         }
         while ($row = PMA_DBI_fetch_row($result)) {
             if ($current_row == 0) {
                 $head = $this->_possibleCRLF() . $this->_exportComment() . $this->_exportComment(__('Dumping data for table') . ' ' . $formatted_table_name) . $this->_exportComment() . $crlf;
                 if (!PMA_exportOutputHandler($head)) {
                     return false;
                 }
             }
             // We need to SET IDENTITY_INSERT ON for MSSQL
             if (isset($GLOBALS['sql_compatibility']) && $GLOBALS['sql_compatibility'] == 'MSSQL' && $current_row == 0) {
                 if (!PMA_exportOutputHandler('SET IDENTITY_INSERT ' . PMA_Util::backquoteCompat($table, $compat) . ' ON ;' . $crlf)) {
                     return false;
                 }
             }
             $current_row++;
             for ($j = 0; $j < $fields_cnt; $j++) {
                 // NULL
                 if (!isset($row[$j]) || is_null($row[$j])) {
                     $values[] = 'NULL';
                 } elseif ($fields_meta[$j]->numeric && $fields_meta[$j]->type != 'timestamp' && !$fields_meta[$j]->blob) {
                     // a number
                     // timestamp is numeric on some MySQL 4.1, BLOBs are
                     // sometimes numeric
                     $values[] = $row[$j];
                 } elseif (stristr($field_flags[$j], 'BINARY') && $fields_meta[$j]->blob && isset($GLOBALS['sql_hex_for_blob'])) {
                     // a true BLOB
                     // - mysqldump only generates hex data when the --hex-blob
                     //   option is used, for fields having the binary attribute
                     //   no hex is generated
                     // - a TEXT field returns type blob but a real blob
                     //   returns also the 'binary' flag
                     // empty blobs need to be different, but '0' is also empty
                     // :-(
                     if (empty($row[$j]) && $row[$j] != '0') {
                         $values[] = '\'\'';
                     } else {
                         $values[] = '0x' . bin2hex($row[$j]);
                     }
                 } elseif ($fields_meta[$j]->type == 'bit') {
                     // detection of 'bit' works only on mysqli extension
                     $values[] = "b'" . PMA_Util::sqlAddSlashes(PMA_Util::printableBitValue($row[$j], $fields_meta[$j]->length)) . "'";
                 } else {
                     // something else -> treat as a string
                     $values[] = '\'' . str_replace($search, $replace, PMA_Util::sqlAddSlashes($row[$j])) . '\'';
                 }
                 // end if
             }
             // end for
             // should we make update?
             if (isset($GLOBALS['sql_type']) && $GLOBALS['sql_type'] == 'UPDATE') {
                 $insert_line = $schema_insert;
                 for ($i = 0; $i < $fields_cnt; $i++) {
                     if (0 == $i) {
                         $insert_line .= ' ';
                     }
                     if ($i > 0) {
                         // avoid EOL blank
                         $insert_line .= ',';
                     }
                     $insert_line .= $field_set[$i] . ' = ' . $values[$i];
                 }
                 list($tmp_unique_condition, $tmp_clause_is_unique) = PMA_Util::getUniqueCondition($result, $fields_cnt, $fields_meta, $row);
                 $insert_line .= ' WHERE ' . $tmp_unique_condition;
                 unset($tmp_unique_condition, $tmp_clause_is_unique);
             } else {
                 // Extended inserts case
                 if ($GLOBALS['sql_insert_syntax'] == 'extended' || $GLOBALS['sql_insert_syntax'] == 'both') {
                     if ($current_row == 1) {
                         $insert_line = $schema_insert . '(' . implode(', ', $values) . ')';
                     } else {
                         $insert_line = '(' . implode(', ', $values) . ')';
                         $sql_max_size = $GLOBALS['sql_max_query_size'];
                         if (isset($sql_max_size) && $sql_max_size > 0 && $query_size + strlen($insert_line) > $sql_max_size) {
                             if (!PMA_exportOutputHandler(';' . $crlf)) {
                                 return false;
                             }
                             $query_size = 0;
                             $current_row = 1;
                             $insert_line = $schema_insert . $insert_line;
                         }
                     }
                     $query_size += strlen($insert_line);
                     // Other inserts case
                 } else {
                     $insert_line = $schema_insert . '(' . implode(', ', $values) . ')';
                 }
             }
             unset($values);
             if (!PMA_exportOutputHandler(($current_row == 1 ? '' : $separator . $crlf) . $insert_line)) {
                 return false;
             }
         }
         // end while
         if ($current_row > 0) {
             if (!PMA_exportOutputHandler(';' . $crlf)) {
                 return false;
             }
         }
         // We need to SET IDENTITY_INSERT OFF for MSSQL
         if (isset($GLOBALS['sql_compatibility']) && $GLOBALS['sql_compatibility'] == 'MSSQL' && $current_row > 0) {
             $outputSucceeded = PMA_exportOutputHandler($crlf . 'SET IDENTITY_INSERT ' . PMA_Util::backquoteCompat($table, $compat) . ' OFF;' . $crlf);
             if (!$outputSucceeded) {
                 return false;
             }
         }
     }
     // end if ($result != false)
     PMA_DBI_free_result($result);
     return true;
 }
 /**
  * Returns the analysis of 'SHOW CREATE TABLE' query for the table.
  * In case of a view, the values are taken from the information_schema.
  *
  * @return array analysis of 'SHOW CREATE TABLE' query for the table
  */
 public function analyzeStructure()
 {
     if (empty($this->_db_name) || empty($this->_name)) {
         return false;
     }
     $analyzed_sql = array();
     if ($this->isView()) {
         // For a view, 'SHOW CREATE TABLE' returns the definition,
         // but the structure of the view. So, we try to mock
         // the result of analyzing 'SHOW CREATE TABLE' query.
         $analyzed_sql[0] = array();
         $analyzed_sql[0]['create_table_fields'] = array();
         $results = $this->_dbi->fetchResult("SELECT COLUMN_NAME, DATA_TYPE\r\n                FROM information_schema.COLUMNS\r\n                WHERE TABLE_SCHEMA = '" . PMA_Util::sqlAddSlashes($this->_db_name) . " AND TABLE_NAME = '" . PMA_Util::sqlAddSlashes($this->_name) . "'");
         foreach ($results as $result) {
             $analyzed_sql[0]['create_table_fields'][$result['COLUMN_NAME']] = array('type' => mb_strtoupper($result['DATA_TYPE']));
         }
     } else {
         $show_create_table = $this->_dbi->fetchValue('SHOW CREATE TABLE ' . PMA_Util::backquote($this->_db_name) . '.' . PMA_Util::backquote($this->_name), 0, 1);
         $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
     }
     return $analyzed_sql;
 }
Exemplo n.º 12
0
/**
 * Checks if ROLLBACK is possible for a SQL query or not.
 *
 * @param string $sql_query SQL query
 *
 * @return bool
 */
function PMA_checkIfRollbackPossible($sql_query)
{
    // Supported queries.
    $supported_queries = array('INSERT', 'UPDATE', 'DELETE', 'REPLACE');
    // Parse and Analyze the query.
    $parsed_sql = PMA_SQP_parse($sql_query);
    $analyzed_sql = PMA_SQP_analyze($parsed_sql);
    $analyzed_sql_results = array('parsed_sql' => $parsed_sql, 'analyzed_sql' => $analyzed_sql);
    // Get the query type.
    $query_type = isset($analyzed_sql_results['analyzed_sql'][0]['querytype']) ? $analyzed_sql_results['analyzed_sql'][0]['querytype'] : '';
    // Check if query is supported.
    if (!in_array($query_type, $supported_queries)) {
        return false;
    }
    // Get table_references from the query.
    $table_references = PMA_getTableReferences($analyzed_sql_results);
    $table_references = $table_references ? $table_references : '';
    // Get table names from table_references.
    $tables = PMA_getTableNamesFromTableReferences($table_references);
    // Check if each table is 'InnoDB'.
    foreach ($tables as $table) {
        if (!PMA_isTableTransactional($table)) {
            return false;
        }
    }
    return true;
}
Exemplo n.º 13
0
     // for the PMA_* tables
     $maintain_relations = true;
 }
 $result = @PMA_mysql_query($sql_structure);
 if (PMA_mysql_error()) {
     require_once './header.inc.php';
     PMA_mysqlDie('', $sql_structure, '', $err_url);
 } else {
     if (isset($sql_query)) {
         $sql_query .= "\n" . $sql_structure . ';';
     } else {
         $sql_query = $sql_structure . ';';
     }
 }
 if ((isset($submit_move) || isset($constraints)) && isset($sql_constraints)) {
     $parsed_sql = PMA_SQP_parse($sql_constraints);
     $i = 0;
     while ($parsed_sql[$i]['type'] != 'quote_backtick') {
         $i++;
     }
     /* no need to PMA_backquote() */
     $parsed_sql[$i]['data'] = $target;
     /* Generate query back */
     $sql_constraints = PMA_SQP_formatHtml($parsed_sql, 'query_only');
     $result = @PMA_mysql_query($sql_constraints);
     if (PMA_mysql_error()) {
         require_once './header.inc.php';
         PMA_mysqlDie('', $sql_structure, '', $err_url);
     } else {
         if (isset($sql_query)) {
             $sql_query .= "\n" . $sql_constraints;
Exemplo n.º 14
0
/**
 * displays the message and the query
 * usually the message is the result of the query executed
 *
 * @param   string  $message    the message to display
 * @param   string  $sql_query  the query to display
 * @param   string  $type       the type (level) of the message
 * @global  array   the configuration array
 * @uses    $cfg
 * @access  public
 */
function PMA_showMessage($message, $sql_query = null, $type = 'notice')
{
    global $cfg;
    if (null === $sql_query) {
        if (!empty($GLOBALS['display_query'])) {
            $sql_query = $GLOBALS['display_query'];
        } elseif ($cfg['SQP']['fmtType'] == 'none' && !empty($GLOBALS['unparsed_sql'])) {
            $sql_query = $GLOBALS['unparsed_sql'];
        } elseif (!empty($GLOBALS['sql_query'])) {
            $sql_query = $GLOBALS['sql_query'];
        } else {
            $sql_query = '';
        }
    }
    // Corrects the tooltip text via JS if required
    // @todo this is REALLY the wrong place to do this - very unexpected here
    if (strlen($GLOBALS['table']) && $cfg['ShowTooltip']) {
        $tooltip = PMA_Table::sGetToolTip($GLOBALS['db'], $GLOBALS['table']);
        $uni_tbl = PMA_jsFormat($GLOBALS['db'] . '.' . $GLOBALS['table'], false);
        echo "\n";
        echo '<script type="text/javascript">' . "\n";
        echo '//<![CDATA[' . "\n";
        echo "if (window.parent.updateTableTitle) window.parent.updateTableTitle('" . $uni_tbl . "', '" . PMA_jsFormat($tooltip, false) . "');" . "\n";
        echo '//]]>' . "\n";
        echo '</script>' . "\n";
    }
    // end if ... elseif
    // Checks if the table needs to be repaired after a TRUNCATE query.
    // @todo what about $GLOBALS['display_query']???
    // @todo this is REALLY the wrong place to do this - very unexpected here
    if (strlen($GLOBALS['table']) && $GLOBALS['sql_query'] == 'TRUNCATE TABLE ' . PMA_backquote($GLOBALS['table'])) {
        if (PMA_Table::sGetStatusInfo($GLOBALS['db'], $GLOBALS['table'], 'Index_length') > 1024) {
            PMA_DBI_try_query('REPAIR TABLE ' . PMA_backquote($GLOBALS['table']));
        }
    }
    unset($tbl_status);
    echo '<div align="' . $GLOBALS['cell_align_left'] . '">' . "\n";
    if ($message instanceof PMA_Message) {
        if (isset($GLOBALS['special_message'])) {
            $message->addMessage($GLOBALS['special_message']);
            unset($GLOBALS['special_message']);
        }
        $message->display();
        $type = $message->getLevel();
    } else {
        echo '<div class="' . $type . '">';
        echo PMA_sanitize($message);
        if (isset($GLOBALS['special_message'])) {
            echo PMA_sanitize($GLOBALS['special_message']);
            unset($GLOBALS['special_message']);
        }
        echo '</div>';
    }
    if ($cfg['ShowSQL'] == true && !empty($sql_query)) {
        // Html format the query to be displayed
        // If we want to show some sql code it is easiest to create it here
        /* SQL-Parser-Analyzer */
        if (!empty($GLOBALS['show_as_php'])) {
            $new_line = '\\n"<br />' . "\n" . '&nbsp;&nbsp;&nbsp;&nbsp;. "';
            $query_base = htmlspecialchars(addslashes($sql_query));
            $query_base = preg_replace('/((\\015\\012)|(\\015)|(\\012))/', $new_line, $query_base);
        } else {
            $query_base = $sql_query;
        }
        $query_too_big = false;
        if (strlen($query_base) > $cfg['MaxCharactersInDisplayedSQL']) {
            // when the query is large (for example an INSERT of binary
            // data), the parser chokes; so avoid parsing the query
            $query_too_big = true;
            $shortened_query_base = nl2br(htmlspecialchars(substr($sql_query, 0, $cfg['MaxCharactersInDisplayedSQL']) . '[...]'));
        } elseif (!empty($GLOBALS['parsed_sql']) && $query_base == $GLOBALS['parsed_sql']['raw']) {
            // (here, use "! empty" because when deleting a bookmark,
            // $GLOBALS['parsed_sql'] is set but empty
            $parsed_sql = $GLOBALS['parsed_sql'];
        } else {
            // Parse SQL if needed
            $parsed_sql = PMA_SQP_parse($query_base);
        }
        // Analyze it
        if (isset($parsed_sql)) {
            $analyzed_display_query = PMA_SQP_analyze($parsed_sql);
            // Here we append the LIMIT added for navigation, to
            // enable its display. Adding it higher in the code
            // to $sql_query would create a problem when
            // using the Refresh or Edit links.
            // Only append it on SELECTs.
            /**
             * @todo what would be the best to do when someone hits Refresh:
             * use the current LIMITs ?
             */
            if (isset($analyzed_display_query[0]['queryflags']['select_from']) && isset($GLOBALS['sql_limit_to_append'])) {
                $query_base = $analyzed_display_query[0]['section_before_limit'] . "\n" . $GLOBALS['sql_limit_to_append'] . $analyzed_display_query[0]['section_after_limit'];
                // Need to reparse query
                $parsed_sql = PMA_SQP_parse($query_base);
            }
        }
        if (!empty($GLOBALS['show_as_php'])) {
            $query_base = '$sql  = "' . $query_base;
        } elseif (!empty($GLOBALS['validatequery'])) {
            $query_base = PMA_validateSQL($query_base);
        } elseif (isset($parsed_sql)) {
            $query_base = PMA_formatSql($parsed_sql, $query_base);
        }
        // Prepares links that may be displayed to edit/explain the query
        // (don't go to default pages, we must go to the page
        // where the query box is available)
        // Basic url query part
        $url_params = array();
        if (strlen($GLOBALS['db'])) {
            $url_params['db'] = $GLOBALS['db'];
            if (strlen($GLOBALS['table'])) {
                $url_params['table'] = $GLOBALS['table'];
                $edit_link = 'tbl_sql.php';
            } else {
                $edit_link = 'db_sql.php';
            }
        } else {
            $edit_link = 'server_sql.php';
        }
        // Want to have the query explained (Mike Beck 2002-05-22)
        // but only explain a SELECT (that has not been explained)
        /* SQL-Parser-Analyzer */
        $explain_link = '';
        if (!empty($cfg['SQLQuery']['Explain']) && !$query_too_big) {
            $explain_params = $url_params;
            // Detect if we are validating as well
            // To preserve the validate uRL data
            if (!empty($GLOBALS['validatequery'])) {
                $explain_params['validatequery'] = 1;
            }
            if (preg_match('@^SELECT[[:space:]]+@i', $sql_query)) {
                $explain_params['sql_query'] = 'EXPLAIN ' . $sql_query;
                $_message = $GLOBALS['strExplain'];
            } elseif (preg_match('@^EXPLAIN[[:space:]]+SELECT[[:space:]]+@i', $sql_query)) {
                $explain_params['sql_query'] = substr($sql_query, 8);
                $_message = $GLOBALS['strNoExplain'];
            }
            if (isset($explain_params['sql_query'])) {
                $explain_link = 'import.php' . PMA_generate_common_url($explain_params);
                $explain_link = ' [' . PMA_linkOrButton($explain_link, $_message) . ']';
            }
        }
        //show explain
        $url_params['sql_query'] = $sql_query;
        $url_params['show_query'] = 1;
        if (!empty($cfg['SQLQuery']['Edit']) && !$query_too_big) {
            if ($cfg['EditInWindow'] == true) {
                $onclick = 'window.parent.focus_querywindow(\'' . PMA_jsFormat($sql_query, false) . '\'); return false;';
            } else {
                $onclick = '';
            }
            $edit_link .= PMA_generate_common_url($url_params) . '#querybox';
            $edit_link = ' [' . PMA_linkOrButton($edit_link, $GLOBALS['strEdit'], array('onclick' => $onclick)) . ']';
        } else {
            $edit_link = '';
        }
        $url_qpart = PMA_generate_common_url($url_params);
        // Also we would like to get the SQL formed in some nice
        // php-code (Mike Beck 2002-05-22)
        if (!empty($cfg['SQLQuery']['ShowAsPHP']) && !$query_too_big) {
            $php_params = $url_params;
            if (!empty($GLOBALS['show_as_php'])) {
                $_message = $GLOBALS['strNoPhp'];
            } else {
                $php_params['show_as_php'] = 1;
                $_message = $GLOBALS['strPhp'];
            }
            $php_link = 'import.php' . PMA_generate_common_url($php_params);
            $php_link = ' [' . PMA_linkOrButton($php_link, $_message) . ']';
            if (isset($GLOBALS['show_as_php'])) {
                $runquery_link = 'import.php' . PMA_generate_common_url($url_params);
                $php_link .= ' [' . PMA_linkOrButton($runquery_link, $GLOBALS['strRunQuery']) . ']';
            }
        } else {
            $php_link = '';
        }
        //show as php
        // Refresh query
        if (!empty($cfg['SQLQuery']['Refresh']) && preg_match('@^(SELECT|SHOW)[[:space:]]+@i', $sql_query)) {
            $refresh_link = 'import.php' . PMA_generate_common_url($url_params);
            $refresh_link = ' [' . PMA_linkOrButton($refresh_link, $GLOBALS['strRefresh']) . ']';
        } else {
            $refresh_link = '';
        }
        //show as php
        if (!empty($cfg['SQLValidator']['use']) && !empty($cfg['SQLQuery']['Validate'])) {
            $validate_params = $url_params;
            if (!empty($GLOBALS['validatequery'])) {
                $validate_message = $GLOBALS['strNoValidateSQL'];
            } else {
                $validate_params['validatequery'] = 1;
                $validate_message = $GLOBALS['strValidateSQL'];
            }
            $validate_link = 'import.php' . PMA_generate_common_url($validate_params);
            $validate_link = ' [' . PMA_linkOrButton($validate_link, $validate_message) . ']';
        } else {
            $validate_link = '';
        }
        //validator
        echo '<code class="sql">';
        if ($query_too_big) {
            echo $shortened_query_base;
        } else {
            echo $query_base;
        }
        //Clean up the end of the PHP
        if (!empty($GLOBALS['show_as_php'])) {
            echo '";';
        }
        echo '</code>';
        echo '<div class="tools">';
        // avoid displaying a Profiling checkbox that could
        // be checked, which would reexecute an INSERT, for example
        if (!empty($refresh_link)) {
            PMA_profilingCheckbox($sql_query);
        }
        echo $edit_link . $explain_link . $php_link . $refresh_link . $validate_link;
        echo '</div>';
    }
    echo '</div><br />' . "\n";
}
Exemplo n.º 15
0
 /**
  * replaces db/table/column names with their aliases
  *
  * @param string $sql_query SQL query in which aliases are to be substituted
  * @param array  $aliases   Alias information for db/table/column
  * @param string $db        the database name
  * @param string $table     the tablename
  * @param string &$flag     the flag denoting whether any replacement was done
  *
  * @return string query replaced with aliases
  */
 public function replaceWithAliases($sql_query, $aliases, $db, $table = '', &$flag = null)
 {
     $flag = false;
     // Return original sql query if no aliases are provided.
     if (!is_array($aliases) || empty($aliases) || empty($sql_query)) {
         return $sql_query;
     }
     $supported_query_types = array('CREATE' => true);
     $supported_query_ons = array('TABLE' => true, 'VIEW' => true, 'TRIGGER' => true, 'FUNCTION' => true, 'PROCEDURE' => true);
     $identifier_types = array('alpha_identifier', 'quote_backtick');
     $query_type = '';
     $query_on = '';
     // Adjustment value for each pos value
     // of token after replacement
     $offset = 0;
     $open_braces = 0;
     $in_create_table_fields = false;
     // flag to force end query parsing
     $query_end = false;
     // Convert all line feeds to Unix style
     $sql_query = str_replace("\r\n", "\n", $sql_query);
     $sql_query = str_replace("\r", "\n", $sql_query);
     $tokens = PMA_SQP_parse($sql_query);
     $ref_seen = false;
     $ref_table_seen = false;
     $old_table = $table;
     $on_seen = false;
     $size = $tokens['len'];
     for ($i = 0; $i < $size && !$query_end; $i++) {
         $type = $tokens[$i]['type'];
         $data = $tokens[$i]['data'];
         $data_next = isset($tokens[$i + 1]['data']) ? $tokens[$i + 1]['data'] : '';
         $data_prev = $i > 0 ? $tokens[$i - 1]['data'] : '';
         $d_unq = PMA_Util::unQuote($data);
         $d_unq_next = PMA_Util::unQuote($data_next);
         $d_unq_prev = PMA_Util::unQuote($data_prev);
         $d_upper = mb_strtoupper($d_unq);
         $d_upper_next = mb_strtoupper($d_unq_next);
         $d_upper_prev = mb_strtoupper($d_unq_prev);
         $pos = $tokens[$i]['pos'] + $offset;
         if ($type === 'alpha_reservedWord') {
             if ($query_type === '' && !empty($supported_query_types[$d_upper])) {
                 $query_type = $d_upper;
             } elseif ($query_on === '' && !empty($supported_query_ons[$d_upper])) {
                 $query_on = $d_upper;
             }
         }
         // CREATE TABLE - Alias replacement
         if ($query_type === 'CREATE' && $query_on === 'TABLE') {
             // replace create table name
             if (!$in_create_table_fields && in_array($type, $identifier_types) && !empty($aliases[$db]['tables'][$table]['alias'])) {
                 $sql_query = $this->substituteAlias($sql_query, $data, $aliases[$db]['tables'][$table]['alias'], $pos, $offset);
                 $flag = true;
             } elseif ($type === 'punct_bracket_open_round') {
                 // CREATE TABLE fields started
                 if (!$in_create_table_fields) {
                     $in_create_table_fields = true;
                 }
                 $open_braces++;
             } elseif ($type === 'punct_bracket_close_round') {
                 // end our parsing after last )
                 // no columns appear after that
                 if ($in_create_table_fields && $open_braces === 0) {
                     $query_end = true;
                 }
                 // End of Foreign key reference
                 if ($ref_seen) {
                     $ref_seen = $ref_table_seen = false;
                     $table = $old_table;
                 }
                 $open_braces--;
                 // handles Foreign key references
             } elseif ($type === 'alpha_reservedWord' && $d_upper === 'REFERENCES') {
                 $ref_seen = true;
             } elseif (in_array($type, $identifier_types) && $ref_seen === true && !$ref_table_seen) {
                 $table = $d_unq;
                 $ref_table_seen = true;
                 if (!empty($aliases[$db]['tables'][$table]['alias'])) {
                     $sql_query = $this->substituteAlias($sql_query, $data, $aliases[$db]['tables'][$table]['alias'], $pos, $offset);
                     $flag = true;
                 }
                 // Replace column names
             } elseif (in_array($type, $identifier_types) && !empty($aliases[$db]['tables'][$table]['columns'][$d_unq])) {
                 $sql_query = $this->substituteAlias($sql_query, $data, $aliases[$db]['tables'][$table]['columns'][$d_unq], $pos, $offset);
                 $flag = true;
             }
             // CREATE TRIGGER - Alias replacement
         } elseif ($query_type === 'CREATE' && $query_on === 'TRIGGER') {
             // Skip till 'ON' in encountered
             if (!$on_seen && $type === 'alpha_reservedWord' && $d_upper === 'ON') {
                 $on_seen = true;
             } elseif ($on_seen && in_array($type, $identifier_types)) {
                 if (!$ref_table_seen && !empty($aliases[$db]['tables'][$d_unq]['alias'])) {
                     $ref_table_seen = true;
                     $sql_query = $this->substituteAlias($sql_query, $data, $aliases[$db]['tables'][$d_unq]['alias'], $pos, $offset);
                     $flag = true;
                 } else {
                     // search for identifier alias
                     $alias = $this->getAlias($aliases, $d_unq);
                     if (!empty($alias)) {
                         $sql_query = $this->substituteAlias($sql_query, $data, $alias, $pos, $offset);
                         $flag = true;
                     }
                 }
             }
             // CREATE PROCEDURE|FUNCTION|VIEW - Alias replacement
         } elseif ($query_type === 'CREATE' && ($query_on === 'FUNCTION' || $query_on === 'PROCEDURE' || $query_on === 'VIEW')) {
             // LANGUAGE SQL | (READS|MODIFIES) SQL DATA
             // characteristics are skipped
             if ($type === 'alpha_identifier' && ($d_upper === 'LANGUAGE' && $d_upper_next === 'SQL' || $d_upper === 'DATA' && $d_upper_prev === 'SQL')) {
                 continue;
                 // No need to process further in case of VIEW
                 // when 'WITH' keyword has been detected
             } elseif ($query_on === 'VIEW' && $type === 'alpha_reservedWord' && $d_upper === 'WITH') {
                 $query_end = true;
             } elseif (in_array($type, $identifier_types)) {
                 // search for identifier alias
                 $alias = $this->getAlias($aliases, $d_unq);
                 if (!empty($alias)) {
                     $sql_query = $this->substituteAlias($sql_query, $data, $alias, $pos, $offset);
                     $flag = true;
                 }
             }
         }
     }
     return $sql_query;
 }
Exemplo n.º 16
0
function printServerTraffic()
{
    global $server_status, $PMA_PHP_SELF;
    global $server_master_status, $server_slave_status, $replication_types;
    $hour_factor = 3600 / $server_status['Uptime'];
    /**
     * starttime calculation
     */
    $start_time = PMA_DBI_fetch_value('SELECT UNIX_TIMESTAMP() - ' . $server_status['Uptime']);
    ?>
    <h3><?php 
    echo sprintf(__('Network traffic since startup: %s'), implode(' ', PMA_formatByteDown($server_status['Bytes_received'] + $server_status['Bytes_sent'], 3, 1)));
    ?>
    </h3>

    <p>
    <?php 
    echo sprintf(__('This MySQL server has been running for %1$s. It started up on %2$s.'), PMA_timespanFormat($server_status['Uptime']), PMA_localisedDate($start_time)) . "\n";
    ?>
    </p>

    <?php 
    if ($server_master_status || $server_slave_status) {
        echo '<p class="notice">';
        if ($server_master_status && $server_slave_status) {
            echo __('This MySQL server works as <b>master</b> and <b>slave</b> in <b>replication</b> process.');
        } elseif ($server_master_status) {
            echo __('This MySQL server works as <b>master</b> in <b>replication</b> process.');
        } elseif ($server_slave_status) {
            echo __('This MySQL server works as <b>slave</b> in <b>replication</b> process.');
        }
        echo ' ';
        echo __('For further information about replication status on the server, please visit the <a href="#replication">replication section</a>.');
        echo '</p>';
    }
    /* if the server works as master or slave in replication process, display useful information */
    if ($server_master_status || $server_slave_status) {
        ?>
      <hr class="clearfloat" />

      <h3><a name="replication"></a><?php 
        echo __('Replication status');
        ?>
</h3>
    <?php 
        foreach ($replication_types as $type) {
            if (${"server_{$type}_status"}) {
                PMA_replication_print_status_table($type);
            }
        }
        unset($types);
    }
    ?>

    <table id="serverstatustraffic" class="data noclick">
    <thead>
    <tr>
        <th colspan="2"><?php 
    echo __('Traffic') . '&nbsp;' . PMA_showHint(__('On a busy server, the byte counters may overrun, so those statistics as reported by the MySQL server may be incorrect.'));
    ?>
</th>
        <th>&oslash; <?php 
    echo __('per hour');
    ?>
</th>
    </tr>
    </thead>
    <tbody>
    <tr class="odd">
        <th class="name"><?php 
    echo __('Received');
    ?>
</th>
        <td class="value"><?php 
    echo implode(' ', PMA_formatByteDown($server_status['Bytes_received'], 3, 1));
    ?>
</td>
        <td class="value"><?php 
    echo implode(' ', PMA_formatByteDown($server_status['Bytes_received'] * $hour_factor, 3, 1));
    ?>
</td>
    </tr>
    <tr class="even">
        <th class="name"><?php 
    echo __('Sent');
    ?>
</th>
        <td class="value"><?php 
    echo implode(' ', PMA_formatByteDown($server_status['Bytes_sent'], 3, 1));
    ?>
</td>
        <td class="value"><?php 
    echo implode(' ', PMA_formatByteDown($server_status['Bytes_sent'] * $hour_factor, 3, 1));
    ?>
</td>
    </tr>
    <tr class="odd">
        <th class="name"><?php 
    echo __('Total');
    ?>
</th>
        <td class="value"><?php 
    echo implode(' ', PMA_formatByteDown($server_status['Bytes_received'] + $server_status['Bytes_sent'], 3, 1));
    ?>
</td>
        <td class="value"><?php 
    echo implode(' ', PMA_formatByteDown(($server_status['Bytes_received'] + $server_status['Bytes_sent']) * $hour_factor, 3, 1));
    ?>
</td>
    </tr>
    </tbody>
    </table>

    <table id="serverstatusconnections" class="data noclick">
    <thead>
    <tr>
        <th colspan="2"><?php 
    echo __('Connections');
    ?>
</th>
        <th>&oslash; <?php 
    echo __('per hour');
    ?>
</th>
        <th>%</th>
    </tr>
    </thead>
    <tbody>
    <tr class="odd">
        <th class="name"><?php 
    echo __('max. concurrent connections');
    ?>
</th>
        <td class="value"><?php 
    echo PMA_formatNumber($server_status['Max_used_connections'], 0);
    ?>
  </td>
        <td class="value">--- </td>
        <td class="value">--- </td>
    </tr>
    <tr class="even">
        <th class="name"><?php 
    echo __('Failed attempts');
    ?>
</th>
        <td class="value"><?php 
    echo PMA_formatNumber($server_status['Aborted_connects'], 4, 1, true);
    ?>
</td>
        <td class="value"><?php 
    echo PMA_formatNumber($server_status['Aborted_connects'] * $hour_factor, 4, 2, true);
    ?>
</td>
        <td class="value"><?php 
    echo $server_status['Connections'] > 0 ? PMA_formatNumber($server_status['Aborted_connects'] * 100 / $server_status['Connections'], 0, 2, true) . '%' : '--- ';
    ?>
</td>
    </tr>
    <tr class="odd">
        <th class="name"><?php 
    echo __('Aborted');
    ?>
</th>
        <td class="value"><?php 
    echo PMA_formatNumber($server_status['Aborted_clients'], 4, 1, true);
    ?>
</td>
        <td class="value"><?php 
    echo PMA_formatNumber($server_status['Aborted_clients'] * $hour_factor, 4, 2, true);
    ?>
</td>
        <td class="value"><?php 
    echo $server_status['Connections'] > 0 ? PMA_formatNumber($server_status['Aborted_clients'] * 100 / $server_status['Connections'], 0, 2, true) . '%' : '--- ';
    ?>
</td>
    </tr>
    <tr class="even">
        <th class="name"><?php 
    echo __('Total');
    ?>
</th>
        <td class="value"><?php 
    echo PMA_formatNumber($server_status['Connections'], 4, 0);
    ?>
</td>
        <td class="value"><?php 
    echo PMA_formatNumber($server_status['Connections'] * $hour_factor, 4, 2);
    ?>
</td>
        <td class="value"><?php 
    echo PMA_formatNumber(100, 0, 2);
    ?>
%</td>
    </tr>
    </tbody>
    </table>
    <?php 
    $url_params = array();
    $show_full_sql = !empty($_REQUEST['full']);
    if ($show_full_sql) {
        $url_params['full'] = 1;
        $full_text_link = 'server_status.php' . PMA_generate_common_url(array(), 'html', '?');
    } else {
        $full_text_link = 'server_status.php' . PMA_generate_common_url(array('full' => 1));
    }
    if (PMA_DRIZZLE) {
        $sql_query = "SELECT\n                p.id       AS Id,\n                p.username AS User,\n                p.host     AS Host,\n                p.db       AS db,\n                p.command  AS Command,\n                p.time     AS Time,\n                p.state    AS State,\n                " . ($show_full_sql ? 's.query' : 'left(p.info, ' . (int) $GLOBALS['cfg']['MaxCharactersInDisplayedSQL'] . ')') . " AS Info\n            FROM data_dictionary.PROCESSLIST p\n                " . ($show_full_sql ? 'LEFT JOIN data_dictionary.SESSIONS s ON s.session_id = p.id' : '');
    } else {
        $sql_query = $show_full_sql ? 'SHOW FULL PROCESSLIST' : 'SHOW PROCESSLIST';
    }
    $result = PMA_DBI_query($sql_query);
    /**
     * Displays the page
     */
    ?>
    <table id="tableprocesslist" class="data clearfloat noclick">
    <thead>
    <tr>
        <th><?php 
    echo __('Processes');
    ?>
</th>
        <th><?php 
    echo __('ID');
    ?>
</th>
        <th><?php 
    echo __('User');
    ?>
</th>
        <th><?php 
    echo __('Host');
    ?>
</th>
        <th><?php 
    echo __('Database');
    ?>
</th>
        <th><?php 
    echo __('Command');
    ?>
</th>
        <th><?php 
    echo __('Time');
    ?>
</th>
        <th><?php 
    echo __('Status');
    ?>
</th>
        <th><?php 
    echo __('SQL query');
    if (!PMA_DRIZZLE) {
        ?>
            <a href="<?php 
        echo $full_text_link;
        ?>
"
                title="<?php 
        echo $show_full_sql ? __('Truncate Shown Queries') : __('Show Full Queries');
        ?>
">
                <img src="<?php 
        echo $GLOBALS['pmaThemeImage'] . 's_' . ($show_full_sql ? 'partial' : 'full');
        ?>
text.png"
                alt="<?php 
        echo $show_full_sql ? __('Truncate Shown Queries') : __('Show Full Queries');
        ?>
" />
            </a>
            <?php 
    }
    ?>
        </th>
    </tr>
    </thead>
    <tbody>
    <?php 
    $odd_row = true;
    while ($process = PMA_DBI_fetch_assoc($result)) {
        $url_params['kill'] = $process['Id'];
        $kill_process = 'server_status.php' . PMA_generate_common_url($url_params);
        ?>
    <tr class="<?php 
        echo $odd_row ? 'odd' : 'even';
        ?>
">
        <td><a href="<?php 
        echo $kill_process;
        ?>
"><?php 
        echo __('Kill');
        ?>
</a></td>
        <td class="value"><?php 
        echo $process['Id'];
        ?>
</td>
        <td><?php 
        echo $process['User'];
        ?>
</td>
        <td><?php 
        echo $process['Host'];
        ?>
</td>
        <td><?php 
        echo !isset($process['db']) || !strlen($process['db']) ? '<i>' . __('None') . '</i>' : $process['db'];
        ?>
</td>
        <td><?php 
        echo $process['Command'];
        ?>
</td>
        <td class="value"><?php 
        echo $process['Time'];
        ?>
</td>
        <td><?php 
        echo empty($process['State']) ? '---' : $process['State'];
        ?>
</td>
        <td>
        <?php 
        if (empty($process['Info'])) {
            echo '---';
        } else {
            if (!$show_full_sql && strlen($process['Info']) > $GLOBALS['cfg']['MaxCharactersInDisplayedSQL']) {
                echo htmlspecialchars(substr($process['Info'], 0, $GLOBALS['cfg']['MaxCharactersInDisplayedSQL'])) . '[...]';
            } else {
                echo PMA_SQP_formatHtml(PMA_SQP_parse($process['Info']));
            }
        }
        ?>
        </td>
    </tr>
        <?php 
        $odd_row = !$odd_row;
    }
    ?>
    </tbody>
    </table>
    <?php 
}
Exemplo n.º 17
0
 /**
  * Copies or renames table
  *
  * @param string $source_db    source database
  * @param string $source_table source table
  * @param string $target_db    target database
  * @param string $target_table target table
  * @param string $what         what to be moved or copied (data, dataonly)
  * @param bool   $move         whether to move
  * @param string $mode         mode
  *
  * @return bool true if success, false otherwise
  */
 public static function moveCopy($source_db, $source_table, $target_db, $target_table, $what, $move, $mode)
 {
     global $err_url;
     /* Try moving table directly */
     if ($move && $what == 'data') {
         $tbl = new PMA_Table($source_table, $source_db);
         $result = $tbl->rename($target_table, $target_db);
         if ($result) {
             $GLOBALS['message'] = $tbl->getLastMessage();
             return true;
         }
     }
     // set export settings we need
     $GLOBALS['sql_backquotes'] = 1;
     $GLOBALS['asfile'] = 1;
     // Ensure the target is valid
     if (!$GLOBALS['pma']->databases->exists($source_db, $target_db)) {
         if (!$GLOBALS['pma']->databases->exists($source_db)) {
             $GLOBALS['message'] = PMA_Message::rawError(sprintf(__('Source database `%s` was not found!'), htmlspecialchars($source_db)));
         }
         if (!$GLOBALS['pma']->databases->exists($target_db)) {
             $GLOBALS['message'] = PMA_Message::rawError(sprintf(__('Target database `%s` was not found!'), htmlspecialchars($target_db)));
         }
         return false;
     }
     $source = PMA_Util::backquote($source_db) . '.' . PMA_Util::backquote($source_table);
     if (!isset($target_db) || !strlen($target_db)) {
         $target_db = $source_db;
     }
     // Doing a select_db could avoid some problems with replicated databases,
     // when moving table from replicated one to not replicated one
     PMA_DBI_select_db($target_db);
     $target = PMA_Util::backquote($target_db) . '.' . PMA_Util::backquote($target_table);
     // do not create the table if dataonly
     if ($what != 'dataonly') {
         include_once "libraries/plugin_interface.lib.php";
         // get Export SQL instance
         $export_sql_plugin = PMA_getPlugin("export", "sql", 'libraries/plugins/export/', array('export_type' => 'table', 'single_table' => isset($single_table)));
         $no_constraints_comments = true;
         $GLOBALS['sql_constraints_query'] = '';
         $sql_structure = $export_sql_plugin->getTableDef($source_db, $source_table, "\n", $err_url, false, false);
         unset($no_constraints_comments);
         $parsed_sql = PMA_SQP_parse($sql_structure);
         $analyzed_sql = PMA_SQP_analyze($parsed_sql);
         $i = 0;
         if (empty($analyzed_sql[0]['create_table_fields'])) {
             // this is not a CREATE TABLE, so find the first VIEW
             $target_for_view = PMA_Util::backquote($target_db);
             while (true) {
                 if ($parsed_sql[$i]['type'] == 'alpha_reservedWord' && $parsed_sql[$i]['data'] == 'VIEW') {
                     break;
                 }
                 $i++;
             }
         }
         unset($analyzed_sql);
         if (PMA_DRIZZLE) {
             $table_delimiter = 'quote_backtick';
         } else {
             $server_sql_mode = PMA_DBI_fetch_value("SHOW VARIABLES LIKE 'sql_mode'", 0, 1);
             // ANSI_QUOTES might be a subset of sql_mode, for example
             // REAL_AS_FLOAT,PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ANSI
             if (false !== strpos($server_sql_mode, 'ANSI_QUOTES')) {
                 $table_delimiter = 'quote_double';
             } else {
                 $table_delimiter = 'quote_backtick';
             }
             unset($server_sql_mode);
         }
         /* Find table name in query and replace it */
         while ($parsed_sql[$i]['type'] != $table_delimiter) {
             $i++;
         }
         /* no need to backquote() */
         if (isset($target_for_view)) {
             // this a view definition; we just found the first db name
             // that follows DEFINER VIEW
             // so change it for the new db name
             $parsed_sql[$i]['data'] = $target_for_view;
             // then we have to find all references to the source db
             // and change them to the target db, ensuring we stay into
             // the $parsed_sql limits
             $last = $parsed_sql['len'] - 1;
             $backquoted_source_db = PMA_Util::backquote($source_db);
             for (++$i; $i <= $last; $i++) {
                 if ($parsed_sql[$i]['type'] == $table_delimiter && $parsed_sql[$i]['data'] == $backquoted_source_db && $parsed_sql[$i - 1]['type'] != 'punct_qualifier') {
                     $parsed_sql[$i]['data'] = $target_for_view;
                 }
             }
             unset($last, $backquoted_source_db);
         } else {
             $parsed_sql[$i]['data'] = $target;
         }
         /* Generate query back */
         $sql_structure = PMA_SQP_formatHtml($parsed_sql, 'query_only');
         // If table exists, and 'add drop table' is selected: Drop it!
         $drop_query = '';
         if (isset($_REQUEST['drop_if_exists']) && $_REQUEST['drop_if_exists'] == 'true') {
             if (PMA_Table::isView($target_db, $target_table)) {
                 $drop_query = 'DROP VIEW';
             } else {
                 $drop_query = 'DROP TABLE';
             }
             $drop_query .= ' IF EXISTS ' . PMA_Util::backquote($target_db) . '.' . PMA_Util::backquote($target_table);
             PMA_DBI_query($drop_query);
             $GLOBALS['sql_query'] .= "\n" . $drop_query . ';';
             // If an existing table gets deleted, maintain any
             // entries for the PMA_* tables
             $maintain_relations = true;
         }
         @PMA_DBI_query($sql_structure);
         $GLOBALS['sql_query'] .= "\n" . $sql_structure . ';';
         if (($move || isset($GLOBALS['add_constraints'])) && !empty($GLOBALS['sql_constraints_query'])) {
             $parsed_sql = PMA_SQP_parse($GLOBALS['sql_constraints_query']);
             $i = 0;
             // find the first $table_delimiter, it must be the source
             // table name
             while ($parsed_sql[$i]['type'] != $table_delimiter) {
                 $i++;
                 // maybe someday we should guard against going over limit
                 //if ($i == $parsed_sql['len']) {
                 //    break;
                 //}
             }
             // replace it by the target table name, no need
             // to backquote()
             $parsed_sql[$i]['data'] = $target;
             // now we must remove all $table_delimiter that follow a
             // CONSTRAINT keyword, because a constraint name must be
             // unique in a db
             $cnt = $parsed_sql['len'] - 1;
             for ($j = $i; $j < $cnt; $j++) {
                 if ($parsed_sql[$j]['type'] == 'alpha_reservedWord' && strtoupper($parsed_sql[$j]['data']) == 'CONSTRAINT') {
                     if ($parsed_sql[$j + 1]['type'] == $table_delimiter) {
                         $parsed_sql[$j + 1]['data'] = '';
                     }
                 }
             }
             // Generate query back
             $GLOBALS['sql_constraints_query'] = PMA_SQP_formatHtml($parsed_sql, 'query_only');
             if ($mode == 'one_table') {
                 PMA_DBI_query($GLOBALS['sql_constraints_query']);
             }
             $GLOBALS['sql_query'] .= "\n" . $GLOBALS['sql_constraints_query'];
             if ($mode == 'one_table') {
                 unset($GLOBALS['sql_constraints_query']);
             }
         }
     } else {
         $GLOBALS['sql_query'] = '';
     }
     // Copy the data unless this is a VIEW
     if (($what == 'data' || $what == 'dataonly') && !PMA_Table::isView($target_db, $target_table)) {
         $sql_set_mode = "SET SQL_MODE='NO_AUTO_VALUE_ON_ZERO'";
         PMA_DBI_query($sql_set_mode);
         $GLOBALS['sql_query'] .= "\n\n" . $sql_set_mode . ';';
         $sql_insert_data = 'INSERT INTO ' . $target . ' SELECT * FROM ' . $source;
         PMA_DBI_query($sql_insert_data);
         $GLOBALS['sql_query'] .= "\n\n" . $sql_insert_data . ';';
     }
     $GLOBALS['cfgRelation'] = PMA_getRelationsParam();
     // Drops old table if the user has requested to move it
     if ($move) {
         // This could avoid some problems with replicated databases, when
         // moving table from replicated one to not replicated one
         PMA_DBI_select_db($source_db);
         if (PMA_Table::isView($source_db, $source_table)) {
             $sql_drop_query = 'DROP VIEW';
         } else {
             $sql_drop_query = 'DROP TABLE';
         }
         $sql_drop_query .= ' ' . $source;
         PMA_DBI_query($sql_drop_query);
         // Renable table in configuration storage
         PMA_REL_renameTable($source_db, $target_db, $source_table, $target_table);
         $GLOBALS['sql_query'] .= "\n\n" . $sql_drop_query . ';';
         // end if ($move)
     } else {
         // we are copying
         // Create new entries as duplicates from old PMA DBs
         if ($what != 'dataonly' && !isset($maintain_relations)) {
             if ($GLOBALS['cfgRelation']['commwork']) {
                 // Get all comments and MIME-Types for current table
                 $comments_copy_query = 'SELECT
                                             column_name, comment' . ($GLOBALS['cfgRelation']['mimework'] ? ', mimetype, transformation, transformation_options' : '') . '
                                         FROM ' . PMA_Util::backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_Util::backquote($GLOBALS['cfgRelation']['column_info']) . '
                                         WHERE
                                             db_name = \'' . PMA_Util::sqlAddSlashes($source_db) . '\' AND
                                             table_name = \'' . PMA_Util::sqlAddSlashes($source_table) . '\'';
                 $comments_copy_rs = PMA_queryAsControlUser($comments_copy_query);
                 // Write every comment as new copied entry. [MIME]
                 while ($comments_copy_row = PMA_DBI_fetch_assoc($comments_copy_rs)) {
                     $new_comment_query = 'REPLACE INTO ' . PMA_Util::backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_Util::backquote($GLOBALS['cfgRelation']['column_info']) . ' (db_name, table_name, column_name, comment' . ($GLOBALS['cfgRelation']['mimework'] ? ', mimetype, transformation, transformation_options' : '') . ') ' . ' VALUES(' . '\'' . PMA_Util::sqlAddSlashes($target_db) . '\',' . '\'' . PMA_Util::sqlAddSlashes($target_table) . '\',' . '\'' . PMA_Util::sqlAddSlashes($comments_copy_row['column_name']) . '\'' . ($GLOBALS['cfgRelation']['mimework'] ? ',\'' . PMA_Util::sqlAddSlashes($comments_copy_row['comment']) . '\',' . '\'' . PMA_Util::sqlAddSlashes($comments_copy_row['mimetype']) . '\',' . '\'' . PMA_Util::sqlAddSlashes($comments_copy_row['transformation']) . '\',' . '\'' . PMA_Util::sqlAddSlashes($comments_copy_row['transformation_options']) . '\'' : '') . ')';
                     PMA_queryAsControlUser($new_comment_query);
                 }
                 // end while
                 PMA_DBI_free_result($comments_copy_rs);
                 unset($comments_copy_rs);
             }
             // duplicating the bookmarks must not be done here, but
             // just once per db
             $get_fields = array('display_field');
             $where_fields = array('db_name' => $source_db, 'table_name' => $source_table);
             $new_fields = array('db_name' => $target_db, 'table_name' => $target_table);
             PMA_Table::duplicateInfo('displaywork', 'table_info', $get_fields, $where_fields, $new_fields);
             /**
              * @todo revise this code when we support cross-db relations
              */
             $get_fields = array('master_field', 'foreign_table', 'foreign_field');
             $where_fields = array('master_db' => $source_db, 'master_table' => $source_table);
             $new_fields = array('master_db' => $target_db, 'foreign_db' => $target_db, 'master_table' => $target_table);
             PMA_Table::duplicateInfo('relwork', 'relation', $get_fields, $where_fields, $new_fields);
             $get_fields = array('foreign_field', 'master_table', 'master_field');
             $where_fields = array('foreign_db' => $source_db, 'foreign_table' => $source_table);
             $new_fields = array('master_db' => $target_db, 'foreign_db' => $target_db, 'foreign_table' => $target_table);
             PMA_Table::duplicateInfo('relwork', 'relation', $get_fields, $where_fields, $new_fields);
             $get_fields = array('x', 'y', 'v', 'h');
             $where_fields = array('db_name' => $source_db, 'table_name' => $source_table);
             $new_fields = array('db_name' => $target_db, 'table_name' => $target_table);
             PMA_Table::duplicateInfo('designerwork', 'designer_coords', $get_fields, $where_fields, $new_fields);
             /**
             * @todo Can't get duplicating PDFs the right way. The
             * page numbers always get screwed up independently from
             * duplication because the numbers do not seem to be stored on a
             * per-database basis. Would the author of pdf support please
             * have a look at it?
             *
                             $get_fields = array('page_descr');
                             $where_fields = array('db_name' => $source_db);
                             $new_fields = array('db_name' => $target_db);
                             $last_id = PMA_Table::duplicateInfo(
                'pdfwork',
                'pdf_pages',
                $get_fields,
                $where_fields,
                $new_fields
                             );
             
                             if (isset($last_id) && $last_id >= 0) {
                $get_fields = array('x', 'y');
                $where_fields = array(
                    'db_name' => $source_db,
                    'table_name' => $source_table
                );
                $new_fields = array(
                    'db_name' => $target_db,
                    'table_name' => $target_table,
                    'pdf_page_number' => $last_id
                );
                PMA_Table::duplicateInfo(
                    'pdfwork',
                    'table_coords',
                    $get_fields,
                    $where_fields,
                    $new_fields
                );
                             }
             */
         }
     }
     return true;
 }
    echo !isset($process['db']) || !strlen($process['db']) ? '<i>' . $strNone . '</i>' : $process['db'];
    ?>
</td>
    <td><?php 
    echo $process['Command'];
    ?>
</td>
    <td class="value"><?php 
    echo $process['Time'];
    ?>
</td>
    <td><?php 
    echo empty($process['State']) ? '---' : $process['State'];
    ?>
</td>
    <td><?php 
    echo empty($process['Info']) ? '---' : PMA_SQP_formatHtml(PMA_SQP_parse($process['Info']));
    ?>
</td>
</tr>
    <?php 
    $odd_row = !$odd_row;
}
?>
</tbody>
</table>
<?php 
/**
 * Sends the footer
 */
require_once './libraries/footer.inc.php';
Exemplo n.º 19
0
/**
 * Get Aliases from select query
 * Note: only useful for select query on single table.
 *
 * @param string $select_query The Select SQL Query
 * @param string $db           Current DB
 *
 * @return Array alias information from select query
 */
function PMA_SQP_getAliasesFromQuery($select_query, $db)
{
    if (empty($select_query) || empty($db)) {
        return array();
    }
    $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($select_query));
    $aliases = array($db => array('alias' => null, 'tables' => array()));
    foreach ($analyzed_sql[0]['table_ref'] as $table) {
        $t_db = !empty($table['db']) ? $table['db'] : $db;
        if (!isset($aliases[$t_db])) {
            $aliases[$t_db] = array('alias' => null, 'tables' => array());
        }
        $aliases[$t_db]['tables'][$table['table_true_name']] = array('alias' => !empty($table['table_alias']) ? $table['table_alias'] : null, 'columns' => array());
    }
    foreach ($analyzed_sql[0]['select_expr'] as $cols) {
        if (!empty($cols['alias'])) {
            $t_db = !empty($cols['db']) ? $cols['db'] : $db;
            if (!empty($cols['table_true_name'])) {
                $aliases[$t_db]['tables'][$cols['table_true_name']]['columns'][$cols['column']] = $cols['alias'];
            } else {
                foreach ($aliases[$t_db]['tables'] as $key => $table) {
                    $aliases[$t_db]['tables'][$key]['columns'][$cols['column']] = $cols['alias'];
                }
            }
        }
    }
    return $aliases;
}
Exemplo n.º 20
0
/**
 * Gets all Relations to foreign tables for a given table or
 * optionally a given column in a table
 *
 * @param   string   the name of the db to check for
 * @param   string   the name of the table to check for
 * @param   string   the name of the column to check for
 * @param   string   the source for foreign key information
 *
 * @return  array    db,table,column
 *
 * @global  array    the list of relations settings
 * @global  string   the URL of the page to show in case of error
 *
 * @access  public
 *
 * @author  Mike Beck <*****@*****.**> and Marc Delisle
 */
function PMA_getForeigners($db, $table, $column = '', $source = 'both')
{
    global $cfgRelation, $err_url_0;
    if ($cfgRelation['relwork'] && ($source == 'both' || $source == 'internal')) {
        $rel_query = '
             SELECT master_field,
                    foreign_db,
                    foreign_table,
                    foreign_field
               FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['relation']) . '
              WHERE master_db =  \'' . PMA_sqlAddslashes($db) . '\'
                AND master_table = \'' . PMA_sqlAddslashes($table) . '\' ';
        if (isset($column) && strlen($column)) {
            $rel_query .= ' AND   master_field = \'' . PMA_sqlAddslashes($column) . '\'';
        }
        $relations = PMA_query_as_cu($rel_query);
        $i = 0;
        while ($relrow = PMA_DBI_fetch_assoc($relations)) {
            $field = $relrow['master_field'];
            $foreign[$field]['foreign_db'] = $relrow['foreign_db'];
            $foreign[$field]['foreign_table'] = $relrow['foreign_table'];
            $foreign[$field]['foreign_field'] = $relrow['foreign_field'];
            $i++;
        }
        // end while
        PMA_DBI_free_result($relations);
        unset($relations);
    }
    if (($source == 'both' || $source == 'innodb') && isset($table) && strlen($table)) {
        $show_create_table_query = 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table);
        $show_create_table_res = PMA_DBI_query($show_create_table_query);
        list(, $show_create_table) = PMA_DBI_fetch_row($show_create_table_res);
        PMA_DBI_free_result($show_create_table_res);
        unset($show_create_table_res, $show_create_table_query);
        $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
        foreach ($analyzed_sql[0]['foreign_keys'] as $one_key) {
            // the analyzer may return more than one column name in the
            // index list or the ref_index_list
            foreach ($one_key['index_list'] as $i => $field) {
                // If a foreign key is defined in the 'internal' source (pmadb)
                // and in 'innodb', we won't get it twice if $source='both'
                // because we use $field as key
                // The parser looks for a CONSTRAINT clause just before
                // the FOREIGN KEY clause. It finds it (as output from
                // SHOW CREATE TABLE) in MySQL 4.0.13, but not in older
                // versions like 3.23.58.
                // In those cases, the FOREIGN KEY parsing will put numbers
                // like -1, 0, 1... instead of the constraint number.
                if (isset($one_key['constraint'])) {
                    $foreign[$field]['constraint'] = $one_key['constraint'];
                }
                if (isset($one_key['ref_db_name'])) {
                    $foreign[$field]['foreign_db'] = $one_key['ref_db_name'];
                } else {
                    $foreign[$field]['foreign_db'] = $db;
                }
                $foreign[$field]['foreign_table'] = $one_key['ref_table_name'];
                $foreign[$field]['foreign_field'] = $one_key['ref_index_list'][$i];
                if (isset($one_key['on_delete'])) {
                    $foreign[$field]['on_delete'] = $one_key['on_delete'];
                }
                if (isset($one_key['on_update'])) {
                    $foreign[$field]['on_update'] = $one_key['on_update'];
                }
            }
        }
    }
    /**
     * Emulating relations for some information_schema tables
     */
    if (PMA_MYSQL_INT_VERSION >= 50002 && $db == 'information_schema' && ($source == 'internal' || $source == 'both')) {
        require_once './libraries/information_schema_relations.lib.php';
        if (!isset($foreign)) {
            $foreign = array();
        }
        if (isset($GLOBALS['information_schema_relations'][$table])) {
            foreach ($GLOBALS['information_schema_relations'][$table] as $field => $relations) {
                if ((!isset($column) || !strlen($column) || $column == $field) && (!isset($foreign[$field]) || !strlen($foreign[$field]))) {
                    $foreign[$field] = $relations;
                }
            }
        }
    }
    if (!empty($foreign) && is_array($foreign)) {
        return $foreign;
    } else {
        return FALSE;
    }
}
Exemplo n.º 21
0
/**
 * displays the message and the query
 * usually the message is the result of the query executed
 *
 * @param string  $message   the message to display
 * @param string  $sql_query the query to display
 * @param string  $type      the type (level) of the message
 * @param boolean $is_view   is this a message after a VIEW operation?
 *
 * @return  string
 *
 * @access  public
 */
function PMA_showMessage($message, $sql_query = null, $type = 'notice', $is_view = false)
{
    /*
     * PMA_ajaxResponse uses this function to collect the string of HTML generated
     * for showing the message.  Use output buffering to collect it and return it
     * in a string.  In some special cases on sql.php, buffering has to be disabled
     * and hence we check with $GLOBALS['buffer_message']
     */
    if ($GLOBALS['is_ajax_request'] == true && !isset($GLOBALS['buffer_message'])) {
        ob_start();
    }
    global $cfg;
    if (null === $sql_query) {
        if (!empty($GLOBALS['display_query'])) {
            $sql_query = $GLOBALS['display_query'];
        } elseif ($cfg['SQP']['fmtType'] == 'none' && !empty($GLOBALS['unparsed_sql'])) {
            $sql_query = $GLOBALS['unparsed_sql'];
        } elseif (!empty($GLOBALS['sql_query'])) {
            $sql_query = $GLOBALS['sql_query'];
        } else {
            $sql_query = '';
        }
    }
    if (isset($GLOBALS['using_bookmark_message'])) {
        $GLOBALS['using_bookmark_message']->display();
        unset($GLOBALS['using_bookmark_message']);
    }
    // Corrects the tooltip text via JS if required
    // @todo this is REALLY the wrong place to do this - very unexpected here
    if (!$is_view && strlen($GLOBALS['table']) && $cfg['ShowTooltip']) {
        $tooltip = PMA_Table::sGetToolTip($GLOBALS['db'], $GLOBALS['table']);
        $uni_tbl = PMA_jsFormat($GLOBALS['db'] . '.' . $GLOBALS['table'], false);
        echo "\n";
        echo '<script type="text/javascript">' . "\n";
        echo '//<![CDATA[' . "\n";
        echo "if (window.parent.updateTableTitle) window.parent.updateTableTitle('" . $uni_tbl . "', '" . PMA_jsFormat($tooltip, false) . "');" . "\n";
        echo '//]]>' . "\n";
        echo '</script>' . "\n";
    }
    // end if ... elseif
    // Checks if the table needs to be repaired after a TRUNCATE query.
    // @todo what about $GLOBALS['display_query']???
    // @todo this is REALLY the wrong place to do this - very unexpected here
    if (strlen($GLOBALS['table']) && $GLOBALS['sql_query'] == 'TRUNCATE TABLE ' . PMA_backquote($GLOBALS['table'])) {
        if (PMA_Table::sGetStatusInfo($GLOBALS['db'], $GLOBALS['table'], 'Index_length') > 1024 && !PMA_DRIZZLE) {
            PMA_DBI_try_query('REPAIR TABLE ' . PMA_backquote($GLOBALS['table']));
        }
    }
    unset($tbl_status);
    // In an Ajax request, $GLOBALS['cell_align_left'] may not be defined. Hence,
    // check for it's presence before using it
    echo '<div id="result_query" align="' . (isset($GLOBALS['cell_align_left']) ? $GLOBALS['cell_align_left'] : '') . '">' . "\n";
    if ($message instanceof PMA_Message) {
        if (isset($GLOBALS['special_message'])) {
            $message->addMessage($GLOBALS['special_message']);
            unset($GLOBALS['special_message']);
        }
        $message->display();
        $type = $message->getLevel();
    } else {
        echo '<div class="' . $type . '">';
        echo PMA_sanitize($message);
        if (isset($GLOBALS['special_message'])) {
            echo PMA_sanitize($GLOBALS['special_message']);
            unset($GLOBALS['special_message']);
        }
        echo '</div>';
    }
    if ($cfg['ShowSQL'] == true && !empty($sql_query)) {
        // Html format the query to be displayed
        // If we want to show some sql code it is easiest to create it here
        /* SQL-Parser-Analyzer */
        if (!empty($GLOBALS['show_as_php'])) {
            $new_line = '\\n"<br />' . "\n" . '&nbsp;&nbsp;&nbsp;&nbsp;. "';
            $query_base = htmlspecialchars(addslashes($sql_query));
            $query_base = preg_replace('/((\\015\\012)|(\\015)|(\\012))/', $new_line, $query_base);
        } else {
            $query_base = $sql_query;
        }
        $query_too_big = false;
        if (strlen($query_base) > $cfg['MaxCharactersInDisplayedSQL']) {
            // when the query is large (for example an INSERT of binary
            // data), the parser chokes; so avoid parsing the query
            $query_too_big = true;
            $shortened_query_base = nl2br(htmlspecialchars(substr($sql_query, 0, $cfg['MaxCharactersInDisplayedSQL']) . '[...]'));
        } elseif (!empty($GLOBALS['parsed_sql']) && $query_base == $GLOBALS['parsed_sql']['raw']) {
            // (here, use "! empty" because when deleting a bookmark,
            // $GLOBALS['parsed_sql'] is set but empty
            $parsed_sql = $GLOBALS['parsed_sql'];
        } else {
            // Parse SQL if needed
            $parsed_sql = PMA_SQP_parse($query_base);
        }
        // Analyze it
        if (isset($parsed_sql) && !PMA_SQP_isError()) {
            $analyzed_display_query = PMA_SQP_analyze($parsed_sql);
            // Same as below (append LIMIT), append the remembered ORDER BY
            if ($GLOBALS['cfg']['RememberSorting'] && isset($analyzed_display_query[0]['queryflags']['select_from']) && isset($GLOBALS['sql_order_to_append'])) {
                $query_base = $analyzed_display_query[0]['section_before_limit'] . "\n" . $GLOBALS['sql_order_to_append'] . $analyzed_display_query[0]['limit_clause'] . ' ' . $analyzed_display_query[0]['section_after_limit'];
                // Need to reparse query
                $parsed_sql = PMA_SQP_parse($query_base);
                // update the $analyzed_display_query
                $analyzed_display_query[0]['section_before_limit'] .= $GLOBALS['sql_order_to_append'];
                $analyzed_display_query[0]['order_by_clause'] = $GLOBALS['sorted_col'];
            }
            // Here we append the LIMIT added for navigation, to
            // enable its display. Adding it higher in the code
            // to $sql_query would create a problem when
            // using the Refresh or Edit links.
            // Only append it on SELECTs.
            /**
             * @todo what would be the best to do when someone hits Refresh:
             * use the current LIMITs ?
             */
            if (isset($analyzed_display_query[0]['queryflags']['select_from']) && isset($GLOBALS['sql_limit_to_append'])) {
                $query_base = $analyzed_display_query[0]['section_before_limit'] . "\n" . $GLOBALS['sql_limit_to_append'] . $analyzed_display_query[0]['section_after_limit'];
                // Need to reparse query
                $parsed_sql = PMA_SQP_parse($query_base);
            }
        }
        if (!empty($GLOBALS['show_as_php'])) {
            $query_base = '$sql  = "' . $query_base;
        } elseif (!empty($GLOBALS['validatequery'])) {
            try {
                $query_base = PMA_validateSQL($query_base);
            } catch (Exception $e) {
                PMA_Message::error(__('Failed to connect to SQL validator!'))->display();
            }
        } elseif (isset($parsed_sql)) {
            $query_base = PMA_formatSql($parsed_sql, $query_base);
        }
        // Prepares links that may be displayed to edit/explain the query
        // (don't go to default pages, we must go to the page
        // where the query box is available)
        // Basic url query part
        $url_params = array();
        if (!isset($GLOBALS['db'])) {
            $GLOBALS['db'] = '';
        }
        if (strlen($GLOBALS['db'])) {
            $url_params['db'] = $GLOBALS['db'];
            if (strlen($GLOBALS['table'])) {
                $url_params['table'] = $GLOBALS['table'];
                $edit_link = 'tbl_sql.php';
            } else {
                $edit_link = 'db_sql.php';
            }
        } else {
            $edit_link = 'server_sql.php';
        }
        // Want to have the query explained
        // but only explain a SELECT (that has not been explained)
        /* SQL-Parser-Analyzer */
        $explain_link = '';
        $is_select = false;
        if (!empty($cfg['SQLQuery']['Explain']) && !$query_too_big) {
            $explain_params = $url_params;
            // Detect if we are validating as well
            // To preserve the validate uRL data
            if (!empty($GLOBALS['validatequery'])) {
                $explain_params['validatequery'] = 1;
            }
            if (preg_match('@^SELECT[[:space:]]+@i', $sql_query)) {
                $explain_params['sql_query'] = 'EXPLAIN ' . $sql_query;
                $_message = __('Explain SQL');
                $is_select = true;
            } elseif (preg_match('@^EXPLAIN[[:space:]]+SELECT[[:space:]]+@i', $sql_query)) {
                $explain_params['sql_query'] = substr($sql_query, 8);
                $_message = __('Skip Explain SQL');
            }
            if (isset($explain_params['sql_query'])) {
                $explain_link = 'import.php' . PMA_generate_common_url($explain_params);
                $explain_link = ' [' . PMA_linkOrButton($explain_link, $_message) . ']';
            }
        }
        //show explain
        $url_params['sql_query'] = $sql_query;
        $url_params['show_query'] = 1;
        // even if the query is big and was truncated, offer the chance
        // to edit it (unless it's enormous, see PMA_linkOrButton() )
        if (!empty($cfg['SQLQuery']['Edit'])) {
            if ($cfg['EditInWindow'] == true) {
                $onclick = 'window.parent.focus_querywindow(\'' . PMA_jsFormat($sql_query, false) . '\'); return false;';
            } else {
                $onclick = '';
            }
            $edit_link .= PMA_generate_common_url($url_params) . '#querybox';
            $edit_link = ' [' . PMA_linkOrButton($edit_link, __('Edit'), array('onclick' => $onclick)) . ']';
        } else {
            $edit_link = '';
        }
        $url_qpart = PMA_generate_common_url($url_params);
        // Also we would like to get the SQL formed in some nice
        // php-code
        if (!empty($cfg['SQLQuery']['ShowAsPHP']) && !$query_too_big) {
            $php_params = $url_params;
            if (!empty($GLOBALS['show_as_php'])) {
                $_message = __('Without PHP Code');
            } else {
                $php_params['show_as_php'] = 1;
                $_message = __('Create PHP Code');
            }
            $php_link = 'import.php' . PMA_generate_common_url($php_params);
            $php_link = ' [' . PMA_linkOrButton($php_link, $_message) . ']';
            if (isset($GLOBALS['show_as_php'])) {
                $runquery_link = 'import.php' . PMA_generate_common_url($url_params);
                $php_link .= ' [' . PMA_linkOrButton($runquery_link, __('Submit Query')) . ']';
            }
        } else {
            $php_link = '';
        }
        //show as php
        // Refresh query
        if (!empty($cfg['SQLQuery']['Refresh']) && !isset($GLOBALS['show_as_php']) && preg_match('@^(SELECT|SHOW)[[:space:]]+@i', $sql_query)) {
            $refresh_link = 'import.php' . PMA_generate_common_url($url_params);
            $refresh_link = ' [' . PMA_linkOrButton($refresh_link, __('Refresh')) . ']';
        } else {
            $refresh_link = '';
        }
        //refresh
        if (!empty($cfg['SQLValidator']['use']) && !empty($cfg['SQLQuery']['Validate'])) {
            $validate_params = $url_params;
            if (!empty($GLOBALS['validatequery'])) {
                $validate_message = __('Skip Validate SQL');
            } else {
                $validate_params['validatequery'] = 1;
                $validate_message = __('Validate SQL');
            }
            $validate_link = 'import.php' . PMA_generate_common_url($validate_params);
            $validate_link = ' [' . PMA_linkOrButton($validate_link, $validate_message) . ']';
        } else {
            $validate_link = '';
        }
        //validator
        if (!empty($GLOBALS['validatequery'])) {
            echo '<div class="sqlvalidate">';
        } else {
            echo '<code class="sql">';
        }
        if ($query_too_big) {
            echo $shortened_query_base;
        } else {
            echo $query_base;
        }
        //Clean up the end of the PHP
        if (!empty($GLOBALS['show_as_php'])) {
            echo '";';
        }
        if (!empty($GLOBALS['validatequery'])) {
            echo '</div>';
        } else {
            echo '</code>';
        }
        echo '<div class="tools">';
        // avoid displaying a Profiling checkbox that could
        // be checked, which would reexecute an INSERT, for example
        if (!empty($refresh_link)) {
            PMA_profilingCheckbox($sql_query);
        }
        // if needed, generate an invisible form that contains controls for the
        // Inline link; this way, the behavior of the Inline link does not
        // depend on the profiling support or on the refresh link
        if (empty($refresh_link) || !PMA_profilingSupported()) {
            echo '<form action="sql.php" method="post">';
            echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']);
            echo '<input type="hidden" name="sql_query" value="' . htmlspecialchars($sql_query) . '" />';
            echo '</form>';
        }
        // in the tools div, only display the Inline link when not in ajax
        // mode because 1) it currently does not work and 2) we would
        // have two similar mechanisms on the page for the same goal
        if ($is_select || $GLOBALS['is_ajax_request'] === false && !$query_too_big) {
            // see in js/functions.js the jQuery code attached to id inline_edit
            // document.write conflicts with jQuery, hence used $().append()
            echo "<script type=\"text/javascript\">\n" . "//<![CDATA[\n" . "\$('.tools form').last().after('[<a href=\"#\" title=\"" . PMA_escapeJsString(__('Inline edit of this query')) . "\" class=\"inline_edit_sql\">" . PMA_escapeJsString(_pgettext('Inline edit query', 'Inline')) . "</a>]');\n" . "//]]>\n" . "</script>";
        }
        echo $edit_link . $explain_link . $php_link . $refresh_link . $validate_link;
        echo '</div>';
    }
    echo '</div>';
    if ($GLOBALS['is_ajax_request'] === false) {
        echo '<br class="clearfloat" />';
    }
    // If we are in an Ajax request, we have most probably been called in
    // PMA_ajaxResponse().  Hence, collect the buffer contents and return it
    // to PMA_ajaxResponse(), which will encode it for JSON.
    if ($GLOBALS['is_ajax_request'] == true && !isset($GLOBALS['buffer_message'])) {
        $buffer_contents = ob_get_contents();
        ob_end_clean();
        return $buffer_contents;
    }
    return null;
}
Exemplo n.º 22
0
/**
 * Creates the HTML code that shows the routine execution dialog.
 *
 * @param array $routine Data for the routine returned by
 *                       PMA_RTN_getDataFromName()
 *
 * @return string   HTML code for the routine execution dialog.
 */
function PMA_RTN_getExecuteForm($routine)
{
    global $db, $cfg;
    // Escape special characters
    $routine['item_name'] = htmlentities($routine['item_name'], ENT_QUOTES);
    for ($i = 0; $i < $routine['item_num_params']; $i++) {
        $routine['item_param_name'][$i] = htmlentities($routine['item_param_name'][$i], ENT_QUOTES);
    }
    // Create the output
    $retval = "";
    $retval .= "<!-- START ROUTINE EXECUTE FORM -->\n\n";
    $retval .= "<form action='db_routines.php' method='post' class='rte_form'>\n";
    $retval .= "<input type='hidden' name='item_name'\n";
    $retval .= "       value='{$routine['item_name']}' />\n";
    $retval .= "<input type='hidden' name='item_type'\n";
    $retval .= "       value='{$routine['item_type']}' />\n";
    $retval .= PMA_generate_common_hidden_inputs($db) . "\n";
    $retval .= "<fieldset>\n";
    if ($GLOBALS['is_ajax_request'] != true) {
        $retval .= "<legend>{$routine['item_name']}</legend>\n";
        $retval .= "<table class='rte_table'>\n";
        $retval .= "<caption class='tblHeaders'>\n";
        $retval .= __('Routine parameters');
        $retval .= "</caption>\n";
    } else {
        $retval .= "<legend>" . __('Routine parameters') . "</legend>\n";
        $retval .= "<table class='rte_table' style='width: 100%;'>\n";
    }
    $retval .= "<tr>\n";
    $retval .= "<th>" . __('Name') . "</th>\n";
    $retval .= "<th>" . __('Type') . "</th>\n";
    if ($cfg['ShowFunctionFields']) {
        $retval .= "<th>" . __('Function') . "</th>\n";
    }
    $retval .= "<th>" . __('Value') . "</th>\n";
    $retval .= "</tr>\n";
    // Get a list of data types that are not yet supported.
    $no_support_types = PMA_Util::unsupportedDatatypes();
    for ($i = 0; $i < $routine['item_num_params']; $i++) {
        // Each parameter
        if ($routine['item_type'] == 'PROCEDURE' && $routine['item_param_dir'][$i] == 'OUT') {
            continue;
        }
        $rowclass = $i % 2 == 0 ? 'even' : 'odd';
        $retval .= "\n<tr class='{$rowclass}'>\n";
        $retval .= "<td>{$routine['item_param_name'][$i]}</td>\n";
        $retval .= "<td>{$routine['item_param_type'][$i]}</td>\n";
        if ($cfg['ShowFunctionFields']) {
            $retval .= "<td>\n";
            if (stristr($routine['item_param_type'][$i], 'enum') || stristr($routine['item_param_type'][$i], 'set') || in_array(strtolower($routine['item_param_type'][$i]), $no_support_types)) {
                $retval .= "--\n";
            } else {
                $field = array('True_Type' => strtolower($routine['item_param_type'][$i]), 'Type' => '', 'Key' => '', 'Field' => '', 'Default' => '', 'first_timestamp' => false);
                $retval .= "<select name='funcs[{$routine['item_param_name'][$i]}]'>";
                $retval .= PMA_Util::getFunctionsForField($field, false);
                $retval .= "</select>";
            }
            $retval .= "</td>\n";
        }
        // Append a class to date/time fields so that
        // jQuery can attach a datepicker to them
        $class = '';
        if ($routine['item_param_type'][$i] == 'DATETIME' || $routine['item_param_type'][$i] == 'TIMESTAMP') {
            $class = 'datetimefield';
        } else {
            if ($routine['item_param_type'][$i] == 'DATE') {
                $class = 'datefield';
            }
        }
        $retval .= "<td class='nowrap'>\n";
        if (in_array($routine['item_param_type'][$i], array('ENUM', 'SET'))) {
            $tokens = PMA_SQP_parse($routine['item_param_length'][$i]);
            if ($routine['item_param_type'][$i] == 'ENUM') {
                $input_type = 'radio';
            } else {
                $input_type = 'checkbox';
            }
            for ($j = 0; $j < $tokens['len']; $j++) {
                if ($tokens[$j]['type'] != 'punct_listsep') {
                    $tokens[$j]['data'] = htmlentities(PMA_Util::unquote($tokens[$j]['data']), ENT_QUOTES);
                    $retval .= "<input name='params[{$routine['item_param_name'][$i]}][]' " . "value='{$tokens[$j]['data']}' type='{$input_type}' />" . "{$tokens[$j]['data']}<br />\n";
                }
            }
        } else {
            if (in_array(strtolower($routine['item_param_type'][$i]), $no_support_types)) {
                $retval .= "\n";
            } else {
                $retval .= "<input class='{$class}' type='text' name='params[{$routine['item_param_name'][$i]}]' />\n";
            }
        }
        $retval .= "</td>\n";
        $retval .= "</tr>\n";
    }
    $retval .= "\n</table>\n";
    if ($GLOBALS['is_ajax_request'] != true) {
        $retval .= "</fieldset>\n\n";
        $retval .= "<fieldset class='tblFooters'>\n";
        $retval .= "    <input type='submit' name='execute_routine'\n";
        $retval .= "           value='" . __('Go') . "' />\n";
        $retval .= "</fieldset>\n";
    } else {
        $retval .= "<input type='hidden' name='execute_routine' value='true' />";
        $retval .= "<input type='hidden' name='ajax_request' value='true' />";
    }
    $retval .= "</form>\n\n";
    $retval .= "<!-- END ROUTINE EXECUTE FORM -->\n\n";
    return $retval;
}
<?php

/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
 *
 * @package phpMyAdmin
 */
if (!defined('PHPMYADMIN')) {
    exit;
}
/**
 *
 */
$GLOBALS['unparsed_sql'] = $sql_query;
$parsed_sql = PMA_SQP_parse($sql_query);
$analyzed_sql = PMA_SQP_analyze($parsed_sql);
// for bug 780516: now that we use case insensitive preg_match
// or flags from the analyser, do not put back the reformatted query
// into $sql_query, to make this kind of query work without
// capitalizing keywords:
//
// CREATE TABLE SG_Persons (
//  id int(10) unsigned NOT NULL auto_increment,
//  first varchar(64) NOT NULL default '',
//  PRIMARY KEY  (`id`)
// )
// check for a real SELECT ... FROM
$is_select = isset($analyzed_sql[0]['queryflags']['select_from']);
// 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.
// db and table name may be enclosed with backquotes, db is optionnal,
Exemplo n.º 24
0
/**
 * return html for tables' detail
 *
 * @param array  $the_tables      tables list
 * @param string $db              database name
 * @param array  $cfg             global config
 * @param array  $cfgRelation     config from PMA_getRelationsParam
 * @param int    $cell_align_left cell align left
 *
 * @return string
 */
function PMA_getHtmlForTablesDetail($the_tables, $db, $cfg, $cfgRelation, $cell_align_left)
{
    $html = '';
    $tables_cnt = count($the_tables);
    $multi_tables = count($the_tables) > 1;
    $counter = 0;
    foreach ($the_tables as $table) {
        if ($counter + 1 >= $tables_cnt) {
            $breakstyle = '';
        } else {
            $breakstyle = ' style="page-break-after: always;"';
        }
        $counter++;
        $html .= '<div' . $breakstyle . '>' . "\n";
        $html .= '<h1>' . htmlspecialchars($table) . '</h1>' . "\n";
        /**
         * Gets table informations
         */
        $showtable = PMA_Table::sGetStatusInfo($db, $table);
        $num_rows = isset($showtable['Rows']) ? $showtable['Rows'] : 0;
        $show_comment = isset($showtable['Comment']) ? $showtable['Comment'] : '';
        $tbl_is_view = PMA_Table::isView($db, $table);
        /**
         * Gets fields properties
         */
        $columns = $GLOBALS['dbi']->getColumns($db, $table);
        // We need this to correctly learn if a TIMESTAMP is NOT NULL, since
        // SHOW FULL FIELDS or INFORMATION_SCHEMA incorrectly says NULL
        // and SHOW CREATE TABLE says NOT NULL (tested
        // in MySQL 4.0.25 and 5.0.21, http://bugs.mysql.com/20910).
        $show_create_table = $GLOBALS['dbi']->fetchValue('SHOW CREATE TABLE ' . PMA_Util::backquote($db) . '.' . PMA_Util::backquote($table), 0, 1);
        $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
        // Check if we can use Relations
        // Find which tables are related with the current one and write it in
        // an array
        $res_rel = PMA_getForeigners($db, $table);
        $have_rel = (bool) count($res_rel);
        /**
         * Displays the comments of the table if MySQL >= 3.23
         */
        if (!empty($show_comment)) {
            $html .= __('Table comments:') . ' ' . htmlspecialchars($show_comment) . '<br /><br />';
        }
        $html .= PMA_getHtmlForTableStructure($have_rel, $tbl_is_view, $columns, $analyzed_sql, $res_rel, $db, $table, $cfgRelation, $cfg, $showtable, $cell_align_left);
        if ($multi_tables) {
            unset($num_rows, $show_comment);
            $html .= '<hr />' . "\n";
        }
        // end if
        $html .= '</div>' . "\n";
    }
    // end while
    return $html;
}
Exemplo n.º 25
0
if (!empty($disp_message)) {
    if (!isset($disp_query)) {
        $disp_query = null;
    }
    PMA_showMessage($disp_message, $disp_query);
}
/**
 * Displays top menu links
 */
require_once './libraries/tbl_links.inc.php';
/**
 * Get the analysis of SHOW CREATE TABLE for this table
 * @todo should be handled by class Table
 */
$show_create_table = PMA_DBI_fetch_value('SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table), 0, 1);
$analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
unset($show_create_table);
/**
 * Get the list of the fields of the current table
 */
PMA_DBI_select_db($db);
$table_fields = PMA_DBI_fetch_result('SHOW FIELDS FROM ' . PMA_backquote($table) . ';', null, null, null, PMA_DBI_QUERY_STORE);
$rows = array();
if (isset($where_clause)) {
    // when in edit mode load all selected rows from table
    $insert_mode = false;
    if (is_array($where_clause)) {
        $where_clause_array = $where_clause;
    } else {
        $where_clause_array = array(0 => $where_clause);
    }
 /**
  * Prepare rows
  *
  * @param integer &$dt_result         the link id associated to the query
  *                                    which results have to be displayed
  * @param array   $row                current row data
  * @param integer $row_no             the index of current row
  * @param array   $col_order          the column order
  *                                    false when a property not found
  * @param array   $map                the list of relations
  * @param string  $grid_edit_class    the class for all editable columns
  * @param boolean $col_visib          column is visible(false)
  *        array                       column isn't visible(string array)
  * @param string  $where_clause       where clause
  * @param string  $url_sql_query      the analyzed sql query
  * @param array   $analyzed_sql       the analyzed query
  * @param boolean $directionCondition the directional condition
  *
  * @return  string $row_values_html  html content
  *
  * @access  private
  *
  * @see     _getTableBody()
  */
 private function _getRowValues(&$dt_result, $row, $row_no, $col_order, $map, $grid_edit_class, $col_visib, $where_clause, $url_sql_query, $analyzed_sql, $directionCondition)
 {
     $row_values_html = '';
     // Following variable are needed for use in isset/empty or
     // use with array indexes/safe use in foreach
     $sql_query = $this->__get('_sql_query');
     $fields_meta = $this->__get('_fields_meta');
     $highlight_columns = $this->__get('_highlight_columns');
     $mime_map = $this->__get('_mime_map');
     $row_info = $this->_getRowInfoForSpecialLinks($row, $col_order);
     for ($j = 0; $j < $this->__get('_fields_cnt'); ++$j) {
         // assign $i with appropriate column order
         $i = $col_order ? $col_order[$j] : $j;
         $meta = $fields_meta[$i];
         $not_null_class = $meta->not_null ? 'not_null' : '';
         $relation_class = isset($map[$meta->name]) ? 'relation' : '';
         $hide_class = $col_visib && !$col_visib[$j] && $_SESSION['tmp_user_values']['disp_direction'] != self::DISP_DIR_VERTICAL ? 'hide' : '';
         // handle datetime-related class, for grid editing
         $field_type_class = $this->_getClassForDateTimeRelatedFields($meta->type);
         $pointer = $i;
         $is_field_truncated = false;
         //If the previous column had blob data, we need to reset the class
         // to $inline_edit_class
         $class = $this->_getResettedClassForInlineEdit($grid_edit_class, $not_null_class, $relation_class, $hide_class, $field_type_class, $row_no);
         //  See if this column should get highlight because it's used in the
         //  where-query.
         $condition_field = isset($highlight_columns) && (isset($highlight_columns[$meta->name]) || isset($highlight_columns[$this->getCommonFunctions()->backquote($meta->name)])) ? true : false;
         // Wrap MIME-transformations. [MIME]
         $default_function = '_mimeDefaultFunction';
         // default_function
         $transformation_plugin = $default_function;
         $transform_options = array();
         if ($GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME']) {
             if (isset($mime_map[$meta->name]['mimetype']) && isset($mime_map[$meta->name]['transformation']) && !empty($mime_map[$meta->name]['transformation'])) {
                 $file = $mime_map[$meta->name]['transformation'];
                 $include_file = 'libraries/plugins/transformations/' . $file;
                 if (file_exists($include_file)) {
                     include_once $include_file;
                     $class_name = str_replace('.class.php', '', $file);
                     // todo add $plugin_manager
                     $plugin_manager = null;
                     $transformation_plugin = new $class_name($plugin_manager);
                     $transform_options = PMA_transformation_getOptions(isset($mime_map[$meta->name]['transformation_options']) ? $mime_map[$meta->name]['transformation_options'] : '');
                     $meta->mimetype = str_replace('_', '/', $mime_map[$meta->name]['mimetype']);
                 }
                 // end if file_exists
             }
             // end if transformation is set
         }
         // end if mime/transformation works.
         $_url_params = array('db' => $this->__get('_db'), 'table' => $this->__get('_table'), 'where_clause' => $where_clause, 'transform_key' => $meta->name);
         if (!empty($sql_query)) {
             $_url_params['sql_query'] = $url_sql_query;
         }
         $transform_options['wrapper_link'] = PMA_generate_common_url($_url_params);
         $vertical_display = $this->__get('_vertical_display');
         // Check whether the field needs to display with syntax highlighting
         if ($this->_isNeedToSytaxHighlight($meta->name) && trim($row[$i]) != '') {
             $parsed_sql = PMA_SQP_parse($row[$i]);
             $row[$i] = PMA_CommonFunctions::getInstance()->formatSql($parsed_sql, $row[$i]);
             include_once $this->sytax_highlighting_column_info[strtolower($this->__get('_db'))][strtolower($this->__get('_table'))][strtolower($meta->name)][0];
             $transformation_plugin = new $this->sytax_highlighting_column_info[strtolower($this->__get('_db'))][strtolower($this->__get('_table'))][strtolower($meta->name)][1](null);
             $transform_options = PMA_transformation_getOptions(isset($mime_map[$meta->name]['transformation_options']) ? $mime_map[$meta->name]['transformation_options'] : '');
             $meta->mimetype = str_replace('_', '/', $this->sytax_highlighting_column_info[strtolower($this->__get('_db'))][strtolower($this->__get('_table'))][strtolower($meta->name)][2]);
         }
         // Check for the predefined fields need to show as link in schemas
         include_once 'libraries/special_schema_links.lib.php';
         if (isset($GLOBALS['special_schema_links']) && $this->_isFieldNeedToLink(strtolower($meta->name))) {
             $linking_url = $this->_getSpecialLinkUrl($row[$i], $row_info, strtolower($meta->name));
             include_once "libraries/plugins/transformations/Text_Plain_Link.class.php";
             $transformation_plugin = new Text_Plain_Link(null);
             $transform_options = array(0 => $linking_url, 2 => true);
             $meta->mimetype = str_replace('_', '/', 'Text/Plain');
         }
         if ($meta->numeric == 1) {
             // n u m e r i c
             // if two fields have the same name (this is possible
             //       with self-join queries, for example), using $meta->name
             //       will show both fields NULL even if only one is NULL,
             //       so use the $pointer
             $vertical_display['data'][$row_no][$i] = $this->_getDataCellForNumericColumns($row[$i], $class, $condition_field, $meta, $map, $is_field_truncated, $analyzed_sql, $transformation_plugin, $default_function, $transform_options);
         } elseif (stristr($meta->type, self::BLOB_FIELD)) {
             //  b l o b
             // PMA_mysql_fetch_fields returns BLOB in place of
             // TEXT fields type so we have to ensure it's really a BLOB
             $field_flags = PMA_DBI_field_flags($dt_result, $i);
             $vertical_display['data'][$row_no][$i] = $this->_getDataCellForBlobColumns($row[$i], $class, $meta, $_url_params, $field_flags, $transformation_plugin, $default_function, $transform_options, $condition_field, $is_field_truncated);
         } elseif ($meta->type == self::GEOMETRY_FIELD) {
             // g e o m e t r y
             // Remove 'grid_edit' from $class as we do not allow to
             // inline-edit geometry data.
             $class = str_replace('grid_edit', '', $class);
             $vertical_display['data'][$row_no][$i] = $this->_getDataCellForGeometryColumns($row[$i], $class, $meta, $map, $_url_params, $condition_field, $transformation_plugin, $default_function, $transform_options, $is_field_truncated, $analyzed_sql);
         } else {
             // n o t   n u m e r i c   a n d   n o t   B L O B
             $vertical_display['data'][$row_no][$i] = $this->_getDataCellForNonNumericAndNonBlobColumns($row[$i], $class, $meta, $map, $_url_params, $condition_field, $transformation_plugin, $default_function, $transform_options, $is_field_truncated, $analyzed_sql, $dt_result, $i);
         }
         // output stored cell
         if ($directionCondition) {
             $row_values_html .= $vertical_display['data'][$row_no][$i];
         }
         if (isset($vertical_display['rowdata'][$i][$row_no])) {
             $vertical_display['rowdata'][$i][$row_no] .= $vertical_display['data'][$row_no][$i];
         } else {
             $vertical_display['rowdata'][$i][$row_no] = $vertical_display['data'][$row_no][$i];
         }
         $this->__set('_vertical_display', $vertical_display);
     }
     // end for
     return $row_values_html;
 }
Exemplo n.º 27
0
/**
 * Gets all Relations to foreign tables for a given table or
 * optionally a given column in a table
 *
 * @param string $db     the name of the db to check for
 * @param string $table  the name of the table to check for
 * @param string $column the name of the column to check for
 * @param string $source the source for foreign key information
 *
 * @return array    db,table,column
 *
 * @access  public
 */
function PMA_getForeigners($db, $table, $column = '', $source = 'both')
{
    $cfgRelation = PMA_getRelationsParam();
    $foreign = array();
    if ($cfgRelation['relwork'] && ($source == 'both' || $source == 'internal')) {
        $rel_query = '
             SELECT `master_field`,
                    `foreign_db`,
                    `foreign_table`,
                    `foreign_field`
               FROM ' . PMA_Util::backquote($cfgRelation['db']) . '.' . PMA_Util::backquote($cfgRelation['relation']) . '
              WHERE `master_db`    = \'' . PMA_Util::sqlAddSlashes($db) . '\'
                AND `master_table` = \'' . PMA_Util::sqlAddSlashes($table) . '\' ';
        if (mb_strlen($column)) {
            $rel_query .= ' AND `master_field` = ' . '\'' . PMA_Util::sqlAddSlashes($column) . '\'';
        }
        $foreign = $GLOBALS['dbi']->fetchResult($rel_query, 'master_field', null, $GLOBALS['controllink']);
    }
    if (($source == 'both' || $source == 'foreign') && mb_strlen($table)) {
        $showCreateTableQuery = 'SHOW CREATE TABLE ' . PMA_Util::backquote($db) . '.' . PMA_Util::backquote($table);
        $show_create_table = $GLOBALS['dbi']->fetchValue($showCreateTableQuery, 0, 1);
        if ($show_create_table) {
            $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
            $foreign['foreign_keys_data'] = $analyzed_sql[0]['foreign_keys'];
        }
    }
    /**
     * Emulating relations for some information_schema and data_dictionary tables
     */
    $isInformationSchema = mb_strtolower($db) == 'information_schema';
    $is_data_dictionary = PMA_DRIZZLE && mb_strtolower($db) == 'data_dictionary';
    $isMysql = mb_strtolower($db) == 'mysql';
    if (($isInformationSchema || $is_data_dictionary || $isMysql) && ($source == 'internal' || $source == 'both')) {
        if ($isInformationSchema) {
            $relations_key = 'information_schema_relations';
            include_once './libraries/information_schema_relations.lib.php';
        } else {
            if ($is_data_dictionary) {
                $relations_key = 'data_dictionary_relations';
                include_once './libraries/data_dictionary_relations.lib.php';
            } else {
                $relations_key = 'mysql_relations';
                include_once './libraries/mysql_relations.lib.php';
            }
        }
        if (isset($GLOBALS[$relations_key][$table])) {
            foreach ($GLOBALS[$relations_key][$table] as $field => $relations) {
                if ((!mb_strlen($column) || $column == $field) && (!isset($foreign[$field]) || !mb_strlen($foreign[$field]))) {
                    $foreign[$field] = $relations;
                }
            }
        }
    }
    return $foreign;
}
Exemplo n.º 28
0
/**
 * Prints server traffic information
 *
 * @param Object $ServerStatusData An instance of the PMA_ServerStatusData class
 *
 * @return string
 */
function getServerTrafficHtml($ServerStatusData)
{
    $hour_factor = 3600 / $ServerStatusData->status['Uptime'];
    $start_time = PMA_DBI_fetch_value('SELECT UNIX_TIMESTAMP() - ' . $ServerStatusData->status['Uptime']);
    $retval = '<h3>';
    $retval .= sprintf(__('Network traffic since startup: %s'), implode(' ', PMA_Util::formatByteDown($ServerStatusData->status['Bytes_received'] + $ServerStatusData->status['Bytes_sent'], 3, 1)));
    $retval .= '</h3>';
    $retval .= '<p>';
    $retval .= sprintf(__('This MySQL server has been running for %1$s. It started up on %2$s.'), PMA_Util::timespanFormat($ServerStatusData->status['Uptime']), PMA_Util::localisedDate($start_time)) . "\n";
    $retval .= '</p>';
    if ($GLOBALS['server_master_status'] || $GLOBALS['server_slave_status']) {
        $retval .= '<p class="notice">';
        if ($GLOBALS['server_master_status'] && $GLOBALS['server_slave_status']) {
            $retval .= __('This MySQL server works as <b>master</b> and ' . '<b>slave</b> in <b>replication</b> process.');
        } elseif ($GLOBALS['server_master_status']) {
            $retval .= __('This MySQL server works as <b>master</b> ' . 'in <b>replication</b> process.');
        } elseif ($GLOBALS['server_slave_status']) {
            $retval .= __('This MySQL server works as <b>slave</b> ' . 'in <b>replication</b> process.');
        }
        $retval .= ' ';
        $retval .= __('For further information about replication status on the server, ' . 'please visit the <a href="#replication">replication section</a>.');
        $retval .= '</p>';
    }
    /*
     * if the server works as master or slave in replication process,
     * display useful information
     */
    if ($GLOBALS['server_master_status'] || $GLOBALS['server_slave_status']) {
        $retval .= '<hr class="clearfloat" />';
        $retval .= '<h3><a name="replication">';
        $retval .= __('Replication status');
        $retval .= '</a></h3>';
        foreach ($GLOBALS['replication_types'] as $type) {
            if (isset(${"server_{$type}_status"}) && ${"server_{$type}_status"}) {
                PMA_replication_print_status_table($type);
            }
        }
    }
    $retval .= '<table id="serverstatustraffic" class="data noclick">';
    $retval .= '<thead>';
    $retval .= '<tr>';
    $retval .= '<th colspan="2">';
    $retval .= __('Traffic') . '&nbsp;';
    $retval .= PMA_Util::showHint(__('On a busy server, the byte counters may overrun, so those statistics ' . 'as reported by the MySQL server may be incorrect.'));
    $retval .= '</th>';
    $retval .= '<th>&oslash; ' . __('per hour') . '</th>';
    $retval .= '</tr>';
    $retval .= '</thead>';
    $retval .= '<tbody>';
    $retval .= '<tr class="odd">';
    $retval .= '<th class="name">' . __('Received') . '</th>';
    $retval .= '<td class="value">';
    $retval .= implode(' ', PMA_Util::formatByteDown($ServerStatusData->status['Bytes_received'], 3, 1));
    $retval .= '</td>';
    $retval .= '<td class="value">';
    $retval .= implode(' ', PMA_Util::formatByteDown($ServerStatusData->status['Bytes_received'] * $hour_factor, 3, 1));
    $retval .= '</td>';
    $retval .= '</tr>';
    $retval .= '<tr class="even">';
    $retval .= '<th class="name">' . __('Sent') . '</th>';
    $retval .= '<td class="value">';
    $retval .= implode(' ', PMA_Util::formatByteDown($ServerStatusData->status['Bytes_sent'], 3, 1));
    $retval .= '</td>';
    $retval .= '<td class="value"><?php echo';
    $retval .= implode(' ', PMA_Util::formatByteDown($ServerStatusData->status['Bytes_sent'] * $hour_factor, 3, 1));
    $retval .= '</td>';
    $retval .= '</tr>';
    $retval .= '<tr class="odd">';
    $retval .= '<th class="name">' . __('Total') . '</th>';
    $retval .= '<td class="value">';
    $retval .= implode(' ', PMA_Util::formatByteDown($ServerStatusData->status['Bytes_received'] + $ServerStatusData->status['Bytes_sent'], 3, 1));
    $retval .= '</td>';
    $retval .= '<td class="value">';
    $retval .= implode(' ', PMA_Util::formatByteDown(($ServerStatusData->status['Bytes_received'] + $ServerStatusData->status['Bytes_sent']) * $hour_factor, 3, 1));
    $retval .= '</td>';
    $retval .= '</tr>';
    $retval .= '</tbody>';
    $retval .= '</table>';
    $retval .= '<table id="serverstatusconnections" class="data noclick">';
    $retval .= '<thead>';
    $retval .= '<tr>';
    $retval .= '<th colspan="2">' . __('Connections') . '</th>';
    $retval .= '<th>&oslash; ' . __('per hour') . '</th>';
    $retval .= '<th>%</th>';
    $retval .= '</tr>';
    $retval .= '</thead>';
    $retval .= '<tbody>';
    $retval .= '<tr class="odd">';
    $retval .= '<th class="name">' . __('max. concurrent connections') . '</th>';
    $retval .= '<td class="value">';
    $retval .= PMA_Util::formatNumber($ServerStatusData->status['Max_used_connections'], 0);
    $retval .= '</td>';
    $retval .= '<td class="value">--- </td>';
    $retval .= '<td class="value">--- </td>';
    $retval .= '</tr>';
    $retval .= '<tr class="even">';
    $retval .= '<th class="name">' . __('Failed attempts') . '</th>';
    $retval .= '<td class="value">';
    $retval .= PMA_Util::formatNumber($ServerStatusData->status['Aborted_connects'], 4, 1, true);
    $retval .= '</td>';
    $retval .= '<td class="value">';
    $retval .= PMA_Util::formatNumber($ServerStatusData->status['Aborted_connects'] * $hour_factor, 4, 2, true);
    $retval .= '</td>';
    $retval .= '<td class="value">';
    if ($ServerStatusData->status['Connections'] > 0) {
        $retval .= PMA_Util::formatNumber($ServerStatusData->status['Aborted_connects'] * 100 / $ServerStatusData->status['Connections'], 0, 2, true);
        $retval .= '%';
    } else {
        $retval .= '--- ';
    }
    $retval .= '</td>';
    $retval .= '</tr>';
    $retval .= '<tr class="odd">';
    $retval .= '<th class="name">' . __('Aborted') . '</th>';
    $retval .= '<td class="value">';
    $retval .= PMA_Util::formatNumber($ServerStatusData->status['Aborted_clients'], 4, 1, true);
    $retval .= '</td>';
    $retval .= '<td class="value">';
    $retval .= PMA_Util::formatNumber($ServerStatusData->status['Aborted_clients'] * $hour_factor, 4, 2, true);
    $retval .= '</td>';
    $retval .= '<td class="value">';
    if ($ServerStatusData->status['Connections'] > 0) {
        $retval .= PMA_Util::formatNumber($ServerStatusData->status['Aborted_clients'] * 100 / $ServerStatusData->status['Connections'], 0, 2, true);
        $retval .= '%';
    } else {
        $retval .= '--- ';
    }
    $retval .= '</td>';
    $retval .= '</tr>';
    $retval .= '<tr class="even">';
    $retval .= '<th class="name">' . __('Total') . '</th>';
    $retval .= '<td class="value">';
    $retval .= PMA_Util::formatNumber($ServerStatusData->status['Connections'], 4, 0);
    $retval .= '</td>';
    $retval .= '<td class="value">';
    $retval .= PMA_Util::formatNumber($ServerStatusData->status['Connections'] * $hour_factor, 4, 2);
    $retval .= '</td>';
    $retval .= '<td class="value">';
    $retval .= PMA_Util::formatNumber(100, 0, 2);
    $retval .= '%</td>';
    $retval .= '</tr>';
    $retval .= '</tbody>';
    $retval .= '</table>';
    $url_params = array();
    $show_full_sql = !empty($_REQUEST['full']);
    if ($show_full_sql) {
        $url_params['full'] = 1;
        $full_text_link = 'server_status.php' . PMA_generate_common_url(array(), 'html', '?');
    } else {
        $full_text_link = 'server_status.php' . PMA_generate_common_url(array('full' => 1));
    }
    // This array contains display name and real column name of each
    // sortable column in the table
    $sortable_columns = array(array('column_name' => __('ID'), 'order_by_field' => 'Id'), array('column_name' => __('User'), 'order_by_field' => 'User'), array('column_name' => __('Host'), 'order_by_field' => 'Host'), array('column_name' => __('Database'), 'order_by_field' => 'db'), array('column_name' => __('Command'), 'order_by_field' => 'Command'), array('column_name' => __('Time'), 'order_by_field' => 'Time'), array('column_name' => __('Status'), 'order_by_field' => 'State'), array('column_name' => __('SQL query'), 'order_by_field' => 'Info'));
    $sortable_columns_count = count($sortable_columns);
    if (PMA_DRIZZLE) {
        $sql_query = "SELECT\n                p.id       AS Id,\n                p.username AS User,\n                p.host     AS Host,\n                p.db       AS db,\n                p.command  AS Command,\n                p.time     AS Time,\n                p.state    AS State,\n                " . ($show_full_sql ? 's.query' : 'left(p.info, ' . (int) $GLOBALS['cfg']['MaxCharactersInDisplayedSQL'] . ')') . " AS Info\n            FROM data_dictionary.PROCESSLIST p\n                " . ($show_full_sql ? 'LEFT JOIN data_dictionary.SESSIONS s ON s.session_id = p.id' : '');
        if (!empty($_REQUEST['order_by_field']) && !empty($_REQUEST['sort_order'])) {
            $sql_query .= ' ORDER BY p.' . $_REQUEST['order_by_field'] . ' ' . $_REQUEST['sort_order'];
        }
    } else {
        $sql_query = $show_full_sql ? 'SHOW FULL PROCESSLIST' : 'SHOW PROCESSLIST';
        if (!empty($_REQUEST['order_by_field']) && !empty($_REQUEST['sort_order'])) {
            $sql_query = 'SELECT * FROM `INFORMATION_SCHEMA`.`PROCESSLIST` ORDER BY `' . $_REQUEST['order_by_field'] . '` ' . $_REQUEST['sort_order'];
        }
    }
    $result = PMA_DBI_query($sql_query);
    /**
     * Displays the page
     */
    $retval .= '<table id="tableprocesslist" class="data clearfloat noclick sortable">';
    $retval .= '<thead>';
    $retval .= '<tr>';
    $retval .= '<th>' . __('Processes') . '</th>';
    foreach ($sortable_columns as $column) {
        $is_sorted = !empty($_REQUEST['order_by_field']) && !empty($_REQUEST['sort_order']) && $_REQUEST['order_by_field'] == $column['order_by_field'];
        $column['sort_order'] = 'ASC';
        if ($is_sorted && $_REQUEST['sort_order'] === 'ASC') {
            $column['sort_order'] = 'DESC';
        }
        if ($is_sorted) {
            if ($_REQUEST['sort_order'] == 'ASC') {
                $asc_display_style = 'inline';
                $desc_display_style = 'none';
            } elseif ($_REQUEST['sort_order'] == 'DESC') {
                $desc_display_style = 'inline';
                $asc_display_style = 'none';
            }
        }
        $retval .= '<th>';
        $retval .= '<a href="server_status.php' . PMA_generate_common_url($column) . '" ';
        if ($is_sorted) {
            $retval .= 'onmouseout="$(\'.soimg\').toggle()" ' . 'onmouseover="$(\'.soimg\').toggle()"';
        }
        $retval .= '>';
        $retval .= $column['column_name'];
        if ($is_sorted) {
            $retval .= '<img class="icon ic_s_desc soimg" alt="' . __('Descending') . '" title="" src="themes/dot.gif" ' . 'style="display: ' . $desc_display_style . '" />';
            $retval .= '<img class="icon ic_s_asc soimg hide" alt="' . __('Ascending') . '" title="" src="themes/dot.gif" ' . 'style="display: ' . $asc_display_style . '" />';
        }
        $retval .= '</a>';
        if (!PMA_DRIZZLE && 0 === --$sortable_columns_count) {
            $retval .= '<a href="' . $full_text_link . '">';
            if ($show_full_sql) {
                $retval .= PMA_Util::getImage('s_partialtext.png', __('Truncate Shown Queries'));
            } else {
                $retval .= PMA_Util::getImage('s_fulltext.png', __('Show Full Queries'));
            }
            $retval .= '</a>';
        }
        $retval .= '</th>';
    }
    $retval .= '</tr>';
    $retval .= '</thead>';
    $retval .= '<tbody>';
    $odd_row = true;
    while ($process = PMA_DBI_fetch_assoc($result)) {
        // Array keys need to modify due to the way it has used
        // to display column values
        if (!empty($_REQUEST['order_by_field']) && !empty($_REQUEST['sort_order'])) {
            foreach (array_keys($process) as $key) {
                $new_key = ucfirst(strtolower($key));
                $process[$new_key] = $process[$key];
                unset($process[$key]);
            }
        }
        $url_params['kill'] = $process['Id'];
        $kill_process = 'server_status.php' . PMA_generate_common_url($url_params);
        $retval .= '<tr class="' . ($odd_row ? 'odd' : 'even') . '">';
        $retval .= '<td><a href="' . $kill_process . '">' . __('Kill') . '</a></td>';
        $retval .= '<td class="value">' . $process['Id'] . '</td>';
        $retval .= '<td>' . htmlspecialchars($process['User']) . '</td>';
        $retval .= '<td>' . htmlspecialchars($process['Host']) . '</td>';
        $retval .= '<td>' . (!isset($process['db']) || !strlen($process['db']) ? '<i>' . __('None') . '</i>' : htmlspecialchars($process['db'])) . '</td>';
        $retval .= '<td>' . htmlspecialchars($process['Command']) . '</td>';
        $retval .= '<td class="value">' . $process['Time'] . '</td>';
        $retval .= '<td>' . (empty($process['State']) ? '---' : $process['State']) . '</td>';
        $retval .= '<td>';
        if (empty($process['Info'])) {
            $retval .= '---';
        } else {
            if (!$show_full_sql && strlen($process['Info']) > $GLOBALS['cfg']['MaxCharactersInDisplayedSQL']) {
                $retval .= htmlspecialchars(substr($process['Info'], 0, $GLOBALS['cfg']['MaxCharactersInDisplayedSQL'])) . '[...]';
            } else {
                $retval .= PMA_SQP_formatHtml(PMA_SQP_parse($process['Info']));
            }
        }
        $retval .= '</td>';
        $retval .= '</tr>';
        $odd_row = !$odd_row;
    }
    $retval .= '</tbody>';
    $retval .= '</table>';
    return $retval;
}
Exemplo n.º 29
0
        ?>
</th>
            <th><?php 
        echo $strTrackingDataManipulationStatement;
        ?>
</th>
        </tr>
        </thead>
        <tbody>
        <?php 
        $style = 'odd';
        foreach ($data['dmlog'] as $entry) {
            if (strlen($entry['statement']) > $GLOBALS['cfg']['MaxCharactersInDisplayedSQL']) {
                $statement = substr($entry['statement'], 0, $GLOBALS['cfg']['MaxCharactersInDisplayedSQL']) . '[...]';
            } else {
                $statement = PMA_formatSql(PMA_SQP_parse($entry['statement']));
            }
            $timestamp = strtotime($entry['date']);
            if ($timestamp >= $filter_ts_from && $timestamp <= $filter_ts_to && (in_array('*', $filter_users) || in_array($entry['username'], $filter_users))) {
                ?>
                <tr class="<?php 
                echo $style;
                ?>
">
                    <td><small><?php 
                echo $i;
                ?>
</small></td>
                    <td><small><?php 
                echo $entry['date'];
                ?>
Exemplo n.º 30
0
/**
 * Gets all Relations to foreign tables for a given table or
 * optionally a given column in a table
 *
 * @param string $db     the name of the db to check for
 * @param string $table  the name of the table to check for
 * @param string $column the name of the column to check for
 * @param string $source the source for foreign key information
 *
 * @return  array    db,table,column
 *
 * @access  public
 */
function PMA_getForeigners($db, $table, $column = '', $source = 'both')
{
    $cfgRelation = PMA_getRelationsParam();
    $foreign = array();
    if ($cfgRelation['relwork'] && ($source == 'both' || $source == 'internal')) {
        $rel_query = '
             SELECT `master_field`,
                    `foreign_db`,
                    `foreign_table`,
                    `foreign_field`
               FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['relation']) . '
              WHERE `master_db`    = \'' . PMA_sqlAddSlashes($db) . '\'
                AND `master_table` = \'' . PMA_sqlAddSlashes($table) . '\' ';
        if (strlen($column)) {
            $rel_query .= ' AND `master_field` = \'' . PMA_sqlAddSlashes($column) . '\'';
        }
        $foreign = PMA_DBI_fetch_result($rel_query, 'master_field', null, $GLOBALS['controllink']);
    }
    if (($source == 'both' || $source == 'foreign') && strlen($table)) {
        $show_create_table_query = 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table);
        $show_create_table = PMA_DBI_fetch_value($show_create_table_query, 0, 1);
        $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
        foreach ($analyzed_sql[0]['foreign_keys'] as $one_key) {
            // The analyzer may return more than one column name in the
            // index list or the ref_index_list; if this happens,
            // the current logic just discards the whole index; having
            // more than one index field is currently unsupported (see FAQ 3.6)
            if (count($one_key['index_list']) == 1) {
                foreach ($one_key['index_list'] as $i => $field) {
                    // If a foreign key is defined in the 'internal' source (pmadb)
                    // and as a native foreign key, we won't get it twice
                    // if $source='both' because we use $field as key
                    // The parser looks for a CONSTRAINT clause just before
                    // the FOREIGN KEY clause. It finds it (as output from
                    // SHOW CREATE TABLE) in MySQL 4.0.13, but not in older
                    // versions like 3.23.58.
                    // In those cases, the FOREIGN KEY parsing will put numbers
                    // like -1, 0, 1... instead of the constraint number.
                    if (isset($one_key['constraint'])) {
                        $foreign[$field]['constraint'] = $one_key['constraint'];
                    }
                    if (isset($one_key['ref_db_name'])) {
                        $foreign[$field]['foreign_db'] = $one_key['ref_db_name'];
                    } else {
                        $foreign[$field]['foreign_db'] = $db;
                    }
                    $foreign[$field]['foreign_table'] = $one_key['ref_table_name'];
                    $foreign[$field]['foreign_field'] = $one_key['ref_index_list'][$i];
                    if (isset($one_key['on_delete'])) {
                        $foreign[$field]['on_delete'] = $one_key['on_delete'];
                    }
                    if (isset($one_key['on_update'])) {
                        $foreign[$field]['on_update'] = $one_key['on_update'];
                    }
                }
            }
        }
    }
    /**
     * Emulating relations for some information_schema and data_dictionary tables
     */
    $is_information_schema = strtolower($db) == 'information_schema';
    $is_data_dictionary = PMA_DRIZZLE && strtolower($db) == 'data_dictionary';
    if (($is_information_schema || $is_data_dictionary) && ($source == 'internal' || $source == 'both')) {
        if ($is_information_schema) {
            $relations_key = 'information_schema_relations';
            include_once './libraries/information_schema_relations.lib.php';
        } else {
            $relations_key = 'data_dictionary_relations';
            include_once './libraries/data_dictionary_relations.lib.php';
        }
        if (isset($GLOBALS[$relations_key][$table])) {
            foreach ($GLOBALS[$relations_key][$table] as $field => $relations) {
                if ((!strlen($column) || $column == $field) && (!isset($foreign[$field]) || !strlen($foreign[$field]))) {
                    $foreign[$field] = $relations;
                }
            }
        }
    }
    return $foreign;
}