1
0
mirror of https://github.com/e107inc/e107.git synced 2025-04-20 04:32:01 +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).
|
| $Source: /cvs_backup/e107_0.8/e107_handlers/db_debug_class.php,v $
| $Revision: 1.6 $
| $Date: 2008-05-17 14:41:43 $
| $Revision: 1.7 $
| $Date: 2008-05-17 17:18:36 $
| $Author: e107steved $
+----------------------------------------------------------------------------+
*/
@ -125,21 +125,13 @@ class e107_db_debug {
$ExplainText = '';
// Note the subtle bracket in the second comparison! Also, strcasecmp() returns zero on match
if (!strcasecmp($qtype,'SELECT') || !strcasecmp($qtype,'(SELECT'))
{ // It's a SELECT statement - explain it (usually)
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));
if ($sQryRes)
{ // There's something to explain
$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
{ // It's a SELECT statement - explain it
// $rli should always be set by caller
$sQryRes = (is_null($rli) ? mysql_query("EXPLAIN {$query}") : mysql_query("EXPLAIN {$query}", $rli));
if ($sQryRes)
{ // There's something to explain
$nFields = mysql_num_fields($sQryRes);
$bExplained = TRUE;
}
}
else

View File

@ -12,8 +12,8 @@
| GNU General Public License (http://gnu.org).
|
| $Source: /cvs_backup/e107_0.8/e107_handlers/mysql_class.php,v $
| $Revision: 1.23 $
| $Date: 2008-05-14 20:20:32 $
| $Revision: 1.24 $
| $Date: 2008-05-17 17:18:36 $
| $Author: e107steved $
|
+----------------------------------------------------------------------------+
@ -30,7 +30,7 @@ $db_ConnectionID = NULL; // Stores ID for the first DB connection used - which s
* MySQL Abstraction class
*
* @package e107
* @version $Revision: 1.23 $
* @version $Revision: 1.24 $
* @author $Author: e107steved $
*/
class db {
@ -208,6 +208,15 @@ class db {
$mytime = $eTraffic->TimeDelta($b,$e);
$db_time += $mytime;
$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) {
global $db_debug;
$aTrace = debug_backtrace();
@ -610,12 +619,6 @@ class db {
else
{ // Successful query which does return a row count - get the count and return it
$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();
}
}