1
0
mirror of https://github.com/e107inc/e107.git synced 2025-07-31 20:00:37 +02:00

Make db_debug work with SQL_CALC_FOUND_ROWS

This commit is contained in:
e107steved
2008-05-17 17:18:36 +00:00
parent 7208ea3304
commit 76d836d9f4
2 changed files with 21 additions and 26 deletions

View File

@@ -11,8 +11,8 @@
| GNU General Public License (http://gnu.org). | GNU General Public License (http://gnu.org).
| |
| $Source: /cvs_backup/e107_0.8/e107_handlers/db_debug_class.php,v $ | $Source: /cvs_backup/e107_0.8/e107_handlers/db_debug_class.php,v $
| $Revision: 1.6 $ | $Revision: 1.7 $
| $Date: 2008-05-17 14:41:43 $ | $Date: 2008-05-17 17:18:36 $
| $Author: e107steved $ | $Author: e107steved $
+----------------------------------------------------------------------------+ +----------------------------------------------------------------------------+
*/ */
@@ -125,21 +125,13 @@ class e107_db_debug {
$ExplainText = ''; $ExplainText = '';
// Note the subtle bracket in the second comparison! Also, strcasecmp() returns zero on match // Note the subtle bracket in the second comparison! Also, strcasecmp() returns zero on match
if (!strcasecmp($qtype,'SELECT') || !strcasecmp($qtype,'(SELECT')) if (!strcasecmp($qtype,'SELECT') || !strcasecmp($qtype,'(SELECT'))
{ // It's a SELECT statement - explain it (usually) { // It's a SELECT statement - explain it
if (strpos($args,'SQL_CALC_FOUND_ROWS') === FALSE) // $rli should always be set by caller
{ $sQryRes = (is_null($rli) ? mysql_query("EXPLAIN {$query}") : mysql_query("EXPLAIN {$query}", $rli));
// $rli should always be set by caller if ($sQryRes)
$sQryRes = (is_null($rli) ? mysql_query("EXPLAIN {$query}") : mysql_query("EXPLAIN {$query}", $rli)); { // There's something to explain
if ($sQryRes) $nFields = mysql_num_fields($sQryRes);
{ // There's something to explain $bExplained = TRUE;
$nFields = mysql_num_fields($sQryRes);
$bExplained = TRUE;
}
}
else
{ // Blocked queries containing 'SQL_CALC_FOUND_ROWS' ATM - they get broken by the 'explain'
$ExplainText = "<tr><td class='forumheader3'>Cannot EXPLAIN queries containing SQL_CALC_FOUND_ROWS</td></tr>";
$sQryRes = $origQryRes; // Return from original query could be TRUE or a link resource if success
} }
} }
else else

View File

@@ -12,8 +12,8 @@
| GNU General Public License (http://gnu.org). | GNU General Public License (http://gnu.org).
| |
| $Source: /cvs_backup/e107_0.8/e107_handlers/mysql_class.php,v $ | $Source: /cvs_backup/e107_0.8/e107_handlers/mysql_class.php,v $
| $Revision: 1.23 $ | $Revision: 1.24 $
| $Date: 2008-05-14 20:20:32 $ | $Date: 2008-05-17 17:18:36 $
| $Author: e107steved $ | $Author: e107steved $
| |
+----------------------------------------------------------------------------+ +----------------------------------------------------------------------------+
@@ -30,7 +30,7 @@ $db_ConnectionID = NULL; // Stores ID for the first DB connection used - which s
* MySQL Abstraction class * MySQL Abstraction class
* *
* @package e107 * @package e107
* @version $Revision: 1.23 $ * @version $Revision: 1.24 $
* @author $Author: e107steved $ * @author $Author: e107steved $
*/ */
class db { class db {
@@ -208,6 +208,15 @@ class db {
$mytime = $eTraffic->TimeDelta($b,$e); $mytime = $eTraffic->TimeDelta($b,$e);
$db_time += $mytime; $db_time += $mytime;
$this->mySQLresult = $sQryRes; $this->mySQLresult = $sQryRes;
if ((strpos($query,'SQL_CALC_FOUND_ROWS') !== FALSE) && (strpos($query,'SELECT') !== FALSE))
{ // Need to get the total record count as well. Return code is a resource identifier
// Have to do this before any debug action, otherwise this bit gets messed up
$fr = mysql_query("SELECT FOUND_ROWS()", $this->mySQLaccess);
$rc = mysql_fetch_array($fr);
$this->total_results = $rc['FOUND_ROWS()'];
}
if (E107_DEBUG_LEVEL) { if (E107_DEBUG_LEVEL) {
global $db_debug; global $db_debug;
$aTrace = debug_backtrace(); $aTrace = debug_backtrace();
@@ -610,12 +619,6 @@ class db {
else else
{ // Successful query which does return a row count - get the count and return it { // Successful query which does return a row count - get the count and return it
$this->dbError('db_Select_gen'); $this->dbError('db_Select_gen');
if (strpos($query,'SQL_CALC_FOUND_ROWS') !== FALSE)
{ // Need to get the total record count as well. Return code is a resource identifier
$fr = mysql_query("SELECT FOUND_ROWS()", $this->mySQLaccess);
$rc = mysql_fetch_array($fr);
$this->total_results = $rc['FOUND_ROWS()'];
}
return $this->db_Rows(); return $this->db_Rows();
} }
} }