Skip to content

Commit

Permalink
fix. Postgre and SQLite3
Browse files Browse the repository at this point in the history
  • Loading branch information
nyufeng committed Mar 27, 2020
1 parent 49bf7f9 commit d4ce8ff
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 7 deletions.
3 changes: 2 additions & 1 deletion system/Database/MySQLi/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,12 +332,13 @@ public function execute(string $sql)
}
catch (\mysqli_sql_exception $e)
{
log_message('error', $e);
if ($this->DBDebug)
{
throw $e;
}
return false;
}
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
8 changes: 7 additions & 1 deletion tests/system/Database/Live/DEBugTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class DEBugTest extends CIDatabaseTestCase
public function testDBDebugTrue()
{
$this->setPrivateProperty($this->db, 'DBDebug', true);
$this->expectException('mysqli_sql_exception');
$this->expectException('Exception');
$result = $this->db->simpleQuery('SELECT * FROM db_error');
}

Expand All @@ -23,4 +23,10 @@ public function testDBDebugFalse()
$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 d4ce8ff

Please sign in to comment.