Upgrade to 3.8.3
This commit is contained in:
@@ -19,33 +19,25 @@ abstract class Sql
|
||||
{
|
||||
/**
|
||||
* List of literals which should not be escaped in queries
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $literals = ['NOW()', null];
|
||||
public static array $literals = ['NOW()', null];
|
||||
|
||||
/**
|
||||
* The parent database connection
|
||||
*
|
||||
* @var \Kirby\Database\Database
|
||||
*/
|
||||
protected $database;
|
||||
protected Database $database;
|
||||
|
||||
/**
|
||||
* List of used bindings; used to avoid
|
||||
* duplicate binding names
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $bindings = [];
|
||||
protected array $bindings = [];
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param \Kirby\Database\Database $database
|
||||
*/
|
||||
public function __construct($database)
|
||||
public function __construct(Database $database)
|
||||
{
|
||||
$this->database = $database;
|
||||
}
|
||||
@@ -80,7 +72,6 @@ abstract class Sql
|
||||
* the query needs to return rows with a column `name`
|
||||
*
|
||||
* @param string $table Table name
|
||||
* @return array
|
||||
*/
|
||||
abstract public function columns(string $table): array;
|
||||
|
||||
@@ -136,8 +127,6 @@ abstract class Sql
|
||||
* Abstracted column types to simplify table
|
||||
* creation for multiple database drivers
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function columnTypes(): array
|
||||
{
|
||||
@@ -154,11 +143,8 @@ abstract class Sql
|
||||
/**
|
||||
* Combines an identifier (table and column)
|
||||
*
|
||||
* @param $table string
|
||||
* @param $column string
|
||||
* @param $values bool Whether the identifier is going to be used for a VALUES clause;
|
||||
* only relevant for SQLite
|
||||
* @return string
|
||||
*/
|
||||
public function combineIdentifier(string $table, string $column, bool $values = false): string
|
||||
{
|
||||
@@ -316,7 +302,6 @@ abstract class Sql
|
||||
* Builds a DELETE clause
|
||||
*
|
||||
* @param array $params List of parameters for the DELETE clause. See defaults for more info.
|
||||
* @return array
|
||||
*/
|
||||
public function delete(array $params = []): array
|
||||
{
|
||||
@@ -344,9 +329,6 @@ abstract class Sql
|
||||
|
||||
/**
|
||||
* Creates the sql for dropping a single table
|
||||
*
|
||||
* @param string $table
|
||||
* @return array
|
||||
*/
|
||||
public function dropTable(string $table): array
|
||||
{
|
||||
@@ -359,13 +341,8 @@ abstract class Sql
|
||||
/**
|
||||
* Extends a given query and bindings
|
||||
* by reference
|
||||
*
|
||||
* @param array $query
|
||||
* @param array $bindings
|
||||
* @param array $input
|
||||
* @return void
|
||||
*/
|
||||
public function extend(&$query, array &$bindings, $input)
|
||||
public function extend(array &$query, array &$bindings, array $input): void
|
||||
{
|
||||
if (empty($input['query']) === false) {
|
||||
$query[] = $input['query'];
|
||||
@@ -375,9 +352,6 @@ abstract class Sql
|
||||
|
||||
/**
|
||||
* Creates the from syntax
|
||||
*
|
||||
* @param string $table
|
||||
* @return array
|
||||
*/
|
||||
public function from(string $table): array
|
||||
{
|
||||
@@ -389,51 +363,36 @@ abstract class Sql
|
||||
|
||||
/**
|
||||
* Creates the group by syntax
|
||||
*
|
||||
* @param string $group
|
||||
* @return array
|
||||
*/
|
||||
public function group(string $group = null): array
|
||||
public function group(string|null $group = null): array
|
||||
{
|
||||
if (empty($group) === true) {
|
||||
return [
|
||||
'query' => null,
|
||||
'bindings' => []
|
||||
];
|
||||
if (empty($group) === false) {
|
||||
$query = 'GROUP BY ' . $group;
|
||||
}
|
||||
|
||||
return [
|
||||
'query' => 'GROUP BY ' . $group,
|
||||
'query' => $query ?? null,
|
||||
'bindings' => []
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the having syntax
|
||||
*
|
||||
* @param string|null $having
|
||||
* @return array
|
||||
*/
|
||||
public function having(string $having = null): array
|
||||
public function having(string|null $having = null): array
|
||||
{
|
||||
if (empty($having) === true) {
|
||||
return [
|
||||
'query' => null,
|
||||
'bindings' => []
|
||||
];
|
||||
if (empty($having) === false) {
|
||||
$query = 'HAVING ' . $having;
|
||||
}
|
||||
|
||||
return [
|
||||
'query' => 'HAVING ' . $having,
|
||||
'query' => $query ?? null,
|
||||
'bindings' => []
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an insert query
|
||||
*
|
||||
* @param array $params
|
||||
* @return array
|
||||
*/
|
||||
public function insert(array $params = []): array
|
||||
{
|
||||
@@ -454,10 +413,6 @@ abstract class Sql
|
||||
/**
|
||||
* Creates a join query
|
||||
*
|
||||
* @param string $table
|
||||
* @param string $type
|
||||
* @param string $on
|
||||
* @return array
|
||||
* @throws \Kirby\Exception\InvalidArgumentException if an invalid join type is given
|
||||
*/
|
||||
public function join(string $type, string $table, string $on): array
|
||||
@@ -492,11 +447,8 @@ abstract class Sql
|
||||
|
||||
/**
|
||||
* Create the syntax for multiple joins
|
||||
*
|
||||
* @param array|null $joins
|
||||
* @return array
|
||||
*/
|
||||
public function joins(array $joins = null): array
|
||||
public function joins(array|null $joins = null): array
|
||||
{
|
||||
$query = [];
|
||||
$bindings = [];
|
||||
@@ -513,12 +465,8 @@ abstract class Sql
|
||||
|
||||
/**
|
||||
* Creates a limit and offset query instruction
|
||||
*
|
||||
* @param int $offset
|
||||
* @param int|null $limit
|
||||
* @return array
|
||||
*/
|
||||
public function limit(int $offset = 0, int $limit = null): array
|
||||
public function limit(int $offset = 0, int|null $limit = null): array
|
||||
{
|
||||
// no need to add it to the query
|
||||
if ($offset === 0 && $limit === null) {
|
||||
@@ -544,42 +492,29 @@ abstract class Sql
|
||||
|
||||
/**
|
||||
* Creates the order by syntax
|
||||
*
|
||||
* @param string $order
|
||||
* @return array
|
||||
*/
|
||||
public function order(string $order = null): array
|
||||
public function order(string|null $order = null): array
|
||||
{
|
||||
if (empty($order) === true) {
|
||||
return [
|
||||
'query' => null,
|
||||
'bindings' => []
|
||||
];
|
||||
if (empty($order) === false) {
|
||||
$query = 'ORDER BY ' . $order;
|
||||
}
|
||||
|
||||
return [
|
||||
'query' => 'ORDER BY ' . $order,
|
||||
'query' => $query ?? null,
|
||||
'bindings' => []
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a query array into a final string
|
||||
*
|
||||
* @param array $query
|
||||
* @param string $separator
|
||||
* @return string
|
||||
*/
|
||||
public function query(array $query, string $separator = ' ')
|
||||
public function query(array $query, string $separator = ' '): string
|
||||
{
|
||||
return implode($separator, array_filter($query));
|
||||
}
|
||||
|
||||
/**
|
||||
* Quotes an identifier (table *or* column)
|
||||
*
|
||||
* @param $identifier string
|
||||
* @return string
|
||||
*/
|
||||
public function quoteIdentifier(string $identifier): string
|
||||
{
|
||||
@@ -658,12 +593,8 @@ abstract class Sql
|
||||
|
||||
/**
|
||||
* Creates a columns definition from string or array
|
||||
*
|
||||
* @param string $table
|
||||
* @param array|string|null $columns
|
||||
* @return string
|
||||
*/
|
||||
public function selected($table, $columns = null): string
|
||||
public function selected(string $table, array|string|null $columns = null): string
|
||||
{
|
||||
// all columns
|
||||
if (empty($columns) === true) {
|
||||
@@ -692,12 +623,10 @@ abstract class Sql
|
||||
/**
|
||||
* Splits a (qualified) identifier into table and column
|
||||
*
|
||||
* @param $table string Default table if the identifier is not qualified
|
||||
* @param $identifier string
|
||||
* @return array
|
||||
* @param string $table Default table if the identifier is not qualified
|
||||
* @throws \Kirby\Exception\InvalidArgumentException if an invalid identifier is given
|
||||
*/
|
||||
public function splitIdentifier($table, $identifier): array
|
||||
public function splitIdentifier(string $table, string $identifier): array
|
||||
{
|
||||
// split by dot, but only outside of quotes
|
||||
$parts = preg_split('/(?:`[^`]*`|"[^"]*")(*SKIP)(*F)|\./', $identifier);
|
||||
@@ -720,16 +649,12 @@ abstract class Sql
|
||||
/**
|
||||
* Returns a query to list the tables of the current database;
|
||||
* the query needs to return rows with a column `name`
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
abstract public function tables(): array;
|
||||
|
||||
/**
|
||||
* Validates and quotes a table name
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
* @throws \Kirby\Exception\InvalidArgumentException if an invalid table name is given
|
||||
*/
|
||||
public function tableName(string $table): string
|
||||
@@ -744,9 +669,6 @@ abstract class Sql
|
||||
|
||||
/**
|
||||
* Unquotes an identifier (table *or* column)
|
||||
*
|
||||
* @param $identifier string
|
||||
* @return string
|
||||
*/
|
||||
public function unquoteIdentifier(string $identifier): string
|
||||
{
|
||||
@@ -767,7 +689,6 @@ abstract class Sql
|
||||
* Builds an update clause
|
||||
*
|
||||
* @param array $params List of parameters for the update clause. See defaults for more info.
|
||||
* @return array
|
||||
*/
|
||||
public function update(array $params = []): array
|
||||
{
|
||||
@@ -799,9 +720,6 @@ abstract class Sql
|
||||
/**
|
||||
* Validates a given column name in a table
|
||||
*
|
||||
* @param string $table
|
||||
* @param string $column
|
||||
* @return bool
|
||||
* @throws \Kirby\Exception\InvalidArgumentException If the column is invalid
|
||||
*/
|
||||
public function validateColumn(string $table, string $column): bool
|
||||
@@ -822,8 +740,13 @@ abstract class Sql
|
||||
* @param bool $set If true builds a set list of values for update clauses
|
||||
* @param bool $enforceQualified Always use fully qualified column names
|
||||
*/
|
||||
public function values(string $table, $values, string $separator = ', ', bool $set = true, bool $enforceQualified = false): array
|
||||
{
|
||||
public function values(
|
||||
string $table,
|
||||
$values,
|
||||
string $separator = ', ',
|
||||
bool $set = true,
|
||||
bool $enforceQualified = false
|
||||
): array {
|
||||
if (is_array($values) === false) {
|
||||
return [
|
||||
'query' => $values,
|
||||
@@ -840,15 +763,13 @@ abstract class Sql
|
||||
|
||||
/**
|
||||
* Creates a list of fields and values
|
||||
*
|
||||
* @param string $table
|
||||
* @param string|array $values
|
||||
* @param string $separator
|
||||
* @param bool $enforceQualified
|
||||
* @param array
|
||||
*/
|
||||
public function valueList(string $table, $values, string $separator = ',', bool $enforceQualified = false): array
|
||||
{
|
||||
public function valueList(
|
||||
string $table,
|
||||
string|array $values,
|
||||
string $separator = ',',
|
||||
bool $enforceQualified = false
|
||||
): array {
|
||||
$fields = [];
|
||||
$query = [];
|
||||
$bindings = [];
|
||||
@@ -886,16 +807,13 @@ abstract class Sql
|
||||
|
||||
/**
|
||||
* Creates a set of values
|
||||
*
|
||||
* @param string $table
|
||||
* @param string|array $values
|
||||
* @param string $separator
|
||||
* @param bool $enforceQualified
|
||||
* @param array
|
||||
* @return array
|
||||
*/
|
||||
public function valueSet(string $table, $values, string $separator = ',', bool $enforceQualified = false): array
|
||||
{
|
||||
public function valueSet(
|
||||
string $table,
|
||||
string|array $values,
|
||||
string $separator = ',',
|
||||
bool $enforceQualified = false
|
||||
): array {
|
||||
$query = [];
|
||||
$bindings = [];
|
||||
|
||||
@@ -928,12 +846,7 @@ abstract class Sql
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|array|null $where
|
||||
* @param array $bindings
|
||||
* @return array
|
||||
*/
|
||||
public function where($where, array $bindings = []): array
|
||||
public function where(string|array|null $where, array $bindings = []): array
|
||||
{
|
||||
if (empty($where) === true) {
|
||||
return [
|
||||
|
||||
Reference in New Issue
Block a user