diff options
-rw-r--r-- | phpBB/includes/acp/acp_database.php | 2 | ||||
-rw-r--r-- | phpBB/includes/db/db_tools.php | 2 | ||||
-rw-r--r-- | phpBB/includes/db/dbal.php | 5 | ||||
-rw-r--r-- | phpBB/includes/db/firebird.php | 26 | ||||
-rw-r--r-- | phpBB/includes/db/mssql.php | 32 | ||||
-rw-r--r-- | phpBB/includes/db/mssql_odbc.php | 32 | ||||
-rw-r--r-- | phpBB/includes/db/mysql.php | 40 | ||||
-rw-r--r-- | phpBB/includes/db/mysqli.php | 26 | ||||
-rw-r--r-- | phpBB/includes/db/oracle.php | 25 | ||||
-rw-r--r-- | phpBB/includes/db/postgres.php | 42 | ||||
-rw-r--r-- | phpBB/includes/db/sqlite.php | 19 | ||||
-rw-r--r-- | phpBB/includes/functions_admin.php | 2 | ||||
-rw-r--r-- | phpBB/includes/search/fulltext_mysql.php | 4 | ||||
-rw-r--r-- | phpBB/install/convertors/functions_phpbb20.php | 2 | ||||
-rw-r--r-- | phpBB/install/database_update.php | 5 | ||||
-rw-r--r-- | phpBB/install/install_convert.php | 2 | ||||
-rw-r--r-- | phpBB/install/install_install.php | 6 | ||||
-rw-r--r-- | phpBB/install/schemas/schema_data.sql | 1 |
18 files changed, 199 insertions, 74 deletions
diff --git a/phpBB/includes/acp/acp_database.php b/phpBB/includes/acp/acp_database.php index 5b479a08eb..e2ca66b2f3 100644 --- a/phpBB/includes/acp/acp_database.php +++ b/phpBB/includes/acp/acp_database.php @@ -620,7 +620,7 @@ class mysql_extractor extends base_extractor if ($new_extract === null) { - if ($db->sql_layer === 'mysqli' || version_compare($db->mysql_version, '3.23.20', '>=')) + if ($db->sql_layer === 'mysqli' || version_compare($db->sql_server_info(true), '3.23.20', '>=')) { $new_extract = true; } diff --git a/phpBB/includes/db/db_tools.php b/phpBB/includes/db/db_tools.php index 1a49a98729..703af25086 100644 --- a/phpBB/includes/db/db_tools.php +++ b/phpBB/includes/db/db_tools.php @@ -265,7 +265,7 @@ class phpbb_db_tools break; case 'mysql4': - if (version_compare($this->db->mysql_version, '4.1.3', '>=')) + if (version_compare($this->db->sql_server_info(true), '4.1.3', '>=')) { $this->sql_layer = 'mysql_41'; } diff --git a/phpBB/includes/db/dbal.php b/phpBB/includes/db/dbal.php index 289359ebeb..039545fc1f 100644 --- a/phpBB/includes/db/dbal.php +++ b/phpBB/includes/db/dbal.php @@ -66,6 +66,11 @@ class dbal var $one_char; /** + * Exact version of the DBAL, directly queried + */ + var $sql_server_version = false; + + /** * Constructor */ function dbal() diff --git a/phpBB/includes/db/firebird.php b/phpBB/includes/db/firebird.php index 6765f2af48..0157238fcd 100644 --- a/phpBB/includes/db/firebird.php +++ b/phpBB/includes/db/firebird.php @@ -37,26 +37,42 @@ class dbal_firebird extends dbal $this->persistency = $persistency; $this->user = $sqluser; $this->server = $sqlserver . (($port) ? ':' . $port : ''); - $this->dbname = $database; + $this->dbname = str_replace('\\', '/', $database); - $this->db_connect_id = ($this->persistency) ? @ibase_pconnect($this->server . ':' . $this->dbname, $this->user, $sqlpassword, false, false, 3) : @ibase_connect($this->server . ':' . $this->dbname, $this->user, $sqlpassword, false, false, 3); + // There are three possibilities to connect to an interbase db + if (!$this->server) + { + $use_database = $this->dbname; + } + else if (strpos($this->server, '//') === 0) + { + $use_database = $this->server . $this->dbname; + } + else + { + $use_database = $this->server . ':' . $this->dbname; + } + + $this->db_connect_id = ($this->persistency) ? @ibase_pconnect($use_database, $this->user, $sqlpassword, false, false, 3) : @ibase_connect($use_database, $this->user, $sqlpassword, false, false, 3); - $this->service_handle = (function_exists('ibase_service_attach')) ? @ibase_service_attach($this->server, $this->user, $sqlpassword) : false; + $this->service_handle = (function_exists('ibase_service_attach') && $this->server) ? @ibase_service_attach($this->server, $this->user, $sqlpassword) : false; return ($this->db_connect_id) ? $this->db_connect_id : $this->sql_error(''); } /** * Version information about used database + * @param bool $raw if true, only return the fetched sql_server_version + * @return string sql server version */ - function sql_server_info() + function sql_server_info($raw = false) { if ($this->service_handle !== false && function_exists('ibase_server_info')) { return @ibase_server_info($this->service_handle, IBASE_SVC_SERVER_VERSION); } - return 'Firebird/Interbase'; + return ($raw) ? '2.0' : 'Firebird/Interbase'; } /** diff --git a/phpBB/includes/db/mssql.php b/phpBB/includes/db/mssql.php index 8b67f04b5d..97be2bfb3f 100644 --- a/phpBB/includes/db/mssql.php +++ b/phpBB/includes/db/mssql.php @@ -62,24 +62,38 @@ class dbal_mssql extends dbal /** * Version information about used database + * @param bool $raw if true, only return the fetched sql_server_version + * @return string sql server version */ - function sql_server_info() + function sql_server_info($raw = false) { - $result_id = @mssql_query("SELECT SERVERPROPERTY('productversion'), SERVERPROPERTY('productlevel'), SERVERPROPERTY('edition')", $this->db_connect_id); + global $cache; - $row = false; - if ($result_id) + if (empty($cache) || ($this->sql_server_version = $cache->get('mssql_version')) === false) { - $row = @mssql_fetch_assoc($result_id); - @mssql_free_result($result_id); + $result_id = @mssql_query("SELECT SERVERPROPERTY('productversion'), SERVERPROPERTY('productlevel'), SERVERPROPERTY('edition')", $this->db_connect_id); + + $row = false; + if ($result_id) + { + $row = @mssql_fetch_assoc($result_id); + @mssql_free_result($result_id); + } + + $this->sql_server_version = ($row) ? trim(implode(' ', $row)) : 0; + + if (!empty($cache)) + { + $cache->put('mssql_version', $this->sql_server_version); + } } - if ($row) + if ($raw) { - return 'MSSQL<br />' . implode(' ', $row); + return $this->sql_server_version; } - return 'MSSQL'; + return ($this->sql_server_version) ? 'MSSQL<br />' . $this->sql_server_version : 'MSSQL'; } /** diff --git a/phpBB/includes/db/mssql_odbc.php b/phpBB/includes/db/mssql_odbc.php index bc02971b8d..3b5f41affd 100644 --- a/phpBB/includes/db/mssql_odbc.php +++ b/phpBB/includes/db/mssql_odbc.php @@ -73,24 +73,38 @@ class dbal_mssql_odbc extends dbal /** * Version information about used database + * @param bool $raw if true, only return the fetched sql_server_version + * @return string sql server version */ - function sql_server_info() + function sql_server_info($raw = false) { - $result_id = @odbc_exec($this->db_connect_id, "SELECT SERVERPROPERTY('productversion'), SERVERPROPERTY('productlevel'), SERVERPROPERTY('edition')"); + global $cache; - $row = false; - if ($result_id) + if (empty($cache) || ($this->sql_server_version = $cache->get('mssqlodbc_version')) === false) { - $row = @odbc_fetch_array($result_id); - @odbc_free_result($result_id); + $result_id = @odbc_exec($this->db_connect_id, "SELECT SERVERPROPERTY('productversion'), SERVERPROPERTY('productlevel'), SERVERPROPERTY('edition')"); + + $row = false; + if ($result_id) + { + $row = @odbc_fetch_array($result_id); + @odbc_free_result($result_id); + } + + $this->sql_server_version = ($row) ? trim(implode(' ', $row)) : 0; + + if (!empty($cache)) + { + $cache->put('mssqlodbc_version', $this->sql_server_version); + } } - if ($row) + if ($raw) { - return 'MSSQL (ODBC)<br />' . implode(' ', $row); + return $this->sql_server_version; } - return 'MSSQL (ODBC)'; + return ($this->sql_server_version) ? 'MSSQL (ODBC)<br />' . $this->sql_server_version : 'MSSQL (ODBC)'; } /** diff --git a/phpBB/includes/db/mysql.php b/phpBB/includes/db/mysql.php index edeaf7aa73..31b2850776 100644 --- a/phpBB/includes/db/mysql.php +++ b/phpBB/includes/db/mysql.php @@ -29,7 +29,6 @@ include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx); */ class dbal_mysql extends dbal { - var $mysql_version; var $multi_insert = true; /** @@ -52,13 +51,14 @@ class dbal_mysql extends dbal if (@mysql_select_db($this->dbname, $this->db_connect_id)) { // Determine what version we are using and if it natively supports UNICODE - $this->mysql_version = mysql_get_server_info($this->db_connect_id); + $this->sql_server_info(); - if (version_compare($this->mysql_version, '4.1.3', '>=')) + if (version_compare($this->sql_server_version, '4.1.3', '>=')) { @mysql_query("SET NAMES 'utf8'", $this->db_connect_id); + // enforce strict mode on databases that support it - if (version_compare($this->mysql_version, '5.0.2', '>=')) + if (version_compare($this->sql_server_version, '5.0.2', '>=')) { $result = @mysql_query('SELECT @@session.sql_mode AS sql_mode', $this->db_connect_id); $row = @mysql_fetch_assoc($result); @@ -83,7 +83,7 @@ class dbal_mysql extends dbal @mysql_query("SET SESSION sql_mode='{$mode}'", $this->db_connect_id); } } - else if (version_compare($this->mysql_version, '4.0.0', '<')) + else if (version_compare($this->sql_server_version, '4.0.0', '<')) { $this->sql_layer = 'mysql'; } @@ -97,10 +97,28 @@ class dbal_mysql extends dbal /** * Version information about used database + * @param bool $raw if true, only return the fetched sql_server_version + * @return string sql server version */ - function sql_server_info() + function sql_server_info($raw = false) { - return 'MySQL ' . $this->mysql_version; + global $cache; + + if (empty($cache) || ($this->sql_server_version = $cache->get('mysql_version')) === false) + { + $result = @mysql_query('SELECT VERSION() AS version', $this->db_connect_id); + $row = @mysql_fetch_assoc($result); + @mysql_free_result($result); + + $this->sql_server_version = $row['version']; + + if (!empty($cache)) + { + $cache->put('mysql_version', $this->sql_server_version); + } + } + + return ($raw) ? $this->sql_server_version : 'MySQL ' . $this->sql_server_version; } /** @@ -367,13 +385,9 @@ class dbal_mysql extends dbal if ($test_prof === null) { $test_prof = false; - if (strpos($this->mysql_version, 'community') !== false) + if (version_compare($this->sql_server_info(true), '5.0.37', '>=') && version_compare($this->sql_server_info(true), '5.1', '<')) { - $ver = substr($this->mysql_version, 0, strpos($this->mysql_version, '-')); - if (version_compare($ver, '5.0.37', '>=') && version_compare($ver, '5.1', '<')) - { - $test_prof = true; - } + $test_prof = true; } } diff --git a/phpBB/includes/db/mysqli.php b/phpBB/includes/db/mysqli.php index e8fd35f859..f0e58fd148 100644 --- a/phpBB/includes/db/mysqli.php +++ b/phpBB/includes/db/mysqli.php @@ -45,12 +45,14 @@ class dbal_mysqli extends dbal if ($this->db_connect_id && $this->dbname != '') { @mysqli_query($this->db_connect_id, "SET NAMES 'utf8'"); + // enforce strict mode on databases that support it - if (mysqli_get_server_version($this->db_connect_id) >= 50002) + if (version_compare($this->sql_server_info(true), '5.0.2', '>=')) { $result = @mysqli_query($this->db_connect_id, 'SELECT @@session.sql_mode AS sql_mode'); $row = @mysqli_fetch_assoc($result); @mysqli_free_result($result); + $modes = array_map('trim', explode(',', $row['sql_mode'])); // TRADITIONAL includes STRICT_ALL_TABLES and STRICT_TRANS_TABLES @@ -78,10 +80,28 @@ class dbal_mysqli extends dbal /** * Version information about used database + * @param bool $raw if true, only return the fetched sql_server_version + * @return string sql server version */ - function sql_server_info() + function sql_server_info($raw = false) { - return 'MySQL(i) ' . @mysqli_get_server_info($this->db_connect_id); + global $cache; + + if (empty($cache) || ($this->sql_server_version = $cache->get('mysqli_version')) === false) + { + $result = @mysqli_query($this->db_connect_id, 'SELECT VERSION() AS version'); + $row = @mysqli_fetch_assoc($result); + @mysqli_free_result($result); + + $this->sql_server_version = $row['version']; + + if (!empty($cache)) + { + $cache->put('mysqli_version', $this->sql_server_version); + } + } + + return ($raw) ? $this->sql_server_version : 'MySQL(i) ' . $this->sql_server_version; } /** diff --git a/phpBB/includes/db/oracle.php b/phpBB/includes/db/oracle.php index 582b267ac3..0daddf76cb 100644 --- a/phpBB/includes/db/oracle.php +++ b/phpBB/includes/db/oracle.php @@ -55,10 +55,31 @@ class dbal_oracle extends dbal /** * Version information about used database + * @param bool $raw if true, only return the fetched sql_server_version + * @return string sql server version */ - function sql_server_info() + function sql_server_info($raw = false) { - return @ociserverversion($this->db_connect_id); +/* + global $cache; + + if (empty($cache) || ($this->sql_server_version = $cache->get('oracle_version')) === false) + { + $result = @ociparse($this->db_connect_id, 'SELECT * FROM v$version WHERE banner LIKE \'Oracle%\''); + @ociexecute($result, OCI_DEFAULT); + @ocicommit($this->db_connect_id); + + $row = array(); + @ocifetchinto($result, $row, OCI_ASSOC + OCI_RETURN_NULLS); + @ocifreestatement($result); + $this->sql_server_version = trim($row['BANNER']); + + $cache->put('oracle_version', $this->sql_server_version); + } +*/ + $this->sql_server_version = @ociserverversion($this->db_connect_id); + + return $this->sql_server_version; } /** diff --git a/phpBB/includes/db/postgres.php b/phpBB/includes/db/postgres.php index d6dddb5996..83678e2904 100644 --- a/phpBB/includes/db/postgres.php +++ b/phpBB/includes/db/postgres.php @@ -26,7 +26,6 @@ include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx); class dbal_postgres extends dbal { var $last_query_text = ''; - var $pgsql_version; /** * Connect to server @@ -81,24 +80,7 @@ class dbal_postgres extends dbal if ($this->db_connect_id) { - // determine what version of PostgreSQL is running, we can be more efficient if they are running 8.2+ - if (version_compare(PHP_VERSION, '5.0.0', '>=')) - { - $this->pgsql_version = @pg_parameter_status($this->db_connect_id, 'server_version'); - } - else - { - $query_id = @pg_query($this->db_connect_id, 'SELECT VERSION()'); - $row = @pg_fetch_assoc($query_id, null); - @pg_free_result($query_id); - - if (!empty($row['version'])) - { - $this->pgsql_version = substr($row['version'], 10); - } - } - - if (!empty($this->pgsql_version) && $this->pgsql_version[0] >= '8' && $this->pgsql_version[2] >= '2') + if (version_compare($this->sql_server_info(true), '8.2', '>=')) { $this->multi_insert = true; } @@ -115,10 +97,28 @@ class dbal_postgres extends dbal /** * Version information about used database + * @param bool $raw if true, only return the fetched sql_server_version + * @return string sql server version */ - function sql_server_info() + function sql_server_info($raw = false) { - return 'PostgreSQL ' . $this->pgsql_version; + global $cache; + + if (empty($cache) || ($this->sql_server_version = $cache->get('pgsql_version')) === false) + { + $query_id = @pg_query($this->db_connect_id, 'SELECT VERSION() AS version'); + $row = @pg_fetch_assoc($query_id, null); + @pg_free_result($query_id); + + $this->sql_server_version = (!empty($row['version'])) ? trim(substr($row['version'], 10)) : 0; + + if (!empty($cache)) + { + $cache->put('pgsql_version', $this->sql_server_version); + } + } + + return ($raw) ? $this->sql_server_version : 'PostgreSQL ' . $this->sql_server_version; } /** diff --git a/phpBB/includes/db/sqlite.php b/phpBB/includes/db/sqlite.php index fae9ba3f92..288f6e0992 100644 --- a/phpBB/includes/db/sqlite.php +++ b/phpBB/includes/db/sqlite.php @@ -41,18 +41,31 @@ class dbal_sqlite extends dbal if ($this->db_connect_id) { @sqlite_query('PRAGMA short_column_names = 1', $this->db_connect_id); +// @sqlite_query('PRAGMA encoding = "UTF-8"', $this->db_connect_id); } - return ($this->db_connect_id) ? true : array('message' => $error); } /** * Version information about used database + * @param bool $raw if true, only return the fetched sql_server_version + * @return string sql server version */ - function sql_server_info() + function sql_server_info($raw = false) { - return 'SQLite ' . @sqlite_libversion(); + global $cache; + + if (empty($cache) || ($this->sql_server_version = $cache->get('sqlite_version')) === false) + { + $result = @sqlite_query('SELECT sqlite_version() AS version', $this->db_connect_id); + $row = @sqlite_fetch_array($result, SQLITE_ASSOC); + + $this->sql_server_version = (!empty($row['version'])) ? $row['version'] : 0; + $cache->put('sqlite_version', $this->sql_server_version); + } + + return ($raw) ? $this->sql_server_version : 'SQLite ' . $this->sql_server_version; } /** diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index 78ec47377a..9e89926e1a 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -2616,7 +2616,7 @@ function update_foes($group_id = false, $user_id = false) { case 'mysqli': case 'mysql4': - $sql = 'DELETE ' . (($db->sql_layer === 'mysqli' || version_compare($db->mysql_version, '4.1', '>=')) ? 'z.*' : ZEBRA_TABLE) . ' + $sql = 'DELETE ' . (($db->sql_layer === 'mysqli' || version_compare($db->sql_server_info(true), '4.1', '>=')) ? 'z.*' : ZEBRA_TABLE) . ' FROM ' . ZEBRA_TABLE . ' z, ' . USER_GROUP_TABLE . ' ug WHERE z.zebra_id = ug.user_id AND z.foe = 1 diff --git a/phpBB/includes/search/fulltext_mysql.php b/phpBB/includes/search/fulltext_mysql.php index 80724fb5c5..2a67b58246 100644 --- a/phpBB/includes/search/fulltext_mysql.php +++ b/phpBB/includes/search/fulltext_mysql.php @@ -704,7 +704,7 @@ class fulltext_mysql extends search_backend if (!isset($this->stats['post_subject'])) { - if ($db->sql_layer == 'mysqli' || version_compare($db->mysql_version, '4.1.3', '>=')) + if ($db->sql_layer == 'mysqli' || version_compare($db->sql_server_info(true), '4.1.3', '>=')) { //$alter[] = 'MODIFY post_subject varchar(100) COLLATE utf8_unicode_ci DEFAULT \'\' NOT NULL'; } @@ -717,7 +717,7 @@ class fulltext_mysql extends search_backend if (!isset($this->stats['post_text'])) { - if ($db->sql_layer == 'mysqli' || version_compare($db->mysql_version, '4.1.3', '>=')) + if ($db->sql_layer == 'mysqli' || version_compare($db->sql_server_info(true), '4.1.3', '>=')) { $alter[] = 'MODIFY post_text mediumtext COLLATE utf8_unicode_ci NOT NULL'; } diff --git a/phpBB/install/convertors/functions_phpbb20.php b/phpBB/install/convertors/functions_phpbb20.php index c69574c565..8de647e4db 100644 --- a/phpBB/install/convertors/functions_phpbb20.php +++ b/phpBB/install/convertors/functions_phpbb20.php @@ -1710,7 +1710,7 @@ function phpbb_check_username_collisions() break; case 'mysql4': - if (version_compare($db->mysql_version, '4.1.3', '>=')) + if (version_compare($db->sql_server_info(true), '4.1.3', '>=')) { $map_dbms = 'mysql_41'; } diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 53d22462c0..c9ced1dbcb 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -552,7 +552,7 @@ switch ($db->sql_layer) break; case 'mysql4': - if (version_compare($db->mysql_version, '4.1.3', '>=')) + if (version_compare($db->sql_server_info(true), '4.1.3', '>=')) { $map_dbms = 'mysql_41'; } @@ -1837,6 +1837,9 @@ function change_database_data(&$no_updates, $version) set_config('enable_queue_trigger', '0'); set_config('queue_trigger_posts', '3'); + // Not prefilling yet + set_config('dbms_version', ''); + // Resync post counts $sql = 'SELECT COUNT(p.post_id) AS num_posts, u.user_id FROM ' . USERS_TABLE . ' u diff --git a/phpBB/install/install_convert.php b/phpBB/install/install_convert.php index 25d8551df4..7a4155e09d 100644 --- a/phpBB/install/install_convert.php +++ b/phpBB/install/install_convert.php @@ -685,7 +685,7 @@ class install_convert extends module // Thanks MySQL, for silently converting... case 'mysql': case 'mysql4': - if (version_compare($src_db->mysql_version, '4.1.3', '>=')) + if (version_compare($src_db->sql_server_info(true), '4.1.3', '>=')) { $convert->mysql_convert = true; } diff --git a/phpBB/install/install_install.php b/phpBB/install/install_install.php index cfa74fba03..991d1d02a6 100644 --- a/phpBB/install/install_install.php +++ b/phpBB/install/install_install.php @@ -1157,7 +1157,7 @@ class install_install extends module // If mysql is chosen, we need to adjust the schema filename slightly to reflect the correct version. ;) if ($data['dbms'] == 'mysql') { - if (version_compare($db->mysql_version, '4.1.3', '>=')) + if (version_compare($db->sql_server_info(true), '4.1.3', '>=')) { $available_dbms[$data['dbms']]['SCHEMA'] .= '_41'; } @@ -1363,6 +1363,10 @@ class install_install extends module 'UPDATE ' . $data['table_prefix'] . "forums SET forum_last_post_time = $current_time", + + 'UPDATE ' . $data['table_prefix'] . "config + SET config_value = '" . $db->sql_escape($db->sql_server_info(true)) . "' + WHERE config_name = 'dbms_version'", ); if (@extension_loaded('gd') || can_load_dll('gd')) diff --git a/phpBB/install/schemas/schema_data.sql b/phpBB/install/schemas/schema_data.sql index 422a5b0bda..a4dcb508eb 100644 --- a/phpBB/install/schemas/schema_data.sql +++ b/phpBB/install/schemas/schema_data.sql @@ -75,6 +75,7 @@ INSERT INTO phpbb_config (config_name, config_value) VALUES ('coppa_enable', '0' INSERT INTO phpbb_config (config_name, config_value) VALUES ('coppa_fax', ''); INSERT INTO phpbb_config (config_name, config_value) VALUES ('coppa_mail', ''); INSERT INTO phpbb_config (config_name, config_value) VALUES ('database_gc', '604800'); +INSERT INTO phpbb_config (config_name, config_value) VALUES ('dbms_version', ''); INSERT INTO phpbb_config (config_name, config_value) VALUES ('default_dateformat', 'D M d, Y g:i a'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('default_style', '1'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('display_last_edited', '1'); |