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

fix. MYSQLI::DBDebug can't woker #2755

Merged
merged 2 commits into from
Apr 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 13 additions & 2 deletions system/Database/MySQLi/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,19 @@ public function execute(string $sql)
$res->free();
}
}

return $this->connID->query($this->prepQuery($sql));
try
{
return $this->connID->query($this->prepQuery($sql));
}
catch (\mysqli_sql_exception $e)
{
log_message('error', $e);
if ($this->DBDebug)
{
throw $e;
}
}
return false;
}

//--------------------------------------------------------------------
Expand Down
16 changes: 14 additions & 2 deletions system/Database/Postgre/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,23 @@ public function getVersion(): string
*
* @param string $sql
*
* @return resource
* @return mixed
*/
public function execute(string $sql)
{
return pg_query($this->connID, $sql);
try
{
return pg_query($this->connID, $sql);
}
catch (\ErrorException $e)
{
log_message('error', $e);
if ($this->DBDebug)
{
throw $e;
}
}
return false;
}

//--------------------------------------------------------------------
Expand Down
18 changes: 15 additions & 3 deletions system/Database/SQLite3/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,21 @@ public function getVersion(): string
*/
public function execute(string $sql)
{
return $this->isWriteType($sql)
? $this->connID->exec($sql)
: $this->connID->query($sql);
try
{
return $this->isWriteType($sql)
? $this->connID->exec($sql)
: $this->connID->query($sql);
}
catch (\ErrorException $e)
{
log_message('error', $e);
if ($this->DBDebug)
{
throw $e;
}
}
return false;
}

//--------------------------------------------------------------------
Expand Down
32 changes: 32 additions & 0 deletions tests/system/Database/Live/DEBugTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php namespace CodeIgniter\Database\Live;

use CodeIgniter\Test\CIDatabaseTestCase;

/**
* @group DatabaseLive
*/
class DEBugTest extends CIDatabaseTestCase
{

protected $refresh = true;

public function testDBDebugTrue()
{
$this->setPrivateProperty($this->db, 'DBDebug', true);
$this->expectException('Exception');
$result = $this->db->simpleQuery('SELECT * FROM db_error');
}

public function testDBDebugFalse()
{
$this->setPrivateProperty($this->db, 'DBDebug', false);
$result = $this->db->simpleQuery('SELECT * FROM db_error');
$this->assertEquals(false, $result);
}

public function tearDown(): void
{
$this->setPrivateProperty($this->db, 'DBDebug', true);
parent::tearDown();
}
}