prevent undefined constants (if server connection fails)
This commit is contained in:
@@ -5,6 +5,10 @@ phpMyAdmin - Changelog
|
|||||||
$Id$
|
$Id$
|
||||||
$Source$
|
$Source$
|
||||||
|
|
||||||
|
2005-11-20 Sebastian Mendel <cybot_tm@users.sourceforge.net>
|
||||||
|
* libraries/common.lib.php::PMA_showMySQLDocu()
|
||||||
|
- prevent undefined constants (if server connection fails)
|
||||||
|
|
||||||
2005-11-18 Marc Delisle <lem9@users.sourceforge.net>
|
2005-11-18 Marc Delisle <lem9@users.sourceforge.net>
|
||||||
* libraries/database_interface.lib.php: initialize in case there are
|
* libraries/database_interface.lib.php: initialize in case there are
|
||||||
no databases (MySQL < 5.0)
|
no databases (MySQL < 5.0)
|
||||||
|
@@ -583,9 +583,12 @@ if ( ! defined( 'PMA_MINIMUM_COMMON' ) ) {
|
|||||||
default:
|
default:
|
||||||
if (empty($link)) $link = 'index';
|
if (empty($link)) $link = 'index';
|
||||||
$mysql = '4.1';
|
$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';
|
$mysql = '5.1';
|
||||||
} elseif (PMA_MYSQL_INT_VERSION > 50000) {
|
} elseif (PMA_MYSQL_INT_VERSION >= 50000) {
|
||||||
$mysql = '5.0';
|
$mysql = '5.0';
|
||||||
}
|
}
|
||||||
$url = $cfg['MySQLManualBase'] . '/' . $mysql . '/en/' . $link . '.html';
|
$url = $cfg['MySQLManualBase'] . '/' . $mysql . '/en/' . $link . '.html';
|
||||||
@@ -728,32 +731,87 @@ if ( ! defined( 'PMA_MINIMUM_COMMON' ) ) {
|
|||||||
if (substr($error_message, 1, 4) == '1062') {
|
if (substr($error_message, 1, 4) == '1062') {
|
||||||
// get the duplicate entry
|
// get the duplicate entry
|
||||||
|
|
||||||
|
$no_duplicate_view = false;
|
||||||
|
|
||||||
// get table name
|
// get table name
|
||||||
preg_match( '<27>ALTER\sTABLE\s\`([^\`]+)\`<60>iu', $the_query, $error_table = array() );
|
if ( preg_match( '<27>(ALTER|UPDATE|INSERT|CREATE)[^\`]*\s\`([^\`]+)\`<60>iu', $the_query, $error_table = array() ) ) {
|
||||||
$error_table = $error_table[1];
|
$error_statement = $error_table[1];
|
||||||
|
$error_table = $error_table[2];
|
||||||
|
|
||||||
// get fields
|
// duplicate value
|
||||||
preg_match( '<27>\(([^\)]+)\)<EFBFBD>i', $the_query, $error_fields = array() );
|
preg_match( '<27>\'([^\']+)\'<EFBFBD>i', $tmp_mysql_error, $duplicate_value = array() );
|
||||||
$error_fields = explode( ',', $error_fields[1] );
|
$duplicate_value = $duplicate_value[1];
|
||||||
|
|
||||||
// duplicate value
|
// get fields from statement
|
||||||
preg_match( '<27>\'([^\']+)\'<27>i', $tmp_mysql_error, $duplicate_value = array() );
|
if ( $error_statement === 'UPDATE' ) {
|
||||||
$duplicate_value = $duplicate_value[1];
|
preg_match_all( '<27>(?:SET|,)\s*(?:\`)?([^\`]*)(?:\`)?\s*=\s*(\'|\"|\`)?([^\\2]*\\2|[^\s]+)<29>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 );
|
||||||
|
}
|
||||||
|
|
||||||
$sql = '
|
if ( $error_statement !== 'ALTER' ) {
|
||||||
SELECT *
|
// no alter statement
|
||||||
FROM ' . PMA_backquote( $error_table ) . '
|
// we need the fields in the affected index
|
||||||
WHERE CONCAT_WS( "-", ' . implode( ', ', $error_fields ) . ' )
|
// and the statement
|
||||||
= "' . 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"
|
$index_fields = array();
|
||||||
.' <input type="hidden" name="sql_query" value="' . htmlentities( $sql ) . '" />' . "\n"
|
|
||||||
.' ' . PMA_generate_common_hidden_inputs($db, $table) . "\n"
|
// get fields from index
|
||||||
.' <input type="submit" name="submit" value="' . $GLOBALS['strBrowse'] . '" />' . "\n"
|
require_once './libraries/tbl_indexes.lib.php';
|
||||||
.' </form>' . "\n";
|
|
||||||
unset( $sql );
|
// get affected index number
|
||||||
|
preg_match( '<27>\s([0-9]+)(?:\s|$)<29>', $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 ' <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
|
} // end of show duplicate entry
|
||||||
|
|
||||||
echo '</div>';
|
echo '</div>';
|
||||||
@@ -1921,7 +1979,6 @@ if (typeof(window.parent) != 'undefined'
|
|||||||
$tooltip .= '(' . PMA_formatNumber( $tbl_status['Rows'], 0 ) . ' ' . $GLOBALS['strRows'] . ')';
|
$tooltip .= '(' . PMA_formatNumber( $tbl_status['Rows'], 0 ) . ' ' . $GLOBALS['strRows'] . ')';
|
||||||
PMA_DBI_free_result($result);
|
PMA_DBI_free_result($result);
|
||||||
$uni_tbl = PMA_jsFormat( $GLOBALS['db'] . '.' . $GLOBALS['table'], false );
|
$uni_tbl = PMA_jsFormat( $GLOBALS['db'] . '.' . $GLOBALS['table'], false );
|
||||||
echo "\n";
|
|
||||||
?>
|
?>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
//<![CDATA[
|
//<![CDATA[
|
||||||
@@ -1930,7 +1987,7 @@ window.parent.updateTableTitle( '<?php echo $uni_tbl; ?>', '<?php echo PMA_jsFor
|
|||||||
</script>
|
</script>
|
||||||
<?php
|
<?php
|
||||||
} // end if
|
} // end if
|
||||||
} // end if... else if
|
} // end if
|
||||||
|
|
||||||
// Checks if the table needs to be repaired after a TRUNCATE query.
|
// Checks if the table needs to be repaired after a TRUNCATE query.
|
||||||
if (isset($GLOBALS['table']) && isset($GLOBALS['sql_query'])
|
if (isset($GLOBALS['table']) && isset($GLOBALS['sql_query'])
|
||||||
@@ -2172,6 +2229,18 @@ window.parent.updateTableTitle( '<?php echo $uni_tbl; ?>', '<?php echo PMA_jsFor
|
|||||||
if (!empty($GLOBALS['show_as_php'])) {
|
if (!empty($GLOBALS['show_as_php'])) {
|
||||||
echo '\';';
|
echo '\';';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$warnings = PMA_DBI_get_warnings();
|
||||||
|
if ( count( $warnings ) > 0 ) {
|
||||||
|
echo ' <strong>' . $GLOBALS['strMySQLSaid'] . '</strong>'
|
||||||
|
.PMA_showMySQLDocu('Error-returns', 'Error-returns');
|
||||||
|
foreach ( $warnings as $warning ) {
|
||||||
|
echo '<div class="' . $warning['Level'] . '">'
|
||||||
|
.'#' . $warning['Code'] . ' - ' . $warning['Message']
|
||||||
|
.'</div>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
echo '</fieldset>' . "\n";
|
echo '</fieldset>' . "\n";
|
||||||
|
|
||||||
if ( ! empty( $edit_target ) ) {
|
if ( ! empty( $edit_target ) ) {
|
||||||
@@ -2573,8 +2642,8 @@ window.parent.updateTableTitle( '<?php echo $uni_tbl; ?>', '<?php echo PMA_jsFor
|
|||||||
. ' value="' . htmlspecialchars($message) . '" />';
|
. ' value="' . htmlspecialchars($message) . '" />';
|
||||||
} else {
|
} else {
|
||||||
$ret .= '<input type="image"' . $submit_name . ' ' . implode( ' ', $tag_params_strings )
|
$ret .= '<input type="image"' . $submit_name . ' ' . implode( ' ', $tag_params_strings )
|
||||||
. ' src="' . preg_replace('<27>^.*\ssrc="([^"]*)".*$<24>si', '\1', $message) . '"'
|
. ' src="' . preg_replace('<27>^.*\ssrc="([^"]*)".*$<24>si', '\1', $message) . '"'
|
||||||
. ' value="' . htmlspecialchars(preg_replace('<27>^.*\salt="([^"]*)".*$<24>si', '\1', $message)) . '" />';
|
. ' value="' . htmlspecialchars(preg_replace('<27>^.*\salt="([^"]*)".*$<24>si', '\1', $message)) . '" />';
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$message = trim( strip_tags( $message ) );
|
$message = trim( strip_tags( $message ) );
|
||||||
|
Reference in New Issue
Block a user