Пример #1
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);
 }
Пример #2
0
 /**
  * Displays a MySQL error message in the right frame.
  *
  * @param   string   the error message
  * @param   string   the sql query that failed
  * @param   boolean  whether to show a "modify" link or not
  * @param   string   the "back" link url (full path is not required)
  * @param   boolean  EXIT the page?
  *
  * @global  array    the configuration array
  *
  * @access  public
  */
 function PMA_mysqlDie($error_message = '', $the_query = '', $is_modify_link = TRUE, $back_url = '', $exit = TRUE)
 {
     global $cfg, $table, $db, $sql_query;
     require_once './header.inc.php';
     if (!$error_message) {
         $error_message = PMA_DBI_getError();
     }
     if (!$the_query && !empty($GLOBALS['sql_query'])) {
         $the_query = $GLOBALS['sql_query'];
     }
     // --- Added to solve bug #641765
     // Robbat2 - 12 January 2003, 9:46PM
     // Revised, Robbat2 - 13 Janurary 2003, 2:59PM
     if (!function_exists('PMA_SQP_isError') || PMA_SQP_isError()) {
         $formatted_sql = htmlspecialchars($the_query);
     } else {
         $formatted_sql = PMA_formatSql(PMA_SQP_parse($the_query), $the_query);
     }
     // ---
     echo "\n" . '<!-- PMA-SQL-ERROR -->' . "\n";
     echo '    <table border="0" cellpadding="2" cellspacing="1">' . '        <tr>' . "\n" . '            <th class="tblHeadError"><div class="errorhead">' . $GLOBALS['strError'] . '</div></th>' . "\n" . '        </tr>' . "\n" . '        <tr>' . "\n" . '            <td>';
     // if the config password is wrong, or the MySQL server does not
     // respond, do not show the query that would reveal the
     // username/password
     if (!empty($the_query) && !strstr($the_query, 'connect')) {
         // --- Added to solve bug #641765
         // Robbat2 - 12 January 2003, 9:46PM
         // Revised, Robbat2 - 13 Janurary 2003, 2:59PM
         if (function_exists('PMA_SQP_isError') && PMA_SQP_isError()) {
             echo PMA_SQP_getErrorString();
         }
         // ---
         // modified to show me the help on sql errors (Michael Keck)
         echo '<div class="tblWarn"><p>' . "\n";
         echo '    <b>' . $GLOBALS['strSQLQuery'] . ':</b>' . "\n";
         if (strstr(strtolower($formatted_sql), 'select')) {
             // please show me help to the error on select
             echo PMA_showMySQLDocu('Reference', 'SELECT');
         }
         if ($is_modify_link && isset($db)) {
             if (isset($table)) {
                 $doedit_goto = '<a href="tbl_properties.php?' . PMA_generate_common_url($db, $table) . '&amp;sql_query=' . urlencode($the_query) . '&amp;show_query=1">';
             } else {
                 $doedit_goto = '<a href="db_details.php?' . PMA_generate_common_url($db) . '&amp;sql_query=' . urlencode($the_query) . '&amp;show_query=1">';
             }
             if ($GLOBALS['cfg']['PropertiesIconic']) {
                 echo $doedit_goto . '<img src=" ' . $GLOBALS['pmaThemeImage'] . 'b_edit.png" width="16" height="16" border="0" hspace="2" align="middle" alt="' . $GLOBALS['strEdit'] . '" />' . '</a>';
             } else {
                 echo '    [' . $doedit_goto . $GLOBALS['strEdit'] . '</a>' . ']' . "\n";
             }
         }
         // end if
         echo '</p>' . "\n" . '<p>' . "\n" . '    ' . $formatted_sql . "\n" . '</p></div>' . "\n";
     }
     // end if
     $tmp_mysql_error = '';
     // for saving the original $error_message
     if (!empty($error_message)) {
         $tmp_mysql_error = strtolower($error_message);
         // save the original $error_message
         $error_message = htmlspecialchars($error_message);
         $error_message = preg_replace("@((\r\n)|(\r)|(\n)){3,}@", "\n\n", $error_message);
     }
     // modified to show me the help on error-returns (Michael Keck)
     echo '<div class="tblWarn"><p>' . "\n" . '    <b>' . $GLOBALS['strMySQLSaid'] . '</b>' . PMA_showMySQLDocu('Error-returns', 'Error-returns') . "\n" . '</p>' . "\n";
     // The error message will be displayed within a CODE segment.
     // To preserve original formatting, but allow wordwrapping, we do a couple of replacements
     // Replace all non-single blanks with their HTML-counterpart
     $error_message = str_replace('  ', '&nbsp;&nbsp;', $error_message);
     // Replace TAB-characters with their HTML-counterpart
     $error_message = str_replace("\t", '&nbsp;&nbsp;&nbsp;&nbsp;', $error_message);
     // Replace linebreaks
     $error_message = nl2br($error_message);
     echo '<code>' . "\n" . $error_message . "\n" . '</code><br />' . "\n";
     // feature request #1036254:
     // Add a link by MySQL-Error #1062 - Duplicate entry
     // 2004-10-20 by mk.keck
     if (substr($error_message, 1, 4) == '1062') {
         // TODO: do not assume that the error message is in English
         // and do not use mysql_result()
         // explode the entry and the column
         $arr_mysql_val_key = explode('entry \'', $tmp_mysql_error);
         $arr_mysql_val_key = explode('\' for key', $arr_mysql_val_key[1]);
         // get the duplicate value
         $string_duplicate_val = trim(strtolower($arr_mysql_val_key[0]));
         // get the field name ...
         $string_duplicate_key = mysql_result(mysql_query("SHOW FIELDS FROM " . $table), $arr_mysql_val_key[1] - 1, 0);
         $duplicate_sql_query = "SELECT * FROM " . $table . " WHERE " . $string_duplicate_key . " LIKE '" . $string_duplicate_val . "'";
         echo '        <form method="post" action="read_dump.php" style="padding: 0px; margin: 0px">' . "\n" . '            <input type="hidden" name="sql_query" value="' . $duplicate_sql_query . '" />' . "\n" . '            ' . PMA_generate_common_hidden_inputs($db, $table) . "\n" . '            <input type="submit" name="submit" value="' . $GLOBALS['strBrowse'] . '" />' . "\n" . '        </form>' . "\n";
     }
     // end of show duplicate entry
     echo '</div>';
     if (!empty($back_url) && $exit) {
         $goto_back_url = '<a href="' . (strstr($back_url, '?') ? $back_url . '&amp;no_history=true' : $back_url . '?no_history=true') . '">&nbsp;';
         echo '            </td> ' . "\n" . '        </tr>' . "\n" . '        <tr><td class="tblHeaders" align="center">';
         echo '[' . $goto_back_url . $GLOBALS['strBack'] . '&nbsp;</a>]';
     }
     echo '            </td>' . "\n" . '        </tr>' . "\n" . '    </table>' . "\n\n";
     if ($exit) {
         require_once './footer.inc.php';
     }
 }
