当前位置: 首页>>代码示例>>PHP>>正文


PHP PMA_SQP_parse函数代码示例

本文整理汇总了PHP中PMA_SQP_parse函数的典型用法代码示例。如果您正苦于以下问题:PHP PMA_SQP_parse函数的具体用法?PHP PMA_SQP_parse怎么用?PHP PMA_SQP_parse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了PMA_SQP_parse函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: PMA_transformation_text_plain__sql

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;
}
开发者ID:robmat,项目名称:samplebator,代码行数:7,代码来源:text_plain__sql.inc.php

示例2: testParser

 /**
  * 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);
 }
开发者ID:nhodges,项目名称:phpmyadmin,代码行数:19,代码来源:PMA_SQL_parser_test.php

示例3: executeQuery

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;
}
开发者ID:alencarmo,项目名称:OCF,代码行数:37,代码来源:dbproperty.php

示例4: PMA_displayHtmlForColumnChange

/**
 * 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';
}
开发者ID:pombredanne,项目名称:ArcherSys,代码行数:55,代码来源:structure.lib.php

示例5: PMA_showMessage


//.........这里部分代码省略.........
    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)
开发者ID:bharathi26,项目名称:openemr,代码行数:67,代码来源:common.lib.php

示例6: getMessage

 /**
  * 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);
//.........这里部分代码省略.........
开发者ID:JaRomero95,项目名称:dwes,代码行数:101,代码来源:Util.class.php

示例7: PMA_showMessage


//.........这里部分代码省略.........
            $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'])) {
开发者ID:Apxe,项目名称:Rubin_final,代码行数:67,代码来源:common.lib.php

示例8: moveCopy

 /**
  * 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 <michal@cihar.com>
  */
 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;
//.........这里部分代码省略.........
开发者ID:jmathai,项目名称:photos,代码行数:101,代码来源:Table.class.php

示例9: exportData

 /**
  * 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;
//.........这里部分代码省略.........
开发者ID:fanscky,项目名称:HTPMS,代码行数:101,代码来源:ExportSql.class.php

示例10: analyzeStructure

 /**
  * 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;
 }
开发者ID:TheBlackBloodyUnicorn,项目名称:pico_wanderblog,代码行数:28,代码来源:Table.class.php

示例11: PMA_checkIfRollbackPossible

/**
 * 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;
}
开发者ID:sruthikudaravalli,项目名称:QuickCabs,代码行数:34,代码来源:import.lib.php

示例12: PMA_mysqlDie

     // 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;
开发者ID:quartemer,项目名称:xoopserver,代码行数:31,代码来源:tbl_move_copy.php

示例13: PMA_showMessage

/**
 * 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 ?
//.........这里部分代码省略.........
开发者ID:kebyn,项目名称:apache_workspace,代码行数:101,代码来源:common.lib.php

示例14: replaceWithAliases

 /**
  * 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
//.........这里部分代码省略.........
开发者ID:aramisf,项目名称:-,代码行数:101,代码来源:ExportSql.class.php

示例15: printServerTraffic


//.........这里部分代码省略.........
</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 
}
开发者ID:AmberWish,项目名称:laba_web,代码行数:101,代码来源:server_status.php


注:本文中的PMA_SQP_parse函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。