1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-07-30 21:40:43 +02:00

- seperate queries and cached queries

- display correct read/unread information while displaying active topics
- fix for SELECT DISTINCT in mssql using sql_query_limit
- fix for forum updating in ACP using mssql (and probably other dbal having problems with primary keys in updates)


git-svn-id: file:///svn/phpbb/trunk@5940 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Meik Sievertsen
2006-05-20 13:20:38 +00:00
parent c81a44ea30
commit 0115e94cfd
12 changed files with 452 additions and 364 deletions

View File

@@ -952,11 +952,18 @@ class acp_forums
$db->sql_query($sql);
}
// Setting the forum id to the forum id is not really received well by some dbs. ;)
$forum_id = $forum_data['forum_id'];
unset($forum_data['forum_id']);
$sql = 'UPDATE ' . FORUMS_TABLE . '
SET ' . $db->sql_build_array('UPDATE', $forum_data) . '
WHERE forum_id = ' . $forum_data['forum_id'];
WHERE forum_id = ' . $forum_id;
$db->sql_query($sql);
// Add it back
$forum_data['forum_id'] = $forum_id;
add_log('admin', 'LOG_FORUM_EDIT', $forum_data['forum_name']);
}
}

View File

@@ -19,20 +19,31 @@ class dbal
var $return_on_error = false;
var $transaction = false;
var $sql_time = 0;
var $num_queries = 0;
var $num_queries = array();
var $open_queries = array();
var $curtime = 0;
var $query_hold = '';
var $html_hold = '';
var $sql_report = '';
var $cache_num_queries = 0;
var $persistency = false;
var $user = '';
var $server = '';
var $dbname = '';
/**
* Constructor
*/
function dbal()
{
$this->num_queries = array(
'cached' => 0,
'normal' => 0,
'total' => 0,
);
}
/**
* return on error or display error message
*/
@@ -42,11 +53,21 @@ class dbal
}
/**
* Return number of sql queries used (cached and real queries are counted the same)
* Return number of sql queries and cached sql queries used
*/
function sql_num_queries()
function sql_num_queries($cached = false)
{
return $this->num_queries;
return ($cached) ? $this->num_queries['cached'] : $this->num_queries['normal'];
}
/**
* Add to query count
*/
function sql_add_num_queries($cached = false)
{
$this->num_queries['cached'] += ($cached) ? 1 : 0;
$this->num_queries['normal'] += ($cached) ? 0 : 1;
$this->num_queries['total'] += 1;
}
/**
@@ -360,7 +381,7 @@ class dbal
<div id="content">
<h1>SQL Report</h1>
<br />
<p><b>Page generated in ' . round($totaltime, 4) . " seconds with {$this->num_queries} queries" . (($this->cache_num_queries) ? " + {$this->cache_num_queries} " . (($this->cache_num_queries == 1) ? 'query' : 'queries') . ' returning data from cache' : '') . '</b></p>
<p><b>Page generated in ' . round($totaltime, 4) . " seconds with {$this->num_queries['normal']} queries" . (($this->num_queries['cached']) ? " + {$this->num_queries['cached']} " . (($this->num_queries['cached'] == 1) ? 'query' : 'queries') . ' returning data from cache' : '') . '</b></p>
<p>Time spent on ' . SQL_LAYER . ' queries: <b>' . round($this->sql_time, 5) . 's</b> | Time spent on PHP: <b>' . round($totaltime - $this->sql_time, 5) . 's</b></p>
@@ -388,7 +409,7 @@ class dbal
<table cellspacing="1">
<thead>
<tr>
<th>Query #' . $this->num_queries . '</th>
<th>Query #' . $this->num_queries['total'] . '</th>
</tr>
</thead>
<tbody>
@@ -466,7 +487,7 @@ class dbal
$this->_sql_report($mode, $query);
$this->cache_num_queries++;
// $this->num_queries['cache']++;
break;

View File

@@ -94,11 +94,10 @@ class dbal_firebird extends dbal
$this->last_query_text = $query;
$this->query_result = ($cache_ttl && method_exists($cache, 'sql_load')) ? $cache->sql_load($query) : false;
$this->sql_add_num_queries($this->query_result);
if (!$this->query_result)
{
$this->num_queries++;
if (($this->query_result = @ibase_query($this->db_connect_id, $query)) === false)
{
$this->sql_error($query);

View File

@@ -105,10 +105,10 @@ class dbal_mssql extends dbal
}
$this->query_result = ($cache_ttl && method_exists($cache, 'sql_load')) ? $cache->sql_load($query) : false;
$this->sql_add_num_queries($this->query_result);
if (!$this->query_result)
{
$this->num_queries++;
if (($this->query_result = @mssql_query($query, $this->db_connect_id)) === false)
{
$this->sql_error($query);
@@ -160,7 +160,14 @@ class dbal_mssql extends dbal
$row_offset = ($total) ? $offset : '';
$num_rows = ($total) ? $total : $offset;
$query = 'SELECT TOP ' . ($row_offset + $num_rows) . ' ' . substr($query, 6);
if (strpos($query, 'SELECT DISTINCT') === 0)
{
$query = 'SELECT DISTINCT TOP ' . ($row_offset + $num_rows) . ' ' . substr($query, 15);
}
else
{
$query = 'SELECT TOP ' . ($row_offset + $num_rows) . ' ' . substr($query, 6);
}
return $this->sql_query($query, $cache_ttl);
}

View File

@@ -104,11 +104,10 @@ class dbal_mssql_odbc extends dbal
$this->last_query_text = $query;
$this->query_result = ($cache_ttl && method_exists($cache, 'sql_load')) ? $cache->sql_load($query) : false;
$this->sql_add_num_queries($this->query_result);
if (!$this->query_result)
{
$this->num_queries++;
if (($this->query_result = @odbc_exec($this->db_connect_id, $query)) === false)
{
$this->sql_error($query);
@@ -160,7 +159,14 @@ class dbal_mssql_odbc extends dbal
$row_offset = ($total) ? $offset : '';
$num_rows = ($total) ? $total : $offset;
$query = 'SELECT TOP ' . ($row_offset + $num_rows) . ' ' . substr($query, 6);
if (strpos($query, 'SELECT DISTINCT') === 0)
{
$query = 'SELECT DISTINCT TOP ' . ($row_offset + $num_rows) . ' ' . substr($query, 15);
}
else
{
$query = 'SELECT TOP ' . ($row_offset + $num_rows) . ' ' . substr($query, 6);
}
return $this->sql_query($query, $cache_ttl);
}

View File

@@ -105,11 +105,10 @@ class dbal_mysql extends dbal
}
$this->query_result = ($cache_ttl && method_exists($cache, 'sql_load')) ? $cache->sql_load($query) : false;
$this->sql_add_num_queries($this->query_result);
if (!$this->query_result)
{
$this->num_queries++;
if (($this->query_result = @mysql_query($query, $this->db_connect_id)) === false)
{
$this->sql_error($query);

View File

@@ -107,11 +107,10 @@ class dbal_mysql4 extends dbal
}
$this->query_result = ($cache_ttl && method_exists($cache, 'sql_load')) ? $cache->sql_load($query) : false;
$this->sql_add_num_queries($this->query_result);
if (!$this->query_result)
{
$this->num_queries++;
if (($this->query_result = @mysql_query($query, $this->db_connect_id)) === false)
{
$this->sql_error($query);

View File

@@ -110,11 +110,10 @@ class dbal_mysqli extends dbal
}
$this->query_result = ($cache_ttl && method_exists($cache, 'sql_load')) ? $cache->sql_load($query) : false;
$this->sql_add_num_queries($this->query_result);
if (!$this->query_result)
{
$this->num_queries++;
if (($this->query_result = @mysqli_query($this->db_connect_id, $query)) === false)
{
$this->sql_error($query);

View File

@@ -99,11 +99,10 @@ class dbal_oracle extends dbal
$this->last_query_text = $query;
$this->query_result = ($cache_ttl && method_exists($cache, 'sql_load')) ? $cache->sql_load($query) : false;
$this->sql_add_num_queries($this->query_result);
if (!$this->query_result)
{
$this->num_queries++;
$in_transaction = false;
if (!$this->transaction)
{

View File

@@ -136,11 +136,10 @@ class dbal_postgres extends dbal
$this->last_query_text = $query;
$this->query_result = ($cache_ttl && method_exists($cache, 'sql_load')) ? $cache->sql_load($query) : false;
$this->sql_add_num_queries($this->query_result);
if (!$this->query_result)
{
$this->num_queries++;
if (($this->query_result = @pg_query($this->db_connect_id, $query)) === false)
{
$this->sql_error($query);

View File

@@ -102,11 +102,10 @@ class dbal_sqlite extends dbal
}
$this->query_result = ($cache_ttl && method_exists($cache, 'sql_load')) ? $cache->sql_load($query) : false;
$this->sql_add_num_queries($this->query_result);
if (!$this->query_result)
{
$this->num_queries++;
if (($this->query_result = @sqlite_query($query, $this->db_connect_id)) === false)
{
$this->sql_error($query);