-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DB: use boolean parameters as a query parameter
- Loading branch information
Showing
7 changed files
with
78 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Forrest79\PhPgSql\Tests\Integration; | ||
|
||
use Tester; | ||
|
||
require_once __DIR__ . '/TestCase.php'; | ||
|
||
/** | ||
* @testCase | ||
*/ | ||
final class QueryTest extends TestCase | ||
{ | ||
|
||
public function testBoolParameters(): void | ||
{ | ||
$this->connection->query(' | ||
CREATE TABLE test( | ||
id integer, | ||
bool_column bool | ||
); | ||
'); | ||
|
||
$this->connection->query('INSERT INTO test(id, bool_column) VALUES(?, ?)', 1, TRUE); | ||
$this->connection->query('INSERT INTO test(id, bool_column) VALUES(?, ?)', 2, FALSE); | ||
|
||
$resultTrue = $this->connection->query('SELECT id, bool_column FROM test WHERE bool_column = ?', TRUE); | ||
|
||
$rowTrue = $resultTrue->fetch() ?? throw new \RuntimeException('No data from database were returned'); | ||
|
||
Tester\Assert::same(1, $rowTrue->id); | ||
Tester\Assert::true($rowTrue->bool_column); | ||
|
||
$resultTrue->free(); | ||
|
||
// --- | ||
|
||
$resultFalse = $this->connection->query('SELECT id, bool_column FROM test WHERE bool_column = ?', FALSE); | ||
|
||
$rowFalse = $resultFalse->fetch() ?? throw new \RuntimeException('No data from database were returned'); | ||
|
||
Tester\Assert::same(2, $rowFalse->id); | ||
Tester\Assert::false($rowFalse->bool_column); | ||
|
||
$resultFalse->free(); | ||
} | ||
|
||
} | ||
|
||
(new QueryTest())->run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters