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
63 changes: 4 additions & 59 deletions system/Database/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,7 @@ public function __construct(ConnectionInterface $db)
$this->db = $db;
}

/**
* Sets the raw query string to use for this statement.
*
* @param mixed $binds
*
* @return $this
*/
public function setQuery(string $sql, $binds = null, bool $setEscape = true)
public function setQuery(string $sql, mixed $binds = null, bool $setEscape = true): self
{
$this->originalQueryString = $sql;
unset($this->swappedQueryString);
Expand Down Expand Up @@ -153,10 +146,6 @@ public function setBinds(array $binds, bool $setEscape = true)
return $this;
}

/**
* Returns the final, processed query string after binding, etal
* has been performed.
*/
public function getQuery(): string
{
if (empty($this->finalQueryString)) {
Expand All @@ -166,14 +155,7 @@ public function getQuery(): string
return $this->finalQueryString;
}

/**
* Records the execution time of the statement using microtime(true)
* for it's start and end values. If no end value is present, will
* use the current time to determine total duration.
*
* @return $this
*/
public function setDuration(float $start, ?float $end = null)
public function setDuration(float $start, ?float $end = null): self
{
$this->startTime = $start;

Expand All @@ -200,68 +182,40 @@ public function getStartTime(bool $returnRaw = false, int $decimals = 6)
return number_format($this->startTime, $decimals);
}

/**
* Returns the duration of this query during execution, or null if
* the query has not been executed yet.
*
* @param int $decimals The accuracy of the returned time.
*/
public function getDuration(int $decimals = 6): string
{
return number_format(($this->endTime - $this->startTime), $decimals);
}

/**
* Stores the error description that happened for this query.
*
* @return $this
*/
public function setError(int $code, string $error)
public function setError(int $code, string $error): self
{
$this->errorCode = $code;
$this->errorString = $error;

return $this;
}

/**
* Reports whether this statement created an error not.
*/
public function hasError(): bool
{
return ! empty($this->errorString);
}

/**
* Returns the error code created while executing this statement.
*/
public function getErrorCode(): int
{
return $this->errorCode;
}

/**
* Returns the error message created while executing this statement.
*/
public function getErrorMessage(): string
{
return $this->errorString;
}

/**
* Determines if the statement is a write-type query or not.
*/
public function isWriteType(): bool
{
return $this->db->isWriteType($this->originalQueryString);
}

/**
* Swaps out one table prefix for a new one.
*
* @return $this
*/
public function swapPrefix(string $orig, string $swap)
public function swapPrefix(string $orig, string $swap): self
{
$sql = $this->swappedQueryString ?? $this->originalQueryString;

Expand All @@ -275,9 +229,6 @@ public function swapPrefix(string $orig, string $swap)
return $this;
}

/**
* Returns the original SQL that was passed into the system.
*/
public function getOriginalQuery(): string
{
return $this->originalQueryString;
Expand Down Expand Up @@ -315,9 +266,6 @@ protected function compileBinds()
}
}

/**
* Match bindings
*/
protected function matchNamedBinds(string $sql, array $binds): string
{
$replacers = [];
Expand All @@ -339,9 +287,6 @@ protected function matchNamedBinds(string $sql, array $binds): string
return strtr($sql, $replacers);
}

/**
* Match bindings
*/
protected function matchSimpleBinds(string $sql, array $binds, int $bindCount, int $ml): string
{
if ($c = preg_match_all("/'[^']*'/", $sql, $matches) >= 1) {
Expand Down
29 changes: 10 additions & 19 deletions system/Database/QueryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,38 +14,28 @@
namespace CodeIgniter\Database;

/**
* Interface QueryInterface
*
* Represents a single statement that can be executed against the database.
* Statements are platform-specific and can handle binding of binds.
*/
interface QueryInterface
{
/**
* Sets the raw query string to use for this statement.
*
* @param mixed $binds
*
* @return $this
*/
public function setQuery(string $sql, $binds = null, bool $setEscape = true);
public function setQuery(string $sql, mixed $binds = null, bool $setEscape = true): self;

/**
* Returns the final, processed query string after binding, etal
* has been performed.
*
* @return string
*/
public function getQuery();
public function getQuery(): string;

/**
* Records the execution time of the statement using microtime(true)
* for it's start and end values. If no end value is present, will
* use the current time to determine total duration.
*
* @return $this
*/
public function setDuration(float $start, ?float $end = null);
public function setDuration(float $start, ?float $end = null): self;

/**
* Returns the duration of this query during execution, or null if
Expand All @@ -57,10 +47,8 @@ public function getDuration(int $decimals = 6): string;

/**
* Stores the error description that happened for this query.
*
* @return $this
*/
public function setError(int $code, string $error);
public function setError(int $code, string $error): self;

/**
* Reports whether this statement created an error not.
Expand All @@ -84,8 +72,11 @@ public function isWriteType(): bool;

/**
* Swaps out one table prefix for a new one.
*
* @return $this
*/
public function swapPrefix(string $orig, string $swap);
public function swapPrefix(string $orig, string $swap): self;

/**
* Returns the original SQL that was passed into the system.
*/
public function getOriginalQuery(): string;
}
13 changes: 11 additions & 2 deletions user_guide_src/source/changelogs/v4.7.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,11 @@ To use a different encryption key permanently, pass a custom config when creatin
Interface Changes
=================

- **Cache:** The ``CacheInterface`` now includes the ``deleteMatching()`` method. If you've implemented your own caching driver from scratch, you will need to provide an implementation for this method to ensure compatibility.
- **Images:** The ``ImageHandlerInterface`` now includes a new method: ``clearMetadata()``. If you've implemented your own handler from scratch, you will need to provide an implementation for this method to ensure compatibility.
**NOTE:** If you've implemented your own classes that implement these interfaces from scratch, you will need to update your implementations to include the new methods to ensure compatibility.

- **Cache:** The ``CacheInterface`` now includes the ``deleteMatching()`` method.
- **Database:** The ``QueryInterface`` now includes the ``getOriginalQuery()`` method.
- **Images:** The ``ImageHandlerInterface`` now includes a new method: ``clearMetadata()``.

Method Signature Changes
========================
Expand All @@ -204,6 +207,12 @@ Method Signature Changes
- ``clean()``
- ``getCacheInfo()``
- ``getMetaData()``
- Added native parameter and return types to ``CodeIgniter\Database\QueryInterface`` methods:
- ``setQuery(string $sql, mixed $binds = null, bool $setEscape = true): self``
- ``getQuery(): string``
- ``setDuration(float $start, ?float $end = null): self``
- ``setError(int $code, string $error): self``
- ``swapPrefix(string $orig, string $swap): self``
- Added native return types to ``CodeIgniter\Debug\Toolbar`` methods:
- ``prepare(): void``
- ``respond(): void``
Expand Down
2 changes: 1 addition & 1 deletion utils/phpstan-baseline/loader.neon
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# total 2166 errors
# total 2165 errors

includes:
- argument.type.neon
Expand Down
7 changes: 1 addition & 6 deletions utils/phpstan-baseline/method.notFound.neon
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
# total 81 errors
# total 80 errors

parameters:
ignoreErrors:
-
message: '#^Call to an undefined method CodeIgniter\\Database\\QueryInterface\:\:getOriginalQuery\(\)\.$#'
count: 1
path: ../../system/Database/BaseConnection.php

-
message: '#^Call to an undefined method CodeIgniter\\View\\RendererInterface\:\:getData\(\)\.$#'
count: 1
Expand Down
Loading