diff options
Diffstat (limited to 'phpBB/includes')
-rw-r--r-- | phpBB/includes/acp/acp_database.php | 19 | ||||
-rw-r--r-- | phpBB/includes/acp/acp_forums.php | 3 | ||||
-rw-r--r-- | phpBB/includes/acp/acp_profile.php | 13 | ||||
-rw-r--r-- | phpBB/includes/acp/acp_users.php | 4 | ||||
-rw-r--r-- | phpBB/includes/db/db2.php | 2 | ||||
-rw-r--r-- | phpBB/includes/db/db_tools.php | 16 | ||||
-rw-r--r-- | phpBB/includes/db/firebird.php | 2 | ||||
-rw-r--r-- | phpBB/includes/db/mssql.php | 2 | ||||
-rw-r--r-- | phpBB/includes/db/mssql_2005.php | 416 | ||||
-rw-r--r-- | phpBB/includes/db/mssql_odbc.php | 1 | ||||
-rw-r--r-- | phpBB/includes/db/mysql.php | 2 | ||||
-rw-r--r-- | phpBB/includes/db/mysqli.php | 2 | ||||
-rw-r--r-- | phpBB/includes/db/oracle.php | 2 | ||||
-rw-r--r-- | phpBB/includes/db/postgres.php | 2 | ||||
-rw-r--r-- | phpBB/includes/db/sqlite.php | 2 | ||||
-rw-r--r-- | phpBB/includes/functions_admin.php | 61 | ||||
-rw-r--r-- | phpBB/includes/functions_convert.php | 18 | ||||
-rw-r--r-- | phpBB/includes/functions_install.php | 15 | ||||
-rw-r--r-- | phpBB/includes/search/fulltext_mysql.php | 2 | ||||
-rwxr-xr-x | phpBB/includes/search/fulltext_native.php | 142 |
20 files changed, 565 insertions, 161 deletions
diff --git a/phpBB/includes/acp/acp_database.php b/phpBB/includes/acp/acp_database.php index 64806eda59..980f4fcf48 100644 --- a/phpBB/includes/acp/acp_database.php +++ b/phpBB/includes/acp/acp_database.php @@ -86,9 +86,8 @@ class acp_database $time = time(); $filename = 'backup_' . $time . '_' . unique_id(); - switch ($db->sql_layer) + switch ($db->dbms_type) { - case 'mysqli': case 'mysql': $extractor = new mysql_extractor($download, $store, $format, $filename, $time); break; @@ -106,7 +105,6 @@ class acp_database break; case 'mssql': - case 'mssql_odbc': $extractor = new mssql_extractor($download, $store, $format, $filename, $time); break; @@ -131,7 +129,7 @@ class acp_database else { // We might wanna empty out all that junk :D - switch ($db->sql_layer) + switch ($db->dbms_type) { case 'sqlite': case 'firebird': @@ -140,7 +138,6 @@ class acp_database break; case 'mssql': - case 'mssql_odbc': $extractor->flush('TRUNCATE TABLE ' . $table_name . "GO\n"); break; @@ -318,11 +315,11 @@ class acp_database break; } - switch ($db->sql_layer) + switch ($db->dbms_type) { case 'mysql': - case 'mysqli': case 'sqlite': + case 'db2': while (($sql = $fgetd($fp, ";\n", $read, $seek, $eof)) !== false) { $db->sql_query($sql); @@ -372,7 +369,6 @@ class acp_database break; case 'mssql': - case 'mssql_odbc': while (($sql = $fgetd($fp, "GO\n", $read, $seek, $eof)) !== false) { $db->sql_query($sql); @@ -1356,10 +1352,15 @@ class mssql_extractor extends base_extractor { $this->write_data_mssql($table_name); } - else + else if ($db->sql_layer === 'mssql_odbc') { $this->write_data_odbc($table_name); } + else + { + // @todo: write code for MS SQL 2005 DBAL + trigger_error('KungFuDeathGrip'); + } } function write_data_mssql($table_name) diff --git a/phpBB/includes/acp/acp_forums.php b/phpBB/includes/acp/acp_forums.php index faf3b7b296..6338559cfc 100644 --- a/phpBB/includes/acp/acp_forums.php +++ b/phpBB/includes/acp/acp_forums.php @@ -1647,10 +1647,9 @@ class acp_forums } $db->sql_freeresult($result); - switch ($db->sql_layer) + if ($db->dbms_type) { case 'mysql': - case 'mysqli': // Delete everything else and thank MySQL for offering multi-table deletion $tables_ary = array( diff --git a/phpBB/includes/acp/acp_profile.php b/phpBB/includes/acp/acp_profile.php index bd7d58717b..253308d153 100644 --- a/phpBB/includes/acp/acp_profile.php +++ b/phpBB/includes/acp/acp_profile.php @@ -120,9 +120,8 @@ class acp_profile $db->sql_query('DELETE FROM ' . PROFILE_FIELDS_LANG_TABLE . " WHERE field_id = $field_id"); $db->sql_query('DELETE FROM ' . PROFILE_LANG_TABLE . " WHERE field_id = $field_id"); - switch ($db->sql_layer) + if ($db->dbms_type == 'sqlite') { - case 'sqlite': $sql = "SELECT sql FROM sqlite_master WHERE type = 'table' @@ -166,9 +165,9 @@ class acp_profile $db->sql_query('CREATE TABLE ' . PROFILE_FIELDS_DATA_TABLE . ' (' . $new_table_cols . ');'); $db->sql_query('INSERT INTO ' . PROFILE_FIELDS_DATA_TABLE . ' (' . $columns . ') SELECT ' . $columns . ' FROM ' . PROFILE_FIELDS_DATA_TABLE . '_temp;'); $db->sql_query('DROP TABLE ' . PROFILE_FIELDS_DATA_TABLE . '_temp'); - break; - - default: + } + else + { $db->sql_query('ALTER TABLE ' . PROFILE_FIELDS_DATA_TABLE . " DROP COLUMN pf_$field_ident"); } @@ -1348,10 +1347,9 @@ class acp_profile { global $db; - switch ($db->sql_layer) + switch ($db->dbms_type) { case 'mysql': - case 'mysqli': // We are defining the biggest common value, because of the possibility to edit the min/max values of each field. $sql = 'ALTER TABLE ' . PROFILE_FIELDS_DATA_TABLE . " ADD `$field_ident` "; @@ -1468,7 +1466,6 @@ class acp_profile break; case 'mssql': - case 'mssql_odbc': // We are defining the biggest common value, because of the possibility to edit the min/max values of each field. $sql = 'ALTER TABLE [' . PROFILE_FIELDS_DATA_TABLE . "] ADD [$field_ident] "; diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index 8279bf92b4..cb33450759 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -1125,7 +1125,7 @@ class acp_users // Update Custom Fields if (sizeof($cp_data)) { - switch ($db->sql_layer) + switch ($db->dbms_type) { case 'oracle': case 'firebird': @@ -1136,13 +1136,11 @@ class acp_users case 'sqlite': case 'mssql': - case 'mssql_odbc': $right_delim = ']'; $left_delim = '['; break; case 'mysql': - case 'mysqli': $right_delim = $left_delim = '`'; break; } diff --git a/phpBB/includes/db/db2.php b/phpBB/includes/db/db2.php index d1917e6c3a..09d56c709a 100644 --- a/phpBB/includes/db/db2.php +++ b/phpBB/includes/db/db2.php @@ -31,6 +31,8 @@ class dbal_db2 extends dbal // can't truncate a table var $truncate = false; + var $dbms_type = 'db2'; + /** * Connect to server */ diff --git a/phpBB/includes/db/db_tools.php b/phpBB/includes/db/db_tools.php index f02ec96a9f..e90e84f348 100644 --- a/phpBB/includes/db/db_tools.php +++ b/phpBB/includes/db/db_tools.php @@ -254,21 +254,7 @@ class phpbb_db_tools { $this->db = $db; - // Determine mapping database type - switch ($this->db->sql_layer) - { - case 'mysqli': - $this->sql_layer = 'mysql'; - break; - - case 'mssql_odbc': - $this->sql_layer = 'mssql'; - break; - - default: - $this->sql_layer = $this->db->sql_layer; - break; - } + $this->sql_layer = $this->db->dbms_type; } /** diff --git a/phpBB/includes/db/firebird.php b/phpBB/includes/db/firebird.php index 21dd6f0127..a58371cf22 100644 --- a/phpBB/includes/db/firebird.php +++ b/phpBB/includes/db/firebird.php @@ -31,6 +31,8 @@ class dbal_firebird extends dbal // can't truncate a table var $truncate = false; + var $dbms_type = 'firebird'; + /** * Connect to server */ diff --git a/phpBB/includes/db/mssql.php b/phpBB/includes/db/mssql.php index f89fcb9d8f..7a1467bd9c 100644 --- a/phpBB/includes/db/mssql.php +++ b/phpBB/includes/db/mssql.php @@ -25,6 +25,8 @@ include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx); */ class dbal_mssql extends dbal { + var $dbms_type = 'mssql'; + /** * Connect to server */ diff --git a/phpBB/includes/db/mssql_2005.php b/phpBB/includes/db/mssql_2005.php new file mode 100644 index 0000000000..ed9cd8edc6 --- /dev/null +++ b/phpBB/includes/db/mssql_2005.php @@ -0,0 +1,416 @@ +<?php +/** +* +* @package dbal +* @version $Id$ +* @copyright (c) 2005 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ + exit; +} + +include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx); + +/** +* MSSQL Database Abstraction Layer +* Minimum Requirement is MSSQL 2005+ +* @package dbal +*/ +class dbal_mssql_2005 extends dbal +{ + var $last_query_text = ''; + var $dbms_type = 'mssql'; + + /** + * Connect to server + */ + function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false, $new_link = false) + { + $this->persistency = $persistency; + $this->user = $sqluser; + $this->server = $sqlserver . (($port) ? ':' . $port : ''); + $this->dbname = $database; + + $this->db_connect_id = sqlsrv_connect($this->server, array('UID' => $this->user, 'PWD' => $sqlpassword)); + + if ($this->db_connect_id && $this->dbname != '') + { + if (!sqlsrv_conn_execute($this->db_connect_id, 'USE ' . $this->dbname)) + { + @sqlsrv_conn_close($this->db_connect_id); + return false; + } + } + + return ($this->db_connect_id) ? $this->db_connect_id : $this->sql_error(''); + } + + /** + * Version information about used database + */ + function sql_server_info() + { + $server_info = sqlsrv_conn_server_info($this->db_connect_id); + + return 'MSSQL (2005)<br />' . $server_info['SQL Server Version']; + } + + /** + * SQL Transaction + * @access private + */ + function _sql_transaction($status = 'begin') + { + switch ($status) + { + case 'begin': + return sqlsrv_conn_execute($this->db_connect_id, 'BEGIN TRANSACTION'); + break; + + case 'commit': + return sqlsrv_conn_execute($this->db_connect_id, 'COMMIT TRANSACTION'); + break; + + case 'rollback': + return sqlsrv_conn_execute($this->db_connect_id, 'ROLLBACK TRANSACTION'); + break; + } + + return true; + } + + /** + * Base query method + * + * @param string $query Contains the SQL query which shall be executed + * @param int $cache_ttl Either 0 to avoid caching or the time in seconds which the result shall be kept in cache + * @return mixed When casted to bool the returned value returns true on success and false on failure + * + * @access public + */ + function sql_query($query = '', $cache_ttl = 0) + { + if ($query != '') + { + global $cache; + + if (strpos($query, 'BEGIN') === 0 || strpos($query, 'COMMIT') === 0) + { + return true; + } + + // EXPLAIN only in extra debug mode + if (defined('DEBUG_EXTRA')) + { + $this->sql_report('start', $query); + } + + $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 === false) + { + if (($this->query_result = @sqlsrv_conn_execute($this->db_connect_id, $query)) === false) + { + $this->sql_error($query); + } + + if (defined('DEBUG_EXTRA')) + { + $this->sql_report('stop', $query); + } + + if ($cache_ttl && method_exists($cache, 'sql_save')) + { + $this->open_queries[(int) $this->query_result] = $this->query_result; + $cache->sql_save($query, $this->query_result, $cache_ttl); + } + else if (strpos($query, 'SELECT') === 0 && $this->query_result) + { + $this->open_queries[(int) $this->query_result] = $this->query_result; + } + } + else if (defined('DEBUG_EXTRA')) + { + $this->sql_report('fromcache', $query); + } + } + else + { + return false; + } + + return ($this->query_result) ? $this->query_result : false; + } + + /** + * Build LIMIT query + */ + function _sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0) + { + $this->query_result = false; + + // Since TOP is only returning a set number of rows we won't need it if total is set to 0 (return all rows) + if ($total) + { + // We need to grab the total number of rows + the offset number of rows to get the correct result + if (strpos($query, 'SELECT DISTINCT') === 0) + { + $query = 'SELECT DISTINCT TOP ' . ($total + $offset) . ' ' . substr($query, 15); + } + else + { + $query = 'SELECT TOP ' . ($total + $offset) . ' ' . substr($query, 6); + } + } + + $result = $this->sql_query($query, $cache_ttl); + + // Seek by $offset rows + if ($offset) + { + $this->sql_rowseek($offset, $result); + } + + return $result; + } + + /** + * Return number of affected rows + */ + function sql_affectedrows() + { + return ($this->db_connect_id) ? sqlsrv_stmt_rows_affected($this->db_connect_id) : false; + } + + /** + * Fetch current row + */ + function sql_fetchrow($query_id = false) + { + global $cache; + + if ($query_id === false) + { + $query_id = $this->query_result; + } + + if (isset($cache->sql_rowset[$query_id])) + { + return $cache->sql_fetchrow($query_id); + } + + if ($query_id === false) + { + return false; + } + + $row = @sqlsrv_stmt_fetch_array($query_id, SQLSRV_FETCH_TYPE_ARRAY); + + // I hope i am able to remove this later... hopefully only a PHP or MSSQL bug + if ($row) + { + foreach ($row as $key => $value) + { + $row[$key] = ($value === ' ' || $value === NULL) ? '' : $value; + } + } + + return $row; + } + + /** + * Seek to given row number + * rownum is zero-based + */ + function sql_rowseek($rownum, &$query_id) + { + global $cache; + + if ($query_id === false) + { + $query_id = $this->query_result; + } + + if (isset($cache->sql_rowset[$query_id])) + { + return $cache->sql_rowseek($rownum, $query_id); + } + + if ($query_id === false) + { + return false; + } + + $this->sql_freeresult($query_id); + $query_id = $this->sql_query($this->last_query_text); + + if ($query_id === false) + { + return false; + } + + // We do not fetch the row for rownum == 0 because then the next resultset would be the second row + for ($i = 0; $i < $rownum; $i++) + { + if (!$this->sql_fetchrow($query_id)) + { + return false; + } + } + + return true; + } + + /** + * Get last inserted id after insert statement + */ + function sql_nextid() + { + $result_id = @sqlsrv_conn_execute($this->db_connect_id, 'SELECT SCOPE_IDENTITY()'); + if ($result_id) + { + if ($row = @sqlsrv_stmt_fetch_array($result_id, SQLSRV_FETCH_TYPE_ARRAY)) + { + @sqlsrv_stmt_close($result_id); + return $row['computed']; + } + @sqlsrv_stmt_close($result_id); + } + + return false; + } + + /** + * Free sql result + */ + function sql_freeresult($query_id = false) + { + global $cache; + + if ($query_id === false) + { + $query_id = $this->query_result; + } + + if (isset($cache->sql_rowset[$query_id])) + { + return $cache->sql_freeresult($query_id); + } + + if (isset($this->open_queries[$query_id])) + { + unset($this->open_queries[$query_id]); + return @sqlsrv_stmt_close($query_id); + } + + return false; + } + + /** + * Escape string used in sql query + */ + function sql_escape($msg) + { + return str_replace("'", "''", $msg); + } + + /** + * 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 + */ + function _sql_like_expression($expression) + { + return $expression . " ESCAPE '\\'"; + } + + /** + * return sql error array + * @access private + */ + function _sql_error() + { + $error = array( + 'message' => '', + 'code' => '' + ); + + foreach (sqlsrv_errors() as $error_array) + { + $error['message'] .= $error_array['message'] . "<br />"; + $error['code'] .= $error_array['code'] . "<br />"; + } + + return $error; + } + + /** + * Build db-specific query data + * @access private + */ + function _sql_custom_build($stage, $data) + { + return $data; + } + + /** + * Close sql connection + * @access private + */ + function _sql_close() + { + return @sqlsrv_conn_close($this->db_connect_id); + } + + /** + * Build db-specific report + * @access private + */ + function _sql_report($mode, $query = '') + { + switch ($mode) + { + case 'fromcache': + $endtime = explode(' ', microtime()); + $endtime = $endtime[0] + $endtime[1]; + + $result = @sqlsrv_conn_execute($this->db_connect_id, $query); + while ($void = @sqlsrv_stmt_fetch_array($result)) + { + // Take the time spent on parsing rows into account + } + @sqlsrv_stmt_close($result); + + $splittime = explode(' ', microtime()); + $splittime = $splittime[0] + $splittime[1]; + + $this->sql_report('record_fromcache', $query, $endtime, $splittime); + + break; + } + } +} + +?>
\ No newline at end of file diff --git a/phpBB/includes/db/mssql_odbc.php b/phpBB/includes/db/mssql_odbc.php index 5ef00c6839..a9a0b1bc1d 100644 --- a/phpBB/includes/db/mssql_odbc.php +++ b/phpBB/includes/db/mssql_odbc.php @@ -32,6 +32,7 @@ include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx); class dbal_mssql_odbc extends dbal { var $last_query_text = ''; + var $dbms_type = 'mssql'; /** * Connect to server diff --git a/phpBB/includes/db/mysql.php b/phpBB/includes/db/mysql.php index 0c949309a1..17daf7093c 100644 --- a/phpBB/includes/db/mysql.php +++ b/phpBB/includes/db/mysql.php @@ -32,6 +32,8 @@ class dbal_mysql extends dbal // Supports multiple table deletion var $multi_table_deletion = true; + var $dbms_type = 'mysql'; + /** * Connect to server * @access public diff --git a/phpBB/includes/db/mysqli.php b/phpBB/includes/db/mysqli.php index c9c89fb824..ed43ec0a82 100644 --- a/phpBB/includes/db/mysqli.php +++ b/phpBB/includes/db/mysqli.php @@ -32,6 +32,8 @@ class dbal_mysqli extends dbal // Supports multiple table deletion var $multi_table_deletion = true; + var $dbms_type = 'mysql'; + /** * Connect to server */ diff --git a/phpBB/includes/db/oracle.php b/phpBB/includes/db/oracle.php index 0640d3d354..95bdfe4174 100644 --- a/phpBB/includes/db/oracle.php +++ b/phpBB/includes/db/oracle.php @@ -26,6 +26,8 @@ class dbal_oracle extends dbal { var $last_query_text = ''; + var $dbms_type = 'oracle'; + /** * Connect to server */ diff --git a/phpBB/includes/db/postgres.php b/phpBB/includes/db/postgres.php index 0f946c2d7c..023a8fda1b 100644 --- a/phpBB/includes/db/postgres.php +++ b/phpBB/includes/db/postgres.php @@ -28,6 +28,8 @@ class dbal_postgres extends dbal var $last_query_text = ''; var $pgsql_version; + var $dbms_type = 'postgres'; + /** * Connect to server */ diff --git a/phpBB/includes/db/sqlite.php b/phpBB/includes/db/sqlite.php index c6f6f8fc9b..9dedf09079 100644 --- a/phpBB/includes/db/sqlite.php +++ b/phpBB/includes/db/sqlite.php @@ -31,6 +31,8 @@ class dbal_sqlite extends dbal // can't truncate a table var $truncate = false; + var $dbms_type = 'sqlite'; + /** * Connect to server */ diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index 8ac66237da..6ad30c3568 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -1236,40 +1236,37 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, break; case 'topic_approved': - switch ($db->sql_layer) + if ($db->dbms_type == 'mysql') { - case 'mysql': - case 'mysqli': - $sql = 'UPDATE ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . " p - SET t.topic_approved = p.post_approved - $where_sql_and t.topic_first_post_id = p.post_id"; - $db->sql_query($sql); - break; - - default: - $sql = 'SELECT t.topic_id, p.post_approved - FROM ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . " p - $where_sql_and p.post_id = t.topic_first_post_id - AND p.post_approved <> t.topic_approved"; - $result = $db->sql_query($sql); + $sql = 'UPDATE ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . " p + SET t.topic_approved = p.post_approved + $where_sql_and t.topic_first_post_id = p.post_id"; + $db->sql_query($sql); + } + else + { + $sql = 'SELECT t.topic_id, p.post_approved + FROM ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . " p + $where_sql_and p.post_id = t.topic_first_post_id + AND p.post_approved <> t.topic_approved"; + $result = $db->sql_query($sql); - $topic_ids = array(); - while ($row = $db->sql_fetchrow($result)) - { - $topic_ids[] = $row['topic_id']; - } - $db->sql_freeresult($result); + $topic_ids = array(); + while ($row = $db->sql_fetchrow($result)) + { + $topic_ids[] = $row['topic_id']; + } + $db->sql_freeresult($result); - if (!sizeof($topic_ids)) - { - return; - } + if (!sizeof($topic_ids)) + { + return; + } - $sql = 'UPDATE ' . TOPICS_TABLE . ' - SET topic_approved = 1 - topic_approved - WHERE ' . $db->sql_in_set('topic_id', $topic_ids); - $db->sql_query($sql); - break; + $sql = 'UPDATE ' . TOPICS_TABLE . ' + SET topic_approved = 1 - topic_approved + WHERE ' . $db->sql_in_set('topic_id', $topic_ids); + $db->sql_query($sql); } break; @@ -2747,10 +2744,9 @@ function get_database_size() $database_size = false; // This code is heavily influenced by a similar routine in phpMyAdmin 2.2.0 - switch ($db->sql_layer) + switch ($db->dbms_type) { case 'mysql': - case 'mysqli': $sql = 'SELECT VERSION() AS mysql_version'; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); @@ -2813,7 +2809,6 @@ function get_database_size() break; case 'mssql': - case 'mssql_odbc': $sql = 'SELECT ((SUM(size) * 8.0) * 1024.0) as dbsize FROM sysfiles'; $result = $db->sql_query($sql, 7200); diff --git a/phpBB/includes/functions_convert.php b/phpBB/includes/functions_convert.php index ed35be3db7..7498882e7c 100644 --- a/phpBB/includes/functions_convert.php +++ b/phpBB/includes/functions_convert.php @@ -1620,10 +1620,9 @@ function mass_auth($ug_type, $forum_id, $ug_id, $acl_list, $setting = ACL_NO) switch ($sql_type) { case 'insert': - switch ($db->sql_layer) + switch ($db->dbms_type) { case 'mysql': - case 'mysql4': $sql = 'VALUES ' . implode(', ', preg_replace('#^(.*?)$#', '(\1)', $sql_subary)); break; @@ -1977,16 +1976,13 @@ function update_topics_posted() { global $db, $config; - 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('DELETE FROM ' . TOPICS_POSTED_TABLE); + } + else + { + $db->sql_query('TRUNCATE TABLE ' . TOPICS_POSTED_TABLE); } // This can get really nasty... therefore we only do the last six months diff --git a/phpBB/includes/functions_install.php b/phpBB/includes/functions_install.php index 97775eacf7..31085344f8 100644 --- a/phpBB/includes/functions_install.php +++ b/phpBB/includes/functions_install.php @@ -82,6 +82,16 @@ function get_available_dbms($dbms = false, $return_unavailable = false, $only_20 'AVAILABLE' => true, '2.0.x' => true, ), + 'mssql_2005'=> array( + 'LABEL' => 'MS SQL Server [ 2005 ]', + 'SCHEMA' => 'mssql', + 'MODULE' => 'sqlsrv', + 'DELIM' => 'GO', + 'COMMENTS' => 'remove_comments', + 'DRIVER' => 'mssql_2005', + 'AVAILABLE' => true, + '2.0.x' => true, + ), 'db2' => array( 'LABEL' => 'IBM DB2', 'SCHEMA' => 'db2', @@ -201,10 +211,9 @@ function dbms_select($default = '', $only_20x_options = false) */ function get_tables($db) { - switch ($db->sql_layer) + switch ($db->dbms_type) { case 'mysql': - case 'mysqli': $sql = 'SHOW TABLES'; break; @@ -215,7 +224,6 @@ function get_tables($db) break; case 'mssql': - case 'mssql_odbc': $sql = "SELECT name FROM sysobjects WHERE type='U'"; @@ -317,6 +325,7 @@ function connect_check_db($error_connect, &$error, $dbms_details, $table_prefix, case 'mssql': case 'mssql_odbc': + case 'mssql_2005': $prefix_length = 90; break; diff --git a/phpBB/includes/search/fulltext_mysql.php b/phpBB/includes/search/fulltext_mysql.php index 17b081a18a..a119f866c4 100644 --- a/phpBB/includes/search/fulltext_mysql.php +++ b/phpBB/includes/search/fulltext_mysql.php @@ -726,7 +726,7 @@ class fulltext_mysql extends search_backend { global $db; - if (strpos($db->sql_layer, 'mysql') === false) + if ($db->dbms_type !== 'mysql') { $this->stats = array(); return; diff --git a/phpBB/includes/search/fulltext_native.php b/phpBB/includes/search/fulltext_native.php index 8501474cfb..949d7bc0f4 100755 --- a/phpBB/includes/search/fulltext_native.php +++ b/phpBB/includes/search/fulltext_native.php @@ -640,35 +640,31 @@ class fulltext_native extends search_backend $sql = ''; $sql_array_count = $sql_array; - switch ($db->sql_layer) + if ($db->dbms_type === 'mysql') { - case 'mysql': - case 'mysqli': - $sql_array['SELECT'] = 'SQL_CALC_FOUND_ROWS ' . $sql_array['SELECT']; - $is_mysql = true; - - break; - - case 'sqlite': + $sql_array['SELECT'] = 'SQL_CALC_FOUND_ROWS ' . $sql_array['SELECT']; + $is_mysql = true; + } + else + { + if (!$db->count_distinct) + { $sql_array_count['SELECT'] = ($type == 'posts') ? 'DISTINCT p.post_id' : 'DISTINCT p.topic_id'; $sql = 'SELECT COUNT(' . (($type == 'posts') ? 'post_id' : 'topic_id') . ') as total_results FROM (' . $db->sql_build_query('SELECT', $sql_array_count) . ')'; + } - // no break - - default: - $sql_array_count['SELECT'] = ($type == 'posts') ? 'COUNT(DISTINCT p.post_id) AS total_results' : 'COUNT(DISTINCT p.topic_id) AS total_results'; - $sql = (!$sql) ? $db->sql_build_query('SELECT', $sql_array_count) : $sql; + $sql_array_count['SELECT'] = ($type == 'posts') ? 'COUNT(DISTINCT p.post_id) AS total_results' : 'COUNT(DISTINCT p.topic_id) AS total_results'; + $sql = (!$sql) ? $db->sql_build_query('SELECT', $sql_array_count) : $sql; - $result = $db->sql_query($sql); - $total_results = (int) $db->sql_fetchfield('total_results'); - $db->sql_freeresult($result); + $result = $db->sql_query($sql); + $total_results = (int) $db->sql_fetchfield('total_results'); + $db->sql_freeresult($result); - if (!$total_results) - { - return false; - } - break; + if (!$total_results) + { + return false; + } } unset($sql_array_count, $sql); @@ -840,57 +836,54 @@ class fulltext_native extends search_backend // If the cache was completely empty count the results if (!$total_results) { - switch ($db->sql_layer) + if ($db->dbms_type === 'mysql') { - case 'mysql': - case 'mysqli': $select = 'SQL_CALC_FOUND_ROWS ' . $select; $is_mysql = true; - break; - - default: - if ($type == 'posts') + } + else + { + if ($type == 'posts') + { + $sql = 'SELECT COUNT(p.post_id) as total_results + FROM ' . POSTS_TABLE . ' p' . (($firstpost_only) ? ', ' . TOPICS_TABLE . ' t ' : ' ') . " + WHERE $sql_author + $sql_topic_id + $sql_firstpost + $m_approve_fid_sql + $sql_fora + $sql_time"; + } + else + { + if ($db->count_distinct) { - $sql = 'SELECT COUNT(p.post_id) as total_results - FROM ' . POSTS_TABLE . ' p' . (($firstpost_only) ? ', ' . TOPICS_TABLE . ' t ' : ' ') . " - WHERE $sql_author - $sql_topic_id - $sql_firstpost - $m_approve_fid_sql - $sql_fora - $sql_time"; + $sql = 'SELECT COUNT(DISTINCT t.topic_id) as total_results'; } else { - if ($db->count_distinct) - { - $sql = 'SELECT COUNT(DISTINCT t.topic_id) as total_results'; - } - else - { - $sql = 'SELECT COUNT(topic_id) as total_results - FROM (SELECT DISTINCT t.topic_id'; - } - - $sql .= ' FROM ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . " p - WHERE $sql_author - $sql_topic_id - $sql_firstpost - $m_approve_fid_sql - $sql_fora - AND t.topic_id = p.topic_id - $sql_time" . (($db->count_distinct) ? '' : ')'); + $sql = 'SELECT COUNT(topic_id) as total_results + FROM (SELECT DISTINCT t.topic_id'; } - $result = $db->sql_query($sql); - $total_results = (int) $db->sql_fetchfield('total_results'); - $db->sql_freeresult($result); + $sql .= ' FROM ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . " p + WHERE $sql_author + $sql_topic_id + $sql_firstpost + $m_approve_fid_sql + $sql_fora + AND t.topic_id = p.topic_id + $sql_time" . (($db->count_distinct) ? '' : ')'); + } + $result = $db->sql_query($sql); - if (!$total_results) - { - return false; - } - break; + $total_results = (int) $db->sql_fetchfield('total_results'); + $db->sql_freeresult($result); + + if (!$total_results) + { + return false; + } } } @@ -1338,20 +1331,17 @@ class fulltext_native extends search_backend { global $db; - switch ($db->sql_layer) + if ($db->truncate) { - case 'sqlite': - case 'firebird': - $db->sql_query('DELETE FROM ' . SEARCH_WORDLIST_TABLE); - $db->sql_query('DELETE FROM ' . SEARCH_WORDMATCH_TABLE); - $db->sql_query('DELETE FROM ' . SEARCH_RESULTS_TABLE); - break; - - default: - $db->sql_query('TRUNCATE TABLE ' . SEARCH_WORDLIST_TABLE); - $db->sql_query('TRUNCATE TABLE ' . SEARCH_WORDMATCH_TABLE); - $db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE); - break; + $db->sql_query('TRUNCATE TABLE ' . SEARCH_WORDLIST_TABLE); + $db->sql_query('TRUNCATE TABLE ' . SEARCH_WORDMATCH_TABLE); + $db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE); + } + else + { + $db->sql_query('DELETE FROM ' . SEARCH_WORDLIST_TABLE); + $db->sql_query('DELETE FROM ' . SEARCH_WORDMATCH_TABLE); + $db->sql_query('DELETE FROM ' . SEARCH_RESULTS_TABLE); } } |