From 59dba8b955788479cdf56dc9cc0f615701d68231 Mon Sep 17 00:00:00 2001 From: Najdanovic Ivan Date: Thu, 7 Jan 2021 14:01:54 +0100 Subject: [PATCH] Database - Make sql query mixed instead of string since most nosql databases use arrays --- system/Database/BaseConnection.php | 18 +++++++++--------- system/Database/BasePreparedQuery.php | 4 ++-- system/Database/ConnectionInterface.php | 10 +++++----- system/Database/MySQLi/Connection.php | 4 ++-- system/Database/MySQLi/PreparedQuery.php | 8 ++++---- system/Database/Postgre/Connection.php | 4 ++-- system/Database/Postgre/PreparedQuery.php | 8 ++++---- system/Database/PreparedQueryInterface.php | 6 +++--- system/Database/Query.php | 8 ++++---- system/Database/QueryInterface.php | 4 ++-- system/Database/SQLSRV/Connection.php | 4 ++-- system/Database/SQLSRV/PreparedQuery.php | 6 +++--- system/Database/SQLite3/Connection.php | 4 ++-- system/Database/SQLite3/PreparedQuery.php | 8 ++++---- system/Test/Mock/MockConnection.php | 14 +++++++------- 15 files changed, 55 insertions(+), 55 deletions(-) diff --git a/system/Database/BaseConnection.php b/system/Database/BaseConnection.php index a37ffaaa1025..1b03a05ea82a 100644 --- a/system/Database/BaseConnection.php +++ b/system/Database/BaseConnection.php @@ -593,11 +593,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); /** * Orchestrates a query against the database. Queries must use @@ -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; @@ -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)) { diff --git a/system/Database/BasePreparedQuery.php b/system/Database/BasePreparedQuery.php index 00f477b65c9e..7b3dd2caaf7b 100644 --- a/system/Database/BasePreparedQuery.php +++ b/system/Database/BasePreparedQuery.php @@ -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 diff --git a/system/Database/ConnectionInterface.php b/system/Database/ConnectionInterface.php index 43806adcb22c..839235d603f1 100644 --- a/system/Database/ConnectionInterface.php +++ b/system/Database/ConnectionInterface.php @@ -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); //-------------------------------------------------------------------- @@ -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); //-------------------------------------------------------------------- /** diff --git a/system/Database/MySQLi/Connection.php b/system/Database/MySQLi/Connection.php index e3c2838d06ac..3a9bd08ea131 100644 --- a/system/Database/MySQLi/Connection.php +++ b/system/Database/MySQLi/Connection.php @@ -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()) { diff --git a/system/Database/MySQLi/PreparedQuery.php b/system/Database/MySQLi/PreparedQuery.php index efc9abee0868..b8e226395ce5 100644 --- a/system/Database/MySQLi/PreparedQuery.php +++ b/system/Database/MySQLi/PreparedQuery.php @@ -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. diff --git a/system/Database/Postgre/Connection.php b/system/Database/Postgre/Connection.php index 010bf4876f2c..4c654d0676ce 100644 --- a/system/Database/Postgre/Connection.php +++ b/system/Database/Postgre/Connection.php @@ -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 { diff --git a/system/Database/Postgre/PreparedQuery.php b/system/Database/Postgre/PreparedQuery.php index bb12cb00fb10..88819588e9ea 100644 --- a/system/Database/Postgre/PreparedQuery.php +++ b/system/Database/Postgre/PreparedQuery.php @@ -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); diff --git a/system/Database/PreparedQueryInterface.php b/system/Database/PreparedQueryInterface.php index e7d7e542be8b..8449a3e4c902 100644 --- a/system/Database/PreparedQueryInterface.php +++ b/system/Database/PreparedQueryInterface.php @@ -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 = []); //-------------------------------------------------------------------- diff --git a/system/Database/Query.php b/system/Database/Query.php index e548dfc189d1..4fdc3cb79789 100644 --- a/system/Database/Query.php +++ b/system/Database/Query.php @@ -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; @@ -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)) { diff --git a/system/Database/QueryInterface.php b/system/Database/QueryInterface.php index af52d4010e70..5f651dcc810a 100644 --- a/system/Database/QueryInterface.php +++ b/system/Database/QueryInterface.php @@ -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); //-------------------------------------------------------------------- diff --git a/system/Database/SQLSRV/Connection.php b/system/Database/SQLSRV/Connection.php index 9c8e42f794d2..02f7cfce7727 100755 --- a/system/Database/SQLSRV/Connection.php +++ b/system/Database/SQLSRV/Connection.php @@ -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) : diff --git a/system/Database/SQLSRV/PreparedQuery.php b/system/Database/SQLSRV/PreparedQuery.php index 4f3b5868a85f..b8f6942cdfc4 100755 --- a/system/Database/SQLSRV/PreparedQuery.php +++ b/system/Database/SQLSRV/PreparedQuery.php @@ -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(); diff --git a/system/Database/SQLite3/Connection.php b/system/Database/SQLite3/Connection.php index 4547ad7c5937..6a3a9004091b 100644 --- a/system/Database/SQLite3/Connection.php +++ b/system/Database/SQLite3/Connection.php @@ -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 { diff --git a/system/Database/SQLite3/PreparedQuery.php b/system/Database/SQLite3/PreparedQuery.php index 333971da9ea8..77e6826e8c2e 100644 --- a/system/Database/SQLite3/PreparedQuery.php +++ b/system/Database/SQLite3/PreparedQuery.php @@ -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))) { diff --git a/system/Test/Mock/MockConnection.php b/system/Test/Mock/MockConnection.php index 9cb660715b7f..e046afbf55aa 100644 --- a/system/Test/Mock/MockConnection.php +++ b/system/Test/Mock/MockConnection.php @@ -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); @@ -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']; }