aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes
diff options
context:
space:
mode:
authorMeik Sievertsen <acydburn@phpbb.com>2006-05-20 13:20:38 +0000
committerMeik Sievertsen <acydburn@phpbb.com>2006-05-20 13:20:38 +0000
commit0115e94cfd255b53ca517d9e8628386a382a239b (patch)
tree38e789805d3d43c8cbe7f569f2118daefecc4fe8 /phpBB/includes
parentc81a44ea303a23d58f4fdff483bbd4d6957c9ef7 (diff)
downloadforums-0115e94cfd255b53ca517d9e8628386a382a239b.tar
forums-0115e94cfd255b53ca517d9e8628386a382a239b.tar.gz
forums-0115e94cfd255b53ca517d9e8628386a382a239b.tar.bz2
forums-0115e94cfd255b53ca517d9e8628386a382a239b.tar.xz
forums-0115e94cfd255b53ca517d9e8628386a382a239b.zip
- 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
Diffstat (limited to 'phpBB/includes')
-rw-r--r--phpBB/includes/acp/acp_forums.php9
-rw-r--r--phpBB/includes/db/dbal.php37
-rw-r--r--phpBB/includes/db/firebird.php3
-rw-r--r--phpBB/includes/db/mssql.php11
-rw-r--r--phpBB/includes/db/mssql_odbc.php12
-rw-r--r--phpBB/includes/db/mysql.php3
-rw-r--r--phpBB/includes/db/mysql4.php3
-rw-r--r--phpBB/includes/db/mysqli.php5
-rw-r--r--phpBB/includes/db/oracle.php5
-rw-r--r--phpBB/includes/db/postgres.php5
-rw-r--r--phpBB/includes/db/sqlite.php3
11 files changed, 65 insertions, 31 deletions
diff --git a/phpBB/includes/acp/acp_forums.php b/phpBB/includes/acp/acp_forums.php
index d5ee879df5..c81081f685 100644
--- a/phpBB/includes/acp/acp_forums.php
+++ b/phpBB/includes/acp/acp_forums.php
@@ -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']);
}
}
diff --git a/phpBB/includes/db/dbal.php b/phpBB/includes/db/dbal.php
index cc70dd3630..83e5b1beed 100644
--- a/phpBB/includes/db/dbal.php
+++ b/phpBB/includes/db/dbal.php
@@ -19,14 +19,13 @@ 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 = '';
@@ -34,6 +33,18 @@ class dbal
var $dbname = '';
/**
+ * Constructor
+ */
+ function dbal()
+ {
+ $this->num_queries = array(
+ 'cached' => 0,
+ 'normal' => 0,
+ 'total' => 0,
+ );
+ }
+
+ /**
* return on error or display error message
*/
function sql_return_on_error($fail = false)
@@ -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($cached = false)
+ {
+ return ($cached) ? $this->num_queries['cached'] : $this->num_queries['normal'];
+ }
+
+ /**
+ * Add to query count
*/
- function sql_num_queries()
+ function sql_add_num_queries($cached = false)
{
- return $this->num_queries;
+ $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;
diff --git a/phpBB/includes/db/firebird.php b/phpBB/includes/db/firebird.php
index e4eca60772..c876483a2b 100644
--- a/phpBB/includes/db/firebird.php
+++ b/phpBB/includes/db/firebird.php
@@ -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);
diff --git a/phpBB/includes/db/mssql.php b/phpBB/includes/db/mssql.php
index 5d6095e502..8e0ca2377c 100644
--- a/phpBB/includes/db/mssql.php
+++ b/phpBB/includes/db/mssql.php
@@ -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);
}
diff --git a/phpBB/includes/db/mssql_odbc.php b/phpBB/includes/db/mssql_odbc.php
index a31c6074bc..2fc4e30a25 100644
--- a/phpBB/includes/db/mssql_odbc.php
+++ b/phpBB/includes/db/mssql_odbc.php
@@ -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);
}
diff --git a/phpBB/includes/db/mysql.php b/phpBB/includes/db/mysql.php
index d9369f3a75..8fc9e2a04b 100644
--- a/phpBB/includes/db/mysql.php
+++ b/phpBB/includes/db/mysql.php
@@ -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);
diff --git a/phpBB/includes/db/mysql4.php b/phpBB/includes/db/mysql4.php
index 47c1ebc41f..ac896ce78f 100644
--- a/phpBB/includes/db/mysql4.php
+++ b/phpBB/includes/db/mysql4.php
@@ -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);
diff --git a/phpBB/includes/db/mysqli.php b/phpBB/includes/db/mysqli.php
index 0233c7092f..79230b178a 100644
--- a/phpBB/includes/db/mysqli.php
+++ b/phpBB/includes/db/mysqli.php
@@ -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);
diff --git a/phpBB/includes/db/oracle.php b/phpBB/includes/db/oracle.php
index 72732d2a50..f2499c5456 100644
--- a/phpBB/includes/db/oracle.php
+++ b/phpBB/includes/db/oracle.php
@@ -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)
{
diff --git a/phpBB/includes/db/postgres.php b/phpBB/includes/db/postgres.php
index eb5f2d17e8..22481267e5 100644
--- a/phpBB/includes/db/postgres.php
+++ b/phpBB/includes/db/postgres.php
@@ -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);
diff --git a/phpBB/includes/db/sqlite.php b/phpBB/includes/db/sqlite.php
index f2f3ceb1f1..85c6986c79 100644
--- a/phpBB/includes/db/sqlite.php
+++ b/phpBB/includes/db/sqlite.php
@@ -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);