1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-08-19 06:51:33 +02:00

[ticket/16955] Clean up code in db classes

PHPBB3-16955
This commit is contained in:
Marc Alexander
2022-12-27 14:13:23 +01:00
parent 3bc100c9a0
commit 948023078b
26 changed files with 277 additions and 327 deletions

View File

@@ -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}
*/