Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 61 additions & 64 deletions system/Database/BaseConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,35 +25,35 @@
use Throwable;

/**
* @property-read array $aliasedTables
* @property-read string $charset
* @property-read bool $compress
* @property-read float $connectDuration
* @property-read float $connectTime
* @property-read string $database
* @property-read array $dateFormat
* @property-read string $DBCollat
* @property-read bool $DBDebug
* @property-read string $DBDriver
* @property-read string $DBPrefix
* @property-read string $DSN
* @property-read array|bool $encrypt
* @property-read array $failover
* @property-read string $hostname
* @property-read Query $lastQuery
* @property-read string $password
* @property-read bool $pConnect
* @property-read int|string $port
* @property-read bool $pretend
* @property-read string $queryClass
* @property-read array $reservedIdentifiers
* @property-read bool $strictOn
* @property-read string $subdriver
* @property-read string $swapPre
* @property-read int $transDepth
* @property-read bool $transFailure
* @property-read bool $transStatus
* @property-read string $username
* @property-read list<string> $aliasedTables
* @property-read string $charset
* @property-read bool $compress
* @property-read float $connectDuration
* @property-read float $connectTime
* @property-read string $database
* @property-read array<string, string> $dateFormat
* @property-read string $DBCollat
* @property-read bool $DBDebug
* @property-read string $DBDriver
* @property-read string $DBPrefix
* @property-read string $DSN
* @property-read array<string, bool|string>|bool $encrypt
* @property-read list<array<string, mixed>> $failover
* @property-read string $hostname
* @property-read Query $lastQuery
* @property-read string $password
* @property-read bool $pConnect
* @property-read int|string $port
* @property-read bool $pretend
* @property-read string $queryClass
* @property-read list<string> $reservedIdentifiers
* @property-read bool $strictOn
* @property-read string $subdriver
* @property-read string $swapPre
* @property-read int $transDepth
* @property-read bool $transFailure
* @property-read bool $transStatus
* @property-read string $username
*
* @template TConnection
* @template TResult
Expand Down Expand Up @@ -177,7 +177,7 @@ abstract class BaseConnection implements ConnectionInterface
/**
* Encryption flag/data
*
* @var array|bool
* @var array<string, bool|string>|bool
*/
protected $encrypt = false;

Expand All @@ -202,7 +202,7 @@ abstract class BaseConnection implements ConnectionInterface
/**
* Settings for a failover connection.
*
* @var array
* @var list<array<string, mixed>>
*/
protected $failover = [];

Expand Down Expand Up @@ -240,14 +240,14 @@ abstract class BaseConnection implements ConnectionInterface
*
* Identifiers that must NOT be escaped.
*
* @var array
* @var list<string>
*/
protected $reservedIdentifiers = ['*'];

/**
* Identifier escape character
*
* @var array|string
* @var list<string>|string
*/
public $escapeChar = '"';

Expand All @@ -268,15 +268,12 @@ abstract class BaseConnection implements ConnectionInterface
/**
* RegExp used to escape identifiers
*
* @var array
* @var list<string>
*/
protected $pregEscapeChar = [];

/**
* Holds previously looked up data
* for performance reasons.
*
* @var array
* @var array<string, mixed>
*/
public $dataCache = [];

Expand Down Expand Up @@ -374,7 +371,7 @@ abstract class BaseConnection implements ConnectionInterface
];