Пример #3
0
/**
 * Displays a MySQL error message in the right frame.
 *
 * @param string $error_message  the error message
 * @param string $the_query      the sql query that failed
 * @param bool   $is_modify_link whether to show a "modify" link or not
 * @param string $back_url       the "back" link url (full path is not required)
 * @param bool   $exit           EXIT the page?
 *
 * @global  string    the curent table
 * @global  string    the current db
 *
 * @access  public
 */
function PMA_mysqlDie($error_message = '', $the_query = '', $is_modify_link = true, $back_url = '', $exit = true)
{
    global $table, $db;
    /**
     * start http output, display html headers
     */
    include_once './libraries/header.inc.php';
    $error_msg_output = '';
    if (!$error_message) {
        $error_message = PMA_DBI_getError();
    }
    if (!$the_query && !empty($GLOBALS['sql_query'])) {
        $the_query = $GLOBALS['sql_query'];
    }
    // --- Added to solve bug #641765
    if (!function_exists('PMA_SQP_isError') || PMA_SQP_isError()) {
        $formatted_sql = htmlspecialchars($the_query);
    } elseif (empty($the_query) || trim($the_query) == '') {
        $formatted_sql = '';
    } else {
        if (strlen($the_query) > $GLOBALS['cfg']['MaxCharactersInDisplayedSQL']) {
            $formatted_sql = htmlspecialchars(substr($the_query, 0, $GLOBALS['cfg']['MaxCharactersInDisplayedSQL'])) . '[...]';
        } else {
            $formatted_sql = PMA_formatSql(PMA_SQP_parse($the_query), $the_query);
        }
    }
    // ---
    $error_msg_output .= "\n" . '<!-- PMA-SQL-ERROR -->' . "\n";
    $error_msg_output .= '    <div class="error"><h1>' . __('Error') . '</h1>' . "\n";
    // if the config password is wrong, or the MySQL server does not
    // respond, do not show the query that would reveal the
    // username/password
    if (!empty($the_query) && !strstr($the_query, 'connect')) {
        // --- Added to solve bug #641765
        if (function_exists('PMA_SQP_isError') && PMA_SQP_isError()) {
            $error_msg_output .= PMA_SQP_getErrorString() . "\n";
            $error_msg_output .= '<br />' . "\n";
        }
        // ---
        // modified to show the help on sql errors
        $error_msg_output .= '    <p><strong>' . __('SQL query') . ':</strong>' . "\n";
        if (strstr(strtolower($formatted_sql), 'select')) {
            // please show me help to the error on select
            $error_msg_output .= PMA_showMySQLDocu('SQL-Syntax', 'SELECT');
        }
        if ($is_modify_link) {
            $_url_params = array('sql_query' => $the_query, 'show_query' => 1);
            if (strlen($table)) {
                $_url_params['db'] = $db;
                $_url_params['table'] = $table;
                $doedit_goto = '<a href="tbl_sql.php' . PMA_generate_common_url($_url_params) . '">';
            } elseif (strlen($db)) {
                $_url_params['db'] = $db;
                $doedit_goto = '<a href="db_sql.php' . PMA_generate_common_url($_url_params) . '">';
            } else {
                $doedit_goto = '<a href="server_sql.php' . PMA_generate_common_url($_url_params) . '">';
            }
            $error_msg_output .= $doedit_goto . PMA_getIcon('b_edit.png', __('Edit')) . '</a>';
        }
        // end if
        $error_msg_output .= '    </p>' . "\n" . '    <p>' . "\n" . '        ' . $formatted_sql . "\n" . '    </p>' . "\n";
    }
    // end if
    if (!empty($error_message)) {
        $error_message = preg_replace("@((\r\n)|(\r)|(\n)){3,}@", "\n\n", $error_message);
    }
    // modified to show the help on error-returns
    // (now error-messages-server)
    $error_msg_output .= '<p>' . "\n" . '    <strong>' . __('MySQL said: ') . '</strong>' . PMA_showMySQLDocu('Error-messages-server', 'Error-messages-server') . "\n" . '</p>' . "\n";
    // The error message will be displayed within a CODE segment.
    // To preserve original formatting, but allow wordwrapping,
    // we do a couple of replacements
    // Replace all non-single blanks with their HTML-counterpart
    $error_message = str_replace('  ', '&nbsp;&nbsp;', $error_message);
    // Replace TAB-characters with their HTML-counterpart
    $error_message = str_replace("\t", '&nbsp;&nbsp;&nbsp;&nbsp;', $error_message);
    // Replace linebreaks
    $error_message = nl2br($error_message);
    $error_msg_output .= '<code>' . "\n" . $error_message . "\n" . '</code><br />' . "\n";
    $error_msg_output .= '</div>';
    $_SESSION['Import_message']['message'] = $error_msg_output;
    if ($exit) {
        /**
         * If in an Ajax request
         * - avoid displaying a Back link
         * - use PMA_ajaxResponse() to transmit the message and exit
         */
        if ($GLOBALS['is_ajax_request'] == true) {
            PMA_ajaxResponse($error_msg_output, false);
        }
        if (!empty($back_url)) {
            if (strstr($back_url, '?')) {
                $back_url .= '&amp;no_history=true';
            } else {
                $back_url .= '?no_history=true';
            }
            $_SESSION['Import_message']['go_back_url'] = $back_url;
            $error_msg_output .= '<fieldset class="tblFooters">';
            $error_msg_output .= '[ <a href="' . $back_url . '">' . __('Back') . '</a> ]';
            $error_msg_output .= '</fieldset>' . "\n\n";
        }
        echo $error_msg_output;
        /**
         * display footer and exit
         */
        include './libraries/footer.inc.php';
    } else {
        echo $error_msg_output;
    }
}
Пример #4
0
/**
 * Displays a MySQL error message in the right frame.
 *
 * @uses    footer.inc.php
 * @uses    header.inc.php
 * @uses    $GLOBALS['sql_query']
 * @uses    $GLOBALS['strError']
 * @uses    $GLOBALS['strSQLQuery']
 * @uses    $GLOBALS['pmaThemeImage']
 * @uses    $GLOBALS['strEdit']
 * @uses    $GLOBALS['strMySQLSaid']
 * @uses    $GLOBALS['cfg']['PropertiesIconic'] 
 * @uses    $GLOBALS['cfg']['MaxCharactersInDisplayedSQL'] 
 * @uses    PMA_backquote()
 * @uses    PMA_DBI_getError()
 * @uses    PMA_formatSql()
 * @uses    PMA_generate_common_hidden_inputs()
 * @uses    PMA_generate_common_url()
 * @uses    PMA_showMySQLDocu()
 * @uses    PMA_sqlAddslashes()
 * @uses    PMA_SQP_isError()
 * @uses    PMA_SQP_parse()
 * @uses    PMA_SQP_getErrorString()
 * @uses    strtolower()
 * @uses    urlencode()
 * @uses    str_replace()
 * @uses    nl2br()
 * @uses    substr()
 * @uses    preg_replace()
 * @uses    preg_match()
 * @uses    explode()
 * @uses    implode()
 * @uses    is_array()
 * @uses    function_exists()
 * @uses    htmlspecialchars()
 * @uses    trim()
 * @uses    strstr()
 * @param   string   the error message
 * @param   string   the sql query that failed
 * @param   boolean  whether to show a "modify" link or not
 * @param   string   the "back" link url (full path is not required)
 * @param   boolean  EXIT the page?
 *
 * @global  string    the curent table
 * @global  string    the current db
 *
 * @access  public
 */
