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
commit07633a66e8c9bbb2b288a286bfbea6f562eeca4d (patch)
treea255efa70ed6f202542649148c0445445504d181 /phpBB/includes/db
parentee82970d96e0a6772b24c48aab8ebd1888ec5216 (diff)
parent5cfa0ec0c32ddc424f9651d8766db3e4ced59f96 (diff)
downloadforums-07633a66e8c9bbb2b288a286bfbea6f562eeca4d.tar
forums-07633a66e8c9bbb2b288a286bfbea6f562eeca4d.tar.gz
forums-07633a66e8c9bbb2b288a286bfbea6f562eeca4d.tar.bz2
forums-07633a66e8c9bbb2b288a286bfbea6f562eeca4d.tar.xz
forums-07633a66e8c9bbb2b288a286bfbea6f562eeca4d.zip
Merge commit 'release-3.0-B3'
Diffstat (limited to 'phpBB/includes/db')
-rw-r--r--phpBB/includes/db/dbal.php125
-rw-r--r--phpBB/includes/db/firebird.php111
-rw-r--r--phpBB/includes/db/mssql.php128
-rw-r--r--phpBB/includes/db/mssql_odbc.php133
-rw-r--r--phpBB/includes/db/mysql.php133
-rw-r--r--phpBB/includes/db/mysql4.php443
-rw-r--r--phpBB/includes/db/mysqli.php95
-rw-r--r--phpBB/includes/db/oracle.php180
-rw-r--r--phpBB/includes/db/postgres.php134
-rw-r--r--phpBB/includes/db/sqlite.php91
10 files changed, 404 insertions, 1169 deletions
diff --git a/phpBB/includes/db/dbal.php b/phpBB/includes/db/dbal.php
index f774b5dcc3..d2d3efedaa 100644
--- a/phpBB/includes/db/dbal.php
+++ b/phpBB/includes/db/dbal.php
@@ -39,6 +39,11 @@ class dbal
var $sql_error_sql = '';
/**
+ * Current sql layer
+ */
+ var $sql_layer = '';
+
+ /**
* Constructor
*/
function dbal()
@@ -48,6 +53,10 @@ class dbal
'normal' => 0,
'total' => 0,
);
+
+ // Fill default sql layer based on the class being called.
+ // This can be changed by the specified layer itself later if needed.
+ $this->sql_layer = substr(get_class($this), 5);
}
/**
@@ -110,12 +119,12 @@ class dbal
*/
function sql_fetchrowset($query_id = false)
{
- if (!$query_id)
+ if ($query_id === false)
{
$query_id = $this->query_result;
}
- if ($query_id)
+ if ($query_id !== false)
{
$result = array();
while ($row = $this->sql_fetchrow($query_id))
@@ -130,8 +139,40 @@ class dbal
}
/**
+ * Fetch field
+ * if rownum is false, the current row is used, else it is pointing to the row (zero-based)
+ */
+ function sql_fetchfield($field, $rownum = false, $query_id = false)
+ {
+ global $cache;
+
+ if ($query_id === false)
+ {
+ $query_id = $this->query_result;
+ }
+
+ if ($query_id !== false)
+ {
+ if ($rownum !== false)
+ {
+ $this->sql_rowseek($rownum, $query_id);
+ }
+
+ if (!is_object($query_id) && isset($cache->sql_rowset[$query_id]))
+ {
+ return $cache->sql_fetchfield($query_id, $field);
+ }
+
+ $row = $this->sql_fetchrow($query_id);
+ return (isset($row[$field])) ? $row[$field] : false;
+ }
+
+ return false;
+ }
+
+ /**
* SQL Transaction
- * @access: private
+ * @access private
*/
function sql_transaction($status = 'begin')
{
@@ -211,6 +252,12 @@ class dbal
$ary = array();
foreach ($assoc_ary as $id => $sql_ary)
{
+ // If by accident the sql array is only one-dimensional we build a normal insert statement
+ if (!is_array($sql_ary))
+ {
+ return $this->sql_build_array('INSERT', $assoc_ary);
+ }
+
$values = array();
foreach ($sql_ary as $key => $var)
{
@@ -234,27 +281,75 @@ class dbal
return $query;
}
+ /**
+ * Build IN, NOT IN, = and <> sql comparison string.
+ * @access public
+ */
function sql_in_set($field, $array, $negate = false)
{
if (!sizeof($array))
{
- trigger_error('No values specified for SQL IN comparison', E_USER_ERROR);
+ // 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');
}
- $values = array();
- foreach ($array as $var)
+ if (!is_array($array))
{
- $values[] = $this->_sql_validate_value($var);
+ $array = array($array);
}
- if (sizeof($values) == 1)
+ if (sizeof($array) == 1)
{
- return $field . ($negate ? ' <> ' : ' = ') . $values[0];
+ @reset($array);
+ $var = current($array);
+
+ return $field . ($negate ? ' <> ' : ' = ') . $this->_sql_validate_value($var);
}
else
{
- return $field . ($negate ? ' NOT IN ' : ' IN ' ) . '(' . implode(', ', $values) . ')';
+ return $field . ($negate ? ' NOT IN ' : ' IN ' ) . '(' . implode(', ', array_map(array($this, '_sql_validate_value'), $array)) . ')';
+ }
+ }
+
+ /**
+ * Run more than one insert statement.
+ *
+ * @param $sql_ary array multi-dimensional array holding the statement data.
+ * @param $table string table name to run the statements on
+ *
+ * @return bool false if no statements were executed.
+ * @access public
+ */
+ function sql_multi_insert($table, &$sql_ary)
+ {
+ if (!sizeof($sql_ary))
+ {
+ return false;
}
+
+ switch ($this->sql_layer)
+ {
+ case 'mysql':
+ case 'mysql4':
+ case 'mysqli':
+ case 'sqlite':
+ $this->sql_query('INSERT INTO ' . $table . ' ' . $this->sql_build_array('MULTI_INSERT', $sql_ary));
+ break;
+
+ default:
+ foreach ($sql_ary as $ary)
+ {
+ if (!is_array($ary))
+ {
+ return false;
+ }
+
+ $this->sql_query('INSERT INTO ' . $table . ' ' . $this->sql_build_array('INSERT', $ary));
+ }
+ break;
+ }
+
+ return true;
}
/**
@@ -354,7 +449,7 @@ class dbal
if (!$this->return_on_error)
{
- $message = '<u>SQL ERROR</u> [ ' . SQL_LAYER . ' ]<br /><br />' . $error['message'] . ' [' . $error['code'] . ']';
+ $message = '<u>SQL ERROR</u> [ ' . $this->sql_layer . ' ]<br /><br />' . $error['message'] . ' [' . $error['code'] . ']';
// Show complete SQL error and path to administrators only
// Additionally show complete error on installation or if extended debug mode is enabled
@@ -364,7 +459,7 @@ class dbal
// Print out a nice backtrace...
$backtrace = get_backtrace();
- $message .= ($sql) ? '<br /><br /><u>SQL</u><br /><br />' . $sql : '';
+ $message .= ($sql) ? '<br /><br /><u>SQL</u><br /><br />' . htmlspecialchars($sql) : '';
$message .= ($backtrace) ? '<br /><br /><u>BACKTRACE</u><br />' . $backtrace : '';
$message .= '<br />';
}
@@ -409,7 +504,7 @@ class dbal
{
global $cache, $starttime, $phpbb_root_path, $user;
- if (empty($_GET['explain']))
+ if (empty($_REQUEST['explain']))
{
return false;
}
@@ -453,7 +548,7 @@ class dbal
<br />
<p><b>Page generated in ' . round($totaltime, 4) . " seconds with {$this->num_queries['normal']} queries" . (($this->num_queries['cached']) ? " + {$this->num_queries['cached']} " . (($this->num_queries['cached'] == 1) ? 'query' : 'queries') . ' returning data from cache' : '') . '</b></p>
- <p>Time spent on ' . SQL_LAYER . ' queries: <b>' . round($this->sql_time, 5) . 's</b> | Time spent on PHP: <b>' . round($totaltime - $this->sql_time, 5) . 's</b></p>
+ <p>Time spent on ' . $this->sql_layer . ' queries: <b>' . round($this->sql_time, 5) . 's</b> | Time spent on PHP: <b>' . round($totaltime - $this->sql_time, 5) . 's</b></p>
<br /><br />
' . $this->sql_report . '
@@ -504,7 +599,7 @@ class dbal
else
{
$error = $this->sql_error();
- $this->sql_report .= '<b style="color: red">FAILED</b> - ' . SQL_LAYER . ' Error ' . $error['code'] . ': ' . htmlspecialchars($error['message']);
+ $this->sql_report .= '<b style="color: red">FAILED</b> - ' . $this->sql_layer . ' Error ' . $error['code'] . ': ' . htmlspecialchars($error['message']);
}
$this->sql_report .= '</p><br /><br />';
diff --git a/phpBB/includes/db/firebird.php b/phpBB/includes/db/firebird.php
index 7ea5dd3612..7fd034c7dc 100644
--- a/phpBB/includes/db/firebird.php
+++ b/phpBB/includes/db/firebird.php
@@ -9,24 +9,18 @@
*/
/**
+* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
-/**
-* @ignore
-*/
-if (!defined('SQL_LAYER'))
-{
-
- define('SQL_LAYER', 'firebird');
- include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx);
+include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx);
/**
* Firebird/Interbase Database Abstraction Layer
-* Minimum Requirement is Firebird 1.5+/Interbase 7.1+
+* Minimum Requirement is Firebird 2.0
* @package dbal
*/
class dbal_firebird extends dbal
@@ -66,7 +60,7 @@ class dbal_firebird extends dbal
/**
* SQL Transaction
- * @access: private
+ * @access private
*/
function _sql_transaction($status = 'begin')
{
@@ -107,7 +101,7 @@ class dbal_firebird extends dbal
$this->query_result = ($cache_ttl && method_exists($cache, 'sql_load')) ? $cache->sql_load($query) : false;
$this->sql_add_num_queries($this->query_result);
- if (!$this->query_result)
+ if ($this->query_result === false)
{
if (($this->query_result = @ibase_query($this->db_connect_id, $query)) === false)
{
@@ -122,7 +116,8 @@ class dbal_firebird extends dbal
}
else
{
- @ibase_commit();
+ // way cooler than ibase_commit_ret :D
+ @ibase_query('COMMIT RETAIN;');
}
}
@@ -165,27 +160,6 @@ class dbal_firebird extends dbal
}
/**
- * Return number of rows
- * Not used within core code
- */
- function sql_numrows($query_id = false)
- {
- global $cache;
-
- if (!$query_id)
- {
- $query_id = $this->query_result;
- }
-
- if (isset($cache->sql_rowset[$query_id]))
- {
- return $cache->sql_numrows($query_id);
- }
-
- return false;
- }
-
- /**
* Return number of affected rows
*/
function sql_affectedrows()
@@ -208,7 +182,7 @@ class dbal_firebird extends dbal
{
global $cache;
- if (!$query_id)
+ if ($query_id === false)
{
$query_id = $this->query_result;
}
@@ -218,6 +192,11 @@ class dbal_firebird extends dbal
return $cache->sql_fetchrow($query_id);
}
+ if ($query_id === false)
+ {
+ return false;
+ }
+
$row = array();
$cur_row = @ibase_fetch_object($query_id, IBASE_TEXT);
@@ -228,60 +207,41 @@ class dbal_firebird extends dbal
foreach (get_object_vars($cur_row) as $key => $value)
{
- $row[strtolower($key)] = trim(str_replace("\\0", "\0", str_replace("\\n", "\n", $value)));
+ $row[strtolower($key)] = trim(str_replace(array("\\0", "\\n"), array("\0", "\n"), $value));
}
return (sizeof($row)) ? $row : false;
}
/**
- * Fetch field
- * if rownum is false, the current row is used, else it is pointing to the row (zero-based)
+ * Seek to given row number
+ * rownum is zero-based
*/
- function sql_fetchfield($field, $rownum = false, $query_id = false)
+ function sql_rowseek($rownum, $query_id = false)
{
global $cache;
- if (!$query_id)
+ if ($query_id === false)
{
$query_id = $this->query_result;
}
- if ($query_id)
+ if (isset($cache->sql_rowset[$query_id]))
{
- if ($rownum !== false)
- {
- $this->sql_rowseek($rownum, $query_id);
- }
-
- if (isset($cache->sql_rowset[$query_id]))
- {
- return $cache->sql_fetchfield($query_id, $field);
- }
-
- $row = $this->sql_fetchrow($query_id);
- return isset($row[$field]) ? $row[$field] : false;
+ return $cache->sql_rowseek($rownum, $query_id);
}
- return false;
- }
-
- /**
- * Seek to given row number
- * rownum is zero-based
- */
- function sql_rowseek($rownum, $query_id = false)
- {
- global $cache;
-
- if (!$query_id)
+ if ($query_id === false)
{
- $query_id = $this->query_result;
+ return;
}
- if (isset($cache->sql_rowset[$query_id]))
+ $this->sql_freeresult($query_id);
+ $query_id = $this->sql_query($this->last_query_text);
+
+ if ($query_id === false)
{
- return $cache->sql_rowseek($query_id, $rownum);
+ return false;
}
// We do not fetch the row for rownum == 0 because then the next resultset would be the second row
@@ -303,7 +263,7 @@ class dbal_firebird extends dbal
{
$query_id = $this->query_result;
- if ($query_id && $this->last_query_text != '')
+ if ($query_id !== false && $this->last_query_text != '')
{
if ($this->query_result && preg_match('#^INSERT[\t\n ]+INTO[\t\n ]+([a-z0-9\_\-]+)#is', $this->last_query_text, $tablename))
{
@@ -331,7 +291,7 @@ class dbal_firebird extends dbal
{
global $cache;
- if (!$query_id)
+ if ($query_id === false)
{
$query_id = $this->query_result;
}
@@ -355,12 +315,12 @@ class dbal_firebird extends dbal
*/
function sql_escape($msg)
{
- return (@ini_get('magic_quotes_sybase') || strtolower(@ini_get('magic_quotes_sybase')) == 'on') ? str_replace('\\\'', '\'', addslashes($msg)) : str_replace('\'', '\'\'', stripslashes($msg));
+ return (@ini_get('magic_quotes_sybase') == 1 || strtolower(@ini_get('magic_quotes_sybase')) == 'on') ? str_replace('\\\'', '\'', addslashes($msg)) : str_replace('\'', '\'\'', stripslashes($msg));
}
/**
* Build db-specific query data
- * @access: private
+ * @access private
*/
function _sql_custom_build($stage, $data)
{
@@ -369,7 +329,7 @@ class dbal_firebird extends dbal
/**
* return sql error array
- * @access: private
+ * @access private
*/
function _sql_error()
{
@@ -381,7 +341,7 @@ class dbal_firebird extends dbal
/**
* Close sql connection
- * @access: private
+ * @access private
*/
function _sql_close()
{
@@ -395,7 +355,7 @@ class dbal_firebird extends dbal
/**
* Build db-specific report
- * @access: private
+ * @access private
*/
function _sql_report($mode, $query = '')
{
@@ -423,9 +383,6 @@ class dbal_firebird extends dbal
break;
}
}
-
}
-} // if ... define
-
?> \ No newline at end of file
diff --git a/phpBB/includes/db/mssql.php b/phpBB/includes/db/mssql.php
index fe6cf75b12..f95f99969c 100644
--- a/phpBB/includes/db/mssql.php
+++ b/phpBB/includes/db/mssql.php
@@ -9,20 +9,14 @@
*/
/**
+* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
-/**
-* @ignore
-*/
-if (!defined('SQL_LAYER'))
-{
-
- define('SQL_LAYER', 'mssql');
- include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx);
+include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx);
/**
* MSSQL Database Abstraction Layer
@@ -79,7 +73,7 @@ class dbal_mssql extends dbal
/**
* SQL Transaction
- * @access: private
+ * @access private
*/
function _sql_transaction($status = 'begin')
{
@@ -122,10 +116,13 @@ class dbal_mssql extends dbal
$this->sql_report('start', $query);
}
+ // For now, MSSQL has no real UTF-8 support
+ $query = utf8_decode($query);
+
$this->query_result = ($cache_ttl && method_exists($cache, 'sql_load')) ? $cache->sql_load($query) : false;
$this->sql_add_num_queries($this->query_result);
- if (!$this->query_result)
+ if ($this->query_result === false)
{
if (($this->query_result = @mssql_query($query, $this->db_connect_id)) === false)
{
@@ -169,30 +166,26 @@ class dbal_mssql extends dbal
{
$this->query_result = false;
- // if $total is set to 0 we do not want to limit the number of rows
- if ($total == 0)
+ // 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)
{
- $total = -1;
- }
-
- $row_offset = ($total) ? $offset : '';
- $num_rows = ($total) ? $total : $offset;
-
- if (strpos($query, 'SELECT DISTINCT') === 0)
- {
- $query = 'SELECT DISTINCT TOP ' . ($row_offset + $num_rows) . ' ' . substr($query, 15);
- }
- else
- {
- $query = 'SELECT TOP ' . ($row_offset + $num_rows) . ' ' . substr($query, 6);
+ // We need to grab the total number of rows + the offset number of rows to get the correct result
+ if (strpos($query, 'SELECT DISTINCT') === 0)
+ {
+ $query = 'SELECT DISTINCT TOP ' . ($total + $offset) . ' ' . substr($query, 15);
+ }
+ else
+ {
+ $query = 'SELECT TOP ' . ($total + $offset) . ' ' . substr($query, 6);
+ }
}
$result = $this->sql_query($query, $cache_ttl);
- // Seek by $row_offset rows
- if ($row_offset)
+ // Seek by $offset rows
+ if ($offset)
{
- $this->sql_rowseek($result, $row_offset);
+ $this->sql_rowseek($offset, $result);
}
return $result;
@@ -204,27 +197,6 @@ class dbal_mssql extends dbal
}
/**
- * Return number of rows
- * Not used within core code
- */
- function sql_numrows($query_id = false)
- {
- global $cache;
-
- if (!$query_id)
- {
- $query_id = $this->query_result;
- }
-
- if (isset($cache->sql_rowset[$query_id]))
- {
- return $cache->sql_numrows($query_id);
- }
-
- return ($query_id) ? @mssql_num_rows($query_id) : false;
- }
-
- /**
* Return number of affected rows
*/
function sql_affectedrows()
@@ -239,7 +211,7 @@ class dbal_mssql extends dbal
{
global $cache;
- if (!$query_id)
+ if ($query_id === false)
{
$query_id = $this->query_result;
}
@@ -249,6 +221,11 @@ class dbal_mssql extends dbal
return $cache->sql_fetchrow($query_id);
}
+ if ($query_id === false)
+ {
+ return false;
+ }
+
$row = @mssql_fetch_assoc($query_id);
// I hope i am able to remove this later... hopefully only a PHP or MSSQL bug
@@ -264,38 +241,6 @@ class dbal_mssql extends dbal
}
/**
- * Fetch field
- * if rownum is false, the current row is used, else it is pointing to the row (zero-based)
- */
- function sql_fetchfield($field, $rownum = false, $query_id = false)
- {
- global $cache;
-
- if (!$query_id)
- {
- $query_id = $this->query_result;
- }
-
- if ($query_id)
- {
- if ($rownum !== false)
- {
- $this->sql_rowseek($rownum, $query_id);
- }
-
- if (isset($cache->sql_rowset[$query_id]))
- {
- return $cache->sql_fetchfield($query_id, $field);
- }
-
- $row = $this->sql_fetchrow($query_id);
- return isset($row[$field]) ? $row[$field] : false;
- }
-
- return false;
- }
-
- /**
* Seek to given row number
* rownum is zero-based
*/
@@ -303,17 +248,17 @@ class dbal_mssql extends dbal
{
global $cache;
- if (!$query_id)
+ if ($query_id === false)
{
$query_id = $this->query_result;
}
if (isset($cache->sql_rowset[$query_id]))
{
- return $cache->sql_rowseek($query_id, $rownum);
+ return $cache->sql_rowseek($rownum, $query_id);
}
- return ($query_id) ? @mssql_data_seek($query_id, $rownum) : false;
+ return ($query_id !== false) ? @mssql_data_seek($query_id, $rownum) : false;
}
/**
@@ -342,7 +287,7 @@ class dbal_mssql extends dbal
{
global $cache;
- if (!$query_id)
+ if ($query_id === false)
{
$query_id = $this->query_result;
}
@@ -371,7 +316,7 @@ class dbal_mssql extends dbal
/**
* return sql error array
- * @access: private
+ * @access private
*/
function _sql_error()
{
@@ -410,7 +355,7 @@ class dbal_mssql extends dbal
/**
* Build db-specific query data
- * @access: private
+ * @access private
*/
function _sql_custom_build($stage, $data)
{
@@ -419,7 +364,7 @@ class dbal_mssql extends dbal
/**
* Close sql connection
- * @access: private
+ * @access private
*/
function _sql_close()
{
@@ -428,7 +373,7 @@ class dbal_mssql extends dbal
/**
* Build db-specific report
- * @access: private
+ * @access private
*/
function _sql_report($mode, $query = '')
{
@@ -486,9 +431,6 @@ class dbal_mssql extends dbal
break;
}
}
-
}
-} // if ... define
-
?> \ No newline at end of file
diff --git a/phpBB/includes/db/mssql_odbc.php b/phpBB/includes/db/mssql_odbc.php
index e1b2675a23..12e3ca686e 100644
--- a/phpBB/includes/db/mssql_odbc.php
+++ b/phpBB/includes/db/mssql_odbc.php
@@ -9,20 +9,14 @@
*/
/**
+* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
-/**
-* @ignore
-*/
-if (!defined('SQL_LAYER'))
-{
-
- define('SQL_LAYER', 'mssql_odbc');
- include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx);
+include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx);
/**
* Unified ODBC functions
@@ -73,7 +67,7 @@ class dbal_mssql_odbc extends dbal
/**
* SQL Transaction
- * @access: private
+ * @access private
*/
function _sql_transaction($status = 'begin')
{
@@ -120,11 +114,14 @@ class dbal_mssql_odbc extends dbal
$this->sql_report('start', $query);
}
+ // For now, MSSQL has no real UTF-8 support
+ $query = utf8_decode($query);
+
$this->last_query_text = $query;
$this->query_result = ($cache_ttl && method_exists($cache, 'sql_load')) ? $cache->sql_load($query) : false;
$this->sql_add_num_queries($this->query_result);
- if (!$this->query_result)
+ if ($this->query_result === false)
{
if (($this->query_result = @odbc_exec($this->db_connect_id, $query)) === false)
{
@@ -168,33 +165,26 @@ class dbal_mssql_odbc extends dbal
{
$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;
- }
-
- $row_offset = ($total) ? $offset : 0;
- $num_rows = ($total) ? $total : $offset;
-
- if (strpos($query, 'SELECT DISTINCT') === 0)
- {
- $query = 'SELECT DISTINCT TOP ' . ($row_offset + $num_rows) . ' ' . substr($query, 15);
- }
- else
+ // 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)
{
- $query = 'SELECT TOP ' . ($row_offset + $num_rows) . ' ' . substr($query, 6);
+ // We need to grab the total number of rows + the offset number of rows to get the correct result
+ if (strpos($query, 'SELECT DISTINCT') === 0)
+ {
+ $query = 'SELECT DISTINCT TOP ' . ($total + $offset) . ' ' . substr($query, 15);
+ }
+ else
+ {
+ $query = 'SELECT TOP ' . ($total + $offset) . ' ' . substr($query, 6);
+ }
}
$result = $this->sql_query($query, $cache_ttl);
- // Seek by $row_offset rows
- if ($row_offset)
+ // Seek by $offset rows
+ if ($offset)
{
- for ($i = 0; $i < $row_offset; $i++)
- {
- $this->sql_fetchrow($result);
- }
+ $this->sql_rowseek($offset, $result);
}
return $result;
@@ -206,27 +196,6 @@ class dbal_mssql_odbc extends dbal
}
/**
- * Return number of rows
- * Not used within core code
- */
- function sql_numrows($query_id = false)
- {
- global $cache;
-
- if (!$query_id)
- {
- $query_id = $this->query_result;
- }
-
- if (isset($cache->sql_rowset[$query_id]))
- {
- return $cache->sql_numrows($query_id);
- }
-
- return ($query_id) ? @odbc_num_rows($query_id) : false;
- }
-
- /**
* Return number of affected rows
*/
function sql_affectedrows()
@@ -241,7 +210,7 @@ class dbal_mssql_odbc extends dbal
{
global $cache;
- if (!$query_id)
+ if ($query_id === false)
{
$query_id = $this->query_result;
}
@@ -251,39 +220,7 @@ class dbal_mssql_odbc extends dbal
return $cache->sql_fetchrow($query_id);
}
- return ($query_id) ? @odbc_fetch_array($query_id) : false;
- }
-
- /**
- * Fetch field
- * if rownum is false, the current row is used, else it is pointing to the row (zero-based)
- */
- function sql_fetchfield($field, $rownum = false, $query_id = false)
- {
- global $cache;
-
- if (!$query_id)
- {
- $query_id = $this->query_result;
- }
-
- if ($query_id)
- {
- if ($rownum !== false)
- {
- $this->sql_rowseek($rownum, $query_id);
- }
-
- if (isset($cache->sql_rowset[$query_id]))
- {
- return $cache->sql_fetchfield($query_id, $field);
- }
-
- $row = $this->sql_fetchrow($query_id);
- return isset($row[$field]) ? $row[$field] : false;
- }
-
- return false;
+ return ($query_id !== false) ? @odbc_fetch_array($query_id) : false;
}
/**
@@ -294,20 +231,25 @@ class dbal_mssql_odbc extends dbal
{
global $cache;
- if (!$query_id)
+ if ($query_id === false)
{
$query_id = $this->query_result;
}
if (isset($cache->sql_rowset[$query_id]))
{
- return $cache->sql_rowseek($query_id, $rownum);
+ return $cache->sql_rowseek($rownum, $query_id);
+ }
+
+ if ($query_id === false)
+ {
+ return false;
}
$this->sql_freeresult($query_id);
$query_id = $this->sql_query($this->last_query_text);
- if (!$query_id)
+ if ($query_id === false)
{
return false;
}
@@ -352,7 +294,7 @@ class dbal_mssql_odbc extends dbal
{
global $cache;
- if (!$query_id)
+ if ($query_id === false)
{
$query_id = $this->query_result;
}
@@ -381,7 +323,7 @@ class dbal_mssql_odbc extends dbal
/**
* Build db-specific query data
- * @access: private
+ * @access private
*/
function _sql_custom_build($stage, $data)
{
@@ -390,7 +332,7 @@ class dbal_mssql_odbc extends dbal
/**
* return sql error array
- * @access: private
+ * @access private
*/
function _sql_error()
{
@@ -402,7 +344,7 @@ class dbal_mssql_odbc extends dbal
/**
* Close sql connection
- * @access: private
+ * @access private
*/
function _sql_close()
{
@@ -411,7 +353,7 @@ class dbal_mssql_odbc extends dbal
/**
* Build db-specific report
- * @access: private
+ * @access private
*/
function _sql_report($mode, $query = '')
{
@@ -469,9 +411,6 @@ class dbal_mssql_odbc extends dbal
break;
}
}
-
}
-} // if ... define
-
?> \ No newline at end of file
diff --git a/phpBB/includes/db/mysql.php b/phpBB/includes/db/mysql.php
index 7e363721a9..89a6e21d70 100644
--- a/phpBB/includes/db/mysql.php
+++ b/phpBB/includes/db/mysql.php
@@ -9,31 +9,31 @@
*/
/**
+* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
-/**
-* @ignore
-*/
-if (!defined('SQL_LAYER'))
-{
-
- define('SQL_LAYER', 'mysql');
- include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx);
+include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx);
/**
-* MySQL Database Abstraction Layer
-* Minimum Requirement is 3.23+/4.0+/4.1+
+* MySQL4 Database Abstraction Layer
+* Compatible with:
+* MySQL 3.23+
+* MySQL 4.0+
+* MySQL 4.1+
+* MySQL 5.0+
* @package dbal
*/
class dbal_mysql extends dbal
{
+ var $mysql_version;
+
/**
* Connect to server
- * @access: public
+ * @access public
*/
function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false)
{
@@ -42,12 +42,26 @@ class dbal_mysql extends dbal
$this->server = $sqlserver . (($port) ? ':' . $port : '');
$this->dbname = $database;
+ $this->sql_layer = 'mysql4';
+
$this->db_connect_id = ($this->persistency) ? @mysql_pconnect($this->server, $this->user, $sqlpassword) : @mysql_connect($this->server, $this->user, $sqlpassword);
if ($this->db_connect_id && $this->dbname != '')
{
if (@mysql_select_db($this->dbname))
{
+ // Determine what version we are using and if it natively supports UNICODE
+ $this->mysql_version = mysql_get_server_info($this->db_connect_id);
+
+ if (version_compare($this->mysql_version, '4.1.3', '>='))
+ {
+ @mysql_query("SET NAMES 'utf8'", $this->db_connect_id);
+ }
+ else if (version_compare($this->mysql_version, '4.0.0', '<'))
+ {
+ $this->sql_layer = 'mysql';
+ }
+
return $this->db_connect_id;
}
}
@@ -60,12 +74,12 @@ class dbal_mysql extends dbal
*/
function sql_server_info()
{
- return 'MySQL ' . @mysql_get_server_info($this->db_connect_id);
+ return 'MySQL ' . $this->mysql_version;
}
/**
* SQL Transaction
- * @access: private
+ * @access private
*/
function _sql_transaction($status = 'begin')
{
@@ -111,7 +125,7 @@ class dbal_mysql extends dbal
$this->query_result = ($cache_ttl && method_exists($cache, 'sql_load')) ? $cache->sql_load($query) : false;
$this->sql_add_num_queries($this->query_result);
- if (!$this->query_result)
+ if ($this->query_result === false)
{
if (($this->query_result = @mysql_query($query, $this->db_connect_id)) === false)
{
@@ -158,7 +172,8 @@ class dbal_mysql extends dbal
// if $total is set to 0 we do not want to limit the number of rows
if ($total == 0)
{
- $total = -1;
+ // Having a value of -1 was always a bug
+ $total = '18446744073709551615';
}
$query .= "\n LIMIT " . ((!empty($offset)) ? $offset . ', ' . $total : $total);
@@ -172,27 +187,6 @@ class dbal_mysql extends dbal
}
/**
- * Return number of rows
- * Not used within core code
- */
- function sql_numrows($query_id = false)
- {
- global $cache;
-
- if (!$query_id)
- {
- $query_id = $this->query_result;
- }
-
- if (isset($cache->sql_rowset[$query_id]))
- {
- return $cache->sql_numrows($query_id);
- }
-
- return ($query_id) ? @mysql_num_rows($query_id) : false;
- }
-
- /**
* Return number of affected rows
*/
function sql_affectedrows()
@@ -207,7 +201,7 @@ class dbal_mysql extends dbal
{
global $cache;
- if (!$query_id)
+ if ($query_id === false)
{
$query_id = $this->query_result;
}
@@ -217,47 +211,7 @@ class dbal_mysql extends dbal
return $cache->sql_fetchrow($query_id);
}
- return ($query_id) ? @mysql_fetch_assoc($query_id) : false;
- }
-
- /**
- * Fetch field
- * if rownum is false, the current row is used, else it is pointing to the row (zero-based)
- */
- function sql_fetchfield($field, $rownum = false, $query_id = false)
- {
- global $cache;
-
- if (!$query_id)
- {
- $query_id = $this->query_result;
- }
-
- if ($query_id)
- {
- if ($rownum === false)
- {
- if (isset($cache->sql_rowset[$query_id]))
- {
- return $cache->sql_fetchfield($query_id, $field);
- }
-
- $row = $this->sql_fetchrow($query_id);
- return isset($row[$field]) ? $row[$field] : false;
- }
- else
- {
- if (isset($cache->sql_rowset[$query_id]))
- {
- $cache->sql_rowseek($query_id, $rownum);
- return $cache->sql_fetchfield($query_id, $field);
- }
-
- return @mysql_result($query_id, $rownum, $field);
- }
- }
-
- return false;
+ return ($query_id !== false) ? @mysql_fetch_assoc($query_id) : false;
}
/**
@@ -268,17 +222,17 @@ class dbal_mysql extends dbal
{
global $cache;
- if (!$query_id)
+ if ($query_id === false)
{
$query_id = $this->query_result;
}
if (isset($cache->sql_rowset[$query_id]))
{
- return $cache->sql_rowseek($query_id, $rownum);
+ return $cache->sql_rowseek($rownum, $query_id);
}
- return ($query_id) ? @mysql_data_seek($query_id, $rownum) : false;
+ return ($query_id !== false) ? @mysql_data_seek($query_id, $rownum) : false;
}
/**
@@ -296,7 +250,7 @@ class dbal_mysql extends dbal
{
global $cache;
- if (!$query_id)
+ if ($query_id === false)
{
$query_id = $this->query_result;
}
@@ -324,13 +278,13 @@ class dbal_mysql extends dbal
{
return @mysql_real_escape_string($msg);
}
-
+
return @mysql_real_escape_string($msg, $this->db_connect_id);
}
/**
* Build db-specific query data
- * @access: private
+ * @access private
*/
function _sql_custom_build($stage, $data)
{
@@ -343,10 +297,10 @@ class dbal_mysql extends dbal
return $data;
}
-
+
/**
* return sql error array
- * @access: private
+ * @access private
*/
function _sql_error()
{
@@ -366,7 +320,7 @@ class dbal_mysql extends dbal
/**
* Close sql connection
- * @access: private
+ * @access private
*/
function _sql_close()
{
@@ -375,7 +329,7 @@ class dbal_mysql extends dbal
/**
* Build db-specific report
- * @access: private
+ * @access private
*/
function _sql_report($mode, $query = '')
{
@@ -433,9 +387,6 @@ class dbal_mysql extends dbal
break;
}
}
-
}
-} // if ... define
-
?> \ No newline at end of file
diff --git a/phpBB/includes/db/mysql4.php b/phpBB/includes/db/mysql4.php
deleted file mode 100644
index 071f4c4b55..0000000000
--- a/phpBB/includes/db/mysql4.php
+++ /dev/null
@@ -1,443 +0,0 @@
-<?php
-/**
-*
-* @package dbal
-* @version $Id$
-* @copyright (c) 2005 phpBB Group
-* @license http://opensource.org/licenses/gpl-license.php GNU Public License
-*
-*/
-
-/**
-*/
-if (!defined('IN_PHPBB'))
-{
- exit;
-}
-
-/**
-* @ignore
-*/
-if (!defined('SQL_LAYER'))
-{
-
- define('SQL_LAYER', 'mysql4');
- include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx);
-
-/**
-* MySQL4 Database Abstraction Layer
-* Compatible with:
-* MySQL 4.0+
-* MySQL 4.1+
-* MySQL 5.0+
-* @package dbal
-*/
-class dbal_mysql4 extends dbal
-{
- /**
- * Connect to server
- */
- function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false)
- {
- $this->persistency = $persistency;
- $this->user = $sqluser;
- $this->server = $sqlserver . (($port) ? ':' . $port : '');
- $this->dbname = $database;
-
- $this->db_connect_id = ($this->persistency) ? @mysql_pconnect($this->server, $this->user, $sqlpassword) : @mysql_connect($this->server, $this->user, $sqlpassword);
-
- if ($this->db_connect_id && $this->dbname != '')
- {
- if (@mysql_select_db($this->dbname))
- {
- return $this->db_connect_id;
- }
- }
-
- return $this->sql_error('');
- }
-
- /**
- * Version information about used database
- */
- function sql_server_info()
- {
- return 'MySQL ' . @mysql_get_server_info($this->db_connect_id);
- }
-
- /**
- * SQL Transaction
- * @access: private
- */
- function _sql_transaction($status = 'begin')
- {
- switch ($status)
- {
- case 'begin':
- return @mysql_query('BEGIN', $this->db_connect_id);
- break;
-
- case 'commit':
- return @mysql_query('COMMIT', $this->db_connect_id);
- break;
-
- case 'rollback':
- return @mysql_query('ROLLBACK', $this->db_connect_id);
- break;
- }
-
- return true;
- }
-
- /**
- * Base query method
- *
- * @param string $query Contains the SQL query which shall be executed
- * @param int $cache_ttl Either 0 to avoid caching or the time in seconds which the result shall be kept in cache
- * @return mixed When casted to bool the returned value returns true on success and false on failure
- *
- * @access public
- */
- function sql_query($query = '', $cache_ttl = 0)
- {
- if ($query != '')
- {
- global $cache;
-
- // EXPLAIN only in extra debug mode
- if (defined('DEBUG_EXTRA'))
- {
- $this->sql_report('start', $query);
- }
-
- $this->query_result = ($cache_ttl && method_exists($cache, 'sql_load')) ? $cache->sql_load($query) : false;
- $this->sql_add_num_queries($this->query_result);
-
- if (!$this->query_result)
- {
- if (($this->query_result = @mysql_query($query, $this->db_connect_id)) === false)
- {
- $this->sql_error($query);
- }
-
- if (defined('DEBUG_EXTRA'))
- {
- $this->sql_report('stop', $query);
- }
-
- if ($cache_ttl && method_exists($cache, 'sql_save'))
- {
- $this->open_queries[(int) $this->query_result] = $this->query_result;
- $cache->sql_save($query, $this->query_result, $cache_ttl);
- }
- else if (strpos($query, 'SELECT') === 0 && $this->query_result)
- {
- $this->open_queries[(int) $this->query_result] = $this->query_result;
- }
- }
- else if (defined('DEBUG_EXTRA'))
- {
- $this->sql_report('fromcache', $query);
- }
- }
- else
- {
- return false;
- }
-
- return ($this->query_result) ? $this->query_result : false;
- }
-
- /**
- * Build LIMIT query
- */
- function sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0)
- {
- 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)
- {
- // Because MySQL 4.1+ no longer supports -1 in LIMIT queries we set it to the maximum value
- $total = '18446744073709551615';
- }
-
- $query .= "\n LIMIT " . ((!empty($offset)) ? $offset . ', ' . $total : $total);
-
- return $this->sql_query($query, $cache_ttl);
- }
- else
- {
- return false;
- }
- }
-
- /**
- * Return number of rows
- * Not used within core code
- */
- function sql_numrows($query_id = false)
- {
- global $cache;
-
- if (!$query_id)
- {
- $query_id = $this->query_result;
- }
-
- if (isset($cache->sql_rowset[$query_id]))
- {
- return $cache->sql_numrows($query_id);
- }
-
- return ($query_id) ? @mysql_num_rows($query_id) : false;
- }
-
- /**
- * Return number of affected rows
- */
- function sql_affectedrows()
- {
- return ($this->db_connect_id) ? @mysql_affected_rows($this->db_connect_id) : false;
- }
-
- /**
- * Fetch current row
- */
- function sql_fetchrow($query_id = false)
- {
- global $cache;
-
- if (!$query_id)
- {
- $query_id = $this->query_result;
- }
-
- if (isset($cache->sql_rowset[$query_id]))
- {
- return $cache->sql_fetchrow($query_id);
- }
-
- return ($query_id) ? @mysql_fetch_assoc($query_id) : false;
- }
-
- /**
- * Fetch field
- * if rownum is false, the current row is used, else it is pointing to the row (zero-based)
- */
- function sql_fetchfield($field, $rownum = false, $query_id = false)
- {
- global $cache;
-
- if (!$query_id)
- {
- $query_id = $this->query_result;
- }
-
- if ($query_id)
- {
- if ($rownum === false)
- {
- if (isset($cache->sql_rowset[$query_id]))
- {
- return $cache->sql_fetchfield($query_id, $field);
- }
-
- $row = $this->sql_fetchrow($query_id);
- return isset($row[$field]) ? $row[$field] : false;
- }
- else
- {
- if (isset($cache->sql_rowset[$query_id]))
- {
- $cache->sql_rowseek($query_id, $rownum);
- return $cache->sql_fetchfield($query_id, $field);
- }
-
- return @mysql_result($query_id, $rownum, $field);
- }
- }
-
- return false;
- }
-
- /**
- * Seek to given row number
- * rownum is zero-based
- */
- function sql_rowseek($rownum, $query_id = false)
- {
- global $cache;
-
- if (!$query_id)
- {
- $query_id = $this->query_result;
- }
-
- if (isset($cache->sql_rowset[$query_id]))
- {
- return $cache->sql_rowseek($query_id, $rownum);
- }
-
- return ($query_id) ? @mysql_data_seek($query_id, $rownum) : false;
- }
-
- /**
- * Get last inserted id after insert statement
- */
- function sql_nextid()
- {
- return ($this->db_connect_id) ? @mysql_insert_id($this->db_connect_id) : false;
- }
-
- /**
- * Free sql result
- */
- function sql_freeresult($query_id = false)
- {
- global $cache;
-
- if (!$query_id)
- {
- $query_id = $this->query_result;
- }
-
- if (isset($cache->sql_rowset[$query_id]))
- {
- return $cache->sql_freeresult($query_id);
- }
-
- if (isset($this->open_queries[(int) $query_id]))
- {
- unset($this->open_queries[(int) $query_id]);
- return @mysql_free_result($query_id);
- }
-
- return false;
- }
-
- /**
- * Escape string used in sql query
- */
- function sql_escape($msg)
- {
- if (!$this->db_connect_id)
- {
- return @mysql_real_escape_string($msg);
- }
-
- return @mysql_real_escape_string($msg, $this->db_connect_id);
- }
-
- /**
- * Build db-specific query data
- * @access: private
- */
- function _sql_custom_build($stage, $data)
- {
- switch ($stage)
- {
- case 'FROM':
- $data = '(' . $data . ')';
- break;
- }
-
- return $data;
- }
-
- /**
- * return sql error array
- * @access: private
- */
- function _sql_error()
- {
- if (!$this->db_connect_id)
- {
- return array(
- 'message' => @mysql_error(),
- 'code' => @mysql_errno()
- );
- }
-
- return array(
- 'message' => @mysql_error($this->db_connect_id),
- 'code' => @mysql_errno($this->db_connect_id)
- );
- }
-
- /**
- * Close sql connection
- * @access: private
- */
- function _sql_close()
- {
- return @mysql_close($this->db_connect_id);
- }
-
- /**
- * Build db-specific report
- * @access: private
- */
- function _sql_report($mode, $query = '')
- {
- switch ($mode)
- {
- case 'start':
-
- $explain_query = $query;
- if (preg_match('/UPDATE ([a-z0-9_]+).*?WHERE(.*)/s', $query, $m))
- {
- $explain_query = 'SELECT * FROM ' . $m[1] . ' WHERE ' . $m[2];
- }
- else if (preg_match('/DELETE FROM ([a-z0-9_]+).*?WHERE(.*)/s', $query, $m))
- {
- $explain_query = 'SELECT * FROM ' . $m[1] . ' WHERE ' . $m[2];
- }
-
- if (preg_match('/^SELECT/', $explain_query))
- {
- $html_table = false;
-
- if ($result = @mysql_query("EXPLAIN $explain_query", $this->db_connect_id))
- {
- while ($row = @mysql_fetch_assoc($result))
- {
- $html_table = $this->sql_report('add_select_row', $query, $html_table, $row);
- }
- }
- @mysql_free_result($result);
-
- if ($html_table)
- {
- $this->html_hold .= '</table>';
- }
- }
-
- break;
-
- case 'fromcache':
- $endtime = explode(' ', microtime());
- $endtime = $endtime[0] + $endtime[1];
-
- $result = @mysql_query($query, $this->db_connect_id);
- while ($void = @mysql_fetch_assoc($result))
- {
- // Take the time spent on parsing rows into account
- }
- @mysql_free_result($result);
-
- $splittime = explode(' ', microtime());
- $splittime = $splittime[0] + $splittime[1];
-
- $this->sql_report('record_fromcache', $query, $endtime, $splittime);
-
- break;
- }
- }
-}
-
-} // if ... define
-
-?> \ No newline at end of file
diff --git a/phpBB/includes/db/mysqli.php b/phpBB/includes/db/mysqli.php
index fa4d3ffdc7..86700744fb 100644
--- a/phpBB/includes/db/mysqli.php
+++ b/phpBB/includes/db/mysqli.php
@@ -9,20 +9,14 @@
*/
/**
+* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
-/**
-* @ignore
-*/
-if (!defined('SQL_LAYER'))
-{
-
- define('SQL_LAYER', 'mysqli');
- include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx);
+include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx);
/**
* MySQLi Database Abstraction Layer
@@ -48,10 +42,8 @@ class dbal_mysqli extends dbal
if ($this->db_connect_id && $this->dbname != '')
{
- if (@mysqli_select_db($this->db_connect_id, $this->dbname))
- {
- return $this->db_connect_id;
- }
+ @mysqli_query($this->db_connect_id, "SET NAMES 'utf8'");
+ return $this->db_connect_id;
}
return $this->sql_error('');
@@ -67,7 +59,7 @@ class dbal_mysqli extends dbal
/**
* SQL Transaction
- * @access: private
+ * @access private
*/
function _sql_transaction($status = 'begin')
{
@@ -117,7 +109,7 @@ class dbal_mysqli extends dbal
$this->query_result = ($cache_ttl && method_exists($cache, 'sql_load')) ? $cache->sql_load($query) : false;
$this->sql_add_num_queries($this->query_result);
- if (!$this->query_result)
+ if ($this->query_result === false)
{
if (($this->query_result = @mysqli_query($this->db_connect_id, $query)) === false)
{
@@ -174,27 +166,6 @@ class dbal_mysqli extends dbal
}
/**
- * Return number of rows
- * Not used within core code
- */
- function sql_numrows($query_id = false)
- {
- global $cache;
-
- if (!$query_id)
- {
- $query_id = $this->query_result;
- }
-
- if (!is_object($query_id) && isset($cache->sql_rowset[$query_id]))
- {
- return $cache->sql_numrows($query_id);
- }
-
- return ($query_id) ? @mysqli_num_rows($query_id) : false;
- }
-
- /**
* Return number of affected rows
*/
function sql_affectedrows()
@@ -209,7 +180,7 @@ class dbal_mysqli extends dbal
{
global $cache;
- if (!$query_id)
+ if ($query_id === false)
{
$query_id = $this->query_result;
}
@@ -219,39 +190,7 @@ class dbal_mysqli extends dbal
return $cache->sql_fetchrow($query_id);
}
- return ($query_id) ? @mysqli_fetch_assoc($query_id) : false;
- }
-
- /**
- * Fetch field
- * if rownum is false, the current row is used, else it is pointing to the row (zero-based)
- */
- function sql_fetchfield($field, $rownum = false, $query_id = false)
- {
- global $cache;
-
- if (!$query_id)
- {
- $query_id = $this->query_result;
- }
-
- if ($query_id)
- {
- if ($rownum !== false)
- {
- $this->sql_rowseek($rownum, $query_id);
- }
-
- if (!is_object($query_id) && isset($cache->sql_rowset[$query_id]))
- {
- return $cache->sql_fetchfield($query_id, $field);
- }
-
- $row = $this->sql_fetchrow($query_id);
- return isset($row[$field]) ? $row[$field] : false;
- }
-
- return false;
+ return ($query_id !== false) ? @mysqli_fetch_assoc($query_id) : false;
}
/**
@@ -262,17 +201,17 @@ class dbal_mysqli extends dbal
{
global $cache;
- if (!$query_id)
+ if ($query_id === false)
{
$query_id = $this->query_result;
}
if (!is_object($query_id) && isset($cache->sql_rowset[$query_id]))
{
- return $cache->sql_rowseek($query_id, $rownum);
+ return $cache->sql_rowseek($rownum, $query_id);
}
- return ($query_id) ? @mysqli_data_seek($query_id, $rownum) : false;
+ return ($query_id !== false) ? @mysqli_data_seek($query_id, $rownum) : false;
}
/**
@@ -290,7 +229,7 @@ class dbal_mysqli extends dbal
{
global $cache;
- if (!$query_id)
+ if ($query_id === false)
{
$query_id = $this->query_result;
}
@@ -313,7 +252,7 @@ class dbal_mysqli extends dbal
/**
* Build db-specific query data
- * @access: private
+ * @access private
*/
function _sql_custom_build($stage, $data)
{
@@ -329,7 +268,7 @@ class dbal_mysqli extends dbal
/**
* return sql error array
- * @access: private
+ * @access private
*/
function _sql_error()
{
@@ -349,7 +288,7 @@ class dbal_mysqli extends dbal
/**
* Close sql connection
- * @access: private
+ * @access private
*/
function _sql_close()
{
@@ -358,7 +297,7 @@ class dbal_mysqli extends dbal
/**
* Build db-specific report
- * @access: private
+ * @access private
*/
function _sql_report($mode, $query = '')
{
@@ -418,6 +357,4 @@ class dbal_mysqli extends dbal
}
}
-} // if ... define
-
?> \ No newline at end of file
diff --git a/phpBB/includes/db/oracle.php b/phpBB/includes/db/oracle.php
index fc5bf6f78e..e8a0ce3605 100644
--- a/phpBB/includes/db/oracle.php
+++ b/phpBB/includes/db/oracle.php
@@ -9,20 +9,14 @@
*/
/**
+* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
-/**
-* @ignore
-*/
-if(!defined('SQL_LAYER'))
-{
-
- define('SQL_LAYER', 'oracle');
- include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx);
+include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx);
/**
* Oracle Database Abstraction Layer
@@ -42,7 +36,7 @@ class dbal_oracle extends dbal
$this->server = $sqlserver . (($port) ? ':' . $port : '');
$this->dbname = $database;
- $this->db_connect_id = ($this->persistency) ? @ociplogon($this->user, $sqlpassword, $this->server) : @ocinlogon($this->user, $sqlpassword, $this->server);
+ $this->db_connect_id = ($this->persistency) ? @ociplogon($this->user, $sqlpassword, $this->server, 'UTF8') : @ocinlogon($this->user, $sqlpassword, $this->server, 'UTF8');
return ($this->db_connect_id) ? $this->db_connect_id : $this->sql_error('');
}
@@ -57,7 +51,7 @@ class dbal_oracle extends dbal
/**
* SQL Transaction
- * @access: private
+ * @access private
*/
function _sql_transaction($status = 'begin')
{
@@ -104,7 +98,7 @@ class dbal_oracle extends dbal
$this->query_result = ($cache_ttl && method_exists($cache, 'sql_load')) ? $cache->sql_load($query) : false;
$this->sql_add_num_queries($this->query_result);
- if (!$this->query_result)
+ if ($this->query_result === false)
{
$in_transaction = false;
if (!$this->transaction)
@@ -116,7 +110,63 @@ class dbal_oracle extends dbal
$in_transaction = true;
}
+ $array = array();
+
+ // We overcome Oracle's 4000 char limit by binding vars
+ if (preg_match('/^(INSERT INTO[^(]+)\\(([^()]+)\\) VALUES[^(]+\\(([^()]+)\\)$/', $query, $regs))
+ {
+ if (strlen($regs[3]) > 4000)
+ {
+ $cols = explode(', ', $regs[2]);
+ $vals = explode(', ', $regs[3]);
+ foreach ($vals as $key => $value)
+ {
+ if (strlen($value) > 4002) // check to see if this thing is greater than the max + 'x2
+ {
+ $vals[$key] = ':' . strtoupper($cols[$key]);
+ $array[$vals[$key]] = substr($value, 1, -1);
+ }
+ }
+ $query = $regs[1] . '(' . implode(', ', $cols) . ') VALUES (' . implode(', ', $vals) . ')';
+ }
+ }
+ else if (preg_match('/^(UPDATE.*?)SET (.*)(\\sWHERE.*)$/s', $query, $regs))
+ {
+ if (strlen($regs[2]) > 4000)
+ {
+ $args = explode(', ', $regs[2]);
+ $cols = array();
+ foreach ($args as $value)
+ {
+ $temp_array = explode('=', $value);
+ $cols[$temp_array[0]] = $temp_array[1];
+ }
+
+ foreach ($cols as $col => $val)
+ {
+ if (strlen($val) > 4003) // check to see if this thing is greater than the max + 'x2 + a space
+ {
+ $cols[$col] = ' :' . strtoupper(rtrim($col));
+ $array[ltrim($cols[$col])] = substr(trim($val), 2, -1);
+ }
+ }
+
+ $art = array();
+ foreach ($cols as $col => $val)
+ {
+ $art[] = $col . '=' . $val;
+ }
+ $query = $regs[1] . 'SET ' . implode(', ', $art) . $regs[3];
+ }
+ }
+
$this->query_result = @ociparse($this->db_connect_id, $query);
+
+ foreach ($array as $key => $value)
+ {
+ @ocibindbyname($this->query_result, $key, $array[$key], -1);
+ }
+
$success = @ociexecute($this->query_result, OCI_DEFAULT);
if (!$success)
@@ -226,33 +276,6 @@ class dbal_oracle extends dbal
}
/**
- * Return number of rows
- * Not used within core code
- */
- function sql_numrows($query_id = false)
- {
- global $cache;
-
- if (!$query_id)
- {
- $query_id = $this->query_result;
- }
-
- if (isset($cache->sql_rowset[$query_id]))
- {
- return $cache->sql_numrows($query_id);
- }
-
- $result = @ocifetchstatement($query_id, $this->rowset);
-
- // OCIFetchStatment kills our query result so we have to execute the statment again
- // if we ever want to use the query_id again.
- @ociexecute($query_id, OCI_DEFAULT);
-
- return $result;
- }
-
- /**
* Return number of affected rows
*/
function sql_affectedrows()
@@ -267,7 +290,7 @@ class dbal_oracle extends dbal
{
global $cache;
- if (!$query_id)
+ if ($query_id === false)
{
$query_id = $this->query_result;
}
@@ -277,56 +300,29 @@ class dbal_oracle extends dbal
return $cache->sql_fetchrow($query_id);
}
- $row = array();
- $result = @ocifetchinto($query_id, $row, OCI_ASSOC + OCI_RETURN_NULLS);
-
- if (!$result || !$row)
- {
- return false;
- }
-
- $result_row = array();
- foreach ($row as $key => $value)
- {
- // OCI->CLOB?
- if (is_object($value))
- {
- $value = $value->load();
- }
-
- $result_row[strtolower($key)] = $value;
- }
-
- return ($query_id) ? $result_row : false;
- }
-
- /**
- * Fetch field
- * if rownum is false, the current row is used, else it is pointing to the row (zero-based)
- */
- function sql_fetchfield($field, $rownum = false, $query_id = false)
- {
- global $cache;
-
- if (!$query_id)
+ if ($query_id !== false)
{
- $query_id = $this->query_result;
- }
+ $row = array();
+ $result = @ocifetchinto($query_id, $row, OCI_ASSOC + OCI_RETURN_NULLS);
- if ($query_id)
- {
- if ($rownum !== false)
+ if (!$result || !$row)
{
- $this->sql_rowseek($rownum, $query_id);
+ return false;
}
- if (isset($cache->sql_rowset[$query_id]))
+ $result_row = array();
+ foreach ($row as $key => $value)
{
- return $cache->sql_fetchfield($query_id, $field);
+ // OCI->CLOB?
+ if (is_object($value))
+ {
+ $value = $value->load();
+ }
+
+ $result_row[strtolower($key)] = $value;
}
- $row = $this->sql_fetchrow($query_id);
- return isset($row[$field]) ? $row[$field] : false;
+ return $result_row;
}
return false;
@@ -340,17 +336,17 @@ class dbal_oracle extends dbal
{
global $cache;
- if (!$query_id)
+ if ($query_id === false)
{
$query_id = $this->query_result;
}
if (isset($cache->sql_rowset[$query_id]))
{
- return $cache->sql_rowseek($query_id, $rownum);
+ return $cache->sql_rowseek($rownum, $query_id);
}
- if (!$query_id)
+ if ($query_id === false)
{
return false;
}
@@ -377,13 +373,13 @@ class dbal_oracle extends dbal
{
$query_id = $this->query_result;
- if ($query_id && $this->last_query_text != '')
+ if ($query_id !== false && $this->last_query_text != '')
{
if (preg_match('#^INSERT[\t\n ]+INTO[\t\n ]+([a-z0-9\_\-]+)#is', $this->last_query_text, $tablename))
{
$query = 'SELECT ' . $tablename[1] . '_seq.currval FROM DUAL';
$stmt = @ociparse($this->db_connect_id, $query);
- @ociexecute($stmt, OCI_DEFAULT );
+ @ociexecute($stmt, OCI_DEFAULT);
$temp_result = @ocifetchinto($stmt, $temp_array, OCI_ASSOC + OCI_RETURN_NULLS);
@ocifreestatement($stmt);
@@ -409,7 +405,7 @@ class dbal_oracle extends dbal
{
global $cache;
- if (!$query_id)
+ if ($query_id === false)
{
$query_id = $this->query_result;
}
@@ -443,7 +439,7 @@ class dbal_oracle extends dbal
/**
* return sql error array
- * @access: private
+ * @access private
*/
function _sql_error()
{
@@ -465,7 +461,7 @@ class dbal_oracle extends dbal
/**
* Close sql connection
- * @access: private
+ * @access private
*/
function _sql_close()
{
@@ -474,7 +470,7 @@ class dbal_oracle extends dbal
/**
* Build db-specific report
- * @access: private
+ * @access private
*/
function _sql_report($mode, $query = '')
{
@@ -505,10 +501,6 @@ class dbal_oracle extends dbal
break;
}
}
-
-
}
-} // if ... define
-
?> \ No newline at end of file
diff --git a/phpBB/includes/db/postgres.php b/phpBB/includes/db/postgres.php
index 1836952346..c06786a795 100644
--- a/phpBB/includes/db/postgres.php
+++ b/phpBB/includes/db/postgres.php
@@ -9,20 +9,14 @@
*/
/**
+* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
-/**
-* @ignore
-*/
-if (!defined('SQL_LAYER'))
-{
-
- define('SQL_LAYER', 'postgres');
- include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx);
+include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx);
/**
* PostgreSQL Database Abstraction Layer
@@ -38,48 +32,45 @@ class dbal_postgres extends dbal
*/
function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false)
{
- $this->connect_string = '';
+ $connect_string = '';
if ($sqluser)
{
- $this->connect_string .= "user=$sqluser ";
+ $connect_string .= "user=$sqluser ";
}
if ($sqlpassword)
{
- $this->connect_string .= "password=$sqlpassword ";
+ $connect_string .= "password=$sqlpassword ";
}
if ($sqlserver)
{
if (strpos($sqlserver, ':') !== false)
{
- list($sqlserver, $sqlport) = explode(':', $sqlserver);
- $this->connect_string .= "host=$sqlserver port=$sqlport ";
+ list($sqlserver, $port) = explode(':', $sqlserver);
}
- else
+
+ if ($sqlserver !== 'localhost')
{
- if ($sqlserver != "localhost")
- {
- $this->connect_string .= "host=$sqlserver ";
- }
-
- if ($port)
- {
- $this->connect_string .= "port=$port ";
- }
+ $connect_string .= "host=$sqlserver ";
+ }
+
+ if ($port)
+ {
+ $connect_string .= "port=$port ";
}
}
if ($database)
{
$this->dbname = $database;
- $this->connect_string .= "dbname=$database";
+ $connect_string .= "dbname=$database";
}
$this->persistency = $persistency;
- $this->db_connect_id = ($this->persistency) ? @pg_pconnect($this->connect_string) : @pg_connect($this->connect_string);
+ $this->db_connect_id = ($this->persistency) ? @pg_pconnect($connect_string) : @pg_connect($connect_string);
return ($this->db_connect_id) ? $this->db_connect_id : $this->sql_error('');
}
@@ -98,6 +89,8 @@ class dbal_postgres extends dbal
{
$query_id = @pg_query($this->db_connect_id, 'select version()');
$row = @pg_fetch_assoc($query_id, null);
+ @pg_free_result($query_id);
+
$version = $row['version'];
return ((!empty($version)) ? ' ' . $version : '');
}
@@ -105,7 +98,7 @@ class dbal_postgres extends dbal
/**
* SQL Transaction
- * @access: private
+ * @access private
*/
function _sql_transaction($status = 'begin')
{
@@ -152,7 +145,7 @@ class dbal_postgres extends dbal
$this->query_result = ($cache_ttl && method_exists($cache, 'sql_load')) ? $cache->sql_load($query) : false;
$this->sql_add_num_queries($this->query_result);
- if (!$this->query_result)
+ if ($this->query_result === false)
{
if (($this->query_result = @pg_query($this->db_connect_id, $query)) === false)
{
@@ -189,7 +182,7 @@ class dbal_postgres extends dbal
/**
* Build db-specific query data
- * @access: private
+ * @access private
*/
function _sql_custom_build($stage, $data)
{
@@ -222,27 +215,6 @@ class dbal_postgres extends dbal
}
/**
- * Return number of rows
- * Not used within core code
- */
- function sql_numrows($query_id = false)
- {
- global $cache;
-
- if (!$query_id)
- {
- $query_id = $this->query_result;
- }
-
- if (isset($cache->sql_rowset[$query_id]))
- {
- return $cache->sql_numrows($query_id);
- }
-
- return ($query_id) ? @pg_num_rows($query_id) : false;
- }
-
- /**
* Return number of affected rows
*/
function sql_affectedrows()
@@ -257,7 +229,7 @@ class dbal_postgres extends dbal
{
global $cache;
- if (!$query_id)
+ if ($query_id === false)
{
$query_id = $this->query_result;
}
@@ -267,48 +239,7 @@ class dbal_postgres extends dbal
return $cache->sql_fetchrow($query_id);
}
- $row = @pg_fetch_assoc($query_id, null);
- if ($row)
- {
- foreach ($row as $key => $value)
- {
- $row[$key] = (strpos($key, 'bitfield') === false) ? $value : pg_unescape_bytea($value);
- }
- }
-
- return ($query_id) ? $row : false;
- }
-
- /**
- * Fetch field
- * if rownum is false, the current row is used, else it is pointing to the row (zero-based)
- */
- function sql_fetchfield($field, $rownum = false, $query_id = false)
- {
- global $cache;
-
- if (!$query_id)
- {
- $query_id = $this->query_result;
- }
-
- if ($query_id)
- {
- if ($rownum !== false)
- {
- $this->sql_rowseek($rownum, $query_id);
- }
-
- if (isset($cache->sql_rowset[$query_id]))
- {
- return $cache->sql_fetchfield($query_id, $field);
- }
-
- $row = $this->sql_fetchrow($query_id);
- return isset($row[$field]) ? $row[$field] : false;
- }
-
- return false;
+ return ($query_id !== false) ? @pg_fetch_assoc($query_id, null) : false;
}
/**
@@ -319,17 +250,17 @@ class dbal_postgres extends dbal
{
global $cache;
- if (!$query_id)
+ if ($query_id === false)
{
$query_id = $this->query_result;
}
if (isset($cache->sql_rowset[$query_id]))
{
- return $cache->sql_rowseek($query_id, $rownum);
+ return $cache->sql_rowseek($rownum, $query_id);
}
- return ($query_id) ? @pg_result_seek($query_id, $rownum) : false;
+ return ($query_id !== false) ? @pg_result_seek($query_id, $rownum) : false;
}
/**
@@ -339,7 +270,7 @@ class dbal_postgres extends dbal
{
$query_id = $this->query_result;
- if ($query_id && $this->last_query_text != '')
+ if ($query_id !== false && $this->last_query_text != '')
{
if (preg_match("/^INSERT[\t\n ]+INTO[\t\n ]+([a-z0-9\_\-]+)/is", $this->last_query_text, $tablename))
{
@@ -368,7 +299,7 @@ class dbal_postgres extends dbal
{
global $cache;
- if (!$query_id)
+ if ($query_id === false)
{
$query_id = $this->query_result;
}
@@ -398,7 +329,7 @@ class dbal_postgres extends dbal
/**
* return sql error array
- * @access: private
+ * @access private
*/
function _sql_error()
{
@@ -410,7 +341,7 @@ class dbal_postgres extends dbal
/**
* Close sql connection
- * @access: private
+ * @access private
*/
function _sql_close()
{
@@ -419,7 +350,7 @@ class dbal_postgres extends dbal
/**
* Build db-specific report
- * @access: private
+ * @access private
*/
function _sql_report($mode, $query = '')
{
@@ -477,9 +408,6 @@ class dbal_postgres extends dbal
break;
}
}
-
}
-} // if ... defined
-
?> \ No newline at end of file
diff --git a/phpBB/includes/db/sqlite.php b/phpBB/includes/db/sqlite.php
index cd6d40e3c7..708376881c 100644
--- a/phpBB/includes/db/sqlite.php
+++ b/phpBB/includes/db/sqlite.php
@@ -9,20 +9,14 @@
*/
/**
+* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
-/**
-* @ignore
-*/
-if (!defined('SQL_LAYER'))
-{
-
- define('SQL_LAYER', 'sqlite');
- include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx);
+include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx);
/**
* Sqlite Database Abstraction Layer
@@ -63,7 +57,7 @@ class dbal_sqlite extends dbal
/**
* SQL Transaction
- * @access: private
+ * @access private
*/
function _sql_transaction($status = 'begin')
{
@@ -109,7 +103,7 @@ class dbal_sqlite extends dbal
$this->query_result = ($cache_ttl && method_exists($cache, 'sql_load')) ? $cache->sql_load($query) : false;
$this->sql_add_num_queries($this->query_result);
- if (!$this->query_result)
+ if ($this->query_result === false)
{
if (($this->query_result = @sqlite_query($query, $this->db_connect_id)) === false)
{
@@ -170,27 +164,6 @@ class dbal_sqlite extends dbal
}
/**
- * Return number of rows
- * Not used within core code
- */
- function sql_numrows($query_id = false)
- {
- global $cache;
-
- if (!$query_id)
- {
- $query_id = $this->query_result;
- }
-
- if (isset($cache->sql_rowset[$query_id]))
- {
- return $cache->sql_numrows($query_id);
- }
-
- return ($query_id) ? @sqlite_num_rows($query_id) : false;
- }
-
- /**
* Return number of affected rows
*/
function sql_affectedrows()
@@ -205,7 +178,7 @@ class dbal_sqlite extends dbal
{
global $cache;
- if (!$query_id)
+ if ($query_id === false)
{
$query_id = $this->query_result;
}
@@ -215,40 +188,7 @@ class dbal_sqlite extends dbal
return $cache->sql_fetchrow($query_id);
}
- $row = @sqlite_fetch_array($query_id, SQLITE_ASSOC);
-
- return $row;
- }
-
- /**
- * Fetch field
- * if rownum is false, the current row is used, else it is pointing to the row (zero-based)
- */
- function sql_fetchfield($field, $rownum = false, $query_id = false)
- {
- global $cache;
-
- if (!$query_id)
- {
- $query_id = $this->query_result;
- }
-
- if ($query_id)
- {
- if ($rownum !== false)
- {
- $this->sql_rowseek($rownum, $query_id);
- }
-
- if (isset($cache->sql_rowset[$query_id]))
- {
- return $cache->sql_fetchfield($query_id, $field);
- }
-
- return @sqlite_column($query_id, $field);
- }
-
- return false;
+ return ($query_id !== false) ? @sqlite_fetch_array($query_id, SQLITE_ASSOC) : false;
}
/**
@@ -259,17 +199,17 @@ class dbal_sqlite extends dbal
{
global $cache;
- if (!$query_id)
+ if ($query_id === false)
{
$query_id = $this->query_result;
}
if (isset($cache->sql_rowset[$query_id]))
{
- return $cache->sql_rowseek($query_id, $rownum);
+ return $cache->sql_rowseek($rownum, $query_id);
}
- return ($query_id) ? @sqlite_seek($query_id, $rownum) : false;
+ return ($query_id !== false) ? @sqlite_seek($query_id, $rownum) : false;
}
/**
@@ -287,7 +227,7 @@ class dbal_sqlite extends dbal
{
global $cache;
- if (!$query_id)
+ if ($query_id === false)
{
$query_id = $this->query_result;
}
@@ -310,7 +250,7 @@ class dbal_sqlite extends dbal
/**
* return sql error array
- * @access: private
+ * @access private
*/
function _sql_error()
{
@@ -322,7 +262,7 @@ class dbal_sqlite extends dbal
/**
* Build db-specific query data
- * @access: private
+ * @access private
*/
function _sql_custom_build($stage, $data)
{
@@ -331,7 +271,7 @@ class dbal_sqlite extends dbal
/**
* Close sql connection
- * @access: private
+ * @access private
*/
function _sql_close()
{
@@ -340,7 +280,7 @@ class dbal_sqlite extends dbal
/**
* Build db-specific report
- * @access: private
+ * @access private
*/
function _sql_report($mode, $query = '')
{
@@ -367,9 +307,6 @@ class dbal_sqlite extends dbal
break;
}
}
-
}
-} // if ... define
-
?> \ No newline at end of file