diff --git a/ChangeLog b/ChangeLog index a5b66acc0..6f7c59d9d 100755 --- a/ChangeLog +++ b/ChangeLog @@ -6,9 +6,9 @@ $Id$ $Source$ 2001-08-20 Olivier Müller - * db_stats.php3: new file and feature (sorry :) : simply display - an overview of all databases with their respective size + server total. - * lang/*: new string $strDatabasesStats + * db_stats.php3: new file and feature (sorry :) : simply display an + overview of all databases with their respective size + server total. + * lang/*: new string $strDatabasesStats. 2001-08-20 Marc Delisle * config.inc.php3: $cfgProtectBlob is now TRUE by default, to help against @@ -36,6 +36,7 @@ $Source$ * lib.inc.php3, lines 266-277; config.lib.php3, lines 43, 57 & 70; Documentation.html, lines 273-278 & 655-658: merged the socket patch from Dan Allen . + * sql.php3: improved the way the mysql_affected_rows is used. 2001-08-19 Olivier Müller * db_readdump.php3: if file contains mutiple queries, only show this line: @@ -53,7 +54,7 @@ $Source$ * main.php3; db_details.php3; tbl_properties.php3; db_readdump.php3; lib.inc.php3: once a query has been executed phpMyAdmin now moves back to the calling script (rather than db_details.php3 everytime) as soon as - the current database/table exists, else it moves back to a "parent" + the current database/table exists, else it moves back to a "parent" script (the welcome page/'db_details.php3' if the current database/table has has been dropped. * header.inc.php3, lines 63-64; sql.php3; db_details.php3; @@ -61,7 +62,7 @@ $Source$ to the calling script (and not the target one used only if this statement is executed). * db_readdump.php3: improved Olivier's improvement for mutiple queries (see - before). + before). * lib.inc.php3, line 524: beautify a bit the way the query is displayed. * lang/english.inc.php3; lang/french.inc.php3: put $strInstructions at its right place. diff --git a/sql.php3 b/sql.php3 index dba61f25e..b033b3f52 100755 --- a/sql.php3 +++ b/sql.php3 @@ -59,12 +59,12 @@ if (isset($btnDrop) && $btnDrop == $strNo) { /** * Defines some "properties" of the sql query to submit */ -$do_confirm = ($cfgConfirm - && !isset($btnDrop) - && eregi('DROP +(TABLE|DATABASE)|ALTER TABLE +[[:alnum:]_`]* +DROP|DELETE FROM', $sql_query)); -$is_select = eregi('^SELECT ', $sql_query); -$is_count = ($is_select && eregi('^SELECT COUNT\((.*\.+)?\*\) FROM ', $sql_query)); -$is_delupd = eregi('^(DELETE|UPDATE) ', $sql_query); +$do_confirm = ($cfgConfirm + && !isset($btnDrop) + && eregi('DROP +(TABLE|DATABASE)|ALTER TABLE +[[:alnum:]_`]* +DROP|DELETE FROM', $sql_query)); +$is_select = eregi('^SELECT ', $sql_query); +$is_count = ($is_select && eregi('^SELECT COUNT\((.*\.+)?\*\) FROM ', $sql_query)); +$is_affected = eregi('^(DELETE|INSERT|LOAD DATA|UPDATE) ', $sql_query); /** @@ -109,7 +109,7 @@ else { $sql_query = stripslashes($sql_query); } - //defines some variables + // Defines some variables // loic1: A table have to be created -> left frame should be reloaded if (!empty($reload) && eregi('^CREATE TABLE (.*)', $sql_query)) { $reload = 'true'; @@ -128,8 +128,23 @@ else { $full_sql_query = $sql_query . $sql_limit_to_append; } - // Executes the query mysql_select_db($db); + + // If the query is a DELETE query with no WHERE clause, get the number of + // rows that will be deleted (mysql_affected_rows will always return 0 in + // this case) + if ($is_affected + && eregi('^DELETE( .+)?( FROM (.+))$', $sql_query, $parts) + && !eregi(' WHERE ', $parts[3])) { + $OPresult = @mysql_query('SELECT COUNT(*) as count' . $parts[2]); + if ($OPresult) { + $num_rows = mysql_result($OPresult, 0, 'count'); + } else { + $num_rows = 0; + } + } + + // Executes the query $result = @mysql_query($full_sql_query); // Displays an error message if required and stop parsing the script @@ -139,9 +154,12 @@ else { mysql_die($error, $full_sql_query); } - // Gets the number of rows returned ('@' is required because mysql_num_rows - // ran on queries that are not 'SELECT' statements returns an error - $num_rows = @mysql_num_rows($result); + // Gets the number of rows affected/returned + if (!$is_affected) { + $num_rows = @mysql_num_rows($result); + } else if (!isset($num_rows)) { + $num_rows = @mysql_affected_rows(); + } // Counts the total number of rows for the same 'SELECT' query without the // 'LIMIT' clause that may have been programatically added @@ -164,10 +182,10 @@ else { } // end rows total count // No rows returned -> move back to the calling page - if ($num_rows < 1) { + if ($num_rows < 1 || $is_affected) { if (file_exists('./' . $goto)) { - if ($is_delupd) { - $message = $strAffectedRows . ' ' . mysql_affected_rows(); + if ($is_affected) { + $message = $strAffectedRows . ' ' . $num_rows; } else if (!empty($zero_rows)) { $message = $zero_rows; } else {