function PMA_mysqlDie($error_message = '', $the_query = '', $is_modify_link = true, $back_url = '', $exit = true)
{
    global $table, $db;
    /**
     * start http output, display html headers
     */
    require_once './libraries/header.inc.php';
    if (!$error_message) {
        $error_message = PMA_DBI_getError();
    }
    if (!$the_query && !empty($GLOBALS['sql_query'])) {
        $the_query = $GLOBALS['sql_query'];
    }
    // --- Added to solve bug #641765
    // Robbat2 - 12 January 2003, 9:46PM
    // Revised, Robbat2 - 13 January 2003, 2:59PM
    if (!function_exists('PMA_SQP_isError') || PMA_SQP_isError()) {
        $formatted_sql = htmlspecialchars($the_query);
    } elseif (empty($the_query) || trim($the_query) == '') {
        $formatted_sql = '';
    } else {
        if (strlen($the_query) > $GLOBALS['cfg']['MaxCharactersInDisplayedSQL']) {
            $formatted_sql = substr($the_query, 0, $GLOBALS['cfg']['MaxCharactersInDisplayedSQL']) . '[...]';
        } else {
            $formatted_sql = PMA_formatSql(PMA_SQP_parse($the_query), $the_query);
        }
    }
    // ---
    echo "\n" . '<!-- PMA-SQL-ERROR -->' . "\n";
    echo '    <div class="error"><h1>' . $GLOBALS['strError'] . '</h1>' . "\n";
    // if the config password is wrong, or the MySQL server does not
    // respond, do not show the query that would reveal the
    // username/password
    if (!empty($the_query) && !strstr($the_query, 'connect')) {
        // --- Added to solve bug #641765
        // Robbat2 - 12 January 2003, 9:46PM
        // Revised, Robbat2 - 13 January 2003, 2:59PM
        if (function_exists('PMA_SQP_isError') && PMA_SQP_isError()) {
            echo PMA_SQP_getErrorString() . "\n";
            echo '<br />' . "\n";
        }
        // ---
        // modified to show me the help on sql errors (Michael Keck)
        echo '    <p><strong>' . $GLOBALS['strSQLQuery'] . ':</strong>' . "\n";
        if (strstr(strtolower($formatted_sql), 'select')) {
            // please show me help to the error on select
            echo PMA_showMySQLDocu('SQL-Syntax', 'SELECT');
        }
        if ($is_modify_link && strlen($db)) {
            if (strlen($table)) {
                $doedit_goto = '<a href="tbl_sql.php?' . PMA_generate_common_url($db, $table) . '&amp;sql_query=' . urlencode($the_query) . '&amp;show_query=1">';
            } else {
                $doedit_goto = '<a href="db_sql.php?' . PMA_generate_common_url($db) . '&amp;sql_query=' . urlencode($the_query) . '&amp;show_query=1">';
            }
            if ($GLOBALS['cfg']['PropertiesIconic']) {
                echo $doedit_goto . '<img class="icon" src=" ' . $GLOBALS['pmaThemeImage'] . 'b_edit.png" width="16" height="16" alt="' . $GLOBALS['strEdit'] . '" />' . '</a>';
            } else {
                echo '    [' . $doedit_goto . $GLOBALS['strEdit'] . '</a>' . ']' . "\n";
            }
        }
        // end if
        echo '    </p>' . "\n" . '    <p>' . "\n" . '        ' . $formatted_sql . "\n" . '    </p>' . "\n";
    }
    // end if
    $tmp_mysql_error = '';
    // for saving the original $error_message
    if (!empty($error_message)) {
        $tmp_mysql_error = strtolower($error_message);
        // save the original $error_message
        $error_message = htmlspecialchars($error_message);
        $error_message = preg_replace("@((\r\n)|(\r)|(\n)){3,}@", "\n\n", $error_message);
    }
    // modified to show me the help on error-returns (Michael Keck)
    // (now error-messages-server)
    echo '<p>' . "\n" . '    <strong>' . $GLOBALS['strMySQLSaid'] . '</strong>' . PMA_showMySQLDocu('Error-messages-server', 'Error-messages-server') . "\n" . '</p>' . "\n";
    // The error message will be displayed within a CODE segment.
    // To preserve original formatting, but allow wordwrapping, we do a couple of replacements
    // Replace all non-single blanks with their HTML-counterpart
    $error_message = str_replace('  ', '&nbsp;&nbsp;', $error_message);
    // Replace TAB-characters with their HTML-counterpart
    $error_message = str_replace("\t", '&nbsp;&nbsp;&nbsp;&nbsp;', $error_message);
    // Replace linebreaks
    $error_message = nl2br($error_message);
    echo '<code>' . "\n" . $error_message . "\n" . '</code><br />' . "\n";
    echo '</div>';
    echo '<fieldset class="tblFooters">';
    if (!empty($back_url) && $exit) {
        $goto_back_url = '<a href="' . (strstr($back_url, '?') ? $back_url . '&amp;no_history=true' : $back_url . '?no_history=true') . '">';
        echo '[ ' . $goto_back_url . $GLOBALS['strBack'] . '</a> ]';
    }
    echo '    </fieldset>' . "\n\n";
    if ($exit) {
        /**
         * display footer and exit
         */
        require_once './libraries/footer.inc.php';
    }
}
Пример #5
0
 /**
  * Displays a MySQL error message in the right frame.
  *
  * @param   string   the error message
  * @param   string   the sql query that failed
  * @param   boolean  whether to show a "modify" link or not
  * @param   string   the "back" link url (full path is not required)
  * @param   boolean  EXIT the page?
  *
  * @global  array    the configuration array
  *
  * @access  public
  */
 function PMA_mysqlDie($error_message = '', $the_query = '', $is_modify_link = true, $back_url = '', $exit = true)
 {
     global $cfg, $table, $db, $sql_query;
     require_once './libraries/header.inc.php';
     if (!$error_message) {
         $error_message = PMA_DBI_getError();
     }
     if (!$the_query && !empty($GLOBALS['sql_query'])) {
         $the_query = $GLOBALS['sql_query'];
     }
     // --- Added to solve bug #641765
     // Robbat2 - 12 January 2003, 9:46PM
     // Revised, Robbat2 - 13 January 2003, 2:59PM
     if (!function_exists('PMA_SQP_isError') || PMA_SQP_isError()) {
         $formatted_sql = htmlspecialchars($the_query);
     } elseif (empty($the_query) || trim($the_query) == '') {
         $formatted_sql = '';
     } else {
         $formatted_sql = PMA_formatSql(PMA_SQP_parse($the_query), $the_query);
     }
     // ---
     echo "\n" . '<!-- PMA-SQL-ERROR -->' . "\n";
     echo '    <div class="error"><h1>' . $GLOBALS['strError'] . '</h1>' . "\n";
     // if the config password is wrong, or the MySQL server does not
     // respond, do not show the query that would reveal the
     // username/password
     if (!empty($the_query) && !strstr($the_query, 'connect')) {
         // --- Added to solve bug #641765
         // Robbat2 - 12 January 2003, 9:46PM
         // Revised, Robbat2 - 13 January 2003, 2:59PM
         if (function_exists('PMA_SQP_isError') && PMA_SQP_isError()) {
             echo PMA_SQP_getErrorString() . "\n";
             echo '<br />' . "\n";
         }
         // ---
         // modified to show me the help on sql errors (Michael Keck)
         echo '    <p><strong>' . $GLOBALS['strSQLQuery'] . ':</strong>' . "\n";
         if (strstr(strtolower($formatted_sql), 'select')) {
             // please show me help to the error on select
             echo PMA_showMySQLDocu('SQL-Syntax', 'SELECT');
         }
         if ($is_modify_link && isset($db)) {
             if (isset($table)) {
                 $doedit_goto = '<a href="tbl_properties.php?' . PMA_generate_common_url($db, $table) . '&amp;sql_query=' . urlencode($the_query) . '&amp;show_query=1">';
             } else {
                 $doedit_goto = '<a href="db_details.php?' . PMA_generate_common_url($db) . '&amp;sql_query=' . urlencode($the_query) . '&amp;show_query=1">';
             }
             if ($GLOBALS['cfg']['PropertiesIconic']) {
                 echo $doedit_goto . '<img class="icon" src=" ' . $GLOBALS['pmaThemeImage'] . 'b_edit.png" width="16" height="16" alt="' . $GLOBALS['strEdit'] . '" />' . '</a>';
             } else {
                 echo '    [' . $doedit_goto . $GLOBALS['strEdit'] . '</a>' . ']' . "\n";
             }
         }
         // end if
         echo '    </p>' . "\n" . '    <p>' . "\n" . '        ' . $formatted_sql . "\n" . '    </p>' . "\n";
     }
     // end if
     $tmp_mysql_error = '';
     // for saving the original $error_message
     if (!empty($error_message)) {
         $tmp_mysql_error = strtolower($error_message);
         // save the original $error_message
         $error_message = htmlspecialchars($error_message);
         $error_message = preg_replace("@((\r\n)|(\r)|(\n)){3,}@", "\n\n", $error_message);
     }
     // modified to show me the help on error-returns (Michael Keck)
     // (now error-messages-server)
     echo '<p>' . "\n" . '    <strong>' . $GLOBALS['strMySQLSaid'] . '</strong>' . PMA_showMySQLDocu('Error-messages-server', 'Error-messages-server') . "\n" . '</p>' . "\n";
     // The error message will be displayed within a CODE segment.
     // To preserve original formatting, but allow wordwrapping, we do a couple of replacements
     // Replace all non-single blanks with their HTML-counterpart
     $error_message = str_replace('  ', '&nbsp;&nbsp;', $error_message);
     // Replace TAB-characters with their HTML-counterpart
     $error_message = str_replace("\t", '&nbsp;&nbsp;&nbsp;&nbsp;', $error_message);
     // Replace linebreaks
     $error_message = nl2br($error_message);
     echo '<code>' . "\n" . $error_message . "\n" . '</code><br />' . "\n";
     // feature request #1036254:
     // Add a link by MySQL-Error #1062 - Duplicate entry
     // 2004-10-20 by mkkeck
     // 2005-01-17 modified by mkkeck bugfix
     if (substr($error_message, 1, 4) == '1062') {
         // get the duplicate entry
         // get table name
         // TODO: what would be the best delimiter, while avoiding
         // special characters that can become high-ascii after editing,
         // depending upon which editor is used by the developer?
         $error_table = array();
         if (preg_match('@ALTER\\s*TABLE\\s*\\`([^\\`]+)\\`@iu', $the_query, $error_table)) {
             $error_table = $error_table[1];
         } elseif (preg_match('@INSERT\\s*INTO\\s*\\`([^\\`]+)\\`@iu', $the_query, $error_table)) {
             $error_table = $error_table[1];
         } elseif (preg_match('@UPDATE\\s*\\`([^\\`]+)\\`@iu', $the_query, $error_table)) {
             $error_table = $error_table[1];
         } elseif (preg_match('@INSERT\\s*\\`([^\\`]+)\\`@iu', $the_query, $error_table)) {
             $error_table = $error_table[1];
         }
         // get fields
         $error_fields = array();
         if (preg_match('@\\(([^\\)]+)\\)@i', $the_query, $error_fields)) {
             $error_fields = explode(',', $error_fields[1]);
         } elseif (preg_match('@(`[^`]+`)\\s*=@i', $the_query, $error_fields)) {
             $error_fields = explode(',', $error_fields[1]);
         }
         if (is_array($error_table) || is_array($error_fields)) {
             // duplicate value
             $duplicate_value = array();
             preg_match('@\'([^\']+)\'@i', $tmp_mysql_error, $duplicate_value);
             $duplicate_value = $duplicate_value[1];
             $sql = '
                  SELECT *
                    FROM ' . PMA_backquote($error_table) . '
                   WHERE CONCAT_WS("-", ' . implode(', ', $error_fields) . ')
                         = "' . PMA_sqlAddslashes($duplicate_value) . '"
                ORDER BY ' . implode(', ', $error_fields);
             unset($error_table, $error_fields, $duplicate_value);
             echo '        <form method="post" action="import.php" style="padding: 0; margin: 0">' . "\n" . '            <input type="hidden" name="sql_query" value="' . htmlentities($sql) . '" />' . "\n" . '            ' . PMA_generate_common_hidden_inputs($db, $table) . "\n" . '            <input type="submit" name="submit" value="' . $GLOBALS['strBrowse'] . '" />' . "\n" . '        </form>' . "\n";
             unset($sql);
         }
     }
     // end of show duplicate entry
     echo '</div>';
     echo '<fieldset class="tblFooters">';
     if (!empty($back_url) && $exit) {
         $goto_back_url = '<a href="' . (strstr($back_url, '?') ? $back_url . '&amp;no_history=true' : $back_url . '?no_history=true') . '">';
         echo '[ ' . $goto_back_url . $GLOBALS['strBack'] . '</a> ]';
     }
     echo '    </fieldset>' . "\n\n";
     if ($exit) {
         require_once './libraries/footer.inc.php';
     }
 }
