From 851763cb17e2f421f1b896863b74faed67ec059e Mon Sep 17 00:00:00 2001 From: Sebastian Mendel Date: Sun, 20 Nov 2005 11:26:13 +0000 Subject: [PATCH] prevent undefined constants (if server connection fails) --- ChangeLog | 4 ++ libraries/common.lib.php | 135 +++++++++++++++++++++++++++++---------- 2 files changed, 106 insertions(+), 33 deletions(-) diff --git a/ChangeLog b/ChangeLog index b2b9e7a5f..11a0f4135 100755 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,10 @@ phpMyAdmin - Changelog $Id$ $Source$ +2005-11-20 Sebastian Mendel + * libraries/common.lib.php::PMA_showMySQLDocu() + - prevent undefined constants (if server connection fails) + 2005-11-18 Marc Delisle * libraries/database_interface.lib.php: initialize in case there are no databases (MySQL < 5.0) diff --git a/libraries/common.lib.php b/libraries/common.lib.php index a30f58e58..59af10ca9 100644 --- a/libraries/common.lib.php +++ b/libraries/common.lib.php @@ -583,9 +583,12 @@ if ( ! defined( 'PMA_MINIMUM_COMMON' ) ) { default: if (empty($link)) $link = 'index'; $mysql = '4.1'; - if (PMA_MYSQL_INT_VERSION > 50100) { + if ( ! defined( 'PMA_MYSQL_INT_VERSION' ) + || PMA_MYSQL_INT_VERSION < 50000 ) { + $mysql = '4.1'; + } elseif (PMA_MYSQL_INT_VERSION >= 50100) { $mysql = '5.1'; - } elseif (PMA_MYSQL_INT_VERSION > 50000) { + } elseif (PMA_MYSQL_INT_VERSION >= 50000) { $mysql = '5.0'; } $url = $cfg['MySQLManualBase'] . '/' . $mysql . '/en/' . $link . '.html'; @@ -727,33 +730,88 @@ if ( ! defined( 'PMA_MINIMUM_COMMON' ) ) { // 2005-01-17 modified by mkkeck bugfix if (substr($error_message, 1, 4) == '1062') { // get the duplicate entry - + + $no_duplicate_view = false; + // get table name - preg_match( '°ALTER\sTABLE\s\`([^\`]+)\`°iu', $the_query, $error_table = array() ); - $error_table = $error_table[1]; - - // get fields - preg_match( '°\(([^\)]+)\)°i', $the_query, $error_fields = array() ); - $error_fields = explode( ',', $error_fields[1] ); - - // duplicate value - preg_match( '°\'([^\']+)\'°i', $tmp_mysql_error, $duplicate_value = array() ); - $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 '
' ."\n" - .' ' . "\n" - .' ' . PMA_generate_common_hidden_inputs($db, $table) . "\n" - .' ' . "\n" - .'
' . "\n"; - unset( $sql ); + if ( preg_match( '�(ALTER|UPDATE|INSERT|CREATE)[^\`]*\s\`([^\`]+)\`�iu', $the_query, $error_table = array() ) ) { + $error_statement = $error_table[1]; + $error_table = $error_table[2]; + + // duplicate value + preg_match( '�\'([^\']+)\'�i', $tmp_mysql_error, $duplicate_value = array() ); + $duplicate_value = $duplicate_value[1]; + + // get fields from statement + if ( $error_statement === 'UPDATE' ) { + preg_match_all( '�(?:SET|,)\s*(?:\`)?([^\`]*)(?:\`)?\s*=\s*(\'|\"|\`)?([^\\2]*\\2|[^\s]+)�i', $the_query, $founds = array() ); + print_r( $founds ); + $error_fields = $founds[1]; + foreach ( $founds[2] as $value ) { + if ( substr( $value, 0, 1 ) !== "'" + && substr( $value, 0, 1 ) !== '"' + && ! is_numeric( $value ) ) + { + // value is a field name or function + // TODO hanlde fieldname or function here + $no_duplicate_view = true; + } else { + $duplicate_value = trim( $value ) . '-'; + } + } + unset( $founds ); + } + + if ( $error_statement !== 'ALTER' ) { + // no alter statement + // we need the fields in the affected index + // and the statement + + $index_fields = array(); + + // get fields from index + require_once './libraries/tbl_indexes.lib.php'; + + // get affected index number + preg_match( '�\s([0-9]+)(?:\s|$)�', $error_message, $index_number = array() ); + $index_number = $index_number[1]; + + // get indexes + if (!defined('PMA_IDX_INCLUDED')) { + $ret_keys = PMA_get_indexes( $error_table, 'db_details.php?' . PMA_generate_common_url( $db ) ); + } + + PMA_extract_indexes( $ret_keys, $indexes = array(), + $indexes_info = array(), $indexes_data = array() ); + + $array_keys = array_keys($indexes_data); + foreach ( $indexes_data[$array_keys[$index_number]] as $index_part ) { + foreach ( $index_part as $col_name ) { + $index_fields[] = '`' . $col_name . '`'; + } + } + + $error_fields = array_intersect( $error_fields, $index_fields ); + + unset( $array_keys, $index_number, $indexes_data, + $indexes_info, $indexes, $ret_keys, $index_fields ); + } + + $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 '
' ."\n" + .' ' . "\n" + .' ' . PMA_generate_common_hidden_inputs($db, $table) . "\n" + .' ' . "\n" + .'
' . "\n"; + unset( $sql ); + } } // end of show duplicate entry echo ''; @@ -1921,8 +1979,7 @@ if (typeof(window.parent) != 'undefined' $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"; - ?> + ?> ', ' 0 ) { + echo ' ' . $GLOBALS['strMySQLSaid'] . '' + .PMA_showMySQLDocu('Error-returns', 'Error-returns'); + foreach ( $warnings as $warning ) { + echo '
' + .'#' . $warning['Code'] . ' - ' . $warning['Message'] + .'
'; + } + } + echo '' . "\n"; if ( ! empty( $edit_target ) ) { @@ -2573,8 +2642,8 @@ window.parent.updateTableTitle( '', ''; } else { $ret .= ''; + . ' src="' . preg_replace('�^.*\ssrc="([^"]*)".*$�si', '\1', $message) . '"' + . ' value="' . htmlspecialchars(preg_replace('�^.*\salt="([^"]*)".*$�si', '\1', $message)) . '" />'; } } else { $message = trim( strip_tags( $message ) );