From d1f3349f7b7cd7816c125cf83616db154a43b8b1 Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Fri, 22 Apr 2005 17:44:36 +0000 Subject: - dbal changes git-svn-id: file:///svn/phpbb/trunk@5130 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/db/firebird.php | 103 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 102 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/db/firebird.php') diff --git a/phpBB/includes/db/firebird.php b/phpBB/includes/db/firebird.php index b0fb130735..afce881eaf 100644 --- a/phpBB/includes/db/firebird.php +++ b/phpBB/includes/db/firebird.php @@ -233,7 +233,7 @@ class sql_db function sql_affectedrows() { - // hmm, maybe doing something similar as in mssql-odbc.php? + // TODO: hmm, maybe doing something similar as in mssql-odbc.php? return ($this->query_result) ? true : false; } @@ -419,6 +419,107 @@ class sql_db return $result; } + function sql_report($mode, $query = '') + { + if (empty($_GET['explain'])) + { + return; + } + + global $cache, $starttime, $phpbb_root_path; + static $curtime, $query_hold, $html_hold; + static $sql_report = ''; + static $cache_num_queries = 0; + + if (!$query && !empty($query_hold)) + { + $query = $query_hold; + } + + switch ($mode) + { + case 'display': + if (!empty($cache)) + { + $cache->unload(); + } + $this->sql_close(); + + $mtime = explode(' ', microtime()); + $totaltime = $mtime[0] + $mtime[1] - $starttime; + + echo '' . $msg_title . ''; + echo '
phpBB LogoSQL Report      

Page generated in ' . round($totaltime, 4) . " seconds with {$this->num_queries} queries" . (($cache_num_queries) ? " + $cache_num_queries " . (($cache_num_queries == 1) ? 'query' : 'queries') . ' returning data from cache' : '') . '
Time spent on MySQL queries: ' . round($this->sql_time, 5) . 's | Time spent on PHP: ' . round($totaltime - $this->sql_time, 5) . 's
'; + echo $sql_report; + echo '

'; + exit; + break; + + case 'start': + $query_hold = $query; + $html_hold = ''; + + $curtime = explode(' ', microtime()); + $curtime = $curtime[0] + $curtime[1]; + break; + + case 'fromcache': + $endtime = explode(' ', microtime()); + $endtime = $endtime[0] + $endtime[1]; + + $result = @ibase_query($this->db_connect_id, $query); + while ($void = @ibase_fetch_object($result, IBASE_TEXT)) + { + // Take the time spent on parsing rows into account + } + $splittime = explode(' ', microtime()); + $splittime = $splittime[0] + $splittime[1]; + + $time_cache = $endtime - $curtime; + $time_db = $splittime - $endtime; + $color = ($time_db > $time_cache) ? 'green' : 'red'; + + $sql_report .= '

Query results obtained from the cache

'; + + $sql_report .= 'Before: ' . sprintf('%.5f', $curtime - $starttime) . 's | After: ' . sprintf('%.5f', $endtime - $starttime) . 's | Elapsed [cache]: ' . sprintf('%.5f', ($time_cache)) . 's | Elapsed [db]: ' . sprintf('%.5f', $time_db) . 's

'; + + // Pad the start time to not interfere with page timing + $starttime += $time_db; + + @ibase_freeresult($result); + $cache_num_queries++; + break; + + case 'stop': + $endtime = explode(' ', microtime()); + $endtime = $endtime[0] + $endtime[1]; + + $sql_report .= '

Query #' . $this->num_queries . '
' . $html_hold . '

'; + + if ($this->query_result) + { + if (preg_match('/^(UPDATE|DELETE|REPLACE)/', $query)) + { + $sql_report .= "Affected rows: " . $this->sql_affectedrows($this->query_result) . ' | '; + } + $sql_report .= 'Before: ' . sprintf('%.5f', $curtime - $starttime) . 's | After: ' . sprintf('%.5f', $endtime - $starttime) . 's | Elapsed: ' . sprintf('%.5f', $endtime - $curtime) . 's'; + } + else + { + $error = $this->sql_error(); + $sql_report .= 'FAILED - ' . SQL_LAYER . ' Error ' . $error['code'] . ': ' . htmlspecialchars($error['message']); + } + + $sql_report .= '

'; + + $this->sql_time += $endtime - $curtime; + break; + } + } + } // class sql_db } // if ... define -- cgit v1.2.1