Пример #6
0
 /**
  * Displays a MySQL error message in the main panel when $exit is true.
  * Returns the error message otherwise.
  *
  * @param string|bool $error_message  the error message
  * @param string      $the_query      the sql query that failed
  * @param bool        $is_modify_link whether to show a "modify" link or not
  * @param string      $back_url       the "back" link url (full path is not
  *                                    required)
  * @param bool        $exit           EXIT the page?
  *
  * @return string
  *
  * @global string $table the curent table
  * @global string $db    the current db
  *
  * @access public
  */
 public static function mysqlDie($error_message = '', $the_query = '', $is_modify_link = true, $back_url = '', $exit = true)
 {
     global $table, $db;
     $error_msg = '';
     if (!$error_message) {
         $error_message = $GLOBALS['dbi']->getError();
     }
     if (!$the_query && !empty($GLOBALS['sql_query'])) {
         $the_query = $GLOBALS['sql_query'];
     }
     // --- Added to solve bug #641765
     if (!function_exists('PMA_SQP_isError') || PMA_SQP_isError()) {
         $formatted_sql = htmlspecialchars($the_query);
     } elseif (empty($the_query) || trim($the_query) == '') {
         $formatted_sql = '';
     } else {
         $formatted_sql = self::formatSql($the_query, true);
     }
     // ---
     $error_msg .= "\n" . '<!-- PMA-SQL-ERROR -->' . "\n";
     $error_msg .= '    <div class="error"><h1>' . __('Error') . '</h1>' . "\n";
     // if the config password is wrong, or the MySQL server does not
     // respond, do not show the query that would reveal the
     // username/password
     if (!empty($the_query) && !mb_strstr($the_query, 'connect')) {
         // --- Added to solve bug #641765
         if (function_exists('PMA_SQP_isError') && PMA_SQP_isError()) {
             $error_msg .= PMA_SQP_getErrorString() . "\n";
             $error_msg .= '<br />' . "\n";
         }
         // ---
         // modified to show the help on sql errors
         $error_msg .= '<p><strong>' . __('SQL query:') . '</strong>' . "\n";
         $formattedSqlToLower = mb_strtolower($formatted_sql);
         if (mb_strstr($formattedSqlToLower, 'select')) {
             // please show me help to the error on select
             $error_msg .= self::showMySQLDocu('SELECT');
         }
         if ($is_modify_link) {
             $_url_params = array('sql_query' => $the_query, 'show_query' => 1);
             if (mb_strlen($table)) {
                 $_url_params['db'] = $db;
                 $_url_params['table'] = $table;
                 $doedit_goto = '<a href="tbl_sql.php' . PMA_URL_getCommon($_url_params) . '">';
             } elseif (mb_strlen($db)) {
                 $_url_params['db'] = $db;
                 $doedit_goto = '<a href="db_sql.php' . PMA_URL_getCommon($_url_params) . '">';
             } else {
                 $doedit_goto = '<a href="server_sql.php' . PMA_URL_getCommon($_url_params) . '">';
             }
             $error_msg .= $doedit_goto . self::getIcon('b_edit.png', __('Edit')) . '</a>';
         }
         // end if
         $error_msg .= '    </p>' . "\n" . '<p>' . "\n" . $formatted_sql . "\n" . '</p>' . "\n";
     }
     // end if
     if (!empty($error_message)) {
         $error_message = preg_replace("@((\r\n)|(\r)|(\n)){3,}@", "\n\n", $error_message);
     }
     // modified to show the help on error-returns
     // (now error-messages-server)
     $error_msg .= '<p>' . "\n" . '    <strong>' . __('MySQL said: ') . '</strong>' . self::showMySQLDocu('Error-messages-server') . "\n" . '</p>' . "\n";
     // The error message will be displayed within a CODE segment.
     // To preserve original formatting, but allow wordwrapping,
     // we do a couple of replacements
     // Replace all non-single blanks with their HTML-counterpart
     $error_message = str_replace('  ', '&nbsp;&nbsp;', $error_message);
     // Replace TAB-characters with their HTML-counterpart
     $error_message = str_replace("\t", '&nbsp;&nbsp;&nbsp;&nbsp;', $error_message);
     // Replace line breaks
     $error_message = nl2br($error_message);
     $error_msg .= '<code>' . "\n" . $error_message . "\n" . '</code><br />' . "\n";
     $error_msg .= '</div>';
     $_SESSION['Import_message']['message'] = $error_msg;
     if (!$exit) {
         return $error_msg;
     }
     /**
      * If in an Ajax request
      * - avoid displaying a Back link
      * - use PMA_Response() to transmit the message and exit
      */
     if (isset($GLOBALS['is_ajax_request']) && $GLOBALS['is_ajax_request'] == true) {
         $response = PMA_Response::getInstance();
         $response->isSuccess(false);
         $response->addJSON('message', $error_msg);
         exit;
     }
     if (!empty($back_url)) {
         if (mb_strstr($back_url, '?')) {
             $back_url .= '&amp;no_history=true';
         } else {
             $back_url .= '?no_history=true';
         }
         $_SESSION['Import_message']['go_back_url'] = $back_url;
         $error_msg .= '<fieldset class="tblFooters">' . '[ <a href="' . $back_url . '">' . __('Back') . '</a> ]' . '</fieldset>' . "\n\n";
     }
     echo $error_msg;
     exit;
 }
