From d74ae1d783b68ff9b6bacb98f7810350a54601f3 Mon Sep 17 00:00:00 2001 From: Najdanovic Ivan Date: Thu, 7 Jan 2021 14:01:54 +0100 Subject: [PATCH 1/2] BaseConnection - Added automatic handling of query class for 3rd party drivers --- system/Database/BaseConnection.php | 20 +++++++++++++++++++- system/Test/Mock/MockConnection.php | 4 +++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/system/Database/BaseConnection.php b/system/Database/BaseConnection.php index a70a04b0efe1..ddd3189bc5c2 100644 --- a/system/Database/BaseConnection.php +++ b/system/Database/BaseConnection.php @@ -289,6 +289,13 @@ abstract class BaseConnection implements ConnectionInterface */ protected $aliasedTables = []; + /** + * Query Class + * + * @var string + */ + protected $queryClass = 'CodeIgniter\\Database\\Query'; + //-------------------------------------------------------------------- /** @@ -302,6 +309,13 @@ public function __construct(array $params) { $this->$key = $value; } + + $queryClass = str_replace('Connection', 'Query', static::class); + + if (class_exists($queryClass)) + { + $this->queryClass = $queryClass; + } } //-------------------------------------------------------------------- @@ -594,9 +608,13 @@ abstract protected function execute(string $sql); * @param string $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 = 'CodeIgniter\\Database\\Query') + public function query(string $sql, $binds = null, bool $setEscapeFlags = true, string $queryClass = '') { + $queryClass = $queryClass ?: $this->queryClass; + if (empty($this->connID)) { $this->initialize(); diff --git a/system/Test/Mock/MockConnection.php b/system/Test/Mock/MockConnection.php index 65f729598ef0..2bdf149cd53a 100644 --- a/system/Test/Mock/MockConnection.php +++ b/system/Test/Mock/MockConnection.php @@ -49,8 +49,10 @@ public function shouldReturn(string $method, $return) * @param string $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 = 'CodeIgniter\\Database\\Query') + public function query(string $sql, $binds = null, bool $setEscapeFlags = true, string $queryClass = '') { $queryClass = str_replace('Connection', 'Query', get_class($this)); From 3545ca9b8581094af7fce9790823fd3f1b20aa91 Mon Sep 17 00:00:00 2001 From: Najdanovic Ivan Date: Sun, 10 Jan 2021 19:37:13 +0100 Subject: [PATCH 2/2] MockConnection - Use static::class for queryClass Co-authored-by: John Paul E. Balandan, CPA <51850998+paulbalandan@users.noreply.github.com> --- system/Test/Mock/MockConnection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/Test/Mock/MockConnection.php b/system/Test/Mock/MockConnection.php index 2bdf149cd53a..147e1d1c36d0 100644 --- a/system/Test/Mock/MockConnection.php +++ b/system/Test/Mock/MockConnection.php @@ -54,7 +54,7 @@ public function shouldReturn(string $method, $return) */ public function query(string $sql, $binds = null, bool $setEscapeFlags = true, string $queryClass = '') { - $queryClass = str_replace('Connection', 'Query', get_class($this)); + $queryClass = str_replace('Connection', 'Query', static::class); $query = new $queryClass($this);