/**
* Saves our connection settings.
* @param array<string, mixed> $params
*/
public function __construct(array $params)
{
Expand Down Expand Up @@ -739,6 +736,8 @@ public function getPlatform(): string
* collected during use of the Builder, and set here
* so queries are built correctly.
*
* @param list<string> $aliases
*
* @return $this
*/
public function setAliasedTables(array $aliases)
Expand Down Expand Up @@ -1111,7 +1110,7 @@ abstract protected function _transRollback(): bool;
/**
* Returns a non-shared new instance of the query builder for this connection.
*
* @param array|string|TableName $tableName
* @param array<array-key, string>|string|TableName $tableName
*
* @return BaseBuilder
*
Expand Down Expand Up @@ -1156,6 +1155,7 @@ public function newQuery(): BaseBuilder
* })
*
* @param Closure(BaseConnection): mixed $func
* @param array<string, mixed> $options
*
* @return BasePreparedQuery|null
*/
Expand Down Expand Up @@ -1242,12 +1242,12 @@ public function getConnectDuration(int $decimals = 6): string
* insert the table prefix (if it exists) in the proper position, and escape only
* the correct identifiers.
*
* @param array|int|string|TableName $item
* @param bool $prefixSingle Prefix a table name with no segments?
* @param bool $protectIdentifiers Protect table or column names?
* @param bool $fieldExists Supplied $item contains a column name?
* @param array<array-key, mixed>|int|string|TableName $item
* @param bool $prefixSingle Prefix a table name with no segments?
* @param bool $protectIdentifiers Protect table or column names?
* @param bool $fieldExists Supplied $item contains a column name?
*
* @return ($item is array ? array : string)
* @return ($item is array ? array<array-key, mixed> : string)
*/
public function protectIdentifiers($item, bool $prefixSingle = false, ?bool $protectIdentifiers = null, bool $fieldExists = true)
{
Expand Down Expand Up @@ -1448,9 +1448,9 @@ private function escapeTableName(TableName $tableName): string
*
* This function escapes column and table names
*
* @param array|string $item
* @param array<array-key, mixed>|string $item
*
* @return ($item is array ? array : string)
* @return ($item is array ? array<array-key, mixed> : string)
*/
public function escapeIdentifiers($item)
{
Expand Down Expand Up @@ -1534,7 +1534,7 @@ abstract public function affectedRows(): int;
*
* @param mixed $str
*
* @return ($str is array ? array : float|int|string)
* @return ($str is array ? array<array-key, mixed> : float|int|string)
*/
public function escape($str)
{
Expand Down Expand Up @@ -1638,7 +1638,7 @@ protected function _escapeString(string $str): string
* This function enables you to call PHP database functions that are not natively included
* in CodeIgniter, in a platform independent manner.
*
* @param array ...$params
* @param mixed ...$params
*
* @throws DatabaseException
*/
Expand Down Expand Up @@ -1682,7 +1682,7 @@ protected function getDriverFunctionPrefix(): string
*/
public function listTables(bool $constrainByPrefix = false)
{
if (isset($this->dataCache['table_names']) && $this->dataCache['table_names']) {
if (($this->dataCache['table_names'] ?? []) !== []) {
$tables = $constrainByPrefix
? preg_grep("/^{$this->DBPrefix}/", $this->dataCache['table_names'])
: $this->dataCache['table_names'];
Expand Down Expand Up @@ -1847,21 +1847,18 @@ public function getForeignKeyData(string $table)
/**
* Converts array of arrays generated by _foreignKeyData() to array of objects
*
* @return array<string, stdClass>
* @param array<array-key, array{
* constraint_name: string|null,
* table_name: string,
* column_name: list<string>,
* foreign_table_name: string,
* foreign_column_name: list<string>,
* on_delete: string,
* on_update: string|null,
* match: string|null,
* }> $data
*
* array[
* {constraint_name} =>
* stdClass[
* 'constraint_name' => string,
* 'table_name' => string,
* 'column_name' => string[],
* 'foreign_table_name' => string,
* 'foreign_column_name' => string[],
* 'on_delete' => string,
* 'on_update' => string,
* 'match' => string
* ]
* ]
* @return array<string, stdClass>
*/
protected function foreignKeyDataToObjects(array $data)
{
Expand Down
6 changes: 3 additions & 3 deletions system/Database/ConnectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function simpleQuery(string $sql);
/**
* Returns an instance of the query builder for this connection.
*
* @param array|string $tableName Table name.
* @param array<array-key, string>|string $tableName Table name.
*
* @return BaseBuilder Builder.
*/
Expand All @@ -139,15 +139,15 @@ public function getLastQuery();
*
* @param mixed $str
*
* @return ($str is array ? array : float|int|string)
* @return ($str is array ? array<array-key, mixed> : float|int|string)
*/
public function escape($str);

/**
* Allows for custom calls to the database engine that are not
* supported through our database layer.
*
* @param array ...$params
* @param mixed ...$params
*
* @return mixed
*/
Expand Down
37 changes: 1 addition & 36 deletions system/Database/MySQLi/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

use CodeIgniter\Database\BaseConnection;
use CodeIgniter\Database\Exceptions\DatabaseException;
use CodeIgniter\Database\TableName;
use CodeIgniter\Exceptions\LogicException;
use mysqli;
use mysqli_result;
Expand Down Expand Up @@ -51,7 +50,7 @@ class Connection extends BaseConnection
/**
* Identifier escape character
*
* @var string
* @var list<string>|string
*/
public $escapeChar = '`';

Expand Down Expand Up @@ -234,11 +233,6 @@ public function connect(bool $persistent = false)
return false;
}

/**
* Close the database connection.
*
* @return void
*/
protected function _close()
{
$this->connID->close();
Expand Down Expand Up @@ -379,10 +373,7 @@ public function escapeLikeStringDirect($str)
}

/**
* Generates the SQL for listing tables in a platform-dependent manner.
* Uses escapeLikeStringDirect().
*
* @param string|null $tableName If $tableName is provided will return only this table if exists.
*/
protected function _listTables(bool $prefixLimit = false, ?string $tableName = null): string
{
Expand All @@ -399,11 +390,6 @@ protected function _listTables(bool $prefixLimit = false, ?string $tableName = n
return $sql;
}

/**
* Generates a platform-specific query string so that the column names can be fetched.
*
* @param string|TableName $table
*/
protected function _listColumns($table = ''): string
{
$tableName = $this->protectIdentifiers(
Expand All @@ -417,10 +403,6 @@ protected function _listColumns($table = ''): string
}

/**
* Returns an array of objects with field data
*
* @return list<stdClass>
*
* @throws DatabaseException
*/
protected function _fieldData(string $table): array
Expand Down Expand Up @@ -449,10 +431,6 @@ protected function _fieldData(string $table): array
}

/**
* Returns an array of objects with index data
*
* @return array<string, stdClass>
*
* @throws DatabaseException
* @throws LogicException
*/
Expand Down Expand Up @@ -497,10 +475,6 @@ protected function _indexData(string $table): array
}

/**
* Returns an array of objects with Foreign key data
*
* @return array<string, stdClass>
*
* @throws DatabaseException
*/
protected function _foreignKeyData(string $table): array
Expand Down Expand Up @@ -598,25 +572,16 @@ public function insertID(): int
return $this->connID->insert_id;
}

/**
* Begin Transaction
*/
protected function _transBegin(): bool
{
return $this->connID->begin_transaction();
}

/**
* Commit Transaction
*/
protected function _transCommit(): bool
{
return $this->connID->commit();
}

/**
* Rollback Transaction
*/
protected function _transRollback(): bool
{
return $this->connID->rollback();
Expand Down
Loading
Loading