diff --git a/ChangeLog b/ChangeLog index 5f20f7c97..2f30df364 100644 --- a/ChangeLog +++ b/ChangeLog @@ -134,6 +134,7 @@ thanks to erickoh75 - erickoh75 - patch #3150164 [structure] Ordering by size gives incorrect results, thanks to Madhura Jayaratne - madhuracj +- bug #3153409 [core] 0 row(s) affected 3.3.9.0 (2011-01-03) - bug [doc] Fix references to MySQL doc diff --git a/libraries/database_interface.lib.php b/libraries/database_interface.lib.php index 0877dda71..012eb7c1f 100644 --- a/libraries/database_interface.lib.php +++ b/libraries/database_interface.lib.php @@ -69,8 +69,8 @@ require_once './libraries/dbi/' . $GLOBALS['cfg']['Server']['extension'] . '.dbi /** * Common Functions */ -function PMA_DBI_query($query, $link = null, $options = 0) { - $res = PMA_DBI_try_query($query, $link, $options) +function PMA_DBI_query($query, $link = null, $options = 0, $cache_affected_rows = true) { + $res = PMA_DBI_try_query($query, $link, $options, $cache_affected_rows) or PMA_mysqlDie(PMA_DBI_getError($link), $query); return $res; } diff --git a/libraries/dbi/mysql.dbi.lib.php b/libraries/dbi/mysql.dbi.lib.php index c5ff26f17..1db4f1eac 100644 --- a/libraries/dbi/mysql.dbi.lib.php +++ b/libraries/dbi/mysql.dbi.lib.php @@ -154,7 +154,7 @@ function PMA_DBI_select_db($dbname, $link = null) * @param integer $options * @return mixed */ -function PMA_DBI_try_query($query, $link = null, $options = 0) +function PMA_DBI_try_query($query, $link = null, $options = 0, $cache_affected_rows = true) { if (empty($link)) { if (isset($GLOBALS['userlink'])) { @@ -175,6 +175,10 @@ function PMA_DBI_try_query($query, $link = null, $options = 0) $r = mysql_query($query, $link); } + if ($cache_affected_rows) { + $GLOBALS['cached_affected_rows'] = PMA_DBI_affected_rows($link, $get_from_cache = false); + } + if ($GLOBALS['cfg']['DBG']['sql']) { $time = microtime(true) - $time; @@ -398,7 +402,16 @@ function PMA_DBI_insert_id($link = null) return PMA_DBI_fetch_value('SELECT LAST_INSERT_ID();', 0, 0, $link); } -function PMA_DBI_affected_rows($link = null) +/** + * returns the number of rows affected by last query + * + * @uses $GLOBALS['userlink'] + * @uses mysql_affected_rows() + * @param object mysql $link the mysql object + * @param boolean $get_from_cache + * @return string integer + */ +function PMA_DBI_affected_rows($link = null, $get_from_cache = true) { if (empty($link)) { if (isset($GLOBALS['userlink'])) { @@ -407,7 +420,12 @@ function PMA_DBI_affected_rows($link = null) return false; } } - return mysql_affected_rows($link); + + if ($get_from_cache) { + return $GLOBALS['cached_affected_rows']; + } else { + return mysql_affected_rows($link); + } } /** diff --git a/libraries/dbi/mysqli.dbi.lib.php b/libraries/dbi/mysqli.dbi.lib.php index e027f236f..8022c771d 100644 --- a/libraries/dbi/mysqli.dbi.lib.php +++ b/libraries/dbi/mysqli.dbi.lib.php @@ -172,9 +172,10 @@ function PMA_DBI_select_db($dbname, $link = null) * @param string $query query to execute * @param object mysqli $link mysqli object * @param integer $options + * @param boolean $cache_affected_rows * @return mixed true, false or result object */ -function PMA_DBI_try_query($query, $link = null, $options = 0) +function PMA_DBI_try_query($query, $link = null, $options = 0, $cache_affected_rows = true) { if ($options == ($options | PMA_DBI_QUERY_STORE)) { $method = MYSQLI_STORE_RESULT; @@ -196,6 +197,11 @@ function PMA_DBI_try_query($query, $link = null, $options = 0) $time = microtime(true); } $r = mysqli_query($link, $query, $method); + + if ($cache_affected_rows) { + $GLOBALS['cached_affected_rows'] = PMA_DBI_affected_rows($link, $get_from_cache = false); + } + if ($GLOBALS['cfg']['DBG']['sql']) { $time = microtime(true) - $time; @@ -455,9 +461,10 @@ function PMA_DBI_insert_id($link = '') * @uses $GLOBALS['userlink'] * @uses mysqli_affected_rows() * @param object mysqli $link the mysqli object + * @param boolean $get_from_cache * @return string integer */ -function PMA_DBI_affected_rows($link = null) +function PMA_DBI_affected_rows($link = null, $get_from_cache = true) { if (empty($link)) { if (isset($GLOBALS['userlink'])) { @@ -466,7 +473,11 @@ function PMA_DBI_affected_rows($link = null) return false; } } - return mysqli_affected_rows($link); + if ($get_from_cache) { + return $GLOBALS['cached_affected_rows']; + } else { + return mysqli_affected_rows($link); + } } /** diff --git a/libraries/relation.lib.php b/libraries/relation.lib.php index 960e8905a..18504e255 100644 --- a/libraries/relation.lib.php +++ b/libraries/relation.lib.php @@ -22,10 +22,16 @@ if (! defined('PHPMYADMIN')) { */ function PMA_query_as_controluser($sql, $show_error = true, $options = 0) { + // Avoid caching of the number of rows affected; for example, this function + // is called for tracking purposes but we want to display the correct number + // of rows affected by the original query, not by the query generated for + // tracking. + $cache_affected_rows = false; + if ($show_error) { - $result = PMA_DBI_query($sql, $GLOBALS['controllink'], $options); + $result = PMA_DBI_query($sql, $GLOBALS['controllink'], $options, $cache_affected_rows); } else { - $result = @PMA_DBI_try_query($sql, $GLOBALS['controllink'], $options); + $result = @PMA_DBI_try_query($sql, $GLOBALS['controllink'], $options, $cache_affected_rows); } // end if... else... if ($result) { diff --git a/tbl_replace.php b/tbl_replace.php index f7371ec8e..7a60ddb66 100644 --- a/tbl_replace.php +++ b/tbl_replace.php @@ -363,7 +363,7 @@ foreach ($query as $single_query) { if (! $result) { $error_messages[] = PMA_DBI_getError(); } else { - // the following is a real assignment: + // The next line contains a real assignment, it's not a typo if ($tmp = @PMA_DBI_affected_rows()) { $total_affected_rows += $tmp; }