Skip to content

Commit

Permalink
Merge pull request #1938 from atishamte/db_typos
Browse files Browse the repository at this point in the history
Database typos changes
  • Loading branch information
jim-parry authored Apr 11, 2019
2 parents 5d49d2c + b3029fd commit d2465a8
Show file tree
Hide file tree
Showing 28 changed files with 305 additions and 252 deletions.
8 changes: 4 additions & 4 deletions system/Database/BaseBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1251,18 +1251,18 @@ public function orderBy(string $orderBy, string $direction = '', bool $escape =

if ($escape === false)
{
$qb_orderby[] = [
$qb_orderBy[] = [
'field' => $orderBy,
'direction' => $direction,
'escape' => false,
];
}
else
{
$qb_orderby = [];
$qb_orderBy = [];
foreach (explode(',', $orderBy) as $field)
{
$qb_orderby[] = ($direction === '' && preg_match('/\s+(ASC|DESC)$/i', rtrim($field), $match, PREG_OFFSET_CAPTURE))
$qb_orderBy[] = ($direction === '' && preg_match('/\s+(ASC|DESC)$/i', rtrim($field), $match, PREG_OFFSET_CAPTURE))
?
[
'field' => ltrim(substr($field, 0, $match[0][1])),
Expand All @@ -1278,7 +1278,7 @@ public function orderBy(string $orderBy, string $direction = '', bool $escape =
}
}

$this->QBOrderBy = array_merge($this->QBOrderBy, $qb_orderby);
$this->QBOrderBy = array_merge($this->QBOrderBy, $qb_orderBy);

return $this;
}
Expand Down
83 changes: 47 additions & 36 deletions system/Database/BaseConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -422,12 +422,14 @@ public function initialize()
* @param boolean $persistent
* @return mixed
*/
abstract public function connect($persistent = false);
abstract public function connect(bool $persistent = false);

//--------------------------------------------------------------------

/**
* Close the database connection.
*
* @return void
*/
public function close()
{
Expand Down Expand Up @@ -526,9 +528,9 @@ public function getError()
/**
* The name of the platform in use (MySQLi, mssql, etc)
*
* @return mixed
* @return string
*/
public function getPlatform()
public function getPlatform(): string
{
return $this->DBDriver;
}
Expand All @@ -538,9 +540,9 @@ public function getPlatform()
/**
* Returns a string containing the version of the database being used.
*
* @return mixed
* @return string
*/
abstract public function getVersion();
abstract public function getVersion(): string;

//--------------------------------------------------------------------

Expand Down Expand Up @@ -586,7 +588,7 @@ public function addTableAlias(string $table)
*
* @return mixed
*/
abstract protected function execute($sql);
abstract protected function execute(string $sql);

//--------------------------------------------------------------------

Expand All @@ -599,13 +601,13 @@ abstract protected function execute($sql);
* queries if needed.
*
* @param string $sql
* @param array ...$binds
* @param mixed ...$binds
* @param boolean $setEscapeFlags
* @param string $queryClass
*
* @return BaseResult|Query|false
*/
public function query(string $sql, $binds = null, bool $setEscapeFlags = true, $queryClass = 'CodeIgniter\\Database\\Query')
public function query(string $sql, $binds = null, bool $setEscapeFlags = true, string $queryClass = 'CodeIgniter\\Database\\Query')
{
if (empty($this->connID))
{
Expand Down Expand Up @@ -713,6 +715,8 @@ public function simpleQuery(string $sql)
* Disable Transactions
*
* This permits transactions to be disabled at run-time.
*
* @return void
*/
public function transOff()
{
Expand Down Expand Up @@ -750,7 +754,7 @@ public function transStrict(bool $mode = true)
* @param boolean $test_mode = FALSE
* @return boolean
*/
public function transStart($test_mode = false)
public function transStart(bool $test_mode = false): bool
{
if (! $this->transEnabled)
{
Expand All @@ -767,7 +771,7 @@ public function transStart($test_mode = false)
*
* @return boolean
*/
public function transComplete()
public function transComplete(): bool
{
if (! $this->transEnabled)
{
Expand Down Expand Up @@ -924,7 +928,7 @@ abstract protected function _transRollback(): bool;
/**
* Returns an instance of the query builder for this connection.
*
* @param string $tableName
* @param string|array $tableName
*
* @return BaseBuilder
* @throws DatabaseException
Expand Down Expand Up @@ -1008,7 +1012,7 @@ public function getLastQuery()
*
* @return string
*/
public function showLastQuery()
public function showLastQuery(): string
{
return (string) $this->lastQuery;
}
Expand All @@ -1023,7 +1027,7 @@ public function showLastQuery()
*
* @return float
*/
public function getConnectStart()
public function getConnectStart(): float
{
return $this->connectTime;
}
Expand All @@ -1038,9 +1042,9 @@ public function getConnectStart()
*
* @param integer $decimals
*
* @return mixed
* @return string
*/
public function getConnectDuration($decimals = 6)
public function getConnectDuration(int $decimals = 6): string
{
return number_format($this->connectDuration, $decimals);
}
Expand All @@ -1067,14 +1071,14 @@ public function getConnectDuration($decimals = 6)
* insert the table prefix (if it exists) in the proper position, and escape only
* the correct identifiers.
*
* @param string|array
* @param boolean
* @param mixed
* @param boolean
* @param string|array $item
* @param boolean $prefixSingle
* @param boolean $protectIdentifiers
* @param boolean $fieldExists
*
* @return string|array
*/
public function protectIdentifiers($item, $prefixSingle = false, $protectIdentifiers = null, $fieldExists = true)
public function protectIdentifiers($item, bool $prefixSingle = false, bool $protectIdentifiers = null, bool $fieldExists = true)
{
if (! is_bool($protectIdentifiers))
{
Expand Down Expand Up @@ -1313,7 +1317,7 @@ public function escapeIdentifiers($item)
* @return string
* @throws \CodeIgniter\Database\Exceptions\DatabaseException
*/
public function prefixTable($table = '')
public function prefixTable(string $table = ''): string
{
if ($table === '')
{
Expand All @@ -1334,7 +1338,7 @@ public function prefixTable($table = '')
*
* @return string
*/
public function setPrefix($prefix = '')
public function setPrefix(string $prefix = ''): string
{
return $this->DBPrefix = $prefix;
}
Expand All @@ -1356,7 +1360,7 @@ abstract public function affectedRows(): int;
* Escapes data based on type.
* Sets boolean and null types
*
* @param $str
* @param mixed $str
*
* @return mixed
*/
Expand Down Expand Up @@ -1395,9 +1399,9 @@ public function escape($str)
*
* @param string|string[] $str Input string
* @param boolean $like Whether or not the string will be used in a LIKE condition
* @return string
* @return string|string[]
*/
public function escapeString($str, $like = false)
public function escapeString($str, bool $like = false)
{
if (is_array($str))
{
Expand Down Expand Up @@ -1473,7 +1477,7 @@ protected function _escapeString(string $str): string
* @return boolean
* @throws DatabaseException
*/
public function callFunction(string $functionName, ...$params)
public function callFunction(string $functionName, ...$params): bool
{
$driver = ($this->DBDriver === 'postgre' ? 'pg' : strtolower($this->DBDriver)) . '_';

Expand Down Expand Up @@ -1507,7 +1511,7 @@ public function callFunction(string $functionName, ...$params)
* @return boolean|array
* @throws \CodeIgniter\Database\Exceptions\DatabaseException
*/
public function listTables($constrain_by_prefix = false)
public function listTables(bool $constrain_by_prefix = false)
{
// Is there a cached result?
if (isset($this->dataCache['table_names']) && $this->dataCache['table_names'])
Expand Down Expand Up @@ -1566,7 +1570,7 @@ public function listTables($constrain_by_prefix = false)
* @param string $table_name
* @return boolean
*/
public function tableExists($table_name)
public function tableExists(string $table_name): bool
{
return in_array($this->protectIdentifiers($table_name, true, false, false), $this->listTables());
}
Expand All @@ -1581,7 +1585,7 @@ public function tableExists($table_name)
* @return array|false
* @throws DatabaseException
*/
public function getFieldNames($table)
public function getFieldNames(string $table)
{
// Is there a cached result?
if (isset($this->dataCache['field_names'][$table]))
Expand Down Expand Up @@ -1637,11 +1641,11 @@ public function getFieldNames($table)
/**
* Determine if a particular field exists
*
* @param string
* @param string
* @param string $fieldName
* @param string $tableName
* @return boolean
*/
public function fieldExists($fieldName, $tableName)
public function fieldExists(string $fieldName, string $tableName): bool
{
return in_array($fieldName, $this->getFieldNames($tableName));
}
Expand Down Expand Up @@ -1735,7 +1739,7 @@ public function resetDataCache()
*
* @return array
*/
abstract public function error();
abstract public function error(): array;

//--------------------------------------------------------------------

Expand All @@ -1744,7 +1748,7 @@ abstract public function error();
*
* @return integer
*/
abstract public function insertID();
abstract public function insertID(): int;

//--------------------------------------------------------------------

Expand All @@ -1755,7 +1759,7 @@ abstract public function insertID();
*
* @return string
*/
abstract protected function _listTables($constrainByPrefix = false): string;
abstract protected function _listTables(bool $constrainByPrefix = false): string;

//--------------------------------------------------------------------

Expand Down Expand Up @@ -1803,12 +1807,19 @@ abstract protected function _foreignKeyData(string $table): array;

//--------------------------------------------------------------------

public function __get($key)
/**
* @param string $key
*
* @return mixed
*/
public function __get(string $key)
{
if (property_exists($this, $key))
{
return $this->$key;
}

return null;
}

//--------------------------------------------------------------------
Expand Down
15 changes: 9 additions & 6 deletions system/Database/BasePreparedQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

namespace CodeIgniter\Database;

use CodeIgniter\Database\MySQLi\Connection;
use CodeIgniter\Events\Events;

/**
Expand Down Expand Up @@ -85,7 +86,7 @@ abstract class BasePreparedQuery implements PreparedQueryInterface

public function __construct(ConnectionInterface $db)
{
$this->db = & $db;
$this->db = &$db;
}

//--------------------------------------------------------------------
Expand All @@ -103,7 +104,7 @@ public function __construct(ConnectionInterface $db)
*
* @return mixed
*/
public function prepare(string $sql, array $options = [], $queryClass = 'CodeIgniter\\Database\\Query')
public function prepare(string $sql, array $options = [], string $queryClass = 'CodeIgniter\\Database\\Query')
{
// We only supports positional placeholders (?)
// in order to work with the execute method below, so we
Expand Down Expand Up @@ -180,9 +181,9 @@ public function execute(...$data)
*
* @param array $data
*
* @return ResultInterface
* @return boolean
*/
abstract public function _execute($data);
abstract public function _execute(array $data): bool;

//--------------------------------------------------------------------

Expand All @@ -196,7 +197,9 @@ abstract public function _getResult();
//--------------------------------------------------------------------

/**
* Explicity closes the statement.
* Explicitly closes the statement.
*
* @return null|void
*/
public function close()
{
Expand Down Expand Up @@ -232,7 +235,7 @@ public function getQueryString(): string
*
* @return boolean
*/
public function hasError()
public function hasError(): bool
{
return ! empty($this->errorString);
}
Expand Down
Loading

0 comments on commit d2465a8

Please sign in to comment.