Skip to content

Commit

Permalink
BaseConnection - Added automatic handling of query class for 3rd part…
Browse files Browse the repository at this point in the history
…y drivers
  • Loading branch information
najdanovicivan committed Jan 10, 2021
1 parent 6861a58 commit d74ae1d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
20 changes: 19 additions & 1 deletion system/Database/BaseConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,13 @@ abstract class BaseConnection implements ConnectionInterface
*/
protected $aliasedTables = [];

/**
* Query Class
*
* @var string
*/
protected $queryClass = 'CodeIgniter\\Database\\Query';

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

/**
Expand All @@ -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;
}
}

//--------------------------------------------------------------------
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 3 additions & 1 deletion system/Test/Mock/MockConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down

0 comments on commit d74ae1d

Please sign in to comment.