Skip to content
Permalink
Browse files

Merge pull request #56 from shadowhand/fix/insert-update-bool-null

Output boolean and null values in SQL
  • Loading branch information...
shadowhand committed Apr 18, 2018
2 parents f81b533 + ea7c393 commit 8f79c752459f2e3657207059e2e374fa63a34521
Showing with 30 additions and 12 deletions.
  1. +12 −5 src/Partial/Parameter.php
  2. +14 −3 tests/Partial/CriteriaTest.php
  3. +2 −2 tests/Query/Postgres/UpdateTest.php
  4. +2 −2 tests/Query/UpdateTest.php
@@ -8,21 +8,28 @@
final class Parameter implements StatementInterface
{
/** @var mixed */
private $value;
/** @var string */
private $sql = '?';
/** @var array */
private $params = [];
public function __construct($value)
{
$this->value = $value;
if (is_bool($value) || is_null($value)) {
$this->sql = var_export($value, true);
} else {
$this->params[] = $value;
}
}
public function sql(EngineInterface $engine): string
{
return '?';
return $this->sql;
}
public function params(EngineInterface $engine): array
{
return [$this->value];
return $this->params;
}
}
@@ -97,18 +97,29 @@ public function testNull()
$this->assertParams([], $expr);
}
public function testBoolean()
{
$expr = field('is_active')->eq(true);
$this->assertSql('is_active = true', $expr);
$expr = field('is_active')->eq(false);
$this->assertSql('is_active = false', $expr);
}
public function testAnd()
{
$expr = field('id')->eq(5);
$expr = $expr->and(field('is_active')->eq(true));
$expr = $expr->and(field('is_active')->eq(1));
$this->assertSql('id = ? AND is_active = ?', $expr);
}
public function testOr()
{
$expr = field('is_deleted')->eq(true);
$expr = $expr->or(field('is_inactive')->eq(true));
$expr = field('is_deleted')->eq(1);
$expr = $expr->or(field('is_inactive')->eq(1));
$this->assertSql('is_deleted = ? OR is_inactive = ?', $expr);
}
@@ -16,7 +16,7 @@ public function testReturning()
])
->returning('id');
$this->assertSql('UPDATE "users" SET "last_login" = ? RETURNING "id"', $update);
$this->assertParams([null], $update);
$this->assertSql('UPDATE "users" SET "last_login" = NULL RETURNING "id"', $update);
$this->assertParams([], $update);
}
}
@@ -24,8 +24,8 @@ public function testSet()
'last_login' => null,
]);
$this->assertSql('UPDATE users SET last_login = ?', $update);
$this->assertParams([null], $update);
$this->assertSql('UPDATE users SET last_login = NULL', $update);
$this->assertParams([], $update);
}
public function testWhere()

0 comments on commit 8f79c75

Please sign in to comment.
You can’t perform that action at this time.