Skip to content

Commit

Permalink
TRUE/FALSE?
Browse files Browse the repository at this point in the history
  • Loading branch information
forrest79 committed Nov 18, 2024
1 parent 9d82800 commit 4123b2f
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions docs/fluent.md
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ $query = $connection
'phones' => Forrest79\PhPgSql\Db\Helper::createStringPgArray(['732123456', '736987654']),
]);

dump($query); // (Query) INSERT INTO users (nick, inserted_datetime, active, age, height_cm, phones) VALUES($1, now(), $2, $3, $4, $5) [Params: (array) ['James', 't', 37, (NULL), '{\"732123456\",\"736987654\"}']]
dump($query); // (Query) INSERT INTO users (nick, inserted_datetime, active, age, height_cm, phones) VALUES($1, now(), $2, $3, $4, $5) [Params: (array) ['James', 'TRUE', 37, (NULL), '{\"732123456\",\"736987654\"}']]

$result = $query->execute();

Expand Down Expand Up @@ -830,7 +830,7 @@ $query = $connection
->join('user_departments', 'ud', 'ud.department_id = au.id')
->where('ud.department_id IN (?)', Forrest79\PhPgSql\Db\Sql\Query::create('SELECT id FROM active_departments'));

dump($query); // (Query) WITH active_users AS (SELECT id, nick, age, height_cm FROM users WHERE active = TRUE), active_departments AS (SELECT id FROM departments WHERE active = $1) SELECT au.id, au.nick, au.age, au.height_cm FROM active_users AS au INNER JOIN user_departments AS ud ON ud.department_id = au.id WHERE ud.department_id IN (SELECT id FROM active_departments) [Params: (array) ['t']]
dump($query); // (Query) WITH active_users AS (SELECT id, nick, age, height_cm FROM users WHERE active = TRUE), active_departments AS (SELECT id FROM departments WHERE active = $1) SELECT au.id, au.nick, au.age, au.height_cm FROM active_users AS au INNER JOIN user_departments AS ud ON ud.department_id = au.id WHERE ud.department_id IN (SELECT id FROM active_departments) [Params: (array) ['TRUE']]

$query->execute();
```
Expand Down
2 changes: 1 addition & 1 deletion src/Db/SqlDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ static function ($matches) use (&$params, &$parsedParams, &$origParamIndex, &$pa
}

if (\is_bool($param)) {
$parsedParams[] = $param ? 't' : 'f';
$parsedParams[] = $param ? 'TRUE' : 'FALSE';
} else if ($param instanceof \BackedEnum) {
$parsedParams[] = $param->value;
} else {
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public function testPrepareQueryWithBool(): void
{
$query = Db\Sql\Query::create('SELECT * FROM table WHERE column1 = ? AND column2 = ?', TRUE, FALSE)->toDbQuery();
Tester\Assert::same('SELECT * FROM table WHERE column1 = $1 AND column2 = $2', $query->sql);
Tester\Assert::same(['t', 'f'], $query->params);
Tester\Assert::same(['TRUE', 'FALSE'], $query->params);
}


Expand Down

0 comments on commit 4123b2f

Please sign in to comment.