mirror of
https://github.com/phpbb/phpbb.git
synced 2025-07-30 21:40:43 +02:00
[ticket/16955] Clean up code in db classes
PHPBB3-16955
This commit is contained in:
@@ -31,6 +31,9 @@ abstract class driver implements driver_interface
|
||||
var $html_hold = '';
|
||||
var $sql_report = '';
|
||||
|
||||
/** @var string Last query text */
|
||||
protected $last_query_text = '';
|
||||
|
||||
var $persistency = false;
|
||||
var $user = '';
|
||||
var $server = '';
|
||||
@@ -279,6 +282,13 @@ abstract class driver implements driver_interface
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Close sql connection
|
||||
*
|
||||
* @return bool False if failure
|
||||
*/
|
||||
abstract protected function _sql_close(): bool;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@@ -296,6 +306,18 @@ abstract class driver implements driver_interface
|
||||
return $this->_sql_query_limit($query, $total, $offset, $cache_ttl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build LIMIT query
|
||||
*
|
||||
* @param string $query The SQL query to execute
|
||||
* @param int $total The number of rows to select
|
||||
* @param int $offset
|
||||
* @param int $cache_ttl Either 0 to avoid caching or
|
||||
* the time in seconds which the result shall be kept in cache
|
||||
* @return mixed Buffered, seekable result handle, false on error
|
||||
*/
|
||||
abstract protected function _sql_query_limit(string $query, int $total, int $offset = 0, int $cache_ttl = 0);
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@@ -404,6 +426,18 @@ abstract class driver implements driver_interface
|
||||
return $this->_sql_like_expression('LIKE \'' . $this->sql_escape($expression) . '\'');
|
||||
}
|
||||
|
||||
/**
|
||||
* Build LIKE expression
|
||||
*
|
||||
* @param string $expression Base expression
|
||||
*
|
||||
* @return string LIKE expression
|
||||
*/
|
||||
protected function _sql_like_expression(string $expression): string
|
||||
{
|
||||
return $expression;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@@ -415,6 +449,18 @@ abstract class driver implements driver_interface
|
||||
return $this->_sql_not_like_expression('NOT LIKE \'' . $this->sql_escape($expression) . '\'');
|
||||
}
|
||||
|
||||
/**
|
||||
* Build NOT LIKE expression
|
||||
*
|
||||
* @param string $expression Base expression
|
||||
*
|
||||
* @return string NOT LIKE expression
|
||||
*/
|
||||
protected function _sql_not_like_expression(string $expression): string
|
||||
{
|
||||
return $expression;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@@ -510,12 +556,22 @@ abstract class driver implements driver_interface
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* SQL Transaction
|
||||
*
|
||||
* @param string $status Should be one of the following strings:
|
||||
* begin, commit, rollback
|
||||
*
|
||||
* @return bool Success/failure of the transaction query
|
||||
*/
|
||||
abstract protected function _sql_transaction(string $status = 'begin'): bool;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function sql_build_array($query, $assoc_ary = false)
|
||||
function sql_build_array($query, $assoc_ary = [])
|
||||
{
|
||||
if (!is_array($assoc_ary))
|
||||
if (!count($assoc_ary))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -836,6 +892,18 @@ abstract class driver implements driver_interface
|
||||
return $sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build db-specific query data
|
||||
*
|
||||
* @param string $stage Query stage, can be 'FROM' or 'WHERE'
|
||||
* @param string|array $data A string containing the CROSS JOIN query or an array of WHERE clauses
|
||||
*
|
||||
* @return string|array The db-specific query fragment
|
||||
*/
|
||||
protected function _sql_custom_build(string $stage, $data)
|
||||
{
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function _process_boolean_tree_first($operations_ary)
|
||||
{
|
||||
@@ -1017,7 +1085,7 @@ abstract class driver implements driver_interface
|
||||
global $msg_long_text;
|
||||
$msg_long_text = $message;
|
||||
|
||||
trigger_error(false, E_USER_ERROR);
|
||||
trigger_error('', E_USER_ERROR);
|
||||
}
|
||||
|
||||
trigger_error($message, E_USER_ERROR);
|
||||
@@ -1031,6 +1099,13 @@ abstract class driver implements driver_interface
|
||||
return $this->sql_error_returned;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return sql error array
|
||||
*
|
||||
* @return array{message: string, code: int|string} SQL error array with message and error code
|
||||
*/
|
||||
abstract protected function _sql_error(): array;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@@ -1216,6 +1291,16 @@ abstract class driver implements driver_interface
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build db-specific report
|
||||
*
|
||||
* @param string $mode 'start' to add to report, 'fromcache' to output it
|
||||
* @param string $query Query to add to sql report
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
abstract protected function _sql_report(string $mode, string $query = ''): void;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
@@ -180,7 +180,7 @@ interface driver_interface
|
||||
* Return on error or display error message
|
||||
*
|
||||
* @param bool $fail Should we return on errors, or stop
|
||||
* @return null
|
||||
* @return void
|
||||
*/
|
||||
public function sql_return_on_error($fail = false);
|
||||
|
||||
@@ -190,9 +190,9 @@ interface driver_interface
|
||||
* @param string $query Should be on of the following strings:
|
||||
* INSERT, INSERT_SELECT, UPDATE, SELECT, DELETE
|
||||
* @param array $assoc_ary Array with "column => value" pairs
|
||||
* @return string A SQL statement like "c1 = 'a' AND c2 = 'b'"
|
||||
* @return string|false A SQL statement like "c1 = 'a' AND c2 = 'b'", false on invalid assoc_ary
|
||||
*/
|
||||
public function sql_build_array($query, $assoc_ary = array());
|
||||
public function sql_build_array($query, $assoc_ary = []);
|
||||
|
||||
/**
|
||||
* Fetch all rows
|
||||
@@ -299,7 +299,7 @@ interface driver_interface
|
||||
* Add to query count
|
||||
*
|
||||
* @param bool $cached Is this query cached?
|
||||
* @return null
|
||||
* @return void
|
||||
*/
|
||||
public function sql_add_num_queries($cached = false);
|
||||
|
||||
|
@@ -49,7 +49,9 @@ class factory implements driver_interface
|
||||
{
|
||||
if ($this->driver === null)
|
||||
{
|
||||
$this->driver = $this->container->get('dbal.conn.driver');
|
||||
/** @var driver_interface $driver */
|
||||
$driver = $this->container->get('dbal.conn.driver');
|
||||
$this->driver = $driver;
|
||||
}
|
||||
|
||||
return $this->driver;
|
||||
@@ -238,13 +240,13 @@ class factory implements driver_interface
|
||||
*/
|
||||
public function sql_return_on_error($fail = false)
|
||||
{
|
||||
return $this->get_driver()->sql_return_on_error($fail);
|
||||
$this->get_driver()->sql_return_on_error($fail);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function sql_build_array($query, $assoc_ary = array())
|
||||
public function sql_build_array($query, $assoc_ary = [])
|
||||
{
|
||||
return $this->get_driver()->sql_build_array($query, $assoc_ary);
|
||||
}
|
||||
@@ -326,7 +328,7 @@ class factory implements driver_interface
|
||||
*/
|
||||
public function sql_add_num_queries($cached = false)
|
||||
{
|
||||
return $this->get_driver()->sql_add_num_queries($cached);
|
||||
$this->get_driver()->sql_add_num_queries($cached);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -374,7 +376,7 @@ class factory implements driver_interface
|
||||
*/
|
||||
public function sql_freeresult($query_id = false)
|
||||
{
|
||||
return $this->get_driver()->sql_freeresult($query_id);
|
||||
$this->get_driver()->sql_freeresult($query_id);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -43,19 +43,17 @@ abstract class mssql_base extends \phpbb\db\driver\driver
|
||||
}
|
||||
|
||||
/**
|
||||
* Build LIKE expression
|
||||
* @access private
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function _sql_like_expression($expression)
|
||||
protected function _sql_like_expression(string $expression): string
|
||||
{
|
||||
return $expression . " ESCAPE '\\'";
|
||||
}
|
||||
|
||||
/**
|
||||
* Build NOT LIKE expression
|
||||
* @access private
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function _sql_not_like_expression($expression)
|
||||
protected function _sql_not_like_expression(string $expression): string
|
||||
{
|
||||
return $expression . " ESCAPE '\\'";
|
||||
}
|
||||
@@ -68,15 +66,6 @@ abstract class mssql_base extends \phpbb\db\driver\driver
|
||||
return 'CONVERT(BIGINT, ' . $expression . ')';
|
||||
}
|
||||
|
||||
/**
|
||||
* Build db-specific query data
|
||||
* @access private
|
||||
*/
|
||||
function _sql_custom_build($stage, $data)
|
||||
{
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
@@ -24,7 +24,6 @@ namespace phpbb\db\driver;
|
||||
*/
|
||||
class mssql_odbc extends \phpbb\db\driver\mssql_base
|
||||
{
|
||||
var $last_query_text = '';
|
||||
var $connect_error = '';
|
||||
|
||||
/**
|
||||
@@ -112,31 +111,27 @@ class mssql_odbc extends \phpbb\db\driver\mssql_base
|
||||
|
||||
if ($raw)
|
||||
{
|
||||
return $this->sql_server_version;
|
||||
return (string) $this->sql_server_version;
|
||||
}
|
||||
|
||||
return ($this->sql_server_version) ? 'MSSQL (ODBC)<br />' . $this->sql_server_version : 'MSSQL (ODBC)';
|
||||
}
|
||||
|
||||
/**
|
||||
* SQL Transaction
|
||||
* @access private
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function _sql_transaction($status = 'begin')
|
||||
protected function _sql_transaction(string $status = 'begin'): bool
|
||||
{
|
||||
switch ($status)
|
||||
{
|
||||
case 'begin':
|
||||
return @odbc_exec($this->db_connect_id, 'BEGIN TRANSACTION');
|
||||
break;
|
||||
return (bool) @odbc_exec($this->db_connect_id, 'BEGIN TRANSACTION');
|
||||
|
||||
case 'commit':
|
||||
return @odbc_exec($this->db_connect_id, 'COMMIT TRANSACTION');
|
||||
break;
|
||||
return (bool) @odbc_exec($this->db_connect_id, 'COMMIT TRANSACTION');
|
||||
|
||||
case 'rollback':
|
||||
return @odbc_exec($this->db_connect_id, 'ROLLBACK TRANSACTION');
|
||||
break;
|
||||
return (bool) @odbc_exec($this->db_connect_id, 'ROLLBACK TRANSACTION');
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -209,9 +204,9 @@ class mssql_odbc extends \phpbb\db\driver\mssql_base
|
||||
}
|
||||
|
||||
/**
|
||||
* Build LIMIT query
|
||||
*/
|
||||
function _sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0)
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function _sql_query_limit(string $query, int $total, int $offset = 0, int $cache_ttl = 0)
|
||||
{
|
||||
$this->query_result = false;
|
||||
|
||||
@@ -303,23 +298,19 @@ class mssql_odbc extends \phpbb\db\driver\mssql_base
|
||||
|
||||
if ($cache && !is_object($query_id) && $cache->sql_exists($query_id))
|
||||
{
|
||||
return $cache->sql_freeresult($query_id);
|
||||
$cache->sql_freeresult($query_id);
|
||||
}
|
||||
|
||||
if (isset($this->open_queries[(int) $query_id]))
|
||||
else if (isset($this->open_queries[(int) $query_id]))
|
||||
{
|
||||
unset($this->open_queries[(int) $query_id]);
|
||||
return odbc_free_result($query_id);
|
||||
odbc_free_result($query_id);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* return sql error array
|
||||
* @access private
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function _sql_error()
|
||||
protected function _sql_error(): array
|
||||
{
|
||||
if (function_exists('odbc_errormsg'))
|
||||
{
|
||||
@@ -340,19 +331,18 @@ class mssql_odbc extends \phpbb\db\driver\mssql_base
|
||||
}
|
||||
|
||||
/**
|
||||
* Close sql connection
|
||||
* @access private
|
||||
*/
|
||||
function _sql_close()
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function _sql_close(): bool
|
||||
{
|
||||
return @odbc_close($this->db_connect_id);
|
||||
@odbc_close($this->db_connect_id);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build db-specific report
|
||||
* @access private
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function _sql_report($mode, $query = '')
|
||||
protected function _sql_report(string $mode, string $query = ''): void
|
||||
{
|
||||
switch ($mode)
|
||||
{
|
||||
|
@@ -23,10 +23,12 @@ namespace phpbb\db\driver;
|
||||
class mssqlnative extends \phpbb\db\driver\mssql_base
|
||||
{
|
||||
var $m_insert_id = null;
|
||||
var $last_query_text = '';
|
||||
var $query_options = array();
|
||||
var $connect_error = '';
|
||||
|
||||
/** @var string|false Last error result or false if no last error set */
|
||||
private $last_error_result = false;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@@ -92,24 +94,20 @@ class mssqlnative extends \phpbb\db\driver\mssql_base
|
||||
}
|
||||
|
||||
/**
|
||||
* SQL Transaction
|
||||
* @access private
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function _sql_transaction($status = 'begin')
|
||||
protected function _sql_transaction(string $status = 'begin'): bool
|
||||
{
|
||||
switch ($status)
|
||||
{
|
||||
case 'begin':
|
||||
return sqlsrv_begin_transaction($this->db_connect_id);
|
||||
break;
|
||||
|
||||
case 'commit':
|
||||
return sqlsrv_commit($this->db_connect_id);
|
||||
break;
|
||||
|
||||
case 'rollback':
|
||||
return sqlsrv_rollback($this->db_connect_id);
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -182,9 +180,9 @@ class mssqlnative extends \phpbb\db\driver\mssql_base
|
||||
}
|
||||
|
||||
/**
|
||||
* Build LIMIT query
|
||||
*/
|
||||
function _sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0)
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function _sql_query_limit(string $query, int $total, int $offset = 0, int $cache_ttl = 0)
|
||||
{
|
||||
$this->query_result = false;
|
||||
|
||||
@@ -280,7 +278,7 @@ class mssqlnative extends \phpbb\db\driver\mssql_base
|
||||
if ($result_id)
|
||||
{
|
||||
$row = sqlsrv_fetch_array($result_id);
|
||||
$id = $row[0];
|
||||
$id = isset($row[0]) ? (int) $row[0] : false;
|
||||
sqlsrv_free_stmt($result_id);
|
||||
return $id;
|
||||
}
|
||||
@@ -304,23 +302,19 @@ class mssqlnative extends \phpbb\db\driver\mssql_base
|
||||
|
||||
if ($cache && !is_object($query_id) && $cache->sql_exists($query_id))
|
||||
{
|
||||
return $cache->sql_freeresult($query_id);
|
||||
$cache->sql_freeresult($query_id);
|
||||
}
|
||||
|
||||
if (isset($this->open_queries[(int) $query_id]))
|
||||
else if (isset($this->open_queries[(int) $query_id]))
|
||||
{
|
||||
unset($this->open_queries[(int) $query_id]);
|
||||
return sqlsrv_free_stmt($query_id);
|
||||
sqlsrv_free_stmt($query_id);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* return sql error array
|
||||
* @access private
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function _sql_error()
|
||||
protected function _sql_error(): array
|
||||
{
|
||||
if (function_exists('sqlsrv_errors'))
|
||||
{
|
||||
@@ -342,7 +336,7 @@ class mssqlnative extends \phpbb\db\driver\mssql_base
|
||||
}
|
||||
else
|
||||
{
|
||||
$error = (isset($this->last_error_result) && $this->last_error_result) ? $this->last_error_result : array();
|
||||
$error = $this->last_error_result ?: '';
|
||||
}
|
||||
|
||||
$error = array(
|
||||
@@ -362,19 +356,17 @@ class mssqlnative extends \phpbb\db\driver\mssql_base
|
||||
}
|
||||
|
||||
/**
|
||||
* Close sql connection
|
||||
* @access private
|
||||
*/
|
||||
function _sql_close()
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function _sql_close(): bool
|
||||
{
|
||||
return @sqlsrv_close($this->db_connect_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build db-specific report
|
||||
* @access private
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function _sql_report($mode, $query = '')
|
||||
protected function _sql_report(string $mode, string $query = ''): void
|
||||
{
|
||||
switch ($mode)
|
||||
{
|
||||
|
@@ -27,9 +27,9 @@ abstract class mysql_base extends \phpbb\db\driver\driver
|
||||
}
|
||||
|
||||
/**
|
||||
* Build LIMIT query
|
||||
*/
|
||||
function _sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0)
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function _sql_query_limit(string $query, int $total, int $offset = 0, int $cache_ttl = 0)
|
||||
{
|
||||
$this->query_result = false;
|
||||
|
||||
@@ -103,34 +103,13 @@ abstract class mysql_base extends \phpbb\db\driver\driver
|
||||
}
|
||||
|
||||
/**
|
||||
* Build LIKE expression
|
||||
* @access private
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function _sql_like_expression($expression)
|
||||
protected function _sql_custom_build(string $stage, $data)
|
||||
{
|
||||
return $expression;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build NOT LIKE expression
|
||||
* @access private
|
||||
*/
|
||||
function _sql_not_like_expression($expression)
|
||||
{
|
||||
return $expression;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build db-specific query data
|
||||
* @access private
|
||||
*/
|
||||
function _sql_custom_build($stage, $data)
|
||||
{
|
||||
switch ($stage)
|
||||
if ($stage === 'FROM' && is_string($data))
|
||||
{
|
||||
case 'FROM':
|
||||
$data = '(' . $data . ')';
|
||||
break;
|
||||
$data = '(' . $data . ')';
|
||||
}
|
||||
|
||||
return $data;
|
||||
|
@@ -69,7 +69,7 @@ class mysqli extends \phpbb\db\driver\mysql_base
|
||||
if ($this->db_connect_id && $this->dbname != '')
|
||||
{
|
||||
// Disable loading local files on client side
|
||||
@mysqli_options($this->db_connect_id, MYSQLI_OPT_LOCAL_INFILE, false);
|
||||
@mysqli_options($this->db_connect_id, MYSQLI_OPT_LOCAL_INFILE, 0);
|
||||
|
||||
/*
|
||||
* As of PHP 8.1 MySQLi default error mode is set to MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT
|
||||
@@ -143,32 +143,28 @@ class mysqli extends \phpbb\db\driver\mysql_base
|
||||
}
|
||||
}
|
||||
|
||||
return ($raw) ? $this->sql_server_version : 'MySQL(i) ' . $this->sql_server_version;
|
||||
return ($raw) ? (string) $this->sql_server_version : 'MySQL(i) ' . $this->sql_server_version;
|
||||
}
|
||||
|
||||
/**
|
||||
* SQL Transaction
|
||||
* @access private
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function _sql_transaction($status = 'begin')
|
||||
protected function _sql_transaction(string $status = 'begin'): bool
|
||||
{
|
||||
switch ($status)
|
||||
{
|
||||
case 'begin':
|
||||
return @mysqli_autocommit($this->db_connect_id, false);
|
||||
break;
|
||||
|
||||
case 'commit':
|
||||
$result = @mysqli_commit($this->db_connect_id);
|
||||
@mysqli_autocommit($this->db_connect_id, true);
|
||||
return $result;
|
||||
break;
|
||||
|
||||
case 'rollback':
|
||||
$result = @mysqli_rollback($this->db_connect_id);
|
||||
@mysqli_autocommit($this->db_connect_id, true);
|
||||
return $result;
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -293,7 +289,7 @@ class mysqli extends \phpbb\db\driver\mysql_base
|
||||
*/
|
||||
function sql_nextid()
|
||||
{
|
||||
return ($this->db_connect_id) ? @mysqli_insert_id($this->db_connect_id) : false;
|
||||
return ($this->db_connect_id) ? (int) @mysqli_insert_id($this->db_connect_id) : false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -310,20 +306,12 @@ class mysqli extends \phpbb\db\driver\mysql_base
|
||||
|
||||
if ($cache && !is_object($query_id) && $cache->sql_exists($query_id))
|
||||
{
|
||||
return $cache->sql_freeresult($query_id);
|
||||
$cache->sql_freeresult($query_id);
|
||||
}
|
||||
|
||||
if (!$query_id)
|
||||
else if ($query_id && $query_id !== true)
|
||||
{
|
||||
return false;
|
||||
mysqli_free_result($query_id);
|
||||
}
|
||||
|
||||
if ($query_id === true)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return mysqli_free_result($query_id);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -335,10 +323,9 @@ class mysqli extends \phpbb\db\driver\mysql_base
|
||||
}
|
||||
|
||||
/**
|
||||
* return sql error array
|
||||
* @access private
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function _sql_error()
|
||||
protected function _sql_error(): array
|
||||
{
|
||||
if ($this->db_connect_id)
|
||||
{
|
||||
@@ -366,19 +353,17 @@ class mysqli extends \phpbb\db\driver\mysql_base
|
||||
}
|
||||
|
||||
/**
|
||||
* Close sql connection
|
||||
* @access private
|
||||
*/
|
||||
function _sql_close()
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function _sql_close(): bool
|
||||
{
|
||||
return @mysqli_close($this->db_connect_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build db-specific report
|
||||
* @access private
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function _sql_report($mode, $query = '')
|
||||
protected function _sql_report(string $mode, string $query = ''): void
|
||||
{
|
||||
static $test_prof;
|
||||
|
||||
|
@@ -18,9 +18,11 @@ namespace phpbb\db\driver;
|
||||
*/
|
||||
class oracle extends \phpbb\db\driver\driver
|
||||
{
|
||||
var $last_query_text = '';
|
||||
var $connect_error = '';
|
||||
|
||||
/** @var array|false Last error result or false if no last error set */
|
||||
private $last_error_result = false;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@@ -107,24 +109,20 @@ class oracle extends \phpbb\db\driver\driver
|
||||
}
|
||||
|
||||
/**
|
||||
* SQL Transaction
|
||||
* @access private
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function _sql_transaction($status = 'begin')
|
||||
protected function _sql_transaction(string $status = 'begin'): bool
|
||||
{
|
||||
switch ($status)
|
||||
{
|
||||
case 'begin':
|
||||
return true;
|
||||
break;
|
||||
|
||||
case 'commit':
|
||||
return @oci_commit($this->db_connect_id);
|
||||
break;
|
||||
|
||||
case 'rollback':
|
||||
return @oci_rollback($this->db_connect_id);
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -465,9 +463,9 @@ class oracle extends \phpbb\db\driver\driver
|
||||
}
|
||||
|
||||
/**
|
||||
* Build LIMIT query
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function _sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0)
|
||||
protected function _sql_query_limit(string $query, int $total, int $offset = 0, int $cache_ttl = 0)
|
||||
{
|
||||
$this->query_result = false;
|
||||
|
||||
@@ -621,16 +619,13 @@ class oracle extends \phpbb\db\driver\driver
|
||||
|
||||
if ($cache && !is_object($query_id) && $cache->sql_exists($query_id))
|
||||
{
|
||||
return $cache->sql_freeresult($query_id);
|
||||
$cache->sql_freeresult($query_id);
|
||||
}
|
||||
|
||||
if (isset($this->open_queries[(int) $query_id]))
|
||||
else if (isset($this->open_queries[(int) $query_id]))
|
||||
{
|
||||
unset($this->open_queries[(int) $query_id]);
|
||||
return oci_free_statement($query_id);
|
||||
oci_free_statement($query_id);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -642,28 +637,21 @@ class oracle extends \phpbb\db\driver\driver
|
||||
}
|
||||
|
||||
/**
|
||||
* Build LIKE expression
|
||||
* @access private
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function _sql_like_expression($expression)
|
||||
protected function _sql_like_expression(string $expression): string
|
||||
{
|
||||
return $expression . " ESCAPE '\\'";
|
||||
}
|
||||
|
||||
/**
|
||||
* Build NOT LIKE expression
|
||||
* @access private
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function _sql_not_like_expression($expression)
|
||||
protected function _sql_not_like_expression(string $expression): string
|
||||
{
|
||||
return $expression . " ESCAPE '\\'";
|
||||
}
|
||||
|
||||
function _sql_custom_build($stage, $data)
|
||||
{
|
||||
return $data;
|
||||
}
|
||||
|
||||
function _sql_bit_and($column_name, $bit, $compare = '')
|
||||
{
|
||||
return 'BITAND(' . $column_name . ', ' . (1 << $bit) . ')' . (($compare) ? ' ' . $compare : '');
|
||||
@@ -675,10 +663,9 @@ class oracle extends \phpbb\db\driver\driver
|
||||
}
|
||||
|
||||
/**
|
||||
* return sql error array
|
||||
* @access private
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function _sql_error()
|
||||
protected function _sql_error(): array
|
||||
{
|
||||
if (function_exists('oci_error'))
|
||||
{
|
||||
@@ -692,7 +679,7 @@ class oracle extends \phpbb\db\driver\driver
|
||||
}
|
||||
else
|
||||
{
|
||||
$error = (isset($this->last_error_result) && $this->last_error_result) ? $this->last_error_result : array();
|
||||
$error = $this->last_error_result ?: ['message' => '', 'code' => ''];
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -707,19 +694,17 @@ class oracle extends \phpbb\db\driver\driver
|
||||
}
|
||||
|
||||
/**
|
||||
* Close sql connection
|
||||
* @access private
|
||||
*/
|
||||
function _sql_close()
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function _sql_close(): bool
|
||||
{
|
||||
return @oci_close($this->db_connect_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build db-specific report
|
||||
* @access private
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function _sql_report($mode, $query = '')
|
||||
protected function _sql_report(string $mode, string $query = ''): void
|
||||
{
|
||||
switch ($mode)
|
||||
{
|
||||
|
@@ -20,7 +20,6 @@ namespace phpbb\db\driver;
|
||||
class postgres extends \phpbb\db\driver\driver
|
||||
{
|
||||
var $multi_insert = true;
|
||||
var $last_query_text = '';
|
||||
var $connect_error = '';
|
||||
|
||||
/**
|
||||
@@ -137,28 +136,24 @@ class postgres extends \phpbb\db\driver\driver
|
||||
}
|
||||
}
|
||||
|
||||
return ($raw) ? $this->sql_server_version : 'PostgreSQL ' . $this->sql_server_version;
|
||||
return ($raw) ? (string) $this->sql_server_version : 'PostgreSQL ' . $this->sql_server_version;
|
||||
}
|
||||
|
||||
/**
|
||||
* SQL Transaction
|
||||
* @access private
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function _sql_transaction($status = 'begin')
|
||||
protected function _sql_transaction(string $status = 'begin'): bool
|
||||
{
|
||||
switch ($status)
|
||||
{
|
||||
case 'begin':
|
||||
return @pg_query($this->db_connect_id, 'BEGIN');
|
||||
break;
|
||||
return @pg_query($this->db_connect_id, 'BEGIN') !== false;
|
||||
|
||||
case 'commit':
|
||||
return @pg_query($this->db_connect_id, 'COMMIT');
|
||||
break;
|
||||
return @pg_query($this->db_connect_id, 'COMMIT') !== false;
|
||||
|
||||
case 'rollback':
|
||||
return @pg_query($this->db_connect_id, 'ROLLBACK');
|
||||
break;
|
||||
return @pg_query($this->db_connect_id, 'ROLLBACK') !== false;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -233,18 +228,9 @@ class postgres extends \phpbb\db\driver\driver
|
||||
}
|
||||
|
||||
/**
|
||||
* Build db-specific query data
|
||||
* @access private
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function _sql_custom_build($stage, $data)
|
||||
{
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build LIMIT query
|
||||
*/
|
||||
function _sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0)
|
||||
protected function _sql_query_limit(string $query, int $total, int $offset = 0, int $cache_ttl = 0)
|
||||
{
|
||||
$this->query_result = false;
|
||||
|
||||
@@ -385,16 +371,13 @@ class postgres extends \phpbb\db\driver\driver
|
||||
$safe_query_id = $this->clean_query_id($query_id);
|
||||
if ($cache && !is_object($query_id) && $cache->sql_exists($safe_query_id))
|
||||
{
|
||||
return $cache->sql_freeresult($safe_query_id);
|
||||
$cache->sql_freeresult($safe_query_id);
|
||||
}
|
||||
|
||||
if (isset($this->open_queries[$safe_query_id]))
|
||||
else if (isset($this->open_queries[$safe_query_id]))
|
||||
{
|
||||
unset($this->open_queries[$safe_query_id]);
|
||||
return pg_free_result($query_id);
|
||||
pg_free_result($query_id);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -405,24 +388,6 @@ class postgres extends \phpbb\db\driver\driver
|
||||
return @pg_escape_string($msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build LIKE expression
|
||||
* @access private
|
||||
*/
|
||||
function _sql_like_expression($expression)
|
||||
{
|
||||
return $expression;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build NOT LIKE expression
|
||||
* @access private
|
||||
*/
|
||||
function _sql_not_like_expression($expression)
|
||||
{
|
||||
return $expression;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@@ -440,10 +405,9 @@ class postgres extends \phpbb\db\driver\driver
|
||||
}
|
||||
|
||||
/**
|
||||
* return sql error array
|
||||
* @access private
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function _sql_error()
|
||||
protected function _sql_error(): array
|
||||
{
|
||||
// pg_last_error only works when there is an established connection.
|
||||
// Connection errors have to be tracked by us manually.
|
||||
@@ -463,10 +427,9 @@ class postgres extends \phpbb\db\driver\driver
|
||||
}
|
||||
|
||||
/**
|
||||
* Close sql connection
|
||||
* @access private
|
||||
*/
|
||||
function _sql_close()
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function _sql_close(): bool
|
||||
{
|
||||
// Released resources are already closed, return true in this case
|
||||
if (!is_resource($this->db_connect_id))
|
||||
@@ -477,10 +440,9 @@ class postgres extends \phpbb\db\driver\driver
|
||||
}
|
||||
|
||||
/**
|
||||
* Build db-specific report
|
||||
* @access private
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function _sql_report($mode, $query = '')
|
||||
protected function _sql_report(string $mode, string $query = ''): void
|
||||
{
|
||||
switch ($mode)
|
||||
{
|
||||
|
@@ -83,27 +83,20 @@ class sqlite3 extends \phpbb\db\driver\driver
|
||||
}
|
||||
|
||||
/**
|
||||
* SQL Transaction
|
||||
*
|
||||
* @param string $status Should be one of the following strings:
|
||||
* begin, commit, rollback
|
||||
* @return bool Success/failure of the transaction query
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function _sql_transaction($status = 'begin')
|
||||
protected function _sql_transaction(string $status = 'begin'): bool
|
||||
{
|
||||
switch ($status)
|
||||
{
|
||||
case 'begin':
|
||||
return $this->dbo->exec('BEGIN IMMEDIATE');
|
||||
break;
|
||||
|
||||
case 'commit':
|
||||
return $this->dbo->exec('COMMIT');
|
||||
break;
|
||||
|
||||
case 'rollback':
|
||||
return @$this->dbo->exec('ROLLBACK');
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -188,16 +181,9 @@ class sqlite3 extends \phpbb\db\driver\driver
|
||||
}
|
||||
|
||||
/**
|
||||
* Build LIMIT query
|
||||
*
|
||||
* @param string $query The SQL query to execute
|
||||
* @param int $total The number of rows to select
|
||||
* @param int $offset
|
||||
* @param int $cache_ttl Either 0 to avoid caching or
|
||||
* the time in seconds which the result shall be kept in cache
|
||||
* @return mixed Buffered, seekable result handle, false on error
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function _sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0)
|
||||
protected function _sql_query_limit(string $query, int $total, int $offset = 0, int $cache_ttl = 0)
|
||||
{
|
||||
$this->query_result = false;
|
||||
|
||||
@@ -263,12 +249,13 @@ class sqlite3 extends \phpbb\db\driver\driver
|
||||
|
||||
if ($cache && !is_object($query_id) && $cache->sql_exists($query_id))
|
||||
{
|
||||
return $cache->sql_freeresult($query_id);
|
||||
$cache->sql_freeresult($query_id);
|
||||
return;
|
||||
}
|
||||
|
||||
if ($query_id)
|
||||
{
|
||||
return @$query_id->finalize();
|
||||
@$query_id->finalize();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -315,11 +302,9 @@ class sqlite3 extends \phpbb\db\driver\driver
|
||||
}
|
||||
|
||||
/**
|
||||
* return sql error array
|
||||
*
|
||||
* @return array
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function _sql_error()
|
||||
protected function _sql_error(): array
|
||||
{
|
||||
if (class_exists('SQLite3', false) && isset($this->dbo))
|
||||
{
|
||||
@@ -340,24 +325,9 @@ class sqlite3 extends \phpbb\db\driver\driver
|
||||
}
|
||||
|
||||
/**
|
||||
* Build db-specific query data
|
||||
*
|
||||
* @param string $stage Available stages: FROM, WHERE
|
||||
* @param mixed $data A string containing the CROSS JOIN query or an array of WHERE clauses
|
||||
*
|
||||
* @return string The db-specific query fragment
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function _sql_custom_build($stage, $data)
|
||||
{
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Close sql connection
|
||||
*
|
||||
* @return bool False if failure
|
||||
*/
|
||||
protected function _sql_close()
|
||||
protected function _sql_close(): bool
|
||||
{
|
||||
return $this->dbo->close();
|
||||
}
|
||||
@@ -365,12 +335,13 @@ class sqlite3 extends \phpbb\db\driver\driver
|
||||
/**
|
||||
* Build db-specific report
|
||||
*
|
||||
* @param string $mode Available modes: display, start, stop,
|
||||
* @param string $mode Available modes: display, start, stop,
|
||||
* add_select_row, fromcache, record_fromcache
|
||||
* @param string $query The Query that should be explained
|
||||
* @return mixed Either a full HTML page, boolean or null
|
||||
* @param string $query The Query that should be explained
|
||||
*
|
||||
* @return void Either writes HTML to html_hold or outputs a full HTML page
|
||||
*/
|
||||
protected function _sql_report($mode, $query = '')
|
||||
protected function _sql_report(string $mode, string $query = ''): void
|
||||
{
|
||||
switch ($mode)
|
||||
{
|
||||
|
Reference in New Issue
Block a user