aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid M <davidmj@users.sourceforge.net>2008-01-07 15:19:38 +0000
committerDavid M <davidmj@users.sourceforge.net>2008-01-07 15:19:38 +0000
commit2928574ed46334bb8dbbb6612a62db3c3654ba12 (patch)
treec010569c70e52dbda45dd835a613977fb30f9dc8
parent159ce6f8d1bddbe7afc055f70cab3107b9c74a5f (diff)
downloadforums-2928574ed46334bb8dbbb6612a62db3c3654ba12.tar
forums-2928574ed46334bb8dbbb6612a62db3c3654ba12.tar.gz
forums-2928574ed46334bb8dbbb6612a62db3c3654ba12.tar.bz2
forums-2928574ed46334bb8dbbb6612a62db3c3654ba12.tar.xz
forums-2928574ed46334bb8dbbb6612a62db3c3654ba12.zip
- a few tiny clean ups
- a new MS SQL DBAL, it does not work so hot because of issues with the extension it depends on git-svn-id: file:///svn/phpbb/trunk@8313 89ea8834-ac86-4346-8a33-228a782c2dd0
-rw-r--r--phpBB/includes/acp/acp_database.php19
-rw-r--r--phpBB/includes/acp/acp_forums.php3
-rw-r--r--phpBB/includes/acp/acp_profile.php13
-rw-r--r--phpBB/includes/acp/acp_users.php4
-rw-r--r--phpBB/includes/db/db2.php2
-rw-r--r--phpBB/includes/db/db_tools.php16
-rw-r--r--phpBB/includes/db/firebird.php2
-rw-r--r--phpBB/includes/db/mssql.php2
-rw-r--r--phpBB/includes/db/mssql_2005.php416
-rw-r--r--phpBB/includes/db/mssql_odbc.php1
-rw-r--r--phpBB/includes/db/mysql.php2
-rw-r--r--phpBB/includes/db/mysqli.php2
-rw-r--r--phpBB/includes/db/oracle.php2
-rw-r--r--phpBB/includes/db/postgres.php2
-rw-r--r--phpBB/includes/db/sqlite.php2
-rw-r--r--phpBB/includes/functions_admin.php61
-rw-r--r--phpBB/includes/functions_convert.php18
-rw-r--r--phpBB/includes/functions_install.php15
-rw-r--r--phpBB/includes/search/fulltext_mysql.php2
-rwxr-xr-xphpBB/includes/search/fulltext_native.php142
-rw-r--r--phpBB/install/convertors/functions_phpbb20.php53
-rw-r--r--phpBB/install/database_update.php19
-rw-r--r--phpBB/install/install_convert.php49
-rwxr-xr-xphpBB/install/install_install.php1
-rwxr-xr-xphpBB/language/en/install.php1
25 files changed, 593 insertions, 256 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);
}
}
diff --git a/phpBB/install/convertors/functions_phpbb20.php b/phpBB/install/convertors/functions_phpbb20.php
index 1f62d80852..d503f66939 100644
--- a/phpBB/install/convertors/functions_phpbb20.php
+++ b/phpBB/install/convertors/functions_phpbb20.php
@@ -90,12 +90,9 @@ function phpbb_insert_forums()
$src_db->sql_query("SET NAMES 'utf8'");
}
- switch ($db->sql_layer)
+ if ($db->dbms_type == 'mssql')
{
- case 'mssql':
- case 'mssql_odbc':
- $db->sql_query('SET IDENTITY_INSERT ' . FORUMS_TABLE . ' ON');
- break;
+ $db->sql_query('SET IDENTITY_INSERT ' . FORUMS_TABLE . ' ON');
}
$cats_added = array();
@@ -282,14 +279,13 @@ function phpbb_insert_forums()
}
$src_db->sql_freeresult($result);
- switch ($db->sql_layer)
+ switch ($db->dbms_type)
{
case 'postgres':
$db->sql_query("SELECT SETVAL('" . FORUMS_TABLE . "_seq',(select case when max(forum_id)>0 then max(forum_id)+1 else 1 end from " . FORUMS_TABLE . '));');
break;
case 'mssql':
- case 'mssql_odbc':
$db->sql_query('SET IDENTITY_INSERT ' . FORUMS_TABLE . ' OFF');
break;
@@ -1702,41 +1698,9 @@ function phpbb_check_username_collisions()
{
global $db, $src_db, $convert, $table_prefix, $user, $lang;
- $map_dbms = '';
- switch ($db->sql_layer)
- {
- case 'mysql':
- $map_dbms = 'mysql_40';
- break;
-
- case 'mysql4':
- if (version_compare($db->mysql_version, '4.1.3', '>='))
- {
- $map_dbms = 'mysql_41';
- }
- else
- {
- $map_dbms = 'mysql_40';
- }
- break;
-
- case 'mysqli':
- $map_dbms = 'mysql_41';
- break;
-
- case 'mssql':
- case 'mssql_odbc':
- $map_dbms = 'mssql';
- break;
-
- default:
- $map_dbms = $db->sql_layer;
- break;
- }
-
// create a temporary table in which we store the clean usernames
$drop_sql = 'DROP TABLE ' . $table_prefix . 'userconv';
- switch ($map_dbms)
+ switch ($db->dbms_type)
{
case 'firebird':
$create_sql = 'CREATE TABLE ' . $table_prefix . 'userconv (
@@ -1752,14 +1716,7 @@ function phpbb_check_username_collisions()
)';
break;
- case 'mysql_40':
- $create_sql = 'CREATE TABLE ' . $table_prefix . 'userconv (
- user_id mediumint(8) NOT NULL,
- username_clean blob NOT NULL
- )';
- break;
-
- case 'mysql_41':
+ case 'mysql':
$create_sql = 'CREATE TABLE ' . $table_prefix . 'userconv (
user_id mediumint(8) NOT NULL,
username_clean varchar(255) DEFAULT \'\' NOT NULL
diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php
index d7cbfea28f..40666c29dc 100644
--- a/phpBB/install/database_update.php
+++ b/phpBB/install/database_update.php
@@ -340,21 +340,7 @@ $database_update_info = array(
);
// Determine mapping database type
-switch ($db->sql_layer)
-{
-
- case 'mysqli':
- $map_dbms = 'mysql';
- break;
-
- case 'mssql_odbc':
- $map_dbms = 'mssql';
- break;
-
- default:
- $map_dbms = $db->sql_layer;
- break;
-}
+$map_dbms = $db->dbms_type;
$error_ary = array();
$errored = false;
@@ -624,10 +610,9 @@ _sql($sql, $errored, $error_ary);
/* Optimize/vacuum analyze the tables where appropriate
// this should be done for each version in future along with
// the version number update
-switch ($db->sql_layer)
+switch ($db->dbms_type)
{
case 'mysql':
- case 'mysqli':
$sql = 'OPTIMIZE TABLE ' . $table_prefix . 'auth_access, ' . $table_prefix . 'banlist, ' . $table_prefix . 'categories, ' . $table_prefix . 'config, ' . $table_prefix . 'disallow, ' . $table_prefix . 'forum_prune, ' . $table_prefix . 'forums, ' . $table_prefix . 'groups, ' . $table_prefix . 'posts, ' . $table_prefix . 'posts_text, ' . $table_prefix . 'privmsgs, ' . $table_prefix . 'privmsgs_text, ' . $table_prefix . 'ranks, ' . $table_prefix . 'search_results, ' . $table_prefix . 'search_wordlist, ' . $table_prefix . 'search_wordmatch, ' . $table_prefix . 'sessions_keys' . $table_prefix . 'smilies, ' . $table_prefix . 'themes, ' . $table_prefix . 'themes_name, ' . $table_prefix . 'topics, ' . $table_prefix . 'topics_watch, ' . $table_prefix . 'user_group, ' . $table_prefix . 'users, ' . $table_prefix . 'vote_desc, ' . $table_prefix . 'vote_results, ' . $table_prefix . 'vote_voters, ' . $table_prefix . 'words';
_sql($sql, $errored, $error_ary);
break;
diff --git a/phpBB/install/install_convert.php b/phpBB/install/install_convert.php
index 2fb34aee1d..7c7569c3f9 100644
--- a/phpBB/install/install_convert.php
+++ b/phpBB/install/install_convert.php
@@ -238,18 +238,15 @@ class install_convert extends module
));
}
- switch ($db->sql_layer)
+ if ($db->truncate)
{
- case 'sqlite':
- case 'firebird':
- $db->sql_query('DELETE FROM ' . SESSIONS_KEYS_TABLE);
- $db->sql_query('DELETE FROM ' . SESSIONS_TABLE);
- break;
-
- default:
- $db->sql_query('TRUNCATE TABLE ' . SESSIONS_KEYS_TABLE);
- $db->sql_query('TRUNCATE TABLE ' . SESSIONS_TABLE);
- break;
+ $db->sql_query('TRUNCATE TABLE ' . SESSIONS_KEYS_TABLE);
+ $db->sql_query('TRUNCATE TABLE ' . SESSIONS_TABLE);
+ }
+ else
+ {
+ $db->sql_query('DELETE FROM ' . SESSIONS_KEYS_TABLE);
+ $db->sql_query('DELETE FROM ' . SESSIONS_TABLE);
}
break;
@@ -684,7 +681,6 @@ class install_convert extends module
// Thanks MySQL, for silently converting...
case 'mysql':
- case 'mysql4':
if (version_compare($src_db->mysql_version, '4.1.3', '>='))
{
$convert->mysql_convert = true;
@@ -707,16 +703,13 @@ class install_convert extends module
$src_db->sql_query("SET NAMES 'binary'");
}
- switch ($db->sql_layer)
+ if ($db->truncate)
{
- case 'sqlite':
- case 'firebird':
- $convert->truncate_statement = 'DELETE FROM ';
- break;
-
- default:
- $convert->truncate_statement = 'TRUNCATE TABLE ';
- break;
+ $convert->truncate_statement = 'TRUNCATE TABLE ';
+ }
+ else
+ {
+ $convert->truncate_statement = 'DELETE FROM ';
}
$get_info = false;
@@ -1107,7 +1100,7 @@ class install_convert extends module
if (!empty($schema['autoincrement']))
{
- switch ($db->sql_layer)
+ switch ($db->dbms_type)
{
case 'postgres':
$db->sql_query("SELECT SETVAL('" . $schema['target'] . "_seq',(select case when max(" . $schema['autoincrement'] . ")>0 then max(" . $schema['autoincrement'] . ")+1 else 1 end from " . $schema['target'] . '));');
@@ -1244,10 +1237,9 @@ class install_convert extends module
if (!empty($schema['autoincrement']))
{
- switch ($db->sql_layer)
+ switch ($db->dbms_type)
{
case 'mssql':
- case 'mssql_odbc':
$db->sql_query('SET IDENTITY_INSERT ' . $schema['target'] . ' ON');
break;
}
@@ -1276,12 +1268,10 @@ class install_convert extends module
if ($sql_flag === true)
{
- switch ($db->sql_layer)
+ switch ($db->dbms_type)
{
// If MySQL, we'll wait to have num_wait_rows rows to submit at once
case 'mysql':
- case 'mysql4':
- case 'mysqli':
$waiting_rows[] = '(' . implode(', ', $insert_values) . ')';
if (sizeof($waiting_rows) >= $convert->num_wait_rows)
@@ -1371,10 +1361,9 @@ class install_convert extends module
if (!empty($schema['autoincrement']))
{
- switch ($db->sql_layer)
+ switch ($db->dbms_type)
{
case 'mssql':
- case 'mssql_odbc':
$db->sql_query('SET IDENTITY_INSERT ' . $schema['target'] . ' OFF');
break;
@@ -1780,7 +1769,7 @@ class install_convert extends module
global $convert;
// Can we use IGNORE with this DBMS?
- $sql_ignore = (strpos($db->sql_layer, 'mysql') === 0 && !defined('DEBUG_EXTRA')) ? 'IGNORE ' : '';
+ $sql_ignore = ($db->dbms_type === 'mysql' && !defined('DEBUG_EXTRA')) ? 'IGNORE ' : '';
$insert_query = 'INSERT ' . $sql_ignore . 'INTO ' . $schema['target'] . ' (';
$aliases = array();
diff --git a/phpBB/install/install_install.php b/phpBB/install/install_install.php
index d91d67a065..4be58ed157 100755
--- a/phpBB/install/install_install.php
+++ b/phpBB/install/install_install.php
@@ -1193,6 +1193,7 @@ class install_install extends module
{
case 'mssql':
case 'mssql_odbc':
+ case 'mssql_2005':
$sql_query = preg_replace('#\# MSSQL IDENTITY (phpbb_[a-z_]+) (ON|OFF) \##s', 'SET IDENTITY_INSERT \1 \2;', $sql_query);
break;
diff --git a/phpBB/language/en/install.php b/phpBB/language/en/install.php
index 4a81d2623a..4a1f1add75 100755
--- a/phpBB/language/en/install.php
+++ b/phpBB/language/en/install.php
@@ -146,6 +146,7 @@ $lang = array_merge($lang, array(
'DLL_GD' => 'GD graphics support [ Visual Confirmation ]',
'DLL_MBSTRING' => 'Multi-byte character support',
'DLL_MSSQL' => 'MSSQL Server 2000+',
+ 'DLL_MSSQL_2005' => 'MSSQL Server 2005+',
'DLL_MSSQL_ODBC' => 'MSSQL Server 2000+ via ODBC',
'DLL_MYSQL' => 'MySQL',
'DLL_MYSQLI' => 'MySQL with MySQLi Extension',