Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better support for NoSQL drivers #4074

Closed
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
18 changes: 9 additions & 9 deletions system/Database/BaseConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -593,11 +593,11 @@ public function addTableAlias(string $table)
/**
* Executes the query against the database.
*
* @param string $sql
* @param mixed $sql
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mixed means anything. It does not help for code reading.

Can you change it to string|array?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be even needed to use object for such so it can be string|array|object but the main problem is type hint in the method definition. Since merging this one will break all the exiting user implementation where any of these methods have override.

*
* @return mixed
*/
abstract protected function execute(string $sql);
abstract protected function execute($sql);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As stated, changing the signature may be breaking for existing implementations.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the var name $sql make sense in the context of NoSQL?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The better name for the context will be $statement


/**
* Orchestrates a query against the database. Queries must use
Expand All @@ -607,16 +607,16 @@ abstract protected function execute(string $sql);
* Should automatically handle different connections for read/write
* queries if needed.
*
* @param string $sql
* @param mixed ...$binds
* @param boolean $setEscapeFlags
* @param string $queryClass
* @param mixed $sql
* @param mixed ...$binds
* @param boolean $setEscapeFlags
* @param string|null $queryClass
*
* @return BaseResult|Query|boolean
*
* @todo BC set $queryClass default as null in 4.1
*/
public function query(string $sql, $binds = null, bool $setEscapeFlags = true, string $queryClass = '')
public function query($sql, $binds = null, bool $setEscapeFlags = true, string $queryClass = null)
{
$queryClass = $queryClass ?: $this->queryClass;

Expand Down Expand Up @@ -718,11 +718,11 @@ public function query(string $sql, $binds = null, bool $setEscapeFlags = true, s
* is performed, nor are transactions handled. Simply takes a raw
* query string and returns the database-specific result id.
*
* @param string $sql
* @param mixed $sql
*
* @return mixed
*/
public function simpleQuery(string $sql)
public function simpleQuery($sql)
{
if (empty($this->connID))
{
Expand Down
4 changes: 2 additions & 2 deletions system/Database/BasePreparedQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ public function __construct(BaseConnection $db)
* NOTE: This version is based on SQL code. Child classes should
* override this method.
*
* @param string $sql
* @param mixed $sql
* @param array $options Passed to the connection's prepare statement.
* @param string $queryClass
*
* @return mixed
*/
public function prepare(string $sql, array $options = [], string $queryClass = 'CodeIgniter\\Database\\Query')
public function prepare($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
10 changes: 5 additions & 5 deletions system/Database/ConnectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,12 @@ public function getVersion(): string;
* Should automatically handle different connections for read/write
* queries if needed.
*
* @param string $sql
* @param mixed ...$binds
* @param mixed $sql
* @param mixed ...$binds
*
* @return BaseResult|Query|boolean
*/
public function query(string $sql, $binds = null);
public function query($sql, $binds = null);

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

Expand All @@ -138,11 +138,11 @@ public function query(string $sql, $binds = null);
* is performed, nor are transactions handled. Simply takes a raw
* query string and returns the database-specific result id.
*
* @param string $sql
* @param mixed $sql
*
* @return mixed
*/
public function simpleQuery(string $sql);
public function simpleQuery($sql);

//--------------------------------------------------------------------
/**
Expand Down
4 changes: 2 additions & 2 deletions system/Database/MySQLi/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,11 +310,11 @@ public function getVersion(): string
/**
* Executes the query against the database.
*
* @param string $sql
* @param mixed $sql
*
* @return mixed
*/
public function execute(string $sql)
public function execute($sql)
{
while ($this->connID->more_results())
{
Expand Down
8 changes: 4 additions & 4 deletions system/Database/MySQLi/PreparedQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ class PreparedQuery extends BasePreparedQuery
* NOTE: This version is based on SQL code. Child classes should
* override this method.
*
* @param string $sql
* @param array $options Passed to the connection's prepare statement.
* Unused in the MySQLi driver.
* @param mixed $sql
* @param array $options Passed to the connection's prepare statement.
* Unused in the MySQLi driver.
*
* @return mixed
*/
public function _prepare(string $sql, array $options = [])
public function _prepare($sql, array $options = [])
{
// Mysqli driver doesn't like statements
// with terminating semicolons.
Expand Down
4 changes: 2 additions & 2 deletions system/Database/Postgre/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,11 @@ public function getVersion(): string
/**
* Executes the query against the database.
*
* @param string $sql
* @param mixed $sql
*
* @return mixed
*/
public function execute(string $sql)
public function execute($sql)
{
try
{
Expand Down
8 changes: 4 additions & 4 deletions system/Database/Postgre/PreparedQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ class PreparedQuery extends BasePreparedQuery
* NOTE: This version is based on SQL code. Child classes should
* override this method.
*
* @param string $sql
* @param array $options Passed to the connection's prepare statement.
* Unused in the MySQLi driver.
* @param mixed $sql
* @param array $options Passed to the connection's prepare statement.
* Unused in the MySQLi driver.
*
* @return mixed
* @throws Exception
*/
public function _prepare(string $sql, array $options = [])
public function _prepare($sql, array $options = [])
{
$this->name = (string) random_int(1, 10000000000000000);

Expand Down
6 changes: 3 additions & 3 deletions system/Database/PreparedQueryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ public function execute(...$data);
* Prepares the query against the database, and saves the connection
* info necessary to execute the query later.
*
* @param string $sql
* @param array $options Passed to the connection's prepare statement.
* @param mixed $sql
* @param array $options Passed to the connection's prepare statement.
*
* @return mixed
*/
public function prepare(string $sql, array $options = []);
public function prepare($sql, array $options = []);

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

Expand Down
8 changes: 4 additions & 4 deletions system/Database/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ public function __construct(ConnectionInterface &$db)
/**
* Sets the raw query string to use for this statement.
*
* @param string $sql
* @param mixed $sql
* @param mixed $binds
* @param boolean $setEscape
*
* @return $this
*/
public function setQuery(string $sql, $binds = null, bool $setEscape = true)
public function setQuery($sql, $binds = null, bool $setEscape = true)
{
$this->originalQueryString = $sql;

Expand Down Expand Up @@ -158,9 +158,9 @@ public function setBinds(array $binds, bool $setEscape = true)
* Returns the final, processed query string after binding, etal
* has been performed.
*
* @return string
* @return mixed
*/
public function getQuery(): string
public function getQuery()
{
if (empty($this->finalQueryString))
{
Expand Down
4 changes: 2 additions & 2 deletions system/Database/QueryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ interface QueryInterface
/**
* Sets the raw query string to use for this statement.
*
* @param string $sql
* @param mixed $sql
* @param mixed $binds
* @param boolean $setEscape
*
* @return mixed
*/
public function setQuery(string $sql, $binds = null, bool $setEscape = true);
public function setQuery($sql, $binds = null, bool $setEscape = true);

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

Expand Down
4 changes: 2 additions & 2 deletions system/Database/SQLSRV/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -490,11 +490,11 @@ public function setDatabase(string $databaseName = null)
/**
* Executes the query against the database.
*
* @param string $sql
* @param mixed $sql
*
* @return mixed
*/
public function execute(string $sql)
public function execute($sql)
{
$stmt = ($this->scrollable === false || $this->isWriteType($sql)) ?
sqlsrv_query($this->connID, $sql) :
Expand Down
6 changes: 3 additions & 3 deletions system/Database/SQLSRV/PreparedQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ class PreparedQuery extends BasePreparedQuery
* NOTE: This version is based on SQL code. Child classes should
* override this method.
*
* @param string $sql
* @param array $options Options takes an associative array;
* @param mixed $sql
* @param array $options Options takes an associative array;
*
* @return mixed
* @throws Exception
*/
public function _prepare(string $sql, array $options = [])
public function _prepare($sql, array $options = [])
{
/* Prepare parameters for the query */
$queryString = $this->getQueryString();
Expand Down
4 changes: 2 additions & 2 deletions system/Database/SQLite3/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,11 @@ public function getVersion(): string
/**
* Execute the query
*
* @param string $sql
* @param mixed $sql
*
* @return mixed \SQLite3Result object or bool
*/
public function execute(string $sql)
public function execute($sql)
{
try
{
Expand Down
8 changes: 4 additions & 4 deletions system/Database/SQLite3/PreparedQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ class PreparedQuery extends BasePreparedQuery
* NOTE: This version is based on SQL code. Child classes should
* override this method.
*
* @param string $sql
* @param array $options Passed to the connection's prepare statement.
* Unused in the MySQLi driver.
* @param mixed $sql
* @param array $options Passed to the connection's prepare statement.
* Unused in the MySQLi driver.
*
* @return mixed
*/
public function _prepare(string $sql, array $options = [])
public function _prepare($sql, array $options = [])
{
if (! ($this->statement = $this->db->connID->prepare($sql)))
{
Expand Down
14 changes: 7 additions & 7 deletions system/Test/Mock/MockConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@ public function shouldReturn(string $method, $return)
* Should automatically handle different connections for read/write
* queries if needed.
*
* @param string $sql
* @param mixed ...$binds
* @param boolean $setEscapeFlags
* @param string $queryClass
* @param mixed $sql
* @param mixed ...$binds
* @param boolean $setEscapeFlags
* @param string|null $queryClass
*
* @return BaseResult|Query|boolean
*
* @todo BC set $queryClass default as null in 4.1
*/
public function query(string $sql, $binds = null, bool $setEscapeFlags = true, string $queryClass = '')
public function query($sql, $binds = null, bool $setEscapeFlags = true, string $queryClass = null)
{
$queryClass = str_replace('Connection', 'Query', static::class);

Expand Down Expand Up @@ -161,11 +161,11 @@ public function getVersion(): string
/**
* Executes the query against the database.
*
* @param string $sql
* @param mixed $sql
*
* @return mixed
*/
protected function execute(string $sql)
protected function execute($sql)
{
return $this->returnValues['execute'];
}
Expand Down