Merge remote-tracking branch 'p/ticket/11015' into develop

* p/ticket/11015: (30 commits)
  [ticket/11015] Move comment in the right place.
  [ticket/11015] Correctly transform 'mysqli' etc. in phpbb_convert_30_dbms_to_31
  [ticket/11015] Fix 3.0 to 3.1 dbms conversion for mysqli.
  [ticket/11015] Change permission adding in database updater to new style.
  [ticket/11015] Change more docblocks to phpbb_db_driver.
  [ticket/11015] Installer still needs 3.0-style dbms name.
  [ticket/11015] Include functions.php because it is not always included.
  [ticket/11015] Convert database drivers to new spelling in post setup sync.
  [ticket/11015] Convert connect test to the new syntax.
  [ticket/11015] Restore whitespace to avoid conflict when merging develop.
  [ticket/11015] Fix functional test case.
  [ticket/11015] Change more docblocks.
  [ticket/11015] Include dbms name in exception message.
  [ticket/11015] Make phpbb_convert_30_dbms_to_31 more future proof
  [ticket/11015] Move db driver class name fixing to function
  [ticket/11015] Allow full dbms class name in tests/test_config.php
  [ticket/11015] Allow full dbms class name in config.php
  [ticket/11015] Remove strange method_exists call
  [tracker/11015] Prepend phpbb_db_driver_ for PHPBB_TEST_DBMS
  [ticket/11015] Re-introduce accidentally removed require in install_convert
  ...
This commit is contained in:
Andreas Fischer 2012-12-14 01:50:22 +01:00
commit b5142296b1
45 changed files with 243 additions and 199 deletions

View file

@ -71,7 +71,6 @@ require($phpbb_root_path . 'includes/functions_content.' . $phpEx);
require($phpbb_root_path . 'includes/functions_container.' . $phpEx); require($phpbb_root_path . 'includes/functions_container.' . $phpEx);
require($phpbb_root_path . 'includes/constants.' . $phpEx); require($phpbb_root_path . 'includes/constants.' . $phpEx);
require($phpbb_root_path . 'includes/db/' . ltrim($dbms, 'dbal_') . '.' . $phpEx);
require($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx); require($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx);
// Set PHP error handler to ours // Set PHP error handler to ours

View file

@ -43,7 +43,6 @@ if (isset($_GET['avatar']))
require($phpbb_root_path . 'includes/class_loader.' . $phpEx); require($phpbb_root_path . 'includes/class_loader.' . $phpEx);
require($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx);
require($phpbb_root_path . 'includes/constants.' . $phpEx); require($phpbb_root_path . 'includes/constants.' . $phpEx);
require($phpbb_root_path . 'includes/functions.' . $phpEx); require($phpbb_root_path . 'includes/functions.' . $phpEx);
require($phpbb_root_path . 'includes/functions_container.' . $phpEx); require($phpbb_root_path . 'includes/functions_container.' . $phpEx);

View file

