aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/db
diff options
context:
space:
mode:
authorNils Adermann <naderman@naderman.de>2010-03-02 01:05:34 +0100
committerNils Adermann <naderman@naderman.de>2010-03-02 01:05:34 +0100
commit517f25353246f06eec7d1fdef90a04119a45bbbf (patch)
tree7837b0e54fcd05f2f49a22a078b0f12cad864b30 /phpBB/includes/db
parent89b37954f994a7cd517553d2d16686f91dcaae72 (diff)
parent7068d8b462e388ea87883c5203a28fa6a8e4b6dc (diff)
downloadforums-517f25353246f06eec7d1fdef90a04119a45bbbf.tar
forums-517f25353246f06eec7d1fdef90a04119a45bbbf.tar.gz
forums-517f25353246f06eec7d1fdef90a04119a45bbbf.tar.bz2
forums-517f25353246f06eec7d1fdef90a04119a45bbbf.tar.xz
forums-517f25353246f06eec7d1fdef90a04119a45bbbf.zip
Merge commit 'release-3.0-B5'
Diffstat (limited to 'phpBB/includes/db')
-rw-r--r--phpBB/includes/db/dbal.php60
-rw-r--r--phpBB/includes/db/firebird.php32
-rw-r--r--phpBB/includes/db/mssql.php45
-rw-r--r--phpBB/includes/db/mssql_odbc.php43
-rw-r--r--phpBB/includes/db/mysql.php27
-rw-r--r--phpBB/includes/db/mysqli.php27
-rw-r--r--phpBB/includes/db/oracle.php17
-rw-r--r--phpBB/includes/db/postgres.php27
-rw-r--r--phpBB/includes/db/sqlite.php25
9 files changed, 155 insertions, 148 deletions
diff --git a/phpBB/includes/db/dbal.php b/phpBB/includes/db/dbal.php
index da5efcf55a..da649ed812 100644
--- a/phpBB/includes/db/dbal.php
+++ b/phpBB/includes/db/dbal.php
@@ -115,6 +115,24 @@ class dbal
}
/**
+ * Build LIMIT query
+ * Doing some validation here.
+ */
+ function sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0)
+ {
+ if (empty($query))
+ {
+ return false;
+ }
+
+ // Never use a negative total or offset
+ $total = ($total < 0) ? 0 : $total;
+ $offset = ($offset < 0) ? 0 : $offset;
+
+ return $this->_sql_query_limit($query, $total, $offset, $cache_ttl);
+ }
+
+ /**
* Fetch all rows
*/
function sql_fetchrowset($query_id = false)
@@ -282,15 +300,36 @@ class dbal
}
/**
- * Build IN, NOT IN, = and <> sql comparison string.
+ * Build IN or NOT IN sql comparison string, uses <> or = on single element
+ * arrays to improve comparison speed
* @access public
+ * @param string $field name of the sql column that shall be compared
+ * @param array $array array of values that are allowed (IN) or not allowed (NOT IN)
+ * @param bool $negate true for IN (), false for NOT IN ()
+ * @param bool $allow_empty_set Allow $array to be empty, this function will return 1=1 or 1=0 then
*/
- function sql_in_set($field, $array, $negate = false)
+ function sql_in_set($field, $array, $negate = false, $allow_empty_set = false)
{
if (!sizeof($array))
{
- // Not optimal, but at least the backtrace should help in identifying where the problem lies.
- $this->sql_error('No values specified for SQL IN comparison');
+ if (!$allow_empty_set)
+ {
+ // Print the backtrace to help identifying the location of the problematic code
+ $this->sql_error('No values specified for SQL IN comparison');
+ }
+ else
+ {
+ // NOT IN () actually means everything so use a tautology
+ if ($negate)
+ {
+ return '1=1';
+ }
+ // IN () actually means nothing so use a contradiction
+ else
+ {
+ return '1=0';
+ }
+ }
}
if (!is_array($array))
@@ -438,7 +477,7 @@ class dbal
*/
function sql_error($sql = '')
{
- global $auth, $user;
+ global $auth, $user, $config;
// Set var to retrieve errored status
$this->sql_error_triggered = true;
@@ -459,7 +498,7 @@ class dbal
$backtrace = get_backtrace();
$message .= ($sql) ? '<br /><br /><u>SQL</u><br /><br />' . htmlspecialchars($sql) : '';
- $message .= ($backtrace) ? '<br /><br /><u>BACKTRACE</u><br />' . $backtrace : '';
+ $message .= ($backtrace) ? '<br /><br /><u>BACKTRACE</u><br />' . $backtrace : '';
$message .= '<br />';
}
else
@@ -472,7 +511,14 @@ class dbal
}
else
{
- $message .= '<br /><br />' . $user->lang['SQL_ERROR_OCCURRED'];
+ if (!empty($config['board_contact']))
+ {
+ $message .= '<br /><br />' . sprintf($user->lang['SQL_ERROR_OCCURRED'], '<a href="mailto:' . htmlspecialchars($config['board_contact']) . '">', '</a>');
+ }
+ else
+ {
+ $message .= '<br /><br />' . sprintf($user->lang['SQL_ERROR_OCCURRED'], '', '');
+ }
}
}
diff --git a/phpBB/includes/db/firebird.php b/phpBB/includes/db/firebird.php
index 7fd034c7dc..5ce4949956 100644
--- a/phpBB/includes/db/firebird.php
+++ b/phpBB/includes/db/firebird.php
@@ -97,6 +97,12 @@ class dbal_firebird extends dbal
{
global $cache;
+ // EXPLAIN only in extra debug mode
+ if (defined('DEBUG_EXTRA'))
+ {
+ $this->sql_report('start', $query);
+ }
+
$this->last_query_text = $query;
$this->query_result = ($cache_ttl && method_exists($cache, 'sql_load')) ? $cache->sql_load($query) : false;
$this->sql_add_num_queries($this->query_result);
@@ -108,6 +114,11 @@ class dbal_firebird extends dbal
$this->sql_error($query);
}
+ if (defined('DEBUG_EXTRA'))
+ {
+ $this->sql_report('stop', $query);
+ }
+
if (!$this->transaction)
{
if (function_exists('ibase_commit_ret'))
@@ -131,6 +142,10 @@ class dbal_firebird extends dbal
$this->open_queries[(int) $this->query_result] = $this->query_result;
}
}
+ else if (defined('DEBUG_EXTRA'))
+ {
+ $this->sql_report('fromcache', $query);
+ }
}
else
{
@@ -143,20 +158,13 @@ class dbal_firebird extends dbal
/**
* Build LIMIT query
*/
- function sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0)
+ function _sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0)
{
- if ($query != '')
- {
- $this->query_result = false;
+ $this->query_result = false;
- $query = 'SELECT FIRST ' . $total . ((!empty($offset)) ? ' SKIP ' . $offset : '') . substr($query, 6);
+ $query = 'SELECT FIRST ' . $total . ((!empty($offset)) ? ' SKIP ' . $offset : '') . substr($query, 6);
- return $this->sql_query($query, $cache_ttl);
- }
- else
- {
- return false;
- }
+ return $this->sql_query($query, $cache_ttl);
}
/**
@@ -269,7 +277,7 @@ class dbal_firebird extends dbal
{
$sql = "SELECT GEN_ID(" . $tablename[1] . "_gen, 0) AS new_id FROM RDB\$DATABASE";
- if (!($temp_q_id = @ibase_query($this->db_connect_id, $sql)))
+ if (!($temp_q_id = @ibase_query($this->db_connect_id, $sql)))
{
return false;
}
diff --git a/phpBB/includes/db/mssql.php b/phpBB/includes/db/mssql.php
index 439cb725fb..b28ea01acb 100644
--- a/phpBB/includes/db/mssql.php
+++ b/phpBB/includes/db/mssql.php
@@ -35,6 +35,8 @@ class dbal_mssql extends dbal
$this->server = $sqlserver . (($port) ? ':' . $port : '');
$this->dbname = $database;
+ ini_set('mssql.charset', 'UTF-8');
+
$this->db_connect_id = ($this->persistency) ? @mssql_pconnect($this->server, $this->user, $sqlpassword) : @mssql_connect($this->server, $this->user, $sqlpassword);
if ($this->db_connect_id && $this->dbname != '')
@@ -157,40 +159,33 @@ class dbal_mssql extends dbal
/**
* Build LIMIT query
*/
- function sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0)
+ function _sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0)
{
- if ($query != '')
- {
- $this->query_result = false;
+ $this->query_result = false;
- // Since TOP is only returning a set number of rows we won't need it if total is set to 0 (return all rows)
- if ($total)
+ // Since TOP is only returning a set number of rows we won't need it if total is set to 0 (return all rows)
+ if ($total)
+ {
+ // We need to grab the total number of rows + the offset number of rows to get the correct result
+ if (strpos($query, 'SELECT DISTINCT') === 0)
{
- // We need to grab the total number of rows + the offset number of rows to get the correct result
- if (strpos($query, 'SELECT DISTINCT') === 0)
- {
- $query = 'SELECT DISTINCT TOP ' . ($total + $offset) . ' ' . substr($query, 15);
- }
- else
- {
- $query = 'SELECT TOP ' . ($total + $offset) . ' ' . substr($query, 6);
- }
+ $query = 'SELECT DISTINCT TOP ' . ($total + $offset) . ' ' . substr($query, 15);
}
-
- $result = $this->sql_query($query, $cache_ttl);
-
- // Seek by $offset rows
- if ($offset)
+ else
{
- $this->sql_rowseek($offset, $result);
+ $query = 'SELECT TOP ' . ($total + $offset) . ' ' . substr($query, 6);
}
-
- return $result;
}
- else
+
+ $result = $this->sql_query($query, $cache_ttl);
+
+ // Seek by $offset rows
+ if ($offset)
{
- return false;
+ $this->sql_rowseek($offset, $result);
}
+
+ return $result;
}
/**
diff --git a/phpBB/includes/db/mssql_odbc.php b/phpBB/includes/db/mssql_odbc.php
index 2cb3bf0f2d..0b8f1e2a95 100644
--- a/phpBB/includes/db/mssql_odbc.php
+++ b/phpBB/includes/db/mssql_odbc.php
@@ -156,40 +156,33 @@ class dbal_mssql_odbc extends dbal
/**
* Build LIMIT query
*/
- function sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0)
+ function _sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0)
{
- if ($query != '')
- {
- $this->query_result = false;
+ $this->query_result = false;
- // Since TOP is only returning a set number of rows we won't need it if total is set to 0 (return all rows)
- if ($total)
+ // Since TOP is only returning a set number of rows we won't need it if total is set to 0 (return all rows)
+ if ($total)
+ {
+ // We need to grab the total number of rows + the offset number of rows to get the correct result
+ if (strpos($query, 'SELECT DISTINCT') === 0)
{
- // We need to grab the total number of rows + the offset number of rows to get the correct result
- if (strpos($query, 'SELECT DISTINCT') === 0)
- {
- $query = 'SELECT DISTINCT TOP ' . ($total + $offset) . ' ' . substr($query, 15);
- }
- else
- {
- $query = 'SELECT TOP ' . ($total + $offset) . ' ' . substr($query, 6);
- }
+ $query = 'SELECT DISTINCT TOP ' . ($total + $offset) . ' ' . substr($query, 15);
}
-
- $result = $this->sql_query($query, $cache_ttl);
-
- // Seek by $offset rows
- if ($offset)
+ else
{
- $this->sql_rowseek($offset, $result);
+ $query = 'SELECT TOP ' . ($total + $offset) . ' ' . substr($query, 6);
}
-
- return $result;
}
- else
+
+ $result = $this->sql_query($query, $cache_ttl);
+
+ // Seek by $offset rows
+ if ($offset)
{
- return false;
+ $this->sql_rowseek($offset, $result);
}
+
+ return $result;
}
/**
diff --git a/phpBB/includes/db/mysql.php b/phpBB/includes/db/mysql.php
index 89a6e21d70..b750618ae6 100644
--- a/phpBB/includes/db/mysql.php
+++ b/phpBB/includes/db/mysql.php
@@ -163,27 +163,20 @@ class dbal_mysql extends dbal
/**
* Build LIMIT query
*/
- function sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0)
+ function _sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0)
{
- if ($query != '')
- {
- $this->query_result = false;
-
- // if $total is set to 0 we do not want to limit the number of rows
- if ($total == 0)
- {
- // Having a value of -1 was always a bug
- $total = '18446744073709551615';
- }
-
- $query .= "\n LIMIT " . ((!empty($offset)) ? $offset . ', ' . $total : $total);
+ $this->query_result = false;
- return $this->sql_query($query, $cache_ttl);
- }
- else
+ // if $total is set to 0 we do not want to limit the number of rows
+ if ($total == 0)
{
- return false;
+ // Having a value of -1 was always a bug
+ $total = '18446744073709551615';
}
+
+ $query .= "\n LIMIT " . ((!empty($offset)) ? $offset . ', ' . $total : $total);
+
+ return $this->sql_query($query, $cache_ttl);
}
/**
diff --git a/phpBB/includes/db/mysqli.php b/phpBB/includes/db/mysqli.php
index 86700744fb..da6faa3983 100644
--- a/phpBB/includes/db/mysqli.php
+++ b/phpBB/includes/db/mysqli.php
@@ -142,27 +142,20 @@ class dbal_mysqli extends dbal
/**
* Build LIMIT query
*/
- function sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0)
+ function _sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0)
{
- if ($query != '')
- {
- $this->query_result = false;
-
- // if $total is set to 0 we do not want to limit the number of rows
- if ($total == 0)
- {
- // MySQL 4.1+ no longer supports -1 in limit queries
- $total = '18446744073709551615';
- }
-
- $query .= "\n LIMIT " . ((!empty($offset)) ? $offset . ', ' . $total : $total);
+ $this->query_result = false;
- return $this->sql_query($query, $cache_ttl);
- }
- else
+ // if $total is set to 0 we do not want to limit the number of rows
+ if ($total == 0)
{
- return false;
+ // MySQL 4.1+ no longer supports -1 in limit queries
+ $total = '18446744073709551615';
}
+
+ $query .= "\n LIMIT " . ((!empty($offset)) ? $offset . ', ' . $total : $total);
+
+ return $this->sql_query($query, $cache_ttl);
}
/**
diff --git a/phpBB/includes/db/oracle.php b/phpBB/includes/db/oracle.php
index 8f65c667a7..860c7a3614 100644
--- a/phpBB/includes/db/oracle.php
+++ b/phpBB/includes/db/oracle.php
@@ -46,7 +46,7 @@ class dbal_oracle extends dbal
*/
function sql_server_info()
{
- return 'Oracle ' . @ociserverversion($this->db_connect_id);
+ return @ociserverversion($this->db_connect_id);
}
/**
@@ -213,20 +213,13 @@ class dbal_oracle extends dbal
/**
* Build LIMIT query
*/
- function sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0)
+ function _sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0)
{
- if ($query != '')
- {
- $this->query_result = false;
+ $this->query_result = false;
- $query = 'SELECT * FROM (SELECT /*+ FIRST_ROWS */ rownum AS xrownum, a.* FROM (' . $query . ') a WHERE rownum <= ' . ($offset + $total) . ') WHERE xrownum >= ' . $offset;
+ $query = 'SELECT * FROM (SELECT /*+ FIRST_ROWS */ rownum AS xrownum, a.* FROM (' . $query . ') a WHERE rownum <= ' . ($offset + $total) . ') WHERE xrownum >= ' . $offset;
- return $this->sql_query($query, $cache_ttl);
- }
- else
- {
- return false;
- }
+ return $this->sql_query($query, $cache_ttl);
}
/**
diff --git a/phpBB/includes/db/postgres.php b/phpBB/includes/db/postgres.php
index c06786a795..f2e96260ba 100644
--- a/phpBB/includes/db/postgres.php
+++ b/phpBB/includes/db/postgres.php
@@ -192,26 +192,19 @@ class dbal_postgres extends dbal
/**
* Build LIMIT query
*/
- function sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0)
+ function _sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0)
{
- if ($query != '')
- {
- $this->query_result = false;
-
- // if $total is set to 0 we do not want to limit the number of rows
- if ($total == 0)
- {
- $total = -1;
- }
+ $this->query_result = false;
- $query .= "\n LIMIT $total OFFSET $offset";
-
- return $this->sql_query($query, $cache_ttl);
- }
- else
+ // if $total is set to 0 we do not want to limit the number of rows
+ if ($total == 0)
{
- return false;
+ $total = -1;
}
+
+ $query .= "\n LIMIT $total OFFSET $offset";
+
+ return $this->sql_query($query, $cache_ttl);
}
/**
@@ -275,7 +268,7 @@ class dbal_postgres extends dbal
if (preg_match("/^INSERT[\t\n ]+INTO[\t\n ]+([a-z0-9\_\-]+)/is", $this->last_query_text, $tablename))
{
$query = "SELECT currval('" . $tablename[1] . "_seq') AS last_value";
- $temp_q_id = @pg_query($this->db_connect_id, $query);
+ $temp_q_id = @pg_query($this->db_connect_id, $query);
if (!$temp_q_id)
{
diff --git a/phpBB/includes/db/sqlite.php b/phpBB/includes/db/sqlite.php
index 708376881c..9f44bd6b35 100644
--- a/phpBB/includes/db/sqlite.php
+++ b/phpBB/includes/db/sqlite.php
@@ -141,26 +141,19 @@ class dbal_sqlite extends dbal
/**
* Build LIMIT query
*/
- function sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0)
+ function _sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0)
{
- if ($query != '')
- {
- $this->query_result = false;
-
- // if $total is set to 0 we do not want to limit the number of rows
- if ($total == 0)
- {
- $total = -1;
- }
-
- $query .= "\n LIMIT " . ((!empty($offset)) ? $offset . ', ' . $total : $total);
+ $this->query_result = false;
- return $this->sql_query($query, $cache_ttl);
- }
- else
+ // if $total is set to 0 we do not want to limit the number of rows
+ if ($total == 0)
{
- return false;
+ $total = -1;
}
+
+ $query .= "\n LIMIT " . ((!empty($offset)) ? $offset . ', ' . $total : $total);
+
+ return $this->sql_query($query, $cache_ttl);
}
/**