Skip to content

Commit 3e55588

Browse files
committed
Initial commit fixing wrong return value in Database/BaseConnection::query. When underlying resultID if false, this should return false. Added BadQueryTest to tests.
1 parent 8640252 commit 3e55588

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

system/Database/BaseConnection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ public function query(string $sql, $binds = null, bool $setEscapeFlags = true, s
675675
Events::trigger('DBQuery', $query);
676676
}
677677

678-
return new $resultClass($this->connID, $this->resultID);
678+
return false;
679679
}
680680

681681
$query->setDuration($startTime);
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php namespace CodeIgniter\Database\Live;
2+
3+
use CodeIgniter\Test\CIDatabaseTestCase;
4+
5+
/**
6+
* @group DatabaseLive
7+
*/
8+
class BadQueryTest extends CIDatabaseTestCase
9+
{
10+
protected $refresh = true;
11+
12+
protected $seed = 'Tests\Support\Database\Seeds\CITestSeeder';
13+
14+
public function testBadQuery()
15+
{
16+
// this throws an exception in this testing environment, but in production it'll return FALSE
17+
// perhaps check $this->db->DBDebug for different test?
18+
$query = $this->db->query('SELECT * FROM table_does_not_exist');
19+
$this->assertEquals(false, $query);
20+
}
21+
22+
}

0 commit comments

Comments
 (0)