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

BaseConnection - Added automatic handling of query class for 3rd party drivers #4089

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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));
najdanovicivan marked this conversation as resolved.
Show resolved Hide resolved

Expand Down