From e726fe785d2a521e08263462bbeecbb564494042 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lo=C3=AFc=20Chapeaux?=
' . "\n";
echo '' . "\n" . $error_message . "\n" . '
' . "\n";
echo '
MySQL ' . mysql_result($res, 0, 'version') . ' ' . $strRunning . ' ' . $cfgServer['host']; if (!empty($cfgServer['port'])) { echo ':' . $cfgServer['port']; @@ -61,7 +61,7 @@ if ($server > 0) { * Reload mysql (flush privileges) */ if (($server > 0) && isset($mode) && ($mode == 'reload')) { - $result = mysql_query('FLUSH PRIVILEGES') or mysql_die('', 'FLUSH PRIVILEGES', FALSE); + $result = mysql_query('FLUSH PRIVILEGES') or mysql_die('', 'FLUSH PRIVILEGES', FALSE, 'main.php3?lang=' . $lang . '&server=' . $server); echo '
';
if ($result != 0) {
echo $strMySQLReloaded;
@@ -178,7 +178,7 @@ if ($server > 0
. $cfgServer['host'] . $server_port . $server_socket . ', '
. $cfgServer['stduser'] . ', '
. $cfgServer['stdpass'] . ')';
- mysql_die($conn_error, $local_query, FALSE, FALSE);
+ mysql_die($conn_error, $local_query, FALSE, '');
} else if (PHP_INT_VERSION >= 40000) {
@ini_set('track_errors', $bkp_track_err);
}
@@ -218,7 +218,7 @@ if ($server > 0
. $cfgServer['host'] . $server_port . $server_socket . ', '
. $cfgServer['user'] . ', '
. $cfgServer['password'] . ')';
- mysql_die($conn_error, $local_query, FALSE, FALSE);
+ mysql_die($conn_error, $local_query, FALSE, '');
} else if (PHP_INT_VERSION >= 40000) {
@ini_set('track_errors', $bkp_track_err);
}
@@ -265,7 +265,7 @@ if ($server > 0
-
+
@@ -273,7 +273,7 @@ if ($server > 0
-
+
@@ -286,7 +286,7 @@ if ($server > 0
-
+
@@ -367,7 +367,7 @@ if ($server > 0
-
+
@@ -376,7 +376,7 @@ if ($server > 0
-
+
@@ -385,7 +385,7 @@ if ($server > 0
-
+
diff --git a/mult_submits.inc.php3 b/mult_submits.inc.php3
index 996afc902..79ecc462f 100644
--- a/mult_submits.inc.php3
+++ b/mult_submits.inc.php3
@@ -141,13 +141,13 @@ else if ((get_magic_quotes_gpc() && stripslashes($btnDrop) == $strYes)
if ($query_type != 'drop_db') {
mysql_select_db($db);
}
- $result = @mysql_query($a_query) or mysql_die('', $a_query, FALSE);
+ $result = @mysql_query($a_query) or mysql_die('', $a_query, FALSE, $err_url);
} // end if
} // end for
if ($query_type == 'drop_tbl' || $query_type == 'drop_fld') {
mysql_select_db($db);
- $result = @mysql_query($sql_query) or mysql_die('', '', FALSE);
+ $result = @mysql_query($sql_query) or mysql_die('', '', FALSE, $err_url);
}
show_message($strSuccess);
diff --git a/read_dump.php3 b/read_dump.php3
index c93f3c8ed..11795c231 100644
--- a/read_dump.php3
+++ b/read_dump.php3
@@ -8,7 +8,6 @@
* Last revision: September 11, 2001 - loic1
*
* @param string the sql commands
- * @param string the end of command line delimiter
* @param integer the MySQL release number (because certains php3 versions
* can't get the value of a constant from within a function)
*
@@ -16,7 +15,7 @@
*
* @access public
*/
-function split_sql_file($sql, $delimiter, $release)
+function split_sql_file($sql, $release)
{
$sql = trim($sql);
$sql_len = strlen($sql);
@@ -24,7 +23,6 @@ function split_sql_file($sql, $delimiter, $release)
$ret = array();
$string_start = '';
$in_string = FALSE;
- $in_comment = FALSE;
for ($i = 0; $i < $sql_len; ++$i) {
$char = $sql[$i];
@@ -32,59 +30,51 @@ function split_sql_file($sql, $delimiter, $release)
// We are in a string, check for not escaped end of strings except for
// backquotes than cannot be escaped
if ($in_string) {
- while (1) {
- $i = strpos($sql, $string_start, $i);
+ for (;;) {
+ $i = strpos($sql, $string_start, $i);
// No end of string found -> add the current substring to the
// returned array
if (!$i) {
$ret[] = $sql;
return $ret;
}
- // It's trully the end of the string -> move to the next
- // character
- else if (($string_start == '`')
- || (($i > 1 && $sql[$i-1] . $sql[$i-2] != '\\\\')
- || ($sql[0] != '\\'))) {
+ // Backquotes or no backslashes before (double) quote(s): it's
+ // trully the end of the string -> exit the loop
+ else if ($string_start == '`' || $sql[$i-1] != '\\') {
$string_start = '';
$in_string = FALSE;
break;
- } // end if... elseif
- } // end while
- } // end if ($in_string)
+ }
+ // Backslashes before (double) quote(s) end of string...
+ else {
+ // ... first checks for escaped backslashes
+ $j = 2;
+ $escaped_backslash = FALSE;
+ while ($i-$j > 0 && $sql[$i-$j] == '\\') {
+ $escaped_backslash = !$escaped_backslash;
+ $j++;
+ }
+ // ... if escaped backslashes: it's trully the end of the
+ // string -> exit the loop
+ if ($escaped_backslash) {
+ $string_start = '';
+ $in_string = FALSE;
+ break;
+ }
+ // ... else loop
+ else {
+ $i++;
+ }
+ } // end if...elseif...else
+ } // end for
+ } // end if (in string)
- // We are in a comment, add the parsed part to the returned array and
- // move to the next end of line
- else if ($in_comment) {
- // comment starting position in string depends on the comment type
- $ret_end = (($sql[$i-1] == '#') ? $i-1 : $i-3);
- if (ereg('[^[:space:]]+', substr($sql, 0, $ret_end))) {
- $ret[] = substr($sql, 0, $ret_end);
- }
- // if no "\n" exits in the remaining string, checks for "\r" (Mac
- // eol style)
- $eol_to_find = (strpos($sql, "\012", $i)) ? "\012" : "\015";
- $sql = strstr($sql, $eol_to_find);
- if ($sql == '' || empty($sql[1])) {
- // The submited statement(s) end(s) by a comment -> stop
- // parsing
- return $ret;
- } else {
- $sql = ltrim(substr($sql, 1));
- $sql_len = strlen($sql);
- if ($sql_len) {
- $i = -1;
- $in_comment = FALSE;
- } else {
- // The submited statement(s) end(s) here
- return $ret;
- } // end if...else
- } // end if...else
- } // end if ($in_comment)
-
- // If delimiter found, add the parsed part to the returned array
- else if ($char == $delimiter) {
+ // We are not in a string, first check for delimiter...
+ else if ($char == ';') {
+ // if delimiter found, add the parsed part to the
+ // returned array
$ret[] = substr($sql, 0, $i);
- $sql = ltrim(substr($sql, min($i + 2, $sql_len)));
+ $sql = ltrim(substr($sql, min($i + 1, $sql_len)));
$sql_len = strlen($sql);
if ($sql_len) {
$i = -1;
@@ -92,32 +82,45 @@ function split_sql_file($sql, $delimiter, $release)
// The submited statement(s) end(s) here
return $ret;
}
- } // end if ($char == $delimiter)
+ } // end else if (is delimiter)
- // We are neither in a string nor in a comment, and nor the current
- // character is a delimiter...
- else {
- // ... first check for start of strings...
- if (($char == '"') || ($char == '\'') || ($char == '`')) {
- $in_string = TRUE;
- $string_start = $char;
- }
- // ... then check for start of a comment...
- else if ($char == '#'
- || ($char == ' ' && $i > 1 && $sql[$i-2] . $sql[$i-1] == '--')) {
- $in_comment = TRUE;
- }
- // ... and finally disactivate the "/*!...*/" syntax if
- // MySQL < 3.22.07
- else if ($release < 32270
- && ($char == '!' && $i > 1 && $sql[$i-2] . $sql[$i-1] == '/*')) {
- $sql[$i] = ' ';
- }
- } // end else
+ // ... then check for start of a string,...
+ else if (($char == '"') || ($char == '\'') || ($char == '`')) {
+ $in_string = TRUE;
+ $string_start = $char;
+ } // end else if (is start of string)
+
+ // ... for start of a comment (and remove this comment if found)...
+ else if ($char == '#'
+ || ($char == ' ' && $i > 1 && $sql[$i-2] . $sql[$i-1] == '--')) {
+ // starting position of the comment depends on the comment type
+ $start_of_comment = (($sql[$i] == '#') ? $i : $i-2);
+ // if no "\n" exits in the remaining string, checks for "\r"
+ // (Mac eol style)
+ $end_of_comment = (strpos(' ' . $sql, "\012", $i+2))
+ ? strpos(' ' . $sql, "\012", $i+2)
+ : strpos(' ' . $sql, "\015", $i+2);
+ if (!$end_of_comment) {
+ // no eol found after '#', so we are at end of dump -> stop
+ // parsing
+ return $ret;
+ } else {
+ $sql = substr($sql, 0, $start_of_comment)
+ . ltrim(substr($sql, $end_of_comment));
+ $sql_len = strlen($sql);
+ $i--;
+ } // end if...else
+ } // end else if (is comment)
+
+ // ... and finally disactivate the "/*!...*/" syntax if MySQL < 3.22.07
+ else if ($release < 32270
+ && ($char == '!' && $i > 1 && $sql[$i-2] . $sql[$i-1] == '/*')) {
+ $sql[$i] = ' ';
+ } // end else if
} // end for
// add any rest to the returned array
- if (!empty($sql)) {
+ if (!empty($sql) && ereg('[^[:space:]]+', $sql)) {
$ret[] = $sql;
}
return $ret;
@@ -138,6 +141,20 @@ require('./libraries/grab_globals.lib.php3');
require('./libraries/common.lib.php3');
+/**
+ * Defines the url to return to in case of error in a sql statement
+ */
+if (!isset($goto)
+ || ($goto != 'db_details.php3' && $goto != 'tbl_properties.php3')) {
+ $goto = 'db_details.php3';
+}
+$err_url = $goto
+ . '?lang=' . $lang
+ . '&server=' . $server
+ . '&db=' . urlencode($db)
+ . (($goto == 'tbl_properties.php3') ? '&table=' . urlencode($table) : '');
+
+
/**
* Set up default values for some variables and
*/
@@ -172,8 +189,6 @@ if (!empty($id_bookmark)) {
*/
// Gets the query from a file if required
if ($sql_file != 'none') {
-// loic1: php < 4.05 for windows seems not to list the regexp test
-// if (ereg('^php[0-9A-Za-z_.-]+$', basename($sql_file))) {
if (file_exists($sql_file)) {
$sql_query = fread(fopen($sql_file, 'r'), filesize($sql_file));
if (get_magic_quotes_runtime() == 1) {
@@ -203,7 +218,7 @@ if (!$cfgAllowUserDropDatabase
$result = @mysql_query('USE mysql');
if (mysql_error()) {
include('./header.inc.php3');
- mysql_die($strNoDropDatabases);
+ mysql_die($strNoDropDatabases, '', '', $err_url);
}
}
define('PMA_CHK_DROP', 1);
@@ -213,7 +228,7 @@ define('PMA_CHK_DROP', 1);
* Executes the query
*/
if ($sql_query != '') {
- $pieces = split_sql_file($sql_query, ';', MYSQL_INT_VERSION);
+ $pieces = split_sql_file($sql_query, MYSQL_INT_VERSION);
$pieces_count = count($pieces);
// Copy of the cleaned sql statement for display purpose only (see near the
@@ -226,13 +241,11 @@ if ($sql_query != '') {
// Only one query to run
if ($pieces_count == 1 && !empty($pieces[0]) && $view_bookmark == 0) {
- // loic1: remove non alphabetic characters from the beginning of the
- // query
- // $sql_query = trim($pieces[0]);
- $sql_query = eregi_replace('^[^a-aA-Z]', '', $pieces[0]);
// sql.php3 will stripslash the query if get_magic_quotes_gpc
if (get_magic_quotes_gpc() == 1) {
- $sql_query = addslashes($sql_query);
+ $sql_query = addslashes($pieces[0]);
+ } else {
+ $sql_query = $pieces[0];
}
if (eregi('^(DROP|CREATE)[[:space:]]+(IF EXISTS[[:space:]]+)?(TABLE|DATABASE)[[:space:]]+(.+)', $sql_query)) {
$reload = 1;
@@ -244,13 +257,11 @@ if ($sql_query != '') {
// Runs multiple queries
else if (mysql_select_db($db)) {
for ($i = 0; $i < $pieces_count; $i++) {
- $a_sql_query = trim($pieces[$i]);
- if (!empty($a_sql_query) && $a_sql_query[0] != '#') {
- $result = mysql_query($a_sql_query);
- if ($result == FALSE) { // readdump failed
- $my_die = $a_sql_query;
- break;
- }
+ $a_sql_query = $pieces[$i];
+ $result = mysql_query($a_sql_query);
+ if ($result == FALSE) { // readdump failed
+ $my_die = $a_sql_query;
+ break;
}
if (!isset($reload) && eregi('^(DROP|CREATE)[[:space:]]+(IF EXISTS[[:space:]]+)?(TABLE|DATABASE)[[:space:]]+(.+)', $a_sql_query)) {
$reload = 1;
@@ -267,17 +278,15 @@ if ($sql_query != '') {
$js_to_run = 'functions.js';
require('./header.inc.php3');
if (isset($my_die)) {
- mysql_die('', $my_die);
+ mysql_die('', $my_die, '', $err_url);
}
// Be nice with bandwidth...
-if ($sql_query_cpy == '') {
+if (!empty($sql_query_cpy)) {
$message = "$strSuccess :
$strTheContent ($pieces_count $strInstructions) ";
-} else {
+} else if (!empty($sql_query_cpy)) {
$message = $strSuccess;
-}
-if (!isset($goto)
- || ($goto != 'db_details.php3' && $goto != 'tbl_properties.php3')) {
- $goto = 'db_details.php3';
+} else {
+ $message = $strNoQuery;
}
require('./' . $goto);
?>
diff --git a/sql.php3 b/sql.php3
index 34b8f9e70..10fc2f8d3 100755
--- a/sql.php3
+++ b/sql.php3
@@ -9,6 +9,21 @@ require('./libraries/grab_globals.lib.php3');
require('./libraries/common.lib.php3');
+/**
+ * Defines the url to return to in case of error in a sql statement
+ */
+if (empty($goto)) {
+ $goto = (empty($table)) ? 'db_details.php3' : 'tbl_properties.php3';
+}
+if (!isset($err_url)) {
+ $err_url = $goto
+ . '?lang=' . $lang
+ . '&server=' . $server
+ . (isset($db) ? '&db=' . urlencode($db) : '')
+ . (($goto != 'db_details.php3' && isset($table)) ? '&table=' . urlencode($table) : '');
+}
+
+
/**
* Check rights in case of DROP DATABASE
*
@@ -25,7 +40,7 @@ if (!defined('PMA_CHK_DROP')
$result = @mysql_query('USE mysql');
if (mysql_error()) {
include('./header.inc.php3');
- mysql_die($strNoDropDatabases);
+ mysql_die($strNoDropDatabases, '', '', $err_url);
} // end if
} // end if
@@ -56,9 +71,7 @@ if (isset($btnDrop) || isset($navig)) {
/**
* Sets or modifies the $goto variable if required
*/
-if (empty($goto)) {
- $goto = (empty($table)) ? 'db_details.php3' : 'tbl_properties.php3';
-} else if ($goto == 'sql.php3') {
+if ($goto == 'sql.php3') {
$goto = 'sql.php3'
. '?lang=' . $lang
. '&server=' . $server
@@ -120,7 +133,7 @@ if ($do_confirm) {
-
+
@@ -141,7 +154,6 @@ else {
} else if (get_magic_quotes_gpc()) {
$sql_query = stripslashes($sql_query);
}
-
// Defines some variables
// loic1: A table have to be created -> left frame should be reloaded
if ((!isset($reload) || $reload == 0)
@@ -214,7 +226,7 @@ else {
if (mysql_error()) {
$error = mysql_error();
include('./header.inc.php3');
- mysql_die($error, $full_sql_query);
+ mysql_die($error, $full_sql_query, '', $err_url);
}
// Gets the number of rows affected/returned
@@ -299,7 +311,7 @@ else {
include('./header.inc.php3');
include('./libraries/bookmark.lib.php3');
- // Gets the list of fields properties
+ // Gets the list of fields properties
while ($field = mysql_fetch_field($result)) {
$fields_meta[] = $field;
}
diff --git a/tbl_addfield.php3 b/tbl_addfield.php3
index f44f04d78..1328bb167 100755
--- a/tbl_addfield.php3
+++ b/tbl_addfield.php3
@@ -12,6 +12,16 @@ if (isset($submit)) {
require('./header.inc.php3');
+/**
+ * Defines the url to return to in case of error in a sql statement
+ */
+$err_url = 'tbl_properties.php3'
+ . '?lang=' . $lang
+ . '&server=' . $server
+ . '&db=' . urlencode($db)
+ . '&table=' . urlencode($table);
+
+
/**
* The form used to define the field to add has been submitted
*/
@@ -25,7 +35,7 @@ if (isset($submit)) {
$field_name[$i] = stripslashes($field_name[$i]);
}
if (MYSQL_INT_VERSION < 32306) {
- check_reserved_words($field_name[$i]);
+ check_reserved_words($field_name[$i], $err_url);
}
$query .= backquote($field_name[$i]) . ' ' . $field_type[$i];
@@ -92,7 +102,7 @@ if (isset($submit)) {
$query = ereg_replace(', ADD $', '', $query);
$sql_query = 'ALTER TABLE ' . backquote($db) . '.' . backquote($table) . ' ADD ' . $query;
- $result = mysql_query($sql_query) or mysql_die();
+ $result = mysql_query($sql_query) or mysql_die('', '', '', $err_url);
$sql_query_cpy = $sql_query . ';';
// Builds the primary keys statements and updates the table
@@ -106,7 +116,7 @@ if (isset($submit)) {
$primary = ereg_replace(', $', '', $primary);
if (!empty($primary)) {
$sql_query = 'ALTER TABLE ' . backquote($db) . '.' . backquote($table) . ' ADD PRIMARY KEY (' . $primary . ')';
- $result = mysql_query($sql_query) or mysql_die();
+ $result = mysql_query($sql_query) or mysql_die('', '', '', $err_url);
$sql_query_cpy .= "\n" . $sql_query . ';';
}
} // end if
@@ -122,7 +132,7 @@ if (isset($submit)) {
$index = ereg_replace(', $', '', $index);
if (!empty($index)) {
$sql_query = 'ALTER TABLE ' . backquote($db) . '.' . backquote($table) . ' ADD INDEX (' . $index . ')';
- $result = mysql_query($sql_query) or mysql_die();
+ $result = mysql_query($sql_query) or mysql_die('', '', '', $err_url);
$sql_query_cpy .= "\n" . $sql_query . ';';
}
} // end if
@@ -138,7 +148,7 @@ if (isset($submit)) {
$unique = ereg_replace(', $', '', $unique);
if (!empty($unique)) {
$sql_query = 'ALTER TABLE ' . backquote($db) . '.' . backquote($table) . ' ADD UNIQUE (' . $unique . ')';
- $result = mysql_query($sql_query) or mysql_die();
+ $result = mysql_query($sql_query) or mysql_die('', '', '', $err_url);
$sql_query_cpy .= "\n" . $sql_query . ';';
}
} // end if
@@ -155,7 +165,7 @@ if (isset($submit)) {
$fulltext = ereg_replace(', $', '', $fulltext);
if (!empty($fulltext)) {
$sql_query = 'ALTER TABLE ' . backquote($db) . '.' . backquote($table) . ' ADD FULLTEXT (' . $fulltext . ')';
- $result = mysql_query($sql_query) or mysql_die();
+ $result = mysql_query($sql_query) or mysql_die('', '', '', $err_url);
$sql_query_cpy .= "\n" . $sql_query . ';';
}
} // end if
diff --git a/tbl_alter.php3 b/tbl_alter.php3
index 4a590fccd..75da9f54a 100755
--- a/tbl_alter.php3
+++ b/tbl_alter.php3
@@ -14,6 +14,16 @@ if (!isset($submit_mult)) {
}
+/**
+ * Defines the url to return to in case of error in a sql statement
+ */
+$err_url = 'tbl_properties.php3'
+ . '?lang=' . $lang
+ . '&server=' . $server
+ . '&db=' . urlencode($db)
+ . '&table=' . urlencode($table);
+
+
/**
* Modifications have been submitted -> updates the table
*/
@@ -27,7 +37,7 @@ if (isset($submit)) {
}
if (MYSQL_INT_VERSION < 32306) {
- check_reserved_words($field_name[$i]);
+ check_reserved_words($field_name[$i], $err_url);
}
// Some fields have been urlencoded or double quotes have been translated
@@ -75,7 +85,7 @@ if (isset($submit)) {
// Optimization fix - 2 May 2001 - Robbat2
$sql_query = 'ALTER TABLE ' . backquote($db) . '.' . backquote($table) . ' CHANGE ' . $query;
- $result = mysql_query($sql_query) or mysql_die();
+ $result = mysql_query($sql_query) or mysql_die('', '', '', $err_url);
$message = $strTable . ' ' . htmlspecialchars($table) . ' ' . $strHasBeenAltered;
$btnDrop = 'Fake';
include('./tbl_properties.php3');
@@ -102,7 +112,7 @@ else {
$field = sql_addslashes($selected[$i], TRUE);
}
$local_query = 'SHOW FIELDS FROM ' . backquote($db) . '.' . backquote($table) . " LIKE '$field'";
- $result = mysql_query($local_query) or mysql_die('', $local_query);
+ $result = mysql_query($local_query) or mysql_die('', $local_query, '', $err_url);
$fields_meta[] = mysql_fetch_array($result);
mysql_free_result($result);
}
diff --git a/tbl_change.php3 b/tbl_change.php3
index 184d9d8df..4de5e8884 100755
--- a/tbl_change.php3
+++ b/tbl_change.php3
@@ -17,6 +17,23 @@ if (get_magic_quotes_gpc()) {
}
+/**
+ * Defines the url to return to in case of error in a sql statement
+ */
+if (!isset($goto)) {
+ $goto = 'db_details.php3';
+}
+if ($goto != 'db_details.php3' && $goto != 'tbl_properties.php3') {
+ $err_url = $goto;
+} else {
+ $err_url = $goto
+ . '?lang=' . $lang
+ . '&server=' . $server
+ . '&db=' . urlencode($db)
+ . (($goto == 'tbl_properties.php3') ? '&table=' . urlencode($table) : '');
+}
+
+
/**
* Get the list of the fields of the current table
*/
@@ -24,13 +41,13 @@ mysql_select_db($db);
$table_def = mysql_query('SHOW FIELDS FROM ' . backquote($table));
if (isset($primary_key)) {
$local_query = 'SELECT * FROM ' . backquote($table) . ' WHERE ' . $primary_key;
- $result = mysql_query($local_query) or mysql_die('', $local_query);
+ $result = mysql_query($local_query) or mysql_die('', $local_query, '', $err_url);
$row = mysql_fetch_array($result);
}
else
{
$local_query = 'SELECT * FROM ' . backquote($table) . ' LIMIT 1';
- $result = mysql_query($local_query) or mysql_die('', $local_query);
+ $result = mysql_query($local_query) or mysql_die('', $local_query, '', $err_url);
unset($row);
}
@@ -42,13 +59,14 @@ else