aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--phpBB/includes/acm/acm_file.php36
-rw-r--r--phpBB/includes/acp/acp_icons.php14
-rw-r--r--phpBB/includes/acp/acp_main.php14
-rw-r--r--phpBB/includes/acp/acp_reasons.php53
-rw-r--r--phpBB/includes/cache.php29
-rw-r--r--phpBB/includes/db/dbal.php9
-rw-r--r--phpBB/includes/db/firebird.php17
-rw-r--r--phpBB/includes/db/mssql.php14
-rw-r--r--phpBB/includes/db/mssql_odbc.php14
-rw-r--r--phpBB/includes/db/mysql.php17
-rw-r--r--phpBB/includes/db/mysqli.php17
-rw-r--r--phpBB/includes/db/oracle.php17
-rw-r--r--phpBB/includes/db/postgres.php28
-rw-r--r--phpBB/includes/db/sqlite.php20
-rw-r--r--phpBB/includes/functions.php18
-rw-r--r--phpBB/includes/functions_admin.php183
-rw-r--r--phpBB/includes/mcp/mcp_forum.php21
-rw-r--r--phpBB/includes/message_parser.php26
-rwxr-xr-xphpBB/includes/search/fulltext_native.php10
-rw-r--r--phpBB/search.php29
-rw-r--r--phpBB/style.php7
-rw-r--r--phpBB/viewforum.php27
-rw-r--r--phpBB/viewonline.php24
23 files changed, 347 insertions, 297 deletions
diff --git a/phpBB/includes/acm/acm_file.php b/phpBB/includes/acm/acm_file.php
index fa6e79260b..3be4483774 100644
--- a/phpBB/includes/acm/acm_file.php
+++ b/phpBB/includes/acm/acm_file.php
@@ -88,7 +88,7 @@ class acm
if ($fp = @fopen($this->cache_dir . 'data_global.' . $phpEx, 'wb'))
{
@flock($fp, LOCK_EX);
- fwrite($fp, "<?php\n\$this->vars = " . var_export($this->vars, true) . ";\n\n\$this->var_expires = " . var_export($this->var_expires, true) . "\n?>");
+ fwrite($fp, "<?php\n\$this->vars = unserialize('" . serialize($this->vars) . "');\n\$this->var_expires = unserialize('" . serialize($this->var_expires) . "');");
@flock($fp, LOCK_UN);
fclose($fp);
@@ -192,7 +192,7 @@ class acm
if ($fp = @fopen($this->cache_dir . "data{$var_name}.$phpEx", 'wb'))
{
@flock($fp, LOCK_EX);
- fwrite($fp, "<?php\n\$expired = (time() > " . (time() + $ttl) . ") ? true : false;\nif (\$expired) { return; }\n\n\$data = " . var_export($var, true) . ";\n?>");
+ fwrite($fp, "<?php\n\$expired = (time() > " . (time() + $ttl) . ") ? true : false;\nif (\$expired) { return; }\n\$data = " . (sizeof($var) ? "unserialize('" . serialize($var) . "');" : 'array();'));
@flock($fp, LOCK_UN);
fclose($fp);
@@ -210,7 +210,7 @@ class acm
/**
* Purge cache data
*/
- function purge()
+ public function purge()
{
// Purge all phpbb cache files
$dir = @opendir($this->cache_dir);
@@ -247,7 +247,7 @@ class acm
/**
* Destroy cache data
*/
- function destroy($var_name, $table = '')
+ public function destroy($var_name, $table = '')
{
global $phpEx;
@@ -327,7 +327,7 @@ class acm
/**
* Check if a given cache entry exist
*/
- function _exists($var_name)
+ private function _exists($var_name)
{
if ($var_name[0] === '_')
{
@@ -353,7 +353,7 @@ class acm
/**
* Load cached sql query
*/
- function sql_load($query)
+ public function sql_load($query)
{
global $phpEx;
@@ -386,7 +386,7 @@ class acm
/**
* Save sql query
*/
- function sql_save($query, &$query_result, $ttl)
+ public function sql_save($query, &$query_result, $ttl)
{
global $db, $phpEx;
@@ -408,10 +408,10 @@ class acm
}
$db->sql_freeresult($query_result);
- $file = "<?php\n\n/* " . str_replace('*/', '*\/', $query) . " */\n";
+ $file = "<?php\n/* " . str_replace('*/', '*\/', $query) . " */";
$file .= "\n\$expired = (time() > " . (time() + $ttl) . ") ? true : false;\nif (\$expired) { return; }\n";
- fwrite($fp, $file . "\n\$this->sql_rowset[\$query_id] = " . var_export($this->sql_rowset[$query_id], true) . ";\n?>");
+ fwrite($fp, $file . "\$this->sql_rowset[\$query_id] = " . (sizeof($this->sql_rowset[$query_id]) ? "unserialize('" . serialize($this->sql_rowset[$query_id]) . "');" : 'array();'));
@flock($fp, LOCK_UN);
fclose($fp);
@@ -422,17 +422,9 @@ class acm
}
/**
- * Ceck if a given sql query exist in cache
- */
- function sql_exists($query_id)
- {
- return isset($this->sql_rowset[$query_id]);
- }
-
- /**
* Fetch row from cache (database)
*/
- function sql_fetchrow($query_id)
+ public function sql_fetchrow($query_id)
{
if ($this->sql_row_pointer[$query_id] < sizeof($this->sql_rowset[$query_id]))
{
@@ -445,7 +437,7 @@ class acm
/**
* Fetch a field from the current row of a cached database result (database)
*/
- function sql_fetchfield($query_id, $field)
+ public function sql_fetchfield($query_id, $field)
{
if ($this->sql_row_pointer[$query_id] < sizeof($this->sql_rowset[$query_id]))
{
@@ -458,7 +450,7 @@ class acm
/**
* Seek a specific row in an a cached database result (database)
*/
- function sql_rowseek($rownum, $query_id)
+ public function sql_rowseek($rownum, $query_id)
{
if ($rownum >= sizeof($this->sql_rowset[$query_id]))
{
@@ -472,7 +464,7 @@ class acm
/**
* Free memory used for a cached database result (database)
*/
- function sql_freeresult($query_id)
+ public function sql_freeresult($query_id)
{
if (!isset($this->sql_rowset[$query_id]))
{
@@ -488,7 +480,7 @@ class acm
/**
* Removes/unlinks file
*/
- function remove_file($filename)
+ private function remove_file($filename)
{
if (!@unlink($filename))
{
diff --git a/phpBB/includes/acp/acp_icons.php b/phpBB/includes/acp/acp_icons.php
index 537c0425a2..b4ac697a52 100644
--- a/phpBB/includes/acp/acp_icons.php
+++ b/phpBB/includes/acp/acp_icons.php
@@ -477,16 +477,12 @@ class acp_icons
// The user has already selected a smilies_pak file
if ($current == 'delete')
{
- switch ($db->sql_layer)
+ if ($db->truncate)
{
- case 'sqlite':
- case 'firebird':
- $db->sql_query('DELETE FROM ' . $table);
- break;
-
- default:
- $db->sql_query('TRUNCATE TABLE ' . $table);
- break;
+ $db->sql_query('TRUNCATE TABLE ' . $table);
+ else
+ {
+ $db->sql_query('DELETE FROM ' . $table);
}
switch ($mode)
diff --git a/phpBB/includes/acp/acp_main.php b/phpBB/includes/acp/acp_main.php
index d41e1f4a62..ca3ac20630 100644
--- a/phpBB/includes/acp/acp_main.php
+++ b/phpBB/includes/acp/acp_main.php
@@ -202,16 +202,12 @@ class acp_main
break;
case 'db_track':
- switch ($db->sql_layer)
+ if ($db->truncate)
{
- case 'sqlite':
- case 'firebird':
- $db->sql_query('DELETE FROM ' . TOPICS_POSTED_TABLE);
- break;
-
- default:
- $db->sql_query('TRUNCATE TABLE ' . TOPICS_POSTED_TABLE);
- break;
+ $db->sql_query('TRUNCATE TABLE ' . TOPICS_POSTED_TABLE);
+ else
+ {
+ $db->sql_query('DELETE FROM ' . TOPICS_POSTED_TABLE);
}
// This can get really nasty... therefore we only do the last six months
diff --git a/phpBB/includes/acp/acp_reasons.php b/phpBB/includes/acp/acp_reasons.php
index 8d7bc88769..80c8e5323d 100644
--- a/phpBB/includes/acp/acp_reasons.php
+++ b/phpBB/includes/acp/acp_reasons.php
@@ -211,53 +211,22 @@ class acp_reasons
// Let the deletion be confirmed...
if (confirm_box(true))
{
- $sql = 'SELECT reason_id
+ $sql = 'SELECT reason_id, report_text
FROM ' . REPORTS_REASONS_TABLE . "
WHERE LOWER(reason_title) = 'other'";
$result = $db->sql_query($sql);
- $other_reason_id = (int) $db->sql_fetchfield('reason_id');
+ $row = $db->sql_fetchrow($result);
+
+ $other_reason_id = (int) $row['reason_id'];
+ $report_text = $row['report_text'];
+
$db->sql_freeresult($result);
- switch ($db->sql_layer)
- {
- // The ugly one!
- case 'mysqli':
- case 'mysql4':
- case 'mysql':
- // Change the reports using this reason to 'other'
- $sql = 'UPDATE ' . REPORTS_TABLE . '
- SET reason_id = ' . $other_reason_id . ", report_text = CONCAT('" . $db->sql_escape($reason_row['reason_description']) . "\n\n', report_text)
- WHERE reason_id = $reason_id";
- break;
-
- // Standard? What's that?
- case 'mssql':
- case 'mssql_odbc':
- // Change the reports using this reason to 'other'
- $sql = "DECLARE @ptrval binary(16)
-
- SELECT @ptrval = TEXTPTR(report_text)
- FROM " . REPORTS_TABLE . "
- WHERE reason_id = " . $reason_id . "
-
- UPDATETEXT " . REPORTS_TABLE . ".report_text @ptrval 0 0 '" . $db->sql_escape($reason_row['reason_description']) . "\n\n'
-
- UPDATE " . REPORTS_TABLE . '
- SET reason_id = ' . $other_reason_id . "
- WHERE reason_id = $reason_id";
- break;
-
- // Teh standard
- case 'postgres':
- case 'oracle':
- case 'firebird':
- case 'sqlite':
- // Change the reports using this reason to 'other'
- $sql = 'UPDATE ' . REPORTS_TABLE . '
- SET reason_id = ' . $other_reason_id . ", report_text = '" . $db->sql_escape($reason_row['reason_description']) . "\n\n' || report_text
- WHERE reason_id = $reason_id";
- break;
- }
+ $report_text .= $reason_row['reason_description'] . "\n\n";
+
+ $sql = 'UPDATE ' . REPORTS_TABLE . '
+ SET reason_id = ' . $other_reason_id . ", report_text = '" . $db->sql_escape($report_text) "'
+ WHERE reason_id = $reason_id";
$db->sql_query($sql);
$db->sql_query('DELETE FROM ' . REPORTS_REASONS_TABLE . ' WHERE reason_id = ' . $reason_id);
diff --git a/phpBB/includes/cache.php b/phpBB/includes/cache.php
index 52e0007b28..c5445e7a56 100644
--- a/phpBB/includes/cache.php
+++ b/phpBB/includes/cache.php
@@ -295,31 +295,10 @@ class cache
{
global $db;
- switch ($db->sql_layer)
- {
- case 'mssql':
- case 'mssql_odbc':
- $sql = 'SELECT user_id, bot_agent, bot_ip
- FROM ' . BOTS_TABLE . '
- WHERE bot_active = 1
- ORDER BY LEN(bot_agent) DESC';
- break;
-
- case 'firebird':
- $sql = 'SELECT user_id, bot_agent, bot_ip
- FROM ' . BOTS_TABLE . '
- WHERE bot_active = 1
- ORDER BY CHAR_LENGTH(bot_agent) DESC';
- break;
-
- // LENGTH supported by MySQL, IBM DB2 and Oracle for sure...
- default:
- $sql = 'SELECT user_id, bot_agent, bot_ip
- FROM ' . BOTS_TABLE . '
- WHERE bot_active = 1
- ORDER BY LENGTH(bot_agent) DESC';
- break;
- }
+ $sql = 'SELECT user_id, bot_agent, bot_ip
+ FROM ' . BOTS_TABLE . '
+ WHERE bot_active = 1
+ ORDER BY ' . $db->sql_function('length_varchar', 'bot_agent') . 'DESC';
$result = $db->sql_query($sql);
$bots = array();
diff --git a/phpBB/includes/db/dbal.php b/phpBB/includes/db/dbal.php
index a2a42e173c..d22d2f0520 100644
--- a/phpBB/includes/db/dbal.php
+++ b/phpBB/includes/db/dbal.php
@@ -52,6 +52,15 @@ class dbal
// Supports multi inserts?
var $multi_insert = false;
+ // Supports COUNT(DISTINCT ...)?
+ var $count_distinct = true;
+
+ // Supports multiple table deletion
+ var $multi_table_deletion = false;
+
+ // Supports table truncation
+ var $truncate = true;
+
/**
* Current sql layer
*/
diff --git a/phpBB/includes/db/firebird.php b/phpBB/includes/db/firebird.php
index b258b96fa1..21dd6f0127 100644
--- a/phpBB/includes/db/firebird.php
+++ b/phpBB/includes/db/firebird.php
@@ -28,6 +28,9 @@ class dbal_firebird extends dbal
var $last_query_text = '';
var $service_handle = false;
+ // can't truncate a table
+ var $truncate = false;
+
/**
* Connect to server
*/
@@ -377,6 +380,20 @@ class dbal_firebird extends dbal
}
/**
+ * Expose a DBMS specific function
+ */
+ function sql_function($type, $col)
+ {
+ switch ($type)
+ {
+ case 'length_varchar':
+ case 'length_text':
+ return 'OCTET_LENGTH(' . $col . ')';
+ break;
+ }
+ }
+
+ /**
* Build LIKE expression
* @access private
*/
diff --git a/phpBB/includes/db/mssql.php b/phpBB/includes/db/mssql.php
index 1e42abcce2..f89fcb9d8f 100644
--- a/phpBB/includes/db/mssql.php
+++ b/phpBB/includes/db/mssql.php
@@ -309,6 +309,20 @@ class dbal_mssql extends dbal
}
/**
+ * Expose a DBMS specific function
+ */
+ function sql_function($type, $col)
+ {
+ switch ($type)
+ {
+ case 'length_varchar':
+ case 'length_text':
+ return 'DATALENGTH(' . $col . ')';
+ break;
+ }
+ }
+
+ /**
* Build LIKE expression
* @access private
*/
diff --git a/phpBB/includes/db/mssql_odbc.php b/phpBB/includes/db/mssql_odbc.php
index 7722f79952..5ef00c6839 100644
--- a/phpBB/includes/db/mssql_odbc.php
+++ b/phpBB/includes/db/mssql_odbc.php
@@ -337,6 +337,20 @@ class dbal_mssql_odbc extends dbal
}
/**
+ * Expose a DBMS specific function
+ */
+ function sql_function($type, $col)
+ {
+ switch ($type)
+ {
+ case 'length_varchar':
+ case 'length_text':
+ return 'DATALENGTH(' . $col . ')';
+ break;
+ }
+ }
+
+ /**
* Build LIKE expression
* @access private
*/
diff --git a/phpBB/includes/db/mysql.php b/phpBB/includes/db/mysql.php
index 840d40b03d..108a75c0cc 100644
--- a/phpBB/includes/db/mysql.php
+++ b/phpBB/includes/db/mysql.php
@@ -32,6 +32,9 @@ class dbal_mysql extends dbal
var $mysql_version;
var $multi_insert = true;
+ // Supports multiple table deletion
+ var $multi_table_deletion = false;
+
/**
* Connect to server
* @access public
@@ -302,6 +305,20 @@ class dbal_mysql extends dbal
}
/**
+ * Expose a DBMS specific function
+ */
+ function sql_function($type, $col)
+ {
+ switch ($type)
+ {
+ case 'length_varchar':
+ case 'length_text':
+ return 'LENGTH(' . $col . ')';
+ break;
+ }
+ }
+
+ /**
* Build LIKE expression
* @access private
*/
diff --git a/phpBB/includes/db/mysqli.php b/phpBB/includes/db/mysqli.php
index 32765d15f7..394c547151 100644
--- a/phpBB/includes/db/mysqli.php
+++ b/phpBB/includes/db/mysqli.php
@@ -28,6 +28,9 @@ class dbal_mysqli extends dbal
{
var $multi_insert = true;
+ // Supports multiple table deletion
+ var $multi_table_deletion = false;
+
/**
* Connect to server
*/
@@ -271,6 +274,20 @@ class dbal_mysqli extends dbal
}
/**
+ * Expose a DBMS specific function
+ */
+ function sql_function($type, $col)
+ {
+ switch ($type)
+ {
+ case 'length_varchar':
+ case 'length_text':
+ return 'LENGTH(' . $col . ')';
+ break;
+ }
+ }
+
+ /**
* Build LIKE expression
* @access private
*/
diff --git a/phpBB/includes/db/oracle.php b/phpBB/includes/db/oracle.php
index 18740fb036..0640d3d354 100644
--- a/phpBB/includes/db/oracle.php
+++ b/phpBB/includes/db/oracle.php
@@ -534,6 +534,23 @@ class dbal_oracle extends dbal
}
/**
+ * Expose a DBMS specific function
+ */
+ function sql_function($type, $col)
+ {
+ switch ($type)
+ {
+ case 'length_varchar':
+ return 'LENGTH(' . $col . ')';
+ break;
+
+ case 'length_text':
+ return 'dbms_lob.getlength(' . $col . ')';
+ break;
+ }
+ }
+
+ /**
* Build LIKE expression
* @access private
*/
diff --git a/phpBB/includes/db/postgres.php b/phpBB/includes/db/postgres.php
index 0ac27023f3..0f946c2d7c 100644
--- a/phpBB/includes/db/postgres.php
+++ b/phpBB/includes/db/postgres.php
@@ -27,7 +27,7 @@ class dbal_postgres extends dbal
{
var $last_query_text = '';
var $pgsql_version;
-
+
/**
* Connect to server
*/
@@ -84,9 +84,17 @@ class dbal_postgres extends dbal
// determine what version of PostgreSQL is running, we can be more efficient if they are running 8.2+
$this->pgsql_version = @pg_parameter_status($this->db_connect_id, 'server_version');
- if (!empty($this->pgsql_version) && $this->pgsql_version[0] >= '8' && $this->pgsql_version[2] >= '2')
+ if (!empty($this->pgsql_version) && $this->pgsql_version[0] >= '8')
{
- $this->multi_insert = true;
+ if ($this->pgsql_version[2] >= '1')
+ {
+ $this->multi_table_deletion = true;
+ }
+
+ if ($this->pgsql_version[2] >= '2')
+ {
+ $this->multi_insert = true;
+ }
}
if ($schema !== '')
@@ -332,6 +340,20 @@ class dbal_postgres extends dbal
}
/**
+ * Expose a DBMS specific function
+ */
+ function sql_function($type, $col)
+ {
+ switch ($type)
+ {
+ case 'length_varchar':
+ case 'length_text':
+ return 'LENGTH(' . $col . ')';
+ break;
+ }
+ }
+
+ /**
* Build LIKE expression
* @access private
*/
diff --git a/phpBB/includes/db/sqlite.php b/phpBB/includes/db/sqlite.php
index 5ae36df4f5..c6f6f8fc9b 100644
--- a/phpBB/includes/db/sqlite.php
+++ b/phpBB/includes/db/sqlite.php
@@ -25,6 +25,12 @@ include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx);
*/
class dbal_sqlite extends dbal
{
+ // like MS ACCESS, SQLite does not support COUNT(DISTINCT ...)
+ var $count_distinct = false;
+
+ // can't truncate a table
+ var $truncate = false;
+
/**
* Connect to server
*/
@@ -258,6 +264,20 @@ class dbal_sqlite extends dbal
}
/**
+ * Expose a DBMS specific function
+ */
+ function sql_function($type, $col)
+ {
+ switch ($type)
+ {
+ case 'length_varchar':
+ case 'length_text':
+ return 'LENGTH(' . $col . ')';
+ break;
+ }
+ }
+
+ /**
* return sql error array
* @access private
*/
diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php
index 63a90ee9cc..84fd033ddb 100644
--- a/phpBB/includes/functions.php
+++ b/phpBB/includes/functions.php
@@ -3007,7 +3007,15 @@ function page_header($page_title = '', $display_online_list = true)
// Get number of online guests
if (!$config['load_online_guests'])
{
- if ($db->sql_layer === 'sqlite')
+ if ($db->count_distinct)
+ {
+ $sql = 'SELECT COUNT(DISTINCT s.session_ip) as num_guests
+ FROM ' . SESSIONS_TABLE . ' s
+ WHERE s.session_user_id = ' . ANONYMOUS . '
+ AND s.session_time >= ' . (time() - ($config['load_online_time'] * 60)) .
+ $reading_sql;
+ }
+ else
{
$sql = 'SELECT COUNT(session_ip) as num_guests
FROM (
@@ -3018,14 +3026,6 @@ function page_header($page_title = '', $display_online_list = true)
$reading_sql .
')';
}
- else
- {
- $sql = 'SELECT COUNT(DISTINCT s.session_ip) as num_guests
- FROM ' . SESSIONS_TABLE . ' s
- WHERE s.session_user_id = ' . ANONYMOUS . '
- AND s.session_time >= ' . (time() - ($config['load_online_time'] * 60)) .
- $reading_sql;
- }
$result = $db->sql_query($sql);
$guests_online = (int) $db->sql_fetchfield('num_guests');
$db->sql_freeresult($result);
diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php
index 268eccbca4..b4410bcce1 100644
--- a/phpBB/includes/functions_admin.php
+++ b/phpBB/includes/functions_admin.php
@@ -1004,40 +1004,38 @@ function delete_topic_shadows($max_age, $forum_id = '', $auto_sync = true)
{
$where = (is_array($forum_id)) ? 'AND ' . $db->sql_in_set('t.forum_id', array_map('intval', $forum_id)) : (($forum_id) ? 'AND t.forum_id = ' . (int) $forum_id : '');
- switch ($db->sql_layer)
+ if ($db->multi_table_deletion)
{
- case 'mysql4':
- case 'mysqli':
- $sql = 'DELETE t.*
- FROM ' . TOPICS_TABLE . ' t, ' . TOPICS_TABLE . ' t2
+ $sql = 'DELETE FROM ' . TOPICS_TABLE . ' t
+ USING ' . TOPICS_TABLE . ' t2
WHERE t.topic_moved_id = t2.topic_id
AND t.topic_time < ' . (time() - $max_age)
- . $where;
+ . $where;
$db->sql_query($sql);
- break;
-
- default:
- $sql = 'SELECT t.topic_id
- FROM ' . TOPICS_TABLE . ' t, ' . TOPICS_TABLE . ' t2
- WHERE t.topic_moved_id = t2.topic_id
- AND t.topic_time < ' . (time() - $max_age)
- . $where;
- $result = $db->sql_query($sql);
- $topic_ids = array();
- while ($row = $db->sql_fetchrow($result))
- {
- $topic_ids[] = $row['topic_id'];
- }
- $db->sql_freeresult($result);
+ }
+ else
+ {
+ $sql = 'SELECT t.topic_id
+ FROM ' . TOPICS_TABLE . ' t, ' . TOPICS_TABLE . ' t2
+ WHERE t.topic_moved_id = t2.topic_id
+ AND t.topic_time < ' . (time() - $max_age)
+ . $where;
+ $result = $db->sql_query($sql);
- if (sizeof($topic_ids))
- {
- $sql = 'DELETE FROM ' . TOPICS_TABLE . '
- WHERE ' . $db->sql_in_set('topic_id', $topic_ids);
- $db->sql_query($sql);
- }
- break;
+ $topic_ids = array();
+ while ($row = $db->sql_fetchrow($result))
+ {
+ $topic_ids[] = $row['topic_id'];
+ }
+ $db->sql_freeresult($result);
+
+ if (sizeof($topic_ids))
+ {
+ $sql = 'DELETE FROM ' . TOPICS_TABLE . '
+ WHERE ' . $db->sql_in_set('topic_id', $topic_ids);
+ $db->sql_query($sql);
+ }
}
if ($auto_sync)
@@ -1203,41 +1201,37 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
switch ($mode)
{
case 'topic_moved':
- switch ($db->sql_layer)
+ if ($db->multi_table_deletion)
{
- case 'mysql4':
- case 'mysqli':
- $sql = 'DELETE FROM ' . TOPICS_TABLE . '
- USING ' . TOPICS_TABLE . ' t1, ' . TOPICS_TABLE . " t2
- WHERE t1.topic_moved_id = t2.topic_id
- AND t1.forum_id = t2.forum_id";
- $db->sql_query($sql);
- break;
-
- default:
- $sql = 'SELECT t1.topic_id
- FROM ' .TOPICS_TABLE . ' t1, ' . TOPICS_TABLE . " t2
- WHERE t1.topic_moved_id = t2.topic_id
- AND t1.forum_id = t2.forum_id";
- $result = $db->sql_query($sql);
-
- $topic_id_ary = array();
- while ($row = $db->sql_fetchrow($result))
- {
- $topic_id_ary[] = $row['topic_id'];
- }
- $db->sql_freeresult($result);
+ $sql = 'DELETE FROM ' . TOPICS_TABLE . '
+ USING ' . TOPICS_TABLE . ' t1, ' . TOPICS_TABLE . " t2
+ WHERE t1.topic_moved_id = t2.topic_id
+ AND t1.forum_id = t2.forum_id";
+ $db->sql_query($sql);
+ }
+ else
+ {
+ $sql = 'SELECT t1.topic_id
+ FROM ' .TOPICS_TABLE . ' t1, ' . TOPICS_TABLE . " t2
+ WHERE t1.topic_moved_id = t2.topic_id
+ AND t1.forum_id = t2.forum_id";
+ $result = $db->sql_query($sql);
- if (!sizeof($topic_id_ary))
- {
- return;
- }
+ $topic_id_ary = array();
+ while ($row = $db->sql_fetchrow($result))
+ {
+ $topic_id_ary[] = $row['topic_id'];
+ }
+ $db->sql_freeresult($result);
- $sql = 'DELETE FROM ' . TOPICS_TABLE . '
- WHERE ' . $db->sql_in_set('topic_id', $topic_id_ary);
- $db->sql_query($sql);
+ if (!sizeof($topic_id_ary))
+ {
+ return;
+ }
- break;
+ $sql = 'DELETE FROM ' . TOPICS_TABLE . '
+ WHERE ' . $db->sql_in_set('topic_id', $topic_id_ary);
+ $db->sql_query($sql);
}
break;
@@ -2167,16 +2161,12 @@ function cache_moderators()
$cache->destroy('sql', MODERATOR_CACHE_TABLE);
// Clear table
- switch ($db->sql_layer)
+ if ($db->truncate)
{
- case 'sqlite':
- case 'firebird':
- $db->sql_query('DELETE FROM ' . MODERATOR_CACHE_TABLE);
- break;
-
- default:
- $db->sql_query('TRUNCATE TABLE ' . MODERATOR_CACHE_TABLE);
- break;
+ $db->sql_query('TRUNCATE TABLE ' . MODERATOR_CACHE_TABLE);
+ else
+ {
+ $db->sql_query('DELETE FROM ' . MODERATOR_CACHE_TABLE);
}
// We add moderators who have forum moderator permissions without an explicit ACL_NEVER setting
@@ -2609,39 +2599,36 @@ function update_foes($group_id = false, $user_id = false)
return;
}
- switch ($db->sql_layer)
+ if ($db->multi_table_deletion)
{
- case 'mysqli':
- case 'mysql4':
- $sql = 'DELETE ' . (($db->sql_layer === 'mysqli' || version_compare($db->mysql_version, '4.1', '>=')) ? 'z.*' : ZEBRA_TABLE) . '
- FROM ' . ZEBRA_TABLE . ' z, ' . USER_GROUP_TABLE . ' ug
- WHERE z.zebra_id = ug.user_id
- AND z.foe = 1
- AND ' . $db->sql_in_set('ug.group_id', $groups);
- $db->sql_query($sql);
- break;
-
- default:
- $sql = 'SELECT user_id
- FROM ' . USER_GROUP_TABLE . '
- WHERE ' . $db->sql_in_set('group_id', $groups);
- $result = $db->sql_query($sql);
+ $sql = 'DELETE FROM' . ZEBRA_TABLE . ' z
+ USING ' . USER_GROUP_TABLE . ' ug
+ WHERE z.zebra_id = ug.user_id
+ AND z.foe = 1
+ AND ' . $db->sql_in_set('ug.group_id', $groups);
+ $db->sql_query($sql);
+ }
+ else
+ {
+ $sql = 'SELECT user_id
+ FROM ' . USER_GROUP_TABLE . '
+ WHERE ' . $db->sql_in_set('group_id', $groups);
+ $result = $db->sql_query($sql);
- $users = array();
- while ($row = $db->sql_fetchrow($result))
- {
- $users[] = (int) $row['user_id'];
- }
- $db->sql_freeresult($result);
+ $users = array();
+ while ($row = $db->sql_fetchrow($result))
+ {
+ $users[] = (int) $row['user_id'];
+ }
+ $db->sql_freeresult($result);
- if (sizeof($users))
- {
- $sql = 'DELETE FROM ' . ZEBRA_TABLE . '
- WHERE ' . $db->sql_in_set('zebra_id', $users) . '
- AND foe = 1';
- $db->sql_query($sql);
- }
- break;
+ if (sizeof($users))
+ {
+ $sql = 'DELETE FROM ' . ZEBRA_TABLE . '
+ WHERE ' . $db->sql_in_set('zebra_id', $users) . '
+ AND foe = 1';
+ $db->sql_query($sql);
+ }
}
return;
diff --git a/phpBB/includes/mcp/mcp_forum.php b/phpBB/includes/mcp/mcp_forum.php
index 1cba3157d7..3bc4e9cf03 100644
--- a/phpBB/includes/mcp/mcp_forum.php
+++ b/phpBB/includes/mcp/mcp_forum.php
@@ -146,8 +146,8 @@ function mcp_forum_view($id, $mode, $action, $forum_info)
$read_tracking_join = $read_tracking_select = '';
}
- $sql = "SELECT t.*$read_tracking_select
- FROM " . TOPICS_TABLE . " t $read_tracking_join
+ $sql = "SELECT t.topic_id
+ FROM " . TOPICS_TABLE . " t
WHERE t.forum_id IN($forum_id, 0)
" . (($auth->acl_get('m_approve', $forum_id)) ? '' : 'AND t.topic_approved = 1') . "
$limit_time_sql
@@ -155,13 +155,24 @@ function mcp_forum_view($id, $mode, $action, $forum_info)
$result = $db->sql_query_limit($sql, $topics_per_page, $start);
$topic_list = $topic_tracking_info = array();
+
while ($row = $db->sql_fetchrow($result))
{
- $topic_rows[$row['topic_id']] = $row;
$topic_list[] = $row['topic_id'];
}
$db->sql_freeresult($result);
+ $sql = "SELECT t.*$read_tracking_select
+ FROM " . TOPICS_TABLE . " t $read_tracking_join
+ WHERE " . $db->sql_in_set('t.topic_id', $topic_list);
+
+ $result = $db->sql_query($sql);
+ while ($row = $db->sql_fetchrow($result))
+ {
+ $topic_rows[$row['topic_id']] = $row;
+ }
+ $db->sql_freeresult($result);
+
// If there is more than one page, but we have no topic list, then the start parameter is... erm... out of sync
if (!sizeof($topic_list) && $forum_topics && $start > 0)
{
@@ -181,10 +192,12 @@ function mcp_forum_view($id, $mode, $action, $forum_info)
}
}
- foreach ($topic_rows as $topic_id => $row)
+ foreach ($topic_list as $topic_id)
{
$topic_title = '';
+ $row = &$topic_rows[$topic_id];
+
$replies = ($auth->acl_get('m_approve', $forum_id)) ? $row['topic_replies_real'] : $row['topic_replies'];
if ($row['topic_status'] == ITEM_MOVED)
diff --git a/phpBB/includes/message_parser.php b/phpBB/includes/message_parser.php
index 6e601e1499..82755b1f15 100644
--- a/phpBB/includes/message_parser.php
+++ b/phpBB/includes/message_parser.php
@@ -1251,28 +1251,10 @@ class parse_message extends bbcode_firstpass
// NOTE: obtain_* function? chaching the table contents?
// For now setting the ttl to 10 minutes
- switch ($db->sql_layer)
- {
- case 'mssql':
- case 'mssql_odbc':
- $sql = 'SELECT *
- FROM ' . SMILIES_TABLE . '
- ORDER BY LEN(code) DESC';
- break;
-
- case 'firebird':
- $sql = 'SELECT *
- FROM ' . SMILIES_TABLE . '
- ORDER BY CHAR_LENGTH(code) DESC';
- break;
-
- // LENGTH supported by MySQL, IBM DB2, Oracle and Access for sure...
- default:
- $sql = 'SELECT *
- FROM ' . SMILIES_TABLE . '
- ORDER BY LENGTH(code) DESC';
- break;
- }
+ $sql = 'SELECT *
+ FROM ' . SMILIES_TABLE . '
+ ORDER BY ' . $db->sql_function('length_varchar', 'code') . ' DESC';
+
$result = $db->sql_query($sql, 600);
while ($row = $db->sql_fetchrow($result))
diff --git a/phpBB/includes/search/fulltext_native.php b/phpBB/includes/search/fulltext_native.php
index 89689151fe..788af4b002 100755
--- a/phpBB/includes/search/fulltext_native.php
+++ b/phpBB/includes/search/fulltext_native.php
@@ -864,14 +864,14 @@ class fulltext_native extends search_backend
}
else
{
- if ($db->sql_layer == 'sqlite')
+ if ($db->count_distinct)
{
- $sql = 'SELECT COUNT(topic_id) as total_results
- FROM (SELECT DISTINCT t.topic_id';
+ $sql = 'SELECT COUNT(DISTINCT t.topic_id) as total_results';
}
else
{
- $sql = 'SELECT COUNT(DISTINCT t.topic_id) as total_results';
+ $sql = 'SELECT COUNT(topic_id) as total_results
+ FROM (SELECT DISTINCT t.topic_id';
}
$sql .= ' FROM ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . " p
@@ -881,7 +881,7 @@ class fulltext_native extends search_backend
$m_approve_fid_sql
$sql_fora
AND t.topic_id = p.topic_id
- $sql_time" . (($db->sql_layer == 'sqlite') ? ')' : '');
+ $sql_time" . (($db->count_distinct) ? '' : ')');
}
$result = $db->sql_query($sql);
diff --git a/phpBB/search.php b/phpBB/search.php
index 9176356595..c67581490b 100644
--- a/phpBB/search.php
+++ b/phpBB/search.php
@@ -1047,31 +1047,10 @@ $template->assign_vars(array(
// only show recent searches to search administrators
if ($auth->acl_get('a_search'))
{
- // Handle large objects differently for Oracle and MSSQL
- switch ($db->sql_layer)
- {
- case 'oracle':
- $sql = 'SELECT search_time, search_keywords
- FROM ' . SEARCH_RESULTS_TABLE . '
- WHERE dbms_lob.getlength(search_keywords) > 0
- ORDER BY search_time DESC';
- break;
-
- case 'mssql':
- case 'mssql_odbc':
- $sql = 'SELECT search_time, search_keywords
- FROM ' . SEARCH_RESULTS_TABLE . '
- WHERE DATALENGTH(search_keywords) > 0
- ORDER BY search_time DESC';
- break;
-
- default:
- $sql = 'SELECT search_time, search_keywords
- FROM ' . SEARCH_RESULTS_TABLE . '
- WHERE search_keywords <> \'\'
- ORDER BY search_time DESC';
- break;
- }
+ $sql = 'SELECT search_time, search_keywords
+ FROM ' . SEARCH_RESULTS_TABLE . '
+ WHERE ' . $db->sql_function('length_text', 'search_keywords') . ' > 0
+ ORDER BY search_time DESC';
$result = $db->sql_query_limit($sql, 5);
while ($row = $db->sql_fetchrow($result))
diff --git a/phpBB/style.php b/phpBB/style.php
index 37e396bb29..7dfd3886ff 100644
--- a/phpBB/style.php
+++ b/phpBB/style.php
@@ -140,7 +140,7 @@ if ($id)
}
// Expire time of seven days if not recached
- $expire_time = 7*86400;
+ $expire_time = 7 * 86400;
$recache = false;
// Re-cache stylesheet data if necessary
@@ -177,7 +177,10 @@ if ($id)
if ($recache)
{
- include_once($phpbb_root_path . 'includes/acp/acp_styles.' . $phpEx);
+ if (!class_exists('acp_styles'))
+ {
+ include($phpbb_root_path . 'includes/acp/acp_styles.' . $phpEx);
+ }
$theme['theme_data'] = acp_styles::db_theme_data($theme);
$theme['theme_mtime'] = $update_time;
diff --git a/phpBB/viewforum.php b/phpBB/viewforum.php
index 5a618f4a2c..cb9b125400 100644
--- a/phpBB/viewforum.php
+++ b/phpBB/viewforum.php
@@ -405,28 +405,38 @@ else if (empty($active_forum_ary['exclude_forum_id']))
else
{
$get_forum_ids = array_diff($active_forum_ary['forum_id'], $active_forum_ary['exclude_forum_id']);
- $sql_where = (sizeof($get_forum_ids)) ? $db->sql_in_set('t.forum_id', $get_forum_ids) : 't.forum_id = ' . $forum_id;
+ $sql_where = $db->sql_in_set('t.forum_id', $get_forum_ids);
}
+// Grab just the sorted topic ids
+$sql = 'SELECT t.topic_id
+ FROM ' . TOPICS_TABLE . " t
+ WHERE $sql_where
+ AND t.topic_type IN (" . POST_NORMAL . ', ' . POST_STICKY . ")
+ $sql_approved
+ $sql_limit_time
+ ORDER BY t.topic_type " . ((!$store_reverse) ? 'DESC' : 'ASC') . ', ' . $sql_sort_order;
+$result = $db->sql_query_limit($sql, $sql_limit, $sql_start);
+while ($row = $db->sql_fetchrow($result))
+{
+ $topic_list[] = (int) $row['topic_id'];
+}
+$db->sql_freeresult($result);
+
// SQL array for obtaining topics/stickies
$sql_array = array(
'SELECT' => $sql_array['SELECT'],
'FROM' => $sql_array['FROM'],
'LEFT_JOIN' => $sql_array['LEFT_JOIN'],
- 'WHERE' => $sql_where . '
- AND t.topic_type IN (' . POST_NORMAL . ', ' . POST_STICKY . ")
- $sql_approved
- $sql_limit_time",
-
- 'ORDER_BY' => 't.topic_type ' . ((!$store_reverse) ? 'DESC' : 'ASC') . ', ' . $sql_sort_order,
+ 'WHERE' => $db->sql_in_set('t.topic_id', $topic_list),
);
// If store_reverse, then first obtain topics, then stickies, else the other way around...
// Funnily enough you typically save one query if going from the last page to the middle (store_reverse) because
// the number of stickies are not known
$sql = $db->sql_build_query('SELECT', $sql_array);
-$result = $db->sql_query_limit($sql, $sql_limit, $sql_start);
+$result = $db->sql_query($sql);
$shadow_topic_list = array();
while ($row = $db->sql_fetchrow($result))
@@ -437,7 +447,6 @@ while ($row = $db->sql_fetchrow($result))
}
$rowset[$row['topic_id']] = $row;
- $topic_list[] = $row['topic_id'];
}
$db->sql_freeresult($result);
diff --git a/phpBB/viewonline.php b/phpBB/viewonline.php
index ea29e09660..c27788c4c8 100644
--- a/phpBB/viewonline.php
+++ b/phpBB/viewonline.php
@@ -97,23 +97,21 @@ $guest_counter = 0;
// Get number of online guests (if we do not display them)
if (!$show_guests)
{
- switch ($db->sql_layer)
+ if ($db->count_distinct)
{
- case 'sqlite':
- $sql = 'SELECT COUNT(session_ip) as num_guests
- FROM (
- SELECT DISTINCT session_ip
- FROM ' . SESSIONS_TABLE . '
- WHERE session_user_id = ' . ANONYMOUS . '
- AND session_time >= ' . (time() - ($config['load_online_time'] * 60)) .
- ')';
- break;
-
- default:
- $sql = 'SELECT COUNT(DISTINCT session_ip) as num_guests
+ $sql = 'SELECT COUNT(DISTINCT session_ip) as num_guests
FROM ' . SESSIONS_TABLE . '
WHERE session_user_id = ' . ANONYMOUS . '
AND session_time >= ' . (time() - ($config['load_online_time'] * 60));
+ else
+ {
+ $sql = 'SELECT COUNT(session_ip) as num_guests
+ FROM (
+ SELECT DISTINCT session_ip
+ FROM ' . SESSIONS_TABLE . '
+ WHERE session_user_id = ' . ANONYMOUS . '
+ AND session_time >= ' . (time() - ($config['load_online_time'] * 60)) .
+ ')';
break;
}
$result = $db->sql_query($sql);