Skip to content

Commit

Permalink
Translate false parameters to FALSE. Fixes #10
Browse files Browse the repository at this point in the history
  • Loading branch information
mbonneau committed Jul 27, 2016
1 parent 7a1f58f commit 2e35a7b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/PgAsync/Command/Bind.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ public function encodedMessage()
$message .= Message::int32(-1);
continue;
}
if ($this->params[$i] === false) {
$this->params[$i] = 'FALSE';
}
$message .= Message::int32(strlen($this->params[$i])) . $this->params[$i];
}

Expand Down
35 changes: 35 additions & 0 deletions tests/Integration/BoolTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,39 @@ function () use (&$completes, $client) {
$this->assertEquals(1, $falseCount);
$this->assertEquals(1, $nullCount);
}

/**
* see https://github.com/voryx/PgAsync/issues/10
*/
public function testBoolParam()
{
$client = new Client(["user" => $this::getDbUser(), "database" => $this::getDbName()]);

$args = [false, 1];

$upd = 'UPDATE test_bool_param SET b = $1 WHERE id = $2 RETURNING *';

$completes = false;
$client->executeStatement($upd, $args)->subscribe(
new \Rx\Observer\CallbackObserver(
function ($row) {
$this->assertEquals($row, [ 'id' => '1', 'b' => false]);
},
function ($e) use ($client) {
$client->closeNow();
$this->cancelCurrentTimeoutTimer();
throw $e;
},
function () use (&$completes, $client) {
$completes = true;
$client->closeNow();
$this->cancelCurrentTimeoutTimer();
}
)
);

$this->runLoopWithTimeout(2);

$this->assertTrue($completes);
}
}
7 changes: 7 additions & 0 deletions tests/test_db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,10 @@ INSERT INTO thing(thing_type, thing_description, thing_cost, thing_in_stock)
VALUES('pencil', 'something you write with', 27.50, null);
INSERT INTO thing(thing_type, thing_description, thing_cost, thing_in_stock)
VALUES('marker', NULL, 50.23, 't');

CREATE TABLE test_bool_param (
id serial not null,
b boolean,
primary key(id)
);
insert into test_bool_param(b) values(true);

0 comments on commit 2e35a7b

Please sign in to comment.