Skip to content

Commit

Permalink
Merge pull request #2755 from Instrye/patch-2
Browse files Browse the repository at this point in the history
fix. MYSQLI::DBDebug can't woker
  • Loading branch information
lonnieezell authored Apr 20, 2020
2 parents 34d6338 + d4ce8ff commit b3aeba5
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 7 deletions.
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();
}
}

0 comments on commit b3aeba5

Please sign in to comment.