@ -29,7 +29,7 @@ class phpbb_config_db extends phpbb_config
/** /**
* Database connection * Database connection
* @var dbal * @var phpbb_db_driver
*/ */
protected $db; protected $db;
@ -42,11 +42,11 @@ class phpbb_config_db extends phpbb_config
/** /**
* Creates a configuration container with a default set of values * Creates a configuration container with a default set of values
* *
* @param dbal $db Database connection * @param phpbb_db_driver $db Database connection
* @param phpbb_cache_driver_interface $cache Cache instance * @param phpbb_cache_driver_interface $cache Cache instance
* @param string $table Configuration table name * @param string $table Configuration table name
*/ */
public function __construct(dbal $db, phpbb_cache_driver_interface $cache, $table) public function __construct(phpbb_db_driver $db, phpbb_cache_driver_interface $cache, $table)
{ {
$this->db = $db; $this->db = $db;
$this->cache = $cache; $this->cache = $cache;

View file

@ -37,9 +37,9 @@ class phpbb_cron_task_core_prune_all_forums extends phpbb_cron_task_base
* @param string $phpbb_root_path The root path * @param string $phpbb_root_path The root path
* @param string $php_ext The PHP extension * @param string $php_ext The PHP extension
* @param phpbb_config $config The config * @param phpbb_config $config The config
* @param dbal $db The db connection * @param phpbb_db_driver $db The db connection
*/ */
public function __construct($phpbb_root_path, $php_ext, phpbb_config $config, dbal $db) public function __construct($phpbb_root_path, $php_ext, phpbb_config $config, phpbb_db_driver $db)
{ {
$this->phpbb_root_path = $phpbb_root_path; $this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext; $this->php_ext = $php_ext;

View file

@ -47,9 +47,9 @@ class phpbb_cron_task_core_prune_forum extends phpbb_cron_task_base implements p
* @param string $phpbb_root_path The root path * @param string $phpbb_root_path The root path
* @param string $php_ext The PHP extension * @param string $php_ext The PHP extension
* @param phpbb_config $config The config * @param phpbb_config $config The config
* @param dbal $db The db connection * @param phpbb_db_driver $db The db connection
*/ */
public function __construct($phpbb_root_path, $php_ext, phpbb_config $config, dbal $db) public function __construct($phpbb_root_path, $php_ext, phpbb_config $config, phpbb_db_driver $db)
{ {
$this->phpbb_root_path = $phpbb_root_path; $this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext; $this->php_ext = $php_ext;

View file

@ -38,10 +38,10 @@ class phpbb_cron_task_core_tidy_search extends phpbb_cron_task_base
* @param string $php_ext The PHP extension * @param string $php_ext The PHP extension
* @param phpbb_auth $auth The auth * @param phpbb_auth $auth The auth
* @param phpbb_config $config The config * @param phpbb_config $config The config
* @param dbal $db The db connection * @param phpbb_db_driver $db The db connection
* @param phpbb_user $user The user * @param phpbb_user $user The user
*/ */
public function __construct($phpbb_root_path, $php_ext, phpbb_auth $auth, phpbb_config $config, dbal $db, phpbb_user $user) public function __construct($phpbb_root_path, $php_ext, phpbb_auth $auth, phpbb_config $config, phpbb_db_driver $db, phpbb_user $user)
{ {
$this->phpbb_root_path = $phpbb_root_path; $this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext; $this->php_ext = $php_ext;

View file

@ -300,7 +300,7 @@ class phpbb_db_tools
/** /**
* Constructor. Set DB Object and set {@link $return_statements return_statements}. * Constructor. Set DB Object and set {@link $return_statements return_statements}.
* *
* @param phpbb_dbal $db DBAL object * @param phpbb_db_driver $db Database connection
* @param bool $return_statements True if only statements should be returned and no SQL being executed * @param bool $return_statements True if only statements should be returned and no SQL being executed
*/ */
function phpbb_db_tools(&$db, $return_statements = false) function phpbb_db_tools(&$db, $return_statements = false)

View file

@ -19,7 +19,7 @@ if (!defined('IN_PHPBB'))
* Database Abstraction Layer * Database Abstraction Layer
* @package dbal * @package dbal
*/ */
class dbal class phpbb_db_driver
{ {
var $db_connect_id; var $db_connect_id;
var $query_result; var $query_result;
@ -72,17 +72,17 @@ class dbal
/** /**
* Constructor * Constructor
*/ */
function dbal() function __construct()
{ {
$this->num_queries = array( $this->num_queries = array(
'cached' => 0, 'cached' => 0,
'normal' => 0, 'normal' => 0,
'total' => 0, 'total' => 0,
); );
// Fill default sql layer based on the class being called. // Fill default sql layer based on the class being called.
// This can be changed by the specified layer itself later if needed. // This can be changed by the specified layer itself later if needed.
$this->sql_layer = substr(get_class($this), 5); $this->sql_layer = substr(get_class($this), strlen('phpbb_db_driver_'));
// Do not change this please! This variable is used to easy the use of it - and is hardcoded. // Do not change this please! This variable is used to easy the use of it - and is hardcoded.
$this->any_char = chr(0) . '%'; $this->any_char = chr(0) . '%';
@ -1042,8 +1042,3 @@ class dbal
return $rows_total; return $rows_total;
} }
} }
/**
* This variable holds the class name to use later
*/
$sql_db = (!empty($dbms)) ? 'dbal_' . basename($dbms) : 'dbal';

View file

@ -15,14 +15,12 @@ if (!defined('IN_PHPBB'))
exit; exit;
} }
include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx);
/** /**
* Firebird/Interbase Database Abstraction Layer * Firebird/Interbase Database Abstraction Layer
* Minimum Requirement is Firebird 2.1 * Minimum Requirement is Firebird 2.1
* @package dbal * @package dbal
*/ */
class dbal_firebird extends dbal class phpbb_db_driver_firebird extends phpbb_db_driver
{ {
var $last_query_text = ''; var $last_query_text = '';
var $service_handle = false; var $service_handle = false;

View file

@ -15,14 +15,12 @@ if (!defined('IN_PHPBB'))
exit; exit;
} }
include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx);
/** /**
* MSSQL Database Abstraction Layer * MSSQL Database Abstraction Layer
* Minimum Requirement is MSSQL 2000+ * Minimum Requirement is MSSQL 2000+
* @package dbal * @package dbal
*/ */
class dbal_mssql extends dbal class phpbb_db_driver_mssql extends phpbb_db_driver
{ {
var $connect_error = ''; var $connect_error = '';

View file

@ -15,8 +15,6 @@ if (!defined('IN_PHPBB'))
exit; exit;
} }
include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx);
/** /**
* Unified ODBC functions * Unified ODBC functions
* Unified ODBC functions support any database having ODBC driver, for example Adabas D, IBM DB2, iODBC, Solid, Sybase SQL Anywhere... * Unified ODBC functions support any database having ODBC driver, for example Adabas D, IBM DB2, iODBC, Solid, Sybase SQL Anywhere...
@ -28,7 +26,7 @@ include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx);
* *
* @package dbal * @package dbal
*/ */
class dbal_mssql_odbc extends dbal class phpbb_db_driver_mssql_odbc extends phpbb_db_driver
{ {
var $last_query_text = ''; var $last_query_text = '';
var $connect_error = ''; var $connect_error = '';

View file

@ -19,8 +19,6 @@ if (!defined('IN_PHPBB'))
exit; exit;
} }
include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx);
/** /**
* Prior to version 1.1 the SQL Server Native PHP driver didn't support sqlsrv_num_rows, or cursor based seeking so we recall all rows into an array * Prior to version 1.1 the SQL Server Native PHP driver didn't support sqlsrv_num_rows, or cursor based seeking so we recall all rows into an array
* and maintain our own cursor index into that array. * and maintain our own cursor index into that array.
@ -193,7 +191,7 @@ class result_mssqlnative
/** /**
* @package dbal * @package dbal
*/ */
class dbal_mssqlnative extends dbal class phpbb_db_driver_mssqlnative extends phpbb_db_driver
{ {
var $m_insert_id = NULL; var $m_insert_id = NULL;
var $last_query_text = ''; var $last_query_text = '';

View file

@ -15,8 +15,6 @@ if (!defined('IN_PHPBB'))
exit; exit;
} }
include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx);
/** /**
* MySQL4 Database Abstraction Layer * MySQL4 Database Abstraction Layer
* Compatible with: * Compatible with:
@ -26,7 +24,7 @@ include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx);
* MySQL 5.0+ * MySQL 5.0+
* @package dbal * @package dbal
*/ */
class dbal_mysql extends dbal class phpbb_db_driver_mysql extends phpbb_db_driver
{ {
var $multi_insert = true; var $multi_insert = true;
var $connect_error = ''; var $connect_error = '';

View file

@ -15,15 +15,13 @@ if (!defined('IN_PHPBB'))
exit; exit;
} }
include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx);
/** /**
* MySQLi Database Abstraction Layer * MySQLi Database Abstraction Layer
* mysqli-extension has to be compiled with: * mysqli-extension has to be compiled with:
* MySQL 4.1+ or MySQL 5.0+ * MySQL 4.1+ or MySQL 5.0+
* @package dbal * @package dbal
*/ */
class dbal_mysqli extends dbal class phpbb_db_driver_mysqli extends phpbb_db_driver
{ {
var $multi_insert = true; var $multi_insert = true;
var $connect_error = ''; var $connect_error = '';

View file

@ -15,13 +15,11 @@ if (!defined('IN_PHPBB'))
exit; exit;
} }
include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx);
/** /**
* Oracle Database Abstraction Layer * Oracle Database Abstraction Layer
* @package dbal * @package dbal
*/ */
class dbal_oracle extends dbal class phpbb_db_driver_oracle extends phpbb_db_driver
{ {
var $last_query_text = ''; var $last_query_text = '';
var $connect_error = ''; var $connect_error = '';

View file

@ -15,19 +15,12 @@ if (!defined('IN_PHPBB'))
exit; exit;
} }
include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx);
if (!class_exists('phpbb_error_collector'))
{
include($phpbb_root_path . 'includes/error_collector.' . $phpEx);
}
/** /**
* PostgreSQL Database Abstraction Layer * PostgreSQL Database Abstraction Layer
* Minimum Requirement is Version 7.3+ * Minimum Requirement is Version 7.3+
* @package dbal * @package dbal
*/ */
class dbal_postgres extends dbal class phpbb_db_driver_postgres extends phpbb_db_driver
{ {
var $last_query_text = ''; var $last_query_text = '';
var $connect_error = ''; var $connect_error = '';

View file

@ -15,14 +15,12 @@ if (!defined('IN_PHPBB'))
exit; exit;
} }
include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx);
/** /**
* Sqlite Database Abstraction Layer * Sqlite Database Abstraction Layer
* Minimum Requirement: 2.8.2+ * Minimum Requirement: 2.8.2+
* @package dbal * @package dbal
*/ */
class dbal_sqlite extends dbal class phpbb_db_driver_sqlite extends phpbb_db_driver
{ {
var $connect_error = ''; var $connect_error = '';

View file

@ -43,8 +43,8 @@ class phpbb_di_extension_config extends Extension
require($this->config_file); require($this->config_file);
$container->setParameter('core.table_prefix', $table_prefix); $container->setParameter('core.table_prefix', $table_prefix);
$container->setParameter('cache.driver.class', $this->fix_acm_type($acm_type)); $container->setParameter('cache.driver.class', $this->convert_30_acm_type($acm_type));
$container->setParameter('dbal.driver.class', 'dbal_'.$dbms); $container->setParameter('dbal.driver.class', phpbb_convert_30_dbms_to_31($dbms));
$container->setParameter('dbal.dbhost', $dbhost); $container->setParameter('dbal.dbhost', $dbhost);
$container->setParameter('dbal.dbuser', $dbuser); $container->setParameter('dbal.dbuser', $dbuser);
$container->setParameter('dbal.dbpasswd', $dbpasswd); $container->setParameter('dbal.dbpasswd', $dbpasswd);
@ -66,12 +66,12 @@ class phpbb_di_extension_config extends Extension
} }
/** /**
* Convert old (3.0) values to 3.1 class names * Convert 3.0 ACM type to 3.1 cache driver class name
* *
* @param style $acm_type ACM type * @param string $acm_type ACM type
* @return ACM type class * @return cache driver class
*/ */
protected function fix_acm_type($acm_type) protected function convert_30_acm_type($acm_type)
{ {
if (preg_match('#^[a-z]+$#', $acm_type)) if (preg_match('#^[a-z]+$#', $acm_type))
{ {

View file

@ -34,7 +34,7 @@ class phpbb_extension_manager
/** /**
* Creates a manager and loads information from database * Creates a manager and loads information from database
* *
* @param dbal $db A database connection * @param phpbb_db_driver $db A database connection
* @param phpbb_config $config phpbb_config * @param phpbb_config $config phpbb_config
* @param string $extension_table The name of the table holding extensions * @param string $extension_table The name of the table holding extensions
* @param string $phpbb_root_path Path to the phpbb includes directory. * @param string $phpbb_root_path Path to the phpbb includes directory.
@ -42,7 +42,7 @@ class phpbb_extension_manager
* @param phpbb_cache_driver_interface $cache A cache instance or null * @param phpbb_cache_driver_interface $cache A cache instance or null
* @param string $cache_name The name of the cache variable, defaults to _ext * @param string $cache_name The name of the cache variable, defaults to _ext
*/ */
public function __construct(dbal $db, phpbb_config $config, $extension_table, $phpbb_root_path, $php_ext = '.php', phpbb_cache_driver_interface $cache = null, $cache_name = '_ext') public function __construct(phpbb_db_driver $db, phpbb_config $config, $extension_table, $phpbb_root_path, $php_ext = '.php', phpbb_cache_driver_interface $cache = null, $cache_name = '_ext')
{ {
$this->phpbb_root_path = $phpbb_root_path; $this->phpbb_root_path = $phpbb_root_path;
$this->db = $db; $this->db = $db;

View file

@ -34,12 +34,12 @@ class phpbb_extension_metadata_manager
/** /**
* Creates the metadata manager * Creates the metadata manager
* *
* @param dbal $db A database connection * @param phpbb_db_driver $db A database connection
* @param string $extension_manager An instance of the phpbb extension manager * @param string $extension_manager An instance of the phpbb extension manager
* @param string $phpbb_root_path Path to the phpbb includes directory. * @param string $phpbb_root_path Path to the phpbb includes directory.
* @param string $phpEx php file extension * @param string $phpEx php file extension
*/ */
public function __construct($ext_name, dbal $db, phpbb_extension_manager $extension_manager, $phpbb_root_path, $phpEx = '.php', phpbb_template $template, phpbb_config $config) public function __construct($ext_name, phpbb_db_driver $db, phpbb_extension_manager $extension_manager, $phpbb_root_path, $phpEx = '.php', phpbb_template $template, phpbb_config $config)
{ {
$this->phpbb_root_path = $phpbb_root_path; $this->phpbb_root_path = $phpbb_root_path;
$this->db = $db; $this->db = $db;

View file

@ -5549,6 +5549,52 @@ function phpbb_to_numeric($input)
return ($input > PHP_INT_MAX) ? (float) $input : (int) $input; return ($input > PHP_INT_MAX) ? (float) $input : (int) $input;
} }
/**
* Convert either 3.0 dbms or 3.1 db driver class name to 3.1 db driver class name.
*
* If $dbms is a valid 3.1 db driver class name, returns it unchanged.
* Otherwise prepends phpbb_db_driver_ to the dbms to convert a 3.0 dbms
* to 3.1 db driver class name.
*
* @param string $dbms dbms parameter
* @return db driver class
*/
function phpbb_convert_30_dbms_to_31($dbms)
{
// Note: this check is done first because mysqli extension
// supplies a mysqli class, and class_exists($dbms) would return
// true for mysqli class.
// However, per the docblock any valid 3.1 driver name should be
// recognized by this function, and have priority over 3.0 dbms.
if (class_exists('phpbb_db_driver_' . $dbms))
{
return 'phpbb_db_driver_' . $dbms;
}
if (class_exists($dbms))
{
// Additionally we could check that $dbms extends phpbb_db_driver.
// http://php.net/manual/en/class.reflectionclass.php
// Beware of possible performance issues:
// http://stackoverflow.com/questions/294582/php-5-reflection-api-performance
// We could check for interface implementation in all paths or
// only when we do not prepend phpbb_db_driver_.
/*
$reflection = new \ReflectionClass($dbms);
if ($reflection->isSubclassOf('phpbb_db_driver'))
{
return $dbms;
}
*/
return $dbms;
}
throw new \RuntimeException("You have specified an invalid dbms driver: $dbms");
}
/** /**
* Create a Symfony Request object from phpbb_request object * Create a Symfony Request object from phpbb_request object
* *

View file

@ -596,7 +596,7 @@ function phpbb_parse_range_request($request_array, $filesize)
/** /**
* Increments the download count of all provided attachments * Increments the download count of all provided attachments
* *
* @param dbal $db The database object * @param phpbb_db_driver $db The database object
* @param array|int $ids The attach_id of each attachment * @param array|int $ids The attach_id of each attachment
* *
* @return null * @return null
@ -617,7 +617,7 @@ function phpbb_increment_downloads($db, $ids)
/** /**
* Handles authentication when downloading attachments from a post or topic * Handles authentication when downloading attachments from a post or topic
* *
* @param dbal $db The database object * @param phpbb_db_driver $db The database object
* @param phpbb_auth $auth The authentication object * @param phpbb_auth $auth The authentication object
* @param int $topic_id The id of the topic that we are downloading from * @param int $topic_id The id of the topic that we are downloading from
* *
@ -651,7 +651,7 @@ function phpbb_download_handle_forum_auth($db, $auth, $topic_id)
/** /**
* Handles authentication when downloading attachments from PMs * Handles authentication when downloading attachments from PMs
* *
* @param dbal $db The database object * @param phpbb_db_driver $db The database object
* @param phpbb_auth $auth The authentication object * @param phpbb_auth $auth The authentication object
* @param int $user_id The user id * @param int $user_id The user id
* @param int $msg_id The id of the PM that we are downloading from * @param int $msg_id The id of the PM that we are downloading from
@ -678,7 +678,7 @@ function phpbb_download_handle_pm_auth($db, $auth, $user_id, $msg_id)
/** /**
* Checks whether a user can download from a particular PM * Checks whether a user can download from a particular PM
* *
* @param dbal $db The database object * @param phpbb_db_driver $db The database object
* @param int $user_id The user id * @param int $user_id The user id
* @param int $msg_id The id of the PM that we are downloading from * @param int $msg_id The id of the PM that we are downloading from
* *

View file

@ -28,7 +28,7 @@ function get_available_dbms($dbms = false, $return_unavailable = false, $only_20
'SCHEMA' => 'firebird', 'SCHEMA' => 'firebird',
'MODULE' => 'interbase', 'MODULE' => 'interbase',
'DELIM' => ';;', 'DELIM' => ';;',
'DRIVER' => 'firebird', 'DRIVER' => 'phpbb_db_driver_firebird',
'AVAILABLE' => true, 'AVAILABLE' => true,
'2.0.x' => false, '2.0.x' => false,
), ),
@ -37,7 +37,7 @@ function get_available_dbms($dbms = false, $return_unavailable = false, $only_20
'SCHEMA' => 'mysql_41', 'SCHEMA' => 'mysql_41',
'MODULE' => 'mysqli', 'MODULE' => 'mysqli',
'DELIM' => ';', 'DELIM' => ';',
'DRIVER' => 'mysqli', 'DRIVER' => 'phpbb_db_driver_mysqli',
'AVAILABLE' => true, 'AVAILABLE' => true,
'2.0.x' => true, '2.0.x' => true,
), ),
@ -46,7 +46,7 @@ function get_available_dbms($dbms = false, $return_unavailable = false, $only_20
'SCHEMA' => 'mysql', 'SCHEMA' => 'mysql',
'MODULE' => 'mysql', 'MODULE' => 'mysql',
'DELIM' => ';', 'DELIM' => ';',
'DRIVER' => 'mysql', 'DRIVER' => 'phpbb_db_driver_mysql',
'AVAILABLE' => true, 'AVAILABLE' => true,
'2.0.x' => true, '2.0.x' => true,
), ),
@ -55,7 +55,7 @@ function get_available_dbms($dbms = false, $return_unavailable = false, $only_20
'SCHEMA' => 'mssql', 'SCHEMA' => 'mssql',
'MODULE' => 'mssql', 'MODULE' => 'mssql',
'DELIM' => 'GO', 'DELIM' => 'GO',
'DRIVER' => 'mssql', 'DRIVER' => 'phpbb_db_driver_mssql',
'AVAILABLE' => true, 'AVAILABLE' => true,
'2.0.x' => true, '2.0.x' => true,
), ),
@ -64,7 +64,7 @@ function get_available_dbms($dbms = false, $return_unavailable = false, $only_20
'SCHEMA' => 'mssql', 'SCHEMA' => 'mssql',
'MODULE' => 'odbc', 'MODULE' => 'odbc',
'DELIM' => 'GO', 'DELIM' => 'GO',
'DRIVER' => 'mssql_odbc', 'DRIVER' => 'phpbb_db_driver_mssql_odbc',
'AVAILABLE' => true, 'AVAILABLE' => true,
'2.0.x' => true, '2.0.x' => true,
), ),
@ -73,7 +73,7 @@ function get_available_dbms($dbms = false, $return_unavailable = false, $only_20
'SCHEMA' => 'mssql', 'SCHEMA' => 'mssql',
'MODULE' => 'sqlsrv', 'MODULE' => 'sqlsrv',
'DELIM' => 'GO', 'DELIM' => 'GO',
'DRIVER' => 'mssqlnative', 'DRIVER' => 'phpbb_db_driver_mssqlnative',
'AVAILABLE' => true, 'AVAILABLE' => true,
'2.0.x' => false, '2.0.x' => false,
), ),
@ -82,7 +82,7 @@ function get_available_dbms($dbms = false, $return_unavailable = false, $only_20
'SCHEMA' => 'oracle', 'SCHEMA' => 'oracle',
'MODULE' => 'oci8', 'MODULE' => 'oci8',
'DELIM' => '/', 'DELIM' => '/',
'DRIVER' => 'oracle', 'DRIVER' => 'phpbb_db_driver_oracle',
'AVAILABLE' => true, 'AVAILABLE' => true,
'2.0.x' => false, '2.0.x' => false,
), ),
@ -91,7 +91,7 @@ function get_available_dbms($dbms = false, $return_unavailable = false, $only_20
'SCHEMA' => 'postgres', 'SCHEMA' => 'postgres',
'MODULE' => 'pgsql', 'MODULE' => 'pgsql',
'DELIM' => ';', 'DELIM' => ';',
'DRIVER' => 'postgres', 'DRIVER' => 'phpbb_db_driver_postgres',
'AVAILABLE' => true, 'AVAILABLE' => true,
'2.0.x' => true, '2.0.x' => true,
), ),
@ -100,7 +100,7 @@ function get_available_dbms($dbms = false, $return_unavailable = false, $only_20
'SCHEMA' => 'sqlite', 'SCHEMA' => 'sqlite',
'MODULE' => 'sqlite', 'MODULE' => 'sqlite',
'DELIM' => ';', 'DELIM' => ';',
'DRIVER' => 'sqlite', 'DRIVER' => 'phpbb_db_driver_sqlite',
'AVAILABLE' => true, 'AVAILABLE' => true,
'2.0.x' => false, '2.0.x' => false,
), ),
@ -205,26 +205,19 @@ function connect_check_db($error_connect, &$error, $dbms_details, $table_prefix,
$dbms = $dbms_details['DRIVER']; $dbms = $dbms_details['DRIVER'];
if ($load_dbal)
{
// Include the DB layer
include($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx);
}
// Instantiate it and set return on error true // Instantiate it and set return on error true
$sql_db = 'dbal_' . $dbms; $db = new $dbms();
$db = new $sql_db();
$db->sql_return_on_error(true); $db->sql_return_on_error(true);
// Check that we actually have a database name before going any further..... // Check that we actually have a database name before going any further.....
if ($dbms_details['DRIVER'] != 'sqlite' && $dbms_details['DRIVER'] != 'oracle' && $dbname === '') if ($dbms_details['DRIVER'] != 'phpbb_db_driver_sqlite' && $dbms_details['DRIVER'] != 'phpbb_db_driver_oracle' && $dbname === '')
{ {
$error[] = $lang['INST_ERR_DB_NO_NAME']; $error[] = $lang['INST_ERR_DB_NO_NAME'];
return false; return false;
} }
// Make sure we don't have a daft user who thinks having the SQLite database in the forum directory is a good idea // Make sure we don't have a daft user who thinks having the SQLite database in the forum directory is a good idea
if ($dbms_details['DRIVER'] == 'sqlite' && stripos(phpbb_realpath($dbhost), phpbb_realpath('../')) === 0) if ($dbms_details['DRIVER'] == 'phpbb_db_driver_sqlite' && stripos(phpbb_realpath($dbhost), phpbb_realpath('../')) === 0)
{ {
$error[] = $lang['INST_ERR_DB_FORUM_PATH']; $error[] = $lang['INST_ERR_DB_FORUM_PATH'];
return false; return false;
@ -233,8 +226,8 @@ function connect_check_db($error_connect, &$error, $dbms_details, $table_prefix,
// Check the prefix length to ensure that index names are not too long and does not contain invalid characters // Check the prefix length to ensure that index names are not too long and does not contain invalid characters
switch ($dbms_details['DRIVER']) switch ($dbms_details['DRIVER'])
{ {
case 'mysql': case 'phpbb_db_driver_mysql':
case 'mysqli': case 'phpbb_db_driver_mysqli':
if (strspn($table_prefix, '-./\\') !== 0) if (strspn($table_prefix, '-./\\') !== 0)
{ {
$error[] = $lang['INST_ERR_PREFIX_INVALID']; $error[] = $lang['INST_ERR_PREFIX_INVALID'];
@ -243,22 +236,22 @@ function connect_check_db($error_connect, &$error, $dbms_details, $table_prefix,
// no break; // no break;
case 'postgres': case 'phpbb_db_driver_postgres':
$prefix_length = 36; $prefix_length = 36;
break; break;
case 'mssql': case 'phpbb_db_driver_mssql':
case 'mssql_odbc': case 'phpbb_db_driver_mssql_odbc':
case 'mssqlnative': case 'phpbb_db_driver_mssqlnative':
$prefix_length = 90; $prefix_length = 90;
break; break;
case 'sqlite': case 'phpbb_db_driver_sqlite':
$prefix_length = 200; $prefix_length = 200;
break; break;
case 'firebird': case 'phpbb_db_driver_firebird':
case 'oracle': case 'phpbb_db_driver_oracle':
$prefix_length = 6; $prefix_length = 6;
break; break;
} }
@ -296,21 +289,21 @@ function connect_check_db($error_connect, &$error, $dbms_details, $table_prefix,
// Make sure that the user has selected a sensible DBAL for the DBMS actually installed // Make sure that the user has selected a sensible DBAL for the DBMS actually installed
switch ($dbms_details['DRIVER']) switch ($dbms_details['DRIVER'])
{ {
case 'mysqli': case 'phpbb_db_driver_mysqli':
if (version_compare(mysqli_get_server_info($db->db_connect_id), '4.1.3', '<')) if (version_compare(mysqli_get_server_info($db->db_connect_id), '4.1.3', '<'))
{ {
$error[] = $lang['INST_ERR_DB_NO_MYSQLI']; $error[] = $lang['INST_ERR_DB_NO_MYSQLI'];
} }
break; break;
case 'sqlite': case 'phpbb_db_driver_sqlite':
if (version_compare(sqlite_libversion(), '2.8.2', '<')) if (version_compare(sqlite_libversion(), '2.8.2', '<'))
{ {
$error[] = $lang['INST_ERR_DB_NO_SQLITE']; $error[] = $lang['INST_ERR_DB_NO_SQLITE'];
} }
break; break;
case 'firebird': case 'phpbb_db_driver_firebird':
// check the version of FB, use some hackery if we can't get access to the server info // check the version of FB, use some hackery if we can't get access to the server info
if ($db->service_handle !== false && function_exists('ibase_server_info')) if ($db->service_handle !== false && function_exists('ibase_server_info'))
{ {
@ -391,7 +384,7 @@ function connect_check_db($error_connect, &$error, $dbms_details, $table_prefix,
} }
break; break;
case 'oracle': case 'phpbb_db_driver_oracle':
if ($unicode_check) if ($unicode_check)
{ {
$sql = "SELECT * $sql = "SELECT *
@ -413,7 +406,7 @@ function connect_check_db($error_connect, &$error, $dbms_details, $table_prefix,
} }
break; break;
case 'postgres': case 'phpbb_db_driver_postgres':
if ($unicode_check) if ($unicode_check)
{ {
$sql = "SHOW server_encoding;"; $sql = "SHOW server_encoding;";

View file

@ -48,7 +48,7 @@ class phpbb_lock_db
/** /**
* A database connection * A database connection
* @var dbal * @var phpbb_db_driver
*/ */
private $db; private $db;
@ -59,9 +59,9 @@ class phpbb_lock_db
* *
* @param string $config_name A config variable to be used for locking * @param string $config_name A config variable to be used for locking
* @param array $config The phpBB configuration * @param array $config The phpBB configuration
* @param dbal $db A database connection * @param phpbb_db_driver $db A database connection
*/ */
public function __construct($config_name, phpbb_config $config, dbal $db) public function __construct($config_name, phpbb_config $config, phpbb_db_driver $db)
{ {
$this->config_name = $config_name; $this->config_name = $config_name;
$this->config = $config; $this->config = $config;

View file

@ -260,6 +260,8 @@ class phpbb_questionnaire_phpbb_data_provider
include("{$phpbb_root_path}config.$phpEx"); include("{$phpbb_root_path}config.$phpEx");
unset($dbhost, $dbport, $dbname, $dbuser, $dbpasswd); // Just a precaution unset($dbhost, $dbport, $dbname, $dbuser, $dbpasswd); // Just a precaution
$dbms = phpbb_convert_30_dbms_to_31($dbms);
// Only send certain config vars // Only send certain config vars
$config_vars = array( $config_vars = array(
'active_sessions' => true, 'active_sessions' => true,

View file

@ -41,8 +41,8 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
protected $config; protected $config;
/** /**
* DBAL object * Database connection
* @var dbal * @var phpbb_db_driver
*/ */
protected $db; protected $db;

View file

@ -85,8 +85,8 @@ class phpbb_search_fulltext_native extends phpbb_search_base
protected $config; protected $config;
/** /**
* DBAL object * Database connection
* @var dbal * @var phpbb_db_driver
*/ */
protected $db; protected $db;

View file

@ -66,8 +66,8 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base
protected $config; protected $config;
/** /**
* DBAL object * Database connection
* @var dbal * @var phpbb_db_driver
*/ */
protected $db; protected $db;

View file

@ -84,8 +84,8 @@ class phpbb_search_fulltext_sphinx
protected $config; protected $config;
/** /**
* DBAL object * Database connection
* @var dbal * @var phpbb_db_driver
*/ */
protected $db; protected $db;

View file

@ -24,6 +24,8 @@ if (!defined('IN_PHPBB'))
include($phpbb_root_path . 'config.' . $phpEx); include($phpbb_root_path . 'config.' . $phpEx);
unset($dbpasswd); unset($dbpasswd);
$dbms = phpbb_convert_30_dbms_to_31($dbms);
/** /**
* $convertor_data provides some basic information about this convertor which is * $convertor_data provides some basic information about this convertor which is
* used on the initial list of convertors and to populate the default settings * used on the initial list of convertors and to populate the default settings

View file

@ -83,7 +83,6 @@ phpbb_require_updated('includes/functions_content.' . $phpEx, true);
require($phpbb_root_path . 'includes/functions_admin.' . $phpEx); require($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
require($phpbb_root_path . 'includes/constants.' . $phpEx); require($phpbb_root_path . 'includes/constants.' . $phpEx);
require($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx);
require($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx); require($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx);
phpbb_require_updated('includes/db/db_tools.' . $phpEx); phpbb_require_updated('includes/db/db_tools.' . $phpEx);
@ -822,13 +821,13 @@ function _add_modules($modules_to_install)
* Add a new permission, optionally copy permission setting from another * Add a new permission, optionally copy permission setting from another
* *
* @param auth_admin $auth_admin auth_admin object * @param auth_admin $auth_admin auth_admin object
* @param dbal $db Database object * @param phpbb_db_driver $db Database object
* @param string $permission_name Name of the permission to add * @param string $permission_name Name of the permission to add
* @param bool $is_global True is global, false is local * @param bool $is_global True is global, false is local
* @param string $copy_from Optional permission name from which to copy * @param string $copy_from Optional permission name from which to copy
* @return bool true on success, false on failure * @return bool true on success, false on failure
*/ */
function _add_permission(auth_admin $auth_admin, dbal $db, $permission_name, $is_global = true, $copy_from = '') function _add_permission(auth_admin $auth_admin, phpbb_db_driver $db, $permission_name, $is_global = true, $copy_from = '')
{ {
// Only add a permission that don't already exist // Only add a permission that don't already exist
if (!empty($auth_admin->acl_options['id'][$permission_name])) if (!empty($auth_admin->acl_options['id'][$permission_name]))

View file

@ -121,10 +121,11 @@ class install_convert extends module
require($phpbb_root_path . 'config.' . $phpEx); require($phpbb_root_path . 'config.' . $phpEx);
require($phpbb_root_path . 'includes/constants.' . $phpEx); require($phpbb_root_path . 'includes/constants.' . $phpEx);
require($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx);
require($phpbb_root_path . 'includes/functions_convert.' . $phpEx); require($phpbb_root_path . 'includes/functions_convert.' . $phpEx);
$db = new $sql_db(); $dbms = phpbb_convert_30_dbms_to_31($dbms);
$db = new $dbms();
$db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, true); $db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, true);
unset($dbpasswd); unset($dbpasswd);
@ -209,10 +210,11 @@ class install_convert extends module
require($phpbb_root_path . 'config.' . $phpEx); require($phpbb_root_path . 'config.' . $phpEx);
require($phpbb_root_path . 'includes/constants.' . $phpEx); require($phpbb_root_path . 'includes/constants.' . $phpEx);
require($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx);
require($phpbb_root_path . 'includes/functions_convert.' . $phpEx); require($phpbb_root_path . 'includes/functions_convert.' . $phpEx);
$db = new $sql_db(); $dbms = phpbb_convert_30_dbms_to_31($dbms);
$db = new $dbms();
$db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, true); $db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, true);
unset($dbpasswd); unset($dbpasswd);
@ -332,10 +334,11 @@ class install_convert extends module
require($phpbb_root_path . 'config.' . $phpEx); require($phpbb_root_path . 'config.' . $phpEx);
require($phpbb_root_path . 'includes/constants.' . $phpEx); require($phpbb_root_path . 'includes/constants.' . $phpEx);
require($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx);
require($phpbb_root_path . 'includes/functions_convert.' . $phpEx); require($phpbb_root_path . 'includes/functions_convert.' . $phpEx);
$db = new $sql_db(); $dbms = phpbb_convert_30_dbms_to_31($dbms);
$db = new $dbms();
$db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, true); $db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, true);
unset($dbpasswd); unset($dbpasswd);
@ -425,8 +428,7 @@ class install_convert extends module
if ($src_dbms != $dbms || $src_dbhost != $dbhost || $src_dbport != $dbport || $src_dbname != $dbname || $src_dbuser != $dbuser) if ($src_dbms != $dbms || $src_dbhost != $dbhost || $src_dbport != $dbport || $src_dbname != $dbname || $src_dbuser != $dbuser)
{ {
$sql_db = 'dbal_' . $src_dbms; $src_db = new $src_dbms();
$src_db = new $sql_db();
$src_db->sql_connect($src_dbhost, $src_dbuser, htmlspecialchars_decode($src_dbpasswd), $src_dbname, $src_dbport, false, true); $src_db->sql_connect($src_dbhost, $src_dbuser, htmlspecialchars_decode($src_dbpasswd), $src_dbname, $src_dbport, false, true);
$same_db = false; $same_db = false;
} }
@ -575,10 +577,11 @@ class install_convert extends module
require($phpbb_root_path . 'config.' . $phpEx); require($phpbb_root_path . 'config.' . $phpEx);
require($phpbb_root_path . 'includes/constants.' . $phpEx); require($phpbb_root_path . 'includes/constants.' . $phpEx);
require($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx);
require($phpbb_root_path . 'includes/functions_convert.' . $phpEx); require($phpbb_root_path . 'includes/functions_convert.' . $phpEx);
$db = new $sql_db(); $dbms = phpbb_convert_30_dbms_to_31($dbms);
$db = new $dbms();
$db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, true); $db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, true);
unset($dbpasswd); unset($dbpasswd);
@ -639,12 +642,8 @@ class install_convert extends module
$src_db = $same_db = null; $src_db = $same_db = null;
if ($convert->src_dbms != $dbms || $convert->src_dbhost != $dbhost || $convert->src_dbport != $dbport || $convert->src_dbname != $dbname || $convert->src_dbuser != $dbuser) if ($convert->src_dbms != $dbms || $convert->src_dbhost != $dbhost || $convert->src_dbport != $dbport || $convert->src_dbname != $dbname || $convert->src_dbuser != $dbuser)
{ {
if ($convert->src_dbms != $dbms) $dbms = $convert->src_dbms;
{ $src_db = new $dbms();
require($phpbb_root_path . 'includes/db/' . $convert->src_dbms . '.' . $phpEx);
}
$sql_db = 'dbal_' . $convert->src_dbms;
$src_db = new $sql_db();
$src_db->sql_connect($convert->src_dbhost, $convert->src_dbuser, htmlspecialchars_decode($convert->src_dbpasswd), $convert->src_dbname, $convert->src_dbport, false, true); $src_db->sql_connect($convert->src_dbhost, $convert->src_dbuser, htmlspecialchars_decode($convert->src_dbpasswd), $convert->src_dbname, $convert->src_dbport, false, true);
$same_db = false; $same_db = false;
} }

View file

@ -1118,11 +1118,8 @@ class install_install extends module
$dbms = $available_dbms[$data['dbms']]['DRIVER']; $dbms = $available_dbms[$data['dbms']]['DRIVER'];
// Load the appropriate database class if not already loaded
include($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx);
// Instantiate the database // Instantiate the database
$db = new $sql_db(); $db = new $dbms();
$db->sql_connect($data['dbhost'], $data['dbuser'], htmlspecialchars_decode($data['dbpasswd']), $data['dbname'], $data['dbport'], false, false); $db->sql_connect($data['dbhost'], $data['dbuser'], htmlspecialchars_decode($data['dbpasswd']), $data['dbname'], $data['dbport'], false, false);
// NOTE: trigger_error does not work here. // NOTE: trigger_error does not work here.
@ -1418,11 +1415,8 @@ class install_install extends module
$dbms = $available_dbms[$data['dbms']]['DRIVER']; $dbms = $available_dbms[$data['dbms']]['DRIVER'];
// Load the appropriate database class if not already loaded
include($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx);
// Instantiate the database // Instantiate the database
$db = new $sql_db(); $db = new $dbms();
$db->sql_connect($data['dbhost'], $data['dbuser'], htmlspecialchars_decode($data['dbpasswd']), $data['dbname'], $data['dbport'], false, false); $db->sql_connect($data['dbhost'], $data['dbuser'], htmlspecialchars_decode($data['dbpasswd']), $data['dbname'], $data['dbport'], false, false);
// NOTE: trigger_error does not work here. // NOTE: trigger_error does not work here.

View file

@ -83,7 +83,6 @@ class install_update extends module
// Init DB // Init DB
require($phpbb_root_path . 'config.' . $phpEx); require($phpbb_root_path . 'config.' . $phpEx);
require($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx);
require($phpbb_root_path . 'includes/constants.' . $phpEx); require($phpbb_root_path . 'includes/constants.' . $phpEx);
// Special options for conflicts/modified files // Special options for conflicts/modified files
@ -92,7 +91,9 @@ class install_update extends module
define('MERGE_NEW_FILE', 3); define('MERGE_NEW_FILE', 3);
define('MERGE_MOD_FILE', 4); define('MERGE_MOD_FILE', 4);
$db = new $sql_db(); $dbms = phpbb_convert_30_dbms_to_31($dbms);
$db = new $dbms();
// Connect to DB // Connect to DB
$db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, false); $db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, false);

View file

@ -30,7 +30,7 @@ example for mysqli can be found below. More information on configuration
options can be found on the wiki (see below). options can be found on the wiki (see below).
<?php <?php
$dbms = 'mysqli'; $dbms = 'phpbb_db_driver_mysqli';
$dbhost = 'localhost'; $dbhost = 'localhost';
$dbport = ''; $dbport = '';
$dbname = 'database'; $dbname = 'database';

View file

@ -22,9 +22,7 @@ class phpbb_dbal_connect_test extends phpbb_database_test_case
$config = $this->get_database_config(); $config = $this->get_database_config();
require_once dirname(__FILE__) . '/../../phpBB/includes/db/' . $config['dbms'] . '.php'; $db = new $config['dbms']();
$dbal = 'dbal_' . $config['dbms'];
$db = new $dbal();
// Failure to connect results in a trigger_error call in dbal. // Failure to connect results in a trigger_error call in dbal.
// phpunit converts triggered errors to exceptions. // phpunit converts triggered errors to exceptions.

View file

@ -9,7 +9,6 @@
require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
require_once dirname(__FILE__) . '/../../phpBB/includes/functions_container.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/functions_container.php';
require_once dirname(__FILE__) . '/../../phpBB/includes/db/dbal.php';
class phpbb_di_container_test extends phpbb_test_case class phpbb_di_container_test extends phpbb_test_case
{ {
@ -52,7 +51,7 @@ class phpbb_di_container_test extends phpbb_test_case
} }
} }
class dbal_container_mock extends dbal class phpbb_db_driver_container_mock extends phpbb_db_driver
{ {
public function sql_connect() public function sql_connect()
{ {

View file

@ -0,0 +1,40 @@
<?php
/**
*
* @package testing
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
class phpbb_convert_30_dbms_to_31_test extends phpbb_test_case
{
public function convert_30_dbms_to_31_data()
{
return array(
array('firebird'),
array('mssql'),
array('mssql_odbc'),
array('mssqlnative'),
array('mysql'),
array('mysqli'),
array('oracle'),
array('postgres'),
array('sqlite'),
);
}
/**
* @dataProvider convert_30_dbms_to_31_data
*/
public function test_convert_30_dbms_to_31($input)
{
$expected = "phpbb_db_driver_$input";
$output = phpbb_convert_30_dbms_to_31($input);
$this->assertEquals($expected, $output);
}
}

View file

@ -59,10 +59,10 @@ class phpbb_session_testable_factory
/** /**
* Retrieve the configured session class instance * Retrieve the configured session class instance
* *
* @param dbal $dbal The database connection to use for session data * @param phpbb_db_driver $dbal The database connection to use for session data
* @return phpbb_mock_session_testable A session instance * @return phpbb_mock_session_testable A session instance
*/ */
public function get_session(dbal $dbal) public function get_session(phpbb_db_driver $dbal)
{ {
// set up all the global variables used by session // set up all the global variables used by session
global $SID, $_SID, $db, $config, $cache, $request; global $SID, $_SID, $db, $config, $cache, $request;

View file

@ -49,7 +49,7 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test
$db_config = $this->get_database_config(); $db_config = $this->get_database_config();
// Firebird requires table and column names to be uppercase // Firebird requires table and column names to be uppercase
if ($db_config['dbms'] == 'firebird') if ($db_config['dbms'] == 'phpbb_db_driver_firebird')
{ {
$xml_data = file_get_contents($path); $xml_data = file_get_contents($path);
$xml_data = preg_replace_callback('/(?:(<table name="))([a-z_]+)(?:(">))/', 'phpbb_database_test_case::to_upper', $xml_data); $xml_data = preg_replace_callback('/(?:(<table name="))([a-z_]+)(?:(">))/', 'phpbb_database_test_case::to_upper', $xml_data);
@ -118,9 +118,7 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test
$config = $this->get_database_config(); $config = $this->get_database_config();
require_once dirname(__FILE__) . '/../../phpBB/includes/db/' . $config['dbms'] . '.php'; $db = new $config['dbms']();
$dbal = 'dbal_' . $config['dbms'];
$db = new $dbal();
$db->sql_connect($config['dbhost'], $config['dbuser'], $config['dbpasswd'], $config['dbname'], $config['dbport']); $db->sql_connect($config['dbhost'], $config['dbuser'], $config['dbpasswd'], $config['dbname'], $config['dbport']);
return $db; return $db;

View file

@ -108,7 +108,7 @@ class phpbb_database_test_connection_manager
// These require different connection strings on the phpBB side than they do in PDO // These require different connection strings on the phpBB side than they do in PDO
// so you must provide a DSN string for ODBC separately // so you must provide a DSN string for ODBC separately
if (!empty($this->config['custom_dsn']) && ($this->config['dbms'] == 'mssql' || $this->config['dbms'] == 'firebird')) if (!empty($this->config['custom_dsn']) && ($this->config['dbms'] == 'phpbb_db_driver_mssql' || $this->config['dbms'] == 'phpbb_db_driver_firebird'))
{ {
$dsn = 'odbc:' . $this->config['custom_dsn']; $dsn = 'odbc:' . $this->config['custom_dsn'];
} }
@ -117,12 +117,12 @@ class phpbb_database_test_connection_manager
{ {
switch ($this->config['dbms']) switch ($this->config['dbms'])
{ {
case 'mssql': case 'phpbb_db_driver_mssql':
case 'mssql_odbc': case 'phpbb_db_driver_mssql_odbc':
$this->pdo = new phpbb_database_connection_odbc_pdo_wrapper('mssql', 0, $dsn, $this->config['dbuser'], $this->config['dbpasswd']); $this->pdo = new phpbb_database_connection_odbc_pdo_wrapper('mssql', 0, $dsn, $this->config['dbuser'], $this->config['dbpasswd']);
break; break;
case 'firebird': case 'phpbb_db_driver_firebird':
if (!empty($this->config['custom_dsn'])) if (!empty($this->config['custom_dsn']))
{ {
$this->pdo = new phpbb_database_connection_odbc_pdo_wrapper('firebird', 0, $dsn, $this->config['dbuser'], $this->config['dbpasswd']); $this->pdo = new phpbb_database_connection_odbc_pdo_wrapper('firebird', 0, $dsn, $this->config['dbuser'], $this->config['dbpasswd']);
@ -165,8 +165,8 @@ class phpbb_database_test_connection_manager
{ {
switch ($this->config['dbms']) switch ($this->config['dbms'])
{ {
case 'sqlite': case 'phpbb_db_driver_sqlite':
case 'firebird': case 'phpbb_db_driver_firebird':
$this->connect(); $this->connect();
// Drop all of the tables // Drop all of the tables
foreach ($this->get_tables() as $table) foreach ($this->get_tables() as $table)
@ -176,7 +176,7 @@ class phpbb_database_test_connection_manager
$this->purge_extras(); $this->purge_extras();
break; break;
case 'oracle': case 'phpbb_db_driver_oracle':
$this->connect(); $this->connect();
// Drop all of the tables // Drop all of the tables
foreach ($this->get_tables() as $table) foreach ($this->get_tables() as $table)
@ -226,39 +226,39 @@ class phpbb_database_test_connection_manager
switch ($this->config['dbms']) switch ($this->config['dbms'])
{ {
case 'mysql': case 'phpbb_db_driver_mysql':
case 'mysql4': case 'phpbb_db_driver_mysql4':
case 'mysqli': case 'phpbb_db_driver_mysqli':
$sql = 'SHOW TABLES'; $sql = 'SHOW TABLES';
break; break;
case 'sqlite': case 'phpbb_db_driver_sqlite':
$sql = 'SELECT name $sql = 'SELECT name
FROM sqlite_master FROM sqlite_master
WHERE type = "table"'; WHERE type = "table"';
break; break;
case 'mssql': case 'phpbb_db_driver_mssql':
case 'mssql_odbc': case 'phpbb_db_driver_mssql_odbc':
case 'mssqlnative': case 'phpbb_db_driver_mssqlnative':
$sql = "SELECT name $sql = "SELECT name
FROM sysobjects FROM sysobjects
WHERE type='U'"; WHERE type='U'";
break; break;
case 'postgres': case 'phpbb_db_driver_postgres':
$sql = 'SELECT relname $sql = 'SELECT relname
FROM pg_stat_user_tables'; FROM pg_stat_user_tables';
break; break;
case 'firebird': case 'phpbb_db_driver_firebird':
$sql = 'SELECT rdb$relation_name $sql = 'SELECT rdb$relation_name
FROM rdb$relations FROM rdb$relations
WHERE rdb$view_source is null WHERE rdb$view_source is null
AND rdb$system_flag = 0'; AND rdb$system_flag = 0';
break; break;
case 'oracle': case 'phpbb_db_driver_oracle':
$sql = 'SELECT table_name $sql = 'SELECT table_name
FROM USER_TABLES'; FROM USER_TABLES';
break; break;
@ -294,7 +294,7 @@ class phpbb_database_test_connection_manager
{ {
$schema = $this->dbms['SCHEMA']; $schema = $this->dbms['SCHEMA'];
if ($this->config['dbms'] == 'mysql') if ($this->config['dbms'] == 'phpbb_db_driver_mysql')
{ {
$sth = $this->pdo->query('SELECT VERSION() AS version'); $sth = $this->pdo->query('SELECT VERSION() AS version');
$row = $sth->fetch(PDO::FETCH_ASSOC); $row = $sth->fetch(PDO::FETCH_ASSOC);
@ -328,47 +328,47 @@ class phpbb_database_test_connection_manager
protected function get_dbms_data($dbms) protected function get_dbms_data($dbms)
{ {
$available_dbms = array( $available_dbms = array(
'firebird' => array( 'phpbb_db_driver_firebird' => array(
'SCHEMA' => 'firebird', 'SCHEMA' => 'firebird',
'DELIM' => ';;', 'DELIM' => ';;',
'PDO' => 'firebird', 'PDO' => 'firebird',
), ),
'mysqli' => array( 'phpbb_db_driver_mysqli' => array(
'SCHEMA' => 'mysql_41', 'SCHEMA' => 'mysql_41',
'DELIM' => ';', 'DELIM' => ';',
'PDO' => 'mysql', 'PDO' => 'mysql',
), ),
'mysql' => array( 'phpbb_db_driver_mysql' => array(
'SCHEMA' => 'mysql', 'SCHEMA' => 'mysql',
'DELIM' => ';', 'DELIM' => ';',
'PDO' => 'mysql', 'PDO' => 'mysql',
), ),
'mssql' => array( 'phpbb_db_driver_mssql' => array(
'SCHEMA' => 'mssql', 'SCHEMA' => 'mssql',
'DELIM' => 'GO', 'DELIM' => 'GO',
'PDO' => 'odbc', 'PDO' => 'odbc',
), ),
'mssql_odbc'=> array( 'phpbb_db_driver_mssql_odbc'=> array(
'SCHEMA' => 'mssql', 'SCHEMA' => 'mssql',
'DELIM' => 'GO', 'DELIM' => 'GO',
'PDO' => 'odbc', 'PDO' => 'odbc',
), ),
'mssqlnative' => array( 'phpbb_db_driver_mssqlnative' => array(
'SCHEMA' => 'mssql', 'SCHEMA' => 'mssql',
'DELIM' => 'GO', 'DELIM' => 'GO',
'PDO' => 'sqlsrv', 'PDO' => 'sqlsrv',
), ),
'oracle' => array( 'phpbb_db_driver_oracle' => array(
'SCHEMA' => 'oracle', 'SCHEMA' => 'oracle',
'DELIM' => '/', 'DELIM' => '/',
'PDO' => 'oci', 'PDO' => 'oci',
), ),
'postgres' => array( 'phpbb_db_driver_postgres' => array(
'SCHEMA' => 'postgres', 'SCHEMA' => 'postgres',
'DELIM' => ';', 'DELIM' => ';',
'PDO' => 'pgsql', 'PDO' => 'pgsql',
), ),
'sqlite' => array( 'phpbb_db_driver_sqlite' => array(
'SCHEMA' => 'sqlite', 'SCHEMA' => 'sqlite',
'DELIM' => ';', 'DELIM' => ';',
'PDO' => 'sqlite2', 'PDO' => 'sqlite2',
@ -397,7 +397,7 @@ class phpbb_database_test_connection_manager
switch ($this->config['dbms']) switch ($this->config['dbms'])
{ {
case 'firebird': case 'phpbb_db_driver_firebird':
$sql = 'SELECT RDB$GENERATOR_NAME $sql = 'SELECT RDB$GENERATOR_NAME
FROM RDB$GENERATORS FROM RDB$GENERATORS
WHERE RDB$SYSTEM_FLAG = 0'; WHERE RDB$SYSTEM_FLAG = 0';
@ -409,7 +409,7 @@ class phpbb_database_test_connection_manager
} }
break; break;
case 'oracle': case 'phpbb_db_driver_oracle':
$sql = 'SELECT sequence_name $sql = 'SELECT sequence_name
FROM USER_SEQUENCES'; FROM USER_SEQUENCES';
$result = $this->pdo->query($sql); $result = $this->pdo->query($sql);
@ -444,7 +444,7 @@ class phpbb_database_test_connection_manager
switch ($this->config['dbms']) switch ($this->config['dbms'])
{ {
case 'oracle': case 'phpbb_db_driver_oracle':
// Get all of the information about the sequences // Get all of the information about the sequences
$sql = "SELECT t.table_name, tc.column_name, d.referenced_name as sequence_name, s.increment_by, s.min_value $sql = "SELECT t.table_name, tc.column_name, d.referenced_name as sequence_name, s.increment_by, s.min_value
FROM USER_TRIGGERS t FROM USER_TRIGGERS t
@ -486,7 +486,7 @@ class phpbb_database_test_connection_manager
} }
break; break;
case 'postgres': case 'phpbb_db_driver_postgres':
// Get the sequences attached to the tables // Get the sequences attached to the tables
$sql = 'SELECT column_name, table_name FROM information_schema.columns $sql = 'SELECT column_name, table_name FROM information_schema.columns
WHERE table_name IN (' . implode(', ', $table_names) . ") WHERE table_name IN (' . implode(', ', $table_names) . ")

View file

@ -102,14 +102,10 @@ class phpbb_functional_test_case extends phpbb_test_case
{ {
global $phpbb_root_path, $phpEx; global $phpbb_root_path, $phpEx;
// so we don't reopen an open connection // so we don't reopen an open connection
if (!($this->db instanceof dbal)) if (!($this->db instanceof phpbb_db_driver))
{ {
if (!class_exists('dbal_' . self::$config['dbms'])) $dbms = self::$config['dbms'];
{ $this->db = new $dbms();
include($phpbb_root_path . 'includes/db/' . self::$config['dbms'] . ".$phpEx");
}
$sql_db = 'dbal_' . self::$config['dbms'];
$this->db = new $sql_db();
$this->db->sql_connect(self::$config['dbhost'], self::$config['dbuser'], self::$config['dbpasswd'], self::$config['dbname'], self::$config['dbport']); $this->db->sql_connect(self::$config['dbhost'], self::$config['dbuser'], self::$config['dbpasswd'], self::$config['dbname'], self::$config['dbport']);
} }
return $this->db; return $this->db;
@ -206,6 +202,8 @@ class phpbb_functional_test_case extends phpbb_test_case
self::assertNotSame(false, $content); self::assertNotSame(false, $content);
self::assertContains('Welcome to Installation', $content); self::assertContains('Welcome to Installation', $content);
// Installer uses 3.0-style dbms name
$data['dbms'] = str_replace('phpbb_db_driver_', '', $data['dbms']);
$content = self::do_request('create_table', $data); $content = self::do_request('create_table', $data);
self::assertNotSame(false, $content); self::assertNotSame(false, $content);
self::assertContains('The database tables used by phpBB', $content); self::assertContains('The database tables used by phpBB', $content);

View file

@ -54,7 +54,7 @@ class phpbb_test_case_helpers
if (extension_loaded('sqlite') && version_compare(PHPUnit_Runner_Version::id(), '3.4.15', '>=')) if (extension_loaded('sqlite') && version_compare(PHPUnit_Runner_Version::id(), '3.4.15', '>='))
{ {
$config = array_merge($config, array( $config = array_merge($config, array(
'dbms' => 'sqlite', 'dbms' => 'phpbb_db_driver_sqlite',
'dbhost' => dirname(__FILE__) . '/../phpbb_unit_tests.sqlite2', // filename 'dbhost' => dirname(__FILE__) . '/../phpbb_unit_tests.sqlite2', // filename
'dbport' => '', 'dbport' => '',
'dbname' => '', 'dbname' => '',
@ -78,7 +78,7 @@ class phpbb_test_case_helpers
include($test_config); include($test_config);
$config = array_merge($config, array( $config = array_merge($config, array(
'dbms' => $dbms, 'dbms' => phpbb_convert_30_dbms_to_31($dbms),
'dbhost' => $dbhost, 'dbhost' => $dbhost,
'dbport' => $dbport, 'dbport' => $dbport,
'dbname' => $dbname, 'dbname' => $dbname,
@ -104,8 +104,13 @@ class phpbb_test_case_helpers
if (isset($_SERVER['PHPBB_TEST_DBMS'])) if (isset($_SERVER['PHPBB_TEST_DBMS']))
{ {
if (!function_exists('phpbb_convert_30_dbms_to_31'))
{
require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
}
$config = array_merge($config, array( $config = array_merge($config, array(
'dbms' => isset($_SERVER['PHPBB_TEST_DBMS']) ? $_SERVER['PHPBB_TEST_DBMS'] : '', 'dbms' => isset($_SERVER['PHPBB_TEST_DBMS']) ? phpbb_convert_30_dbms_to_31($_SERVER['PHPBB_TEST_DBMS']) : '',
'dbhost' => isset($_SERVER['PHPBB_TEST_DBHOST']) ? $_SERVER['PHPBB_TEST_DBHOST'] : '', 'dbhost' => isset($_SERVER['PHPBB_TEST_DBHOST']) ? $_SERVER['PHPBB_TEST_DBHOST'] : '',
'dbport' => isset($_SERVER['PHPBB_TEST_DBPORT']) ? $_SERVER['PHPBB_TEST_DBPORT'] : '', 'dbport' => isset($_SERVER['PHPBB_TEST_DBPORT']) ? $_SERVER['PHPBB_TEST_DBPORT'] : '',
'dbname' => isset($_SERVER['PHPBB_TEST_DBNAME']) ? $_SERVER['PHPBB_TEST_DBNAME'] : '', 'dbname' => isset($_SERVER['PHPBB_TEST_DBNAME']) ? $_SERVER['PHPBB_TEST_DBNAME'] : '',

View file

@ -28,7 +28,7 @@
</groups> </groups>
<php> <php>
<server name="PHPBB_TEST_DBMS" value="mysqli" /> <server name="PHPBB_TEST_DBMS" value="phpbb_db_driver_mysqli" />
<server name="PHPBB_TEST_DBHOST" value="0.0.0.0" /> <server name="PHPBB_TEST_DBHOST" value="0.0.0.0" />
<server name="PHPBB_TEST_DBPORT" value="3306" /> <server name="PHPBB_TEST_DBPORT" value="3306" />
<server name="PHPBB_TEST_DBNAME" value="phpbb_tests" /> <server name="PHPBB_TEST_DBNAME" value="phpbb_tests" />

View file

@ -30,7 +30,7 @@
<php> <php>
<!-- "Real" test database --> <!-- "Real" test database -->
<!-- uncomment, otherwise sqlite memory runs --> <!-- uncomment, otherwise sqlite memory runs -->
<server name="PHPBB_TEST_DBMS" value="postgres"/> <server name="PHPBB_TEST_DBMS" value="phpbb_db_driver_postgres"/>
<server name="PHPBB_TEST_DBHOST" value="localhost" /> <server name="PHPBB_TEST_DBHOST" value="localhost" />
<server name="PHPBB_TEST_DBPORT" value="5432" /> <server name="PHPBB_TEST_DBPORT" value="5432" />
<server name="PHPBB_TEST_DBNAME" value="phpbb_tests" /> <server name="PHPBB_TEST_DBNAME" value="phpbb_tests" />