aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/db
diff options
context:
space:
mode:
authorMeik Sievertsen <acydburn@phpbb.com>2008-09-04 12:01:47 +0000
committerMeik Sievertsen <acydburn@phpbb.com>2008-09-04 12:01:47 +0000
commit2fcd96ca72741bdfb36c24a0af9dd8230b5a828f (patch)
treeaf6068957c73f64d5885311396c1d7730aa30b3c /phpBB/includes/db
parent4a225280a0fe1b7c364a007eb43dc93975c544e9 (diff)
downloadforums-2fcd96ca72741bdfb36c24a0af9dd8230b5a828f.tar
forums-2fcd96ca72741bdfb36c24a0af9dd8230b5a828f.tar.gz
forums-2fcd96ca72741bdfb36c24a0af9dd8230b5a828f.tar.bz2
forums-2fcd96ca72741bdfb36c24a0af9dd8230b5a828f.tar.xz
forums-2fcd96ca72741bdfb36c24a0af9dd8230b5a828f.zip
Ok, story real database server info, as well as caching it
Store it on installation too - allows us to check the db version used on installation and used currently to warn the user about incompatibilities git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@8814 89ea8834-ac86-4346-8a33-228a782c2dd0
Diffstat (limited to 'phpBB/includes/db')
-rw-r--r--phpBB/includes/db/db_tools.php2
-rw-r--r--phpBB/includes/db/dbal.php5
-rw-r--r--phpBB/includes/db/firebird.php26
-rw-r--r--phpBB/includes/db/mssql.php32
-rw-r--r--phpBB/includes/db/mssql_odbc.php32
-rw-r--r--phpBB/includes/db/mysql.php40
-rw-r--r--phpBB/includes/db/mysqli.php26
-rw-r--r--phpBB/includes/db/oracle.php25
-rw-r--r--phpBB/includes/db/postgres.php42
-rw-r--r--phpBB/includes/db/sqlite.php19
10 files changed, 183 insertions, 66 deletions
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;
}
/**