Skip to content

Commit

Permalink
Database - Make sql query mixed instead of string since most nosql da…
Browse files Browse the repository at this point in the history
…tabases use arrays
  • Loading branch information
najdanovicivan committed Jan 15, 2021
1 parent 6ee89af commit 1a9415a
Show file tree
Hide file tree
Showing 15 changed files with 55 additions and 59 deletions.
20 changes: 9 additions & 11 deletions system/Database/BaseConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -586,11 +586,11 @@ public function addTableAlias(string $table)
/**
* Executes the query against the database.
*
* @param string $sql
* @param mixed $sql
*
* @return mixed
*/
abstract protected function execute(string $sql);
abstract protected function execute($sql);

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

Expand All @@ -602,16 +602,14 @@ 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|false
*
* @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 @@ -701,11 +699,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 @@ -76,13 +76,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 @@ -123,12 +123,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 mixed
*/
public function query(string $sql, $binds = null);
public function query($sql, $binds = null);

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

Expand All @@ -137,11 +137,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 @@ -295,11 +295,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 @@ -101,13 +101,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 @@ -166,9 +166,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 @@ -479,11 +479,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
16 changes: 7 additions & 9 deletions system/Test/Mock/MockConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,14 @@ 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|false
*
* @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 @@ -155,11 +153,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

0 comments on commit 1a9415a

Please sign in to comment.