- 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
This commit is contained in:
David M 2008-01-07 15:19:38 +00:00
parent 159ce6f8d1
commit 2928574ed4
25 changed files with 593 additions and 256 deletions

View file

@ -86,9 +86,8 @@ class acp_database
$time = time(); $time = time();
$filename = 'backup_' . $time . '_' . unique_id(); $filename = 'backup_' . $time . '_' . unique_id();
switch ($db->sql_layer) switch ($db->dbms_type)
{ {
case 'mysqli':
case 'mysql': case 'mysql':
$extractor = new mysql_extractor($download, $store, $format, $filename, $time); $extractor = new mysql_extractor($download, $store, $format, $filename, $time);
break; break;
@ -106,7 +105,6 @@ class acp_database
break; break;
case 'mssql': case 'mssql':
case 'mssql_odbc':
$extractor = new mssql_extractor($download, $store, $format, $filename, $time); $extractor = new mssql_extractor($download, $store, $format, $filename, $time);
break; break;
@ -131,7 +129,7 @@ class acp_database
else else
{ {
// We might wanna empty out all that junk :D // We might wanna empty out all that junk :D
switch ($db->sql_layer) switch ($db->dbms_type)
{ {
case 'sqlite': case 'sqlite':
case 'firebird': case 'firebird':
@ -140,7 +138,6 @@ class acp_database
break; break;
case 'mssql': case 'mssql':
case 'mssql_odbc':
$extractor->flush('TRUNCATE TABLE ' . $table_name . "GO\n"); $extractor->flush('TRUNCATE TABLE ' . $table_name . "GO\n");
break; break;
@ -318,11 +315,11 @@ class acp_database
break; break;
} }
switch ($db->sql_layer) switch ($db->dbms_type)
{ {
case 'mysql': case 'mysql':
case 'mysqli':
case 'sqlite': case 'sqlite':
case 'db2':
while (($sql = $fgetd($fp, ";\n", $read, $seek, $eof)) !== false) while (($sql = $fgetd($fp, ";\n", $read, $seek, $eof)) !== false)
{ {
$db->sql_query($sql); $db->sql_query($sql);
@ -372,7 +369,6 @@ class acp_database
break; break;
case 'mssql': case 'mssql':
case 'mssql_odbc':
while (($sql = $fgetd($fp, "GO\n", $read, $seek, $eof)) !== false) while (($sql = $fgetd($fp, "GO\n", $read, $seek, $eof)) !== false)
{ {
$db->sql_query($sql); $db->sql_query($sql);
@ -1356,10 +1352,15 @@ class mssql_extractor extends base_extractor
{ {
$this->write_data_mssql($table_name); $this->write_data_mssql($table_name);
} }
else else if ($db->sql_layer === 'mssql_odbc')
{ {
$this->write_data_odbc($table_name); $this->write_data_odbc($table_name);
} }
else
{
// @todo: write code for MS SQL 2005 DBAL
trigger_error('KungFuDeathGrip');
}
} }
function write_data_mssql($table_name) function write_data_mssql($table_name)

View file

@ -1647,10 +1647,9 @@ class acp_forums
} }
$db->sql_freeresult($result); $db->sql_freeresult($result);
switch ($db->sql_layer) if ($db->dbms_type)
{ {
case 'mysql': case 'mysql':
case 'mysqli':
// Delete everything else and thank MySQL for offering multi-table deletion // Delete everything else and thank MySQL for offering multi-table deletion
$tables_ary = array( $tables_ary = array(

View file

@ -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_FIELDS_LANG_TABLE . " WHERE field_id = $field_id");
$db->sql_query('DELETE FROM ' . PROFILE_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 $sql = "SELECT sql
FROM sqlite_master FROM sqlite_master
WHERE type = 'table' 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('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('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'); $db->sql_query('DROP TABLE ' . PROFILE_FIELDS_DATA_TABLE . '_temp');
break; }
else
default: {
$db->sql_query('ALTER TABLE ' . PROFILE_FIELDS_DATA_TABLE . " DROP COLUMN pf_$field_ident"); $db->sql_query('ALTER TABLE ' . PROFILE_FIELDS_DATA_TABLE . " DROP COLUMN pf_$field_ident");
} }
@ -1348,10 +1347,9 @@ class acp_profile
{ {
global $db; global $db;
switch ($db->sql_layer) switch ($db->dbms_type)
{ {
case 'mysql': case 'mysql':
case 'mysqli':
// We are defining the biggest common value, because of the possibility to edit the min/max values of each field. // 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` "; $sql = 'ALTER TABLE ' . PROFILE_FIELDS_DATA_TABLE . " ADD `$field_ident` ";
@ -1468,7 +1466,6 @@ class acp_profile
break; break;
case 'mssql': 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. // 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] "; $sql = 'ALTER TABLE [' . PROFILE_FIELDS_DATA_TABLE . "] ADD [$field_ident] ";

View file

@ -1125,7 +1125,7 @@ class acp_users
// Update Custom Fields // Update Custom Fields
if (sizeof($cp_data)) if (sizeof($cp_data))
{ {
switch ($db->sql_layer) switch ($db->dbms_type)
{ {
case 'oracle': case 'oracle':
case 'firebird': case 'firebird':
@ -1136,13 +1136,11 @@ class acp_users
case 'sqlite': case 'sqlite':
case 'mssql': case 'mssql':
case 'mssql_odbc':
$right_delim = ']'; $right_delim = ']';
$left_delim = '['; $left_delim = '[';
break; break;
case 'mysql': case 'mysql':
case 'mysqli':
$right_delim = $left_delim = '`'; $right_delim = $left_delim = '`';
break; break;
} }

View file

@ -31,6 +31,8 @@ class dbal_db2 extends dbal
// can't truncate a table // can't truncate a table
var $truncate = false; var $truncate = false;
var $dbms_type = 'db2';
/** /**
* Connect to server * Connect to server
*/ */

View file

@ -254,21 +254,7 @@ class phpbb_db_tools
{ {
$this->db = $db; $this->db = $db;
// Determine mapping database type $this->sql_layer = $this->db->dbms_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;
}
} }
/** /**

View file

@ -31,6 +31,8 @@ class dbal_firebird extends dbal
// can't truncate a table // can't truncate a table
var $truncate = false; var $truncate = false;
var $dbms_type = 'firebird';
/** /**
* Connect to server * Connect to server
*/ */

View file

@ -25,6 +25,8 @@ include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx);
*/ */
class dbal_mssql extends dbal class dbal_mssql extends dbal
{ {
var $dbms_type = 'mssql';
/** /**
* Connect to server * Connect to server
*/ */

View file

@ -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;
}
}
}
?>

View file

@ -32,6 +32,7 @@ include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx);
class dbal_mssql_odbc extends dbal class dbal_mssql_odbc extends dbal
{ {
var $last_query_text = ''; var $last_query_text = '';
var $dbms_type = 'mssql';
/** /**
* Connect to server * Connect to server

View file

@ -32,6 +32,8 @@ class dbal_mysql extends dbal
// Supports multiple table deletion // Supports multiple table deletion
var $multi_table_deletion = true; var $multi_table_deletion = true;
var $dbms_type = 'mysql';
/** /**
* Connect to server * Connect to server
* @access public * @access public

View file

@ -32,6 +32,8 @@ class dbal_mysqli extends dbal
// Supports multiple table deletion // Supports multiple table deletion
var $multi_table_deletion = true; var $multi_table_deletion = true;
var $dbms_type = 'mysql';
/** /**
* Connect to server * Connect to server
*/ */

View file

@ -26,6 +26,8 @@ class dbal_oracle extends dbal
{ {
var $last_query_text = ''; var $last_query_text = '';
var $dbms_type = 'oracle';
/** /**
* Connect to server * Connect to server
*/ */

View file

@ -28,6 +28,8 @@ class dbal_postgres extends dbal
var $last_query_text = ''; var $last_query_text = '';
var $pgsql_version; var $pgsql_version;
var $dbms_type = 'postgres';
/** /**
* Connect to server * Connect to server
*/ */

View file

@ -31,6 +31,8 @@ class dbal_sqlite extends dbal
// can't truncate a table // can't truncate a table
var $truncate = false; var $truncate = false;
var $dbms_type = 'sqlite';
/** /**
* Connect to server * Connect to server
*/ */

View file

@ -1236,40 +1236,37 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
break; break;
case 'topic_approved': case 'topic_approved':
switch ($db->sql_layer) if ($db->dbms_type == 'mysql')
{ {
case 'mysql': $sql = 'UPDATE ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . " p
case 'mysqli': SET t.topic_approved = p.post_approved
$sql = 'UPDATE ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . " p $where_sql_and t.topic_first_post_id = p.post_id";
SET t.topic_approved = p.post_approved $db->sql_query($sql);
$where_sql_and t.topic_first_post_id = p.post_id"; }
$db->sql_query($sql); else
break; {
$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);
default: $topic_ids = array();
$sql = 'SELECT t.topic_id, p.post_approved while ($row = $db->sql_fetchrow($result))
FROM ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . " p {
$where_sql_and p.post_id = t.topic_first_post_id $topic_ids[] = $row['topic_id'];
AND p.post_approved <> t.topic_approved"; }
$result = $db->sql_query($sql); $db->sql_freeresult($result);
$topic_ids = array(); if (!sizeof($topic_ids))
while ($row = $db->sql_fetchrow($result)) {
{ return;
$topic_ids[] = $row['topic_id']; }
}
$db->sql_freeresult($result);
if (!sizeof($topic_ids)) $sql = 'UPDATE ' . TOPICS_TABLE . '
{ SET topic_approved = 1 - topic_approved
return; WHERE ' . $db->sql_in_set('topic_id', $topic_ids);
} $db->sql_query($sql);
$sql = 'UPDATE ' . TOPICS_TABLE . '
SET topic_approved = 1 - topic_approved
WHERE ' . $db->sql_in_set('topic_id', $topic_ids);
$db->sql_query($sql);
break;
} }
break; break;
@ -2747,10 +2744,9 @@ function get_database_size()
$database_size = false; $database_size = false;
// This code is heavily influenced by a similar routine in phpMyAdmin 2.2.0 // 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 'mysql':
case 'mysqli':
$sql = 'SELECT VERSION() AS mysql_version'; $sql = 'SELECT VERSION() AS mysql_version';
$result = $db->sql_query($sql); $result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result); $row = $db->sql_fetchrow($result);
@ -2813,7 +2809,6 @@ function get_database_size()
break; break;
case 'mssql': case 'mssql':
case 'mssql_odbc':
$sql = 'SELECT ((SUM(size) * 8.0) * 1024.0) as dbsize $sql = 'SELECT ((SUM(size) * 8.0) * 1024.0) as dbsize
FROM sysfiles'; FROM sysfiles';
$result = $db->sql_query($sql, 7200); $result = $db->sql_query($sql, 7200);

View file

@ -1620,10 +1620,9 @@ function mass_auth($ug_type, $forum_id, $ug_id, $acl_list, $setting = ACL_NO)
switch ($sql_type) switch ($sql_type)
{ {
case 'insert': case 'insert':
switch ($db->sql_layer) switch ($db->dbms_type)
{ {
case 'mysql': case 'mysql':
case 'mysql4':
$sql = 'VALUES ' . implode(', ', preg_replace('#^(.*?)$#', '(\1)', $sql_subary)); $sql = 'VALUES ' . implode(', ', preg_replace('#^(.*?)$#', '(\1)', $sql_subary));
break; break;
@ -1977,16 +1976,13 @@ function update_topics_posted()
{ {
global $db, $config; global $db, $config;
switch ($db->sql_layer) if ($db->truncate)
{ {
case 'sqlite': $db->sql_query('DELETE FROM ' . TOPICS_POSTED_TABLE);
case 'firebird': }
$db->sql_query('DELETE FROM ' . TOPICS_POSTED_TABLE); else
break; {
$db->sql_query('TRUNCATE TABLE ' . TOPICS_POSTED_TABLE);
default:
$db->sql_query('TRUNCATE TABLE ' . TOPICS_POSTED_TABLE);
break;
} }
// This can get really nasty... therefore we only do the last six months // This can get really nasty... therefore we only do the last six months

View file

@ -82,6 +82,16 @@ function get_available_dbms($dbms = false, $return_unavailable = false, $only_20
'AVAILABLE' => true, 'AVAILABLE' => true,
'2.0.x' => 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( 'db2' => array(
'LABEL' => 'IBM DB2', 'LABEL' => 'IBM DB2',
'SCHEMA' => 'db2', 'SCHEMA' => 'db2',
@ -201,10 +211,9 @@ function dbms_select($default = '', $only_20x_options = false)
*/ */
function get_tables($db) function get_tables($db)
{ {
switch ($db->sql_layer) switch ($db->dbms_type)
{ {
case 'mysql': case 'mysql':
case 'mysqli':
$sql = 'SHOW TABLES'; $sql = 'SHOW TABLES';
break; break;
@ -215,7 +224,6 @@ function get_tables($db)
break; break;
case 'mssql': case 'mssql':
case 'mssql_odbc':
$sql = "SELECT name $sql = "SELECT name
FROM sysobjects FROM sysobjects
WHERE type='U'"; WHERE type='U'";
@ -317,6 +325,7 @@ function connect_check_db($error_connect, &$error, $dbms_details, $table_prefix,
case 'mssql': case 'mssql':
case 'mssql_odbc': case 'mssql_odbc':
case 'mssql_2005':
$prefix_length = 90; $prefix_length = 90;
break; break;

View file

@ -726,7 +726,7 @@ class fulltext_mysql extends search_backend
{ {
global $db; global $db;
if (strpos($db->sql_layer, 'mysql') === false) if ($db->dbms_type !== 'mysql')
{ {
$this->stats = array(); $this->stats = array();
return; return;

View file

@ -640,35 +640,31 @@ class fulltext_native extends search_backend
$sql = ''; $sql = '';
$sql_array_count = $sql_array; $sql_array_count = $sql_array;
switch ($db->sql_layer) if ($db->dbms_type === 'mysql')
{ {
case 'mysql': $sql_array['SELECT'] = 'SQL_CALC_FOUND_ROWS ' . $sql_array['SELECT'];
case 'mysqli': $is_mysql = true;
$sql_array['SELECT'] = 'SQL_CALC_FOUND_ROWS ' . $sql_array['SELECT']; }
$is_mysql = true; else
{
break; if (!$db->count_distinct)
{
case 'sqlite':
$sql_array_count['SELECT'] = ($type == 'posts') ? 'DISTINCT p.post_id' : 'DISTINCT p.topic_id'; $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 $sql = 'SELECT COUNT(' . (($type == 'posts') ? 'post_id' : 'topic_id') . ') as total_results
FROM (' . $db->sql_build_query('SELECT', $sql_array_count) . ')'; FROM (' . $db->sql_build_query('SELECT', $sql_array_count) . ')';
}
// no break $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;
default: $result = $db->sql_query($sql);
$sql_array_count['SELECT'] = ($type == 'posts') ? 'COUNT(DISTINCT p.post_id) AS total_results' : 'COUNT(DISTINCT p.topic_id) AS total_results'; $total_results = (int) $db->sql_fetchfield('total_results');
$sql = (!$sql) ? $db->sql_build_query('SELECT', $sql_array_count) : $sql; $db->sql_freeresult($result);
$result = $db->sql_query($sql); if (!$total_results)
$total_results = (int) $db->sql_fetchfield('total_results'); {
$db->sql_freeresult($result); return false;
}
if (!$total_results)
{
return false;
}
break;
} }
unset($sql_array_count, $sql); 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 the cache was completely empty count the results
if (!$total_results) if (!$total_results)
{ {
switch ($db->sql_layer) if ($db->dbms_type === 'mysql')
{ {
case 'mysql':
case 'mysqli':
$select = 'SQL_CALC_FOUND_ROWS ' . $select; $select = 'SQL_CALC_FOUND_ROWS ' . $select;
$is_mysql = true; $is_mysql = true;
break; }
else
default: {
if ($type == 'posts') 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 $sql = 'SELECT COUNT(DISTINCT t.topic_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 else
{ {
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(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) ? '' : ')');
} }
$result = $db->sql_query($sql);
$total_results = (int) $db->sql_fetchfield('total_results'); $sql .= ' FROM ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . " p
$db->sql_freeresult($result); 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) $total_results = (int) $db->sql_fetchfield('total_results');
{ $db->sql_freeresult($result);
return false;
} if (!$total_results)
break; {
return false;
}
} }
} }
@ -1338,20 +1331,17 @@ class fulltext_native extends search_backend
{ {
global $db; global $db;
switch ($db->sql_layer) if ($db->truncate)
{ {
case 'sqlite': $db->sql_query('TRUNCATE TABLE ' . SEARCH_WORDLIST_TABLE);
case 'firebird': $db->sql_query('TRUNCATE TABLE ' . SEARCH_WORDMATCH_TABLE);
$db->sql_query('DELETE FROM ' . SEARCH_WORDLIST_TABLE); $db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE);
$db->sql_query('DELETE FROM ' . SEARCH_WORDMATCH_TABLE); }
$db->sql_query('DELETE FROM ' . SEARCH_RESULTS_TABLE); else
break; {
$db->sql_query('DELETE FROM ' . SEARCH_WORDLIST_TABLE);
default: $db->sql_query('DELETE FROM ' . SEARCH_WORDMATCH_TABLE);
$db->sql_query('TRUNCATE TABLE ' . SEARCH_WORDLIST_TABLE); $db->sql_query('DELETE FROM ' . SEARCH_RESULTS_TABLE);
$db->sql_query('TRUNCATE TABLE ' . SEARCH_WORDMATCH_TABLE);
$db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE);
break;
} }
} }

View file

@ -90,12 +90,9 @@ function phpbb_insert_forums()
$src_db->sql_query("SET NAMES 'utf8'"); $src_db->sql_query("SET NAMES 'utf8'");
} }
switch ($db->sql_layer) if ($db->dbms_type == 'mssql')
{ {
case 'mssql': $db->sql_query('SET IDENTITY_INSERT ' . FORUMS_TABLE . ' ON');
case 'mssql_odbc':
$db->sql_query('SET IDENTITY_INSERT ' . FORUMS_TABLE . ' ON');
break;
} }
$cats_added = array(); $cats_added = array();
@ -282,14 +279,13 @@ function phpbb_insert_forums()
} }
$src_db->sql_freeresult($result); $src_db->sql_freeresult($result);
switch ($db->sql_layer) switch ($db->dbms_type)
{ {
case 'postgres': 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 . '));'); $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; break;
case 'mssql': case 'mssql':
case 'mssql_odbc':
$db->sql_query('SET IDENTITY_INSERT ' . FORUMS_TABLE . ' OFF'); $db->sql_query('SET IDENTITY_INSERT ' . FORUMS_TABLE . ' OFF');
break; break;
@ -1702,41 +1698,9 @@ function phpbb_check_username_collisions()
{ {
global $db, $src_db, $convert, $table_prefix, $user, $lang; 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 // create a temporary table in which we store the clean usernames
$drop_sql = 'DROP TABLE ' . $table_prefix . 'userconv'; $drop_sql = 'DROP TABLE ' . $table_prefix . 'userconv';
switch ($map_dbms) switch ($db->dbms_type)
{ {
case 'firebird': case 'firebird':
$create_sql = 'CREATE TABLE ' . $table_prefix . 'userconv ( $create_sql = 'CREATE TABLE ' . $table_prefix . 'userconv (
@ -1752,14 +1716,7 @@ function phpbb_check_username_collisions()
)'; )';
break; break;
case 'mysql_40': case 'mysql':
$create_sql = 'CREATE TABLE ' . $table_prefix . 'userconv (
user_id mediumint(8) NOT NULL,
username_clean blob NOT NULL
)';
break;
case 'mysql_41':
$create_sql = 'CREATE TABLE ' . $table_prefix . 'userconv ( $create_sql = 'CREATE TABLE ' . $table_prefix . 'userconv (
user_id mediumint(8) NOT NULL, user_id mediumint(8) NOT NULL,
username_clean varchar(255) DEFAULT \'\' NOT NULL username_clean varchar(255) DEFAULT \'\' NOT NULL

View file

@ -340,21 +340,7 @@ $database_update_info = array(
); );
// Determine mapping database type // Determine mapping database type
switch ($db->sql_layer) $map_dbms = $db->dbms_type;
{
case 'mysqli':
$map_dbms = 'mysql';
break;
case 'mssql_odbc':
$map_dbms = 'mssql';
break;
default:
$map_dbms = $db->sql_layer;
break;
}
$error_ary = array(); $error_ary = array();
$errored = false; $errored = false;
@ -624,10 +610,9 @@ _sql($sql, $errored, $error_ary);
/* Optimize/vacuum analyze the tables where appropriate /* Optimize/vacuum analyze the tables where appropriate
// this should be done for each version in future along with // this should be done for each version in future along with
// the version number update // the version number update
switch ($db->sql_layer) switch ($db->dbms_type)
{ {
case 'mysql': 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 = '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); _sql($sql, $errored, $error_ary);
break; break;

View file

@ -238,18 +238,15 @@ class install_convert extends module
)); ));
} }
switch ($db->sql_layer) if ($db->truncate)
{ {
case 'sqlite': $db->sql_query('TRUNCATE TABLE ' . SESSIONS_KEYS_TABLE);
case 'firebird': $db->sql_query('TRUNCATE TABLE ' . SESSIONS_TABLE);
$db->sql_query('DELETE FROM ' . SESSIONS_KEYS_TABLE); }
$db->sql_query('DELETE FROM ' . SESSIONS_TABLE); else
break; {
$db->sql_query('DELETE FROM ' . SESSIONS_KEYS_TABLE);
default: $db->sql_query('DELETE FROM ' . SESSIONS_TABLE);
$db->sql_query('TRUNCATE TABLE ' . SESSIONS_KEYS_TABLE);
$db->sql_query('TRUNCATE TABLE ' . SESSIONS_TABLE);
break;
} }
break; break;
@ -684,7 +681,6 @@ class install_convert extends module
// Thanks MySQL, for silently converting... // Thanks MySQL, for silently converting...
case 'mysql': case 'mysql':
case 'mysql4':
if (version_compare($src_db->mysql_version, '4.1.3', '>=')) if (version_compare($src_db->mysql_version, '4.1.3', '>='))
{ {
$convert->mysql_convert = true; $convert->mysql_convert = true;
@ -707,16 +703,13 @@ class install_convert extends module
$src_db->sql_query("SET NAMES 'binary'"); $src_db->sql_query("SET NAMES 'binary'");
} }
switch ($db->sql_layer) if ($db->truncate)
{ {
case 'sqlite': $convert->truncate_statement = 'TRUNCATE TABLE ';
case 'firebird': }
$convert->truncate_statement = 'DELETE FROM '; else
break; {
$convert->truncate_statement = 'DELETE FROM ';
default:
$convert->truncate_statement = 'TRUNCATE TABLE ';
break;
} }
$get_info = false; $get_info = false;
@ -1107,7 +1100,7 @@ class install_convert extends module
if (!empty($schema['autoincrement'])) if (!empty($schema['autoincrement']))
{ {
switch ($db->sql_layer) switch ($db->dbms_type)
{ {
case 'postgres': 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'] . '));'); $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'])) if (!empty($schema['autoincrement']))
{ {
switch ($db->sql_layer) switch ($db->dbms_type)
{ {
case 'mssql': case 'mssql':
case 'mssql_odbc':
$db->sql_query('SET IDENTITY_INSERT ' . $schema['target'] . ' ON'); $db->sql_query('SET IDENTITY_INSERT ' . $schema['target'] . ' ON');
break; break;
} }
@ -1276,12 +1268,10 @@ class install_convert extends module
if ($sql_flag === true) 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 // If MySQL, we'll wait to have num_wait_rows rows to submit at once
case 'mysql': case 'mysql':
case 'mysql4':
case 'mysqli':
$waiting_rows[] = '(' . implode(', ', $insert_values) . ')'; $waiting_rows[] = '(' . implode(', ', $insert_values) . ')';
if (sizeof($waiting_rows) >= $convert->num_wait_rows) if (sizeof($waiting_rows) >= $convert->num_wait_rows)
@ -1371,10 +1361,9 @@ class install_convert extends module
if (!empty($schema['autoincrement'])) if (!empty($schema['autoincrement']))
{ {
switch ($db->sql_layer) switch ($db->dbms_type)
{ {
case 'mssql': case 'mssql':
case 'mssql_odbc':
$db->sql_query('SET IDENTITY_INSERT ' . $schema['target'] . ' OFF'); $db->sql_query('SET IDENTITY_INSERT ' . $schema['target'] . ' OFF');
break; break;
@ -1780,7 +1769,7 @@ class install_convert extends module
global $convert; global $convert;
// Can we use IGNORE with this DBMS? // 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'] . ' ('; $insert_query = 'INSERT ' . $sql_ignore . 'INTO ' . $schema['target'] . ' (';
$aliases = array(); $aliases = array();

View file

@ -1193,6 +1193,7 @@ class install_install extends module
{ {
case 'mssql': case 'mssql':
case 'mssql_odbc': 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); $sql_query = preg_replace('#\# MSSQL IDENTITY (phpbb_[a-z_]+) (ON|OFF) \##s', 'SET IDENTITY_INSERT \1 \2;', $sql_query);
break; break;

View file

@ -146,6 +146,7 @@ $lang = array_merge($lang, array(
'DLL_GD' => 'GD graphics support [ Visual Confirmation ]', 'DLL_GD' => 'GD graphics support [ Visual Confirmation ]',
'DLL_MBSTRING' => 'Multi-byte character support', 'DLL_MBSTRING' => 'Multi-byte character support',
'DLL_MSSQL' => 'MSSQL Server 2000+', 'DLL_MSSQL' => 'MSSQL Server 2000+',
'DLL_MSSQL_2005' => 'MSSQL Server 2005+',
'DLL_MSSQL_ODBC' => 'MSSQL Server 2000+ via ODBC', 'DLL_MSSQL_ODBC' => 'MSSQL Server 2000+ via ODBC',
'DLL_MYSQL' => 'MySQL', 'DLL_MYSQL' => 'MySQL',
'DLL_MYSQLI' => 'MySQL with MySQLi Extension', 'DLL_MYSQLI' => 'MySQL with MySQLi Extension',