diff --git a/src/PgSqlHandle.php b/src/PgSqlHandle.php index fe0ceba..4cfe74a 100644 --- a/src/PgSqlHandle.php +++ b/src/PgSqlHandle.php @@ -195,6 +195,7 @@ private function fetchTypes(string $id): Promise public function close(): void { if ($this->handle instanceof \PgSql\Connection || \is_resource($this->handle)) { + \pg_cancel_query($this->handle); \pg_close($this->handle); $this->handle = null; } diff --git a/src/PgSqlResultSet.php b/src/PgSqlResultSet.php index 5c9bddd..299447f 100644 --- a/src/PgSqlResultSet.php +++ b/src/PgSqlResultSet.php @@ -130,10 +130,12 @@ private function cast(int $oid, string $value) switch ($oid) { case 700: // float4 case 701: // float8 - case 790: // money case 1700: // numeric return (float) $value; + case 790: + return $value; // money includes currency symbol as string. + default: // Cast all other numeric types to an integer. return (int) $value; } diff --git a/test/AbstractConnectTest.php b/test/AbstractConnectTest.php index 93d8b64..27916fe 100644 --- a/test/AbstractConnectTest.php +++ b/test/AbstractConnectTest.php @@ -66,4 +66,16 @@ public function testConnectInvalidUser(): Promise return $this->connect(PostgresConnectionConfig::fromString('host=localhost user=invalid'), new TimeoutCancellationToken(100)); } + + public function testConnectionClose(): \Generator + { + $connection = yield $this->connect(PostgresConnectionConfig::fromString('host=localhost user=postgres')); + $this->assertInstanceOf(Connection::class, $connection); + + $connection->execute('SELECT pg_sleep(10)'); + + $start = microtime(true); + $connection->close(); + $this->assertEquals(0, round(microtime(true) - $start)); + } }