Пример #7
0
 private function assertParser($sql, $expected, $error = '')
 {
     $parsed_sql = PMA_SQP_parse($sql);
     $this->assertEquals(PMA_SQP_getErrorString(), $error);
     $this->assertEquals($parsed_sql, $expected);
 }
Пример #8
0
 /**
  * Displays a MySQL error message in the right frame.
  *
  * @param   string   the error mesage
  * @param   string   the sql query that failed
  * @param   boolean  whether to show a "modify" link or not
  * @param   string   the "back" link url (full path is not required)
  * @param   boolean  EXIT the page?
  *
  * @global  array    the configuration array
  *
  * @access  public
  */
 function PMA_mysqlDie($error_message = '', $the_query = '', $is_modify_link = TRUE, $back_url = '', $exit = TRUE)
 {
     global $cfg, $table, $db, $sql_query;
     require_once './header.inc.php';
     if (!$error_message) {
         $error_message = PMA_mysql_error();
     }
     if (!$the_query && !empty($GLOBALS['sql_query'])) {
         $the_query = $GLOBALS['sql_query'];
     }
     // --- Added to solve bug #641765
     // Robbat2 - 12 January 2003, 9:46PM
     // Revised, Robbat2 - 13 Janurary 2003, 2:59PM
     if (!function_exists('PMA_SQP_isError') || PMA_SQP_isError()) {
         $formatted_sql = htmlspecialchars($the_query);
     } else {
         $formatted_sql = PMA_formatSql(PMA_SQP_parse($the_query), $the_query);
     }
     // ---
     echo '<p><b>' . $GLOBALS['strError'] . '</b></p>' . "\n";
     // if the config password is wrong, or the MySQL server does not
     // respond, do not show the query that would reveal the
     // username/password
     if (!empty($the_query) && !strstr($the_query, 'connect')) {
         // --- Added to solve bug #641765
         // Robbat2 - 12 January 2003, 9:46PM
         // Revised, Robbat2 - 13 Janurary 2003, 2:59PM
         if (function_exists('PMA_SQP_isError') && PMA_SQP_isError()) {
             echo PMA_SQP_getErrorString();
         }
         // ---
         echo '<p>' . "\n";
         echo '    ' . $GLOBALS['strSQLQuery'] . '&nbsp;:&nbsp;' . "\n";
         if ($is_modify_link && isset($db)) {
             echo '    [' . '<a href="db_details.php?' . PMA_generate_common_url($GLOBALS['db']) . '&amp;sql_query=' . urlencode($the_query) . '&amp;show_query=1">' . $GLOBALS['strEdit'] . '</a>' . ']' . "\n";
         }
         // end if
         echo '</p>' . "\n" . '<p>' . "\n" . '    ' . $formatted_sql . "\n" . '</p>' . "\n";
     }
     // end if
     if (!empty($error_message)) {
         $error_message = htmlspecialchars($error_message);
         $error_message = preg_replace("@((\r\n)|(\r)|(\n)){3,}@", "\n\n", $error_message);
     }
     echo '<p>' . "\n" . '    ' . $GLOBALS['strMySQLSaid'] . '<br />' . "\n" . '</p>' . "\n";
     // The error message will be displayed within a CODE segment.
     // To preserve original formatting, but allow wordwrapping, we do a couple of replacements
     // Replace all non-single blanks with their HTML-counterpart
     $error_message = str_replace('  ', '&nbsp;&nbsp;', $error_message);
     // Replace TAB-characters with their HTML-counterpart
     $error_message = str_replace("\t", '&nbsp;&nbsp;&nbsp;&nbsp;', $error_message);
     // Replace linebreaks
     $error_message = nl2br($error_message);
     echo '<code>' . "\n" . $error_message . "\n" . '</code><br /><br />' . "\n";
     echo PMA_showMySQLDocu('Error-returns', 'Error-returns');
     if (!empty($back_url) && $exit) {
         echo '&nbsp;&middot;&nbsp;[<a href="' . (strstr($back_url, '?') ? $back_url . '&amp;no_history=true' : $back_url . '?no_history=true') . '">' . $GLOBALS['strBack'] . '</a>]';
     }
     echo "\n";
     if ($exit) {
         require_once './footer.inc.php';
     }
 }
 /**
  * Displays a MySQL error message in the right frame.
  *
  * @param   string   the error mesage
  * @param   string   the sql query that failed
  * @param   boolean  whether to show a "modify" link or not
  * @param   string   the "back" link url (full path is not required)
  * @param   boolean  EXIT the page?
  *
  * @global  array    the configuration array
  *
  * @access  public
  */
 function PMA_mysqlDie($error_message = '', $the_query = '', $is_modify_link = TRUE, $back_url = '', $exit = TRUE)
 {
     global $cfg, $table, $db, $sql_query;
     require_once './header.inc.php';
     if (!$error_message) {
         $error_message = PMA_DBI_getError();
     }
     if (!$the_query && !empty($GLOBALS['sql_query'])) {
         $the_query = $GLOBALS['sql_query'];
     }
     // --- Added to solve bug #641765
     // Robbat2 - 12 January 2003, 9:46PM
     // Revised, Robbat2 - 13 Janurary 2003, 2:59PM
     if (!function_exists('PMA_SQP_isError') || PMA_SQP_isError()) {
         $formatted_sql = htmlspecialchars($the_query);
     } else {
         $formatted_sql = PMA_formatSql(PMA_SQP_parse($the_query), $the_query);
     }
     // ---
     echo "\n" . '<!-- PMA-SQL-ERROR -->' . "\n";
     echo '    <table border="0" cellpadding="2" cellspacing="1">' . '        <tr>' . "\n" . '            <th class="tblHeadError"><div class="errorhead">' . $GLOBALS['strError'] . '</div></th>' . "\n" . '        </tr>' . "\n" . '        <tr>' . "\n" . '            <td>';
     // if the config password is wrong, or the MySQL server does not
     // respond, do not show the query that would reveal the
     // username/password
     if (!empty($the_query) && !strstr($the_query, 'connect')) {
         // --- Added to solve bug #641765
         // Robbat2 - 12 January 2003, 9:46PM
         // Revised, Robbat2 - 13 Janurary 2003, 2:59PM
         if (function_exists('PMA_SQP_isError') && PMA_SQP_isError()) {
             echo PMA_SQP_getErrorString();
         }
         // ---
         // modified to show me the help on sql errors (Michael Keck)
         echo '<div class="tblWarn"><p>' . "\n";
         echo '    <b>' . $GLOBALS['strSQLQuery'] . ':</b>' . "\n";
         if (strstr(strtolower($formatted_sql), 'select')) {
             // please show me help to the error on select
             echo PMA_showMySQLDocu('Reference', 'SELECT');
         }
         if ($is_modify_link && isset($db)) {
             if (isset($table)) {
                 $doedit_goto = '<a href="tbl_properties.php?' . PMA_generate_common_url($db, $table) . '&amp;sql_query=' . urlencode($the_query) . '&amp;show_query=1">';
             } else {
                 $doedit_goto = '<a href="db_details.php?' . PMA_generate_common_url($db) . '&amp;sql_query=' . urlencode($the_query) . '&amp;show_query=1">';
             }
             if ($GLOBALS['cfg']['PropertiesIconic']) {
                 echo $doedit_goto . '<img src=" ' . $GLOBALS['pmaThemeImage'] . 'b_edit.png" width="16" height="16" border="0" hspace="2" align="absmiddle" alt="' . $GLOBALS['strEdit'] . '" />' . '</a>';
             } else {
                 echo '    [' . $doedit_goto . $GLOBALS['strEdit'] . '</a>' . ']' . "\n";
             }
         }
         // end if
         echo '</p>' . "\n" . '<p>' . "\n" . '    ' . $formatted_sql . "\n" . '</p></div>' . "\n";
     }
     // end if
     if (!empty($error_message)) {
         $error_message = htmlspecialchars($error_message);
         $error_message = preg_replace("@((\r\n)|(\r)|(\n)){3,}@", "\n\n", $error_message);
     }
     // modified to show me the help on error-returns (Michael Keck)
     echo '<div class="tblWarn"><p>' . "\n" . '    <b>' . $GLOBALS['strMySQLSaid'] . '</b>' . PMA_showMySQLDocu('Error-returns', 'Error-returns') . "\n" . '</p>' . "\n";
     // The error message will be displayed within a CODE segment.
     // To preserve original formatting, but allow wordwrapping, we do a couple of replacements
     // Replace all non-single blanks with their HTML-counterpart
     $error_message = str_replace('  ', '&nbsp;&nbsp;', $error_message);
     // Replace TAB-characters with their HTML-counterpart
     $error_message = str_replace("\t", '&nbsp;&nbsp;&nbsp;&nbsp;', $error_message);
     // Replace linebreaks
     $error_message = nl2br($error_message);
     echo '<code>' . "\n" . $error_message . "\n" . '</code><br /><br />' . "\n";
     echo '</div>';
     if (!empty($back_url) && $exit) {
         $goto_back_url = '<a href="' . (strstr($back_url, '?') ? $back_url . '&amp;no_history=true' : $back_url . '?no_history=true') . '">&nbsp;';
         echo '            </td> ' . "\n" . '        </tr>' . "\n" . '        <tr><td class="tblHeaders" align="center">';
         echo '[' . $goto_back_url . $GLOBALS['strBack'] . '&nbsp;</a>]';
     }
     echo '            </td>' . "\n" . '        </tr>' . "\n" . '    </table>' . "\n\n";
     if ($exit) {
         require_once './footer.inc.php';
     }
 }