diff --git a/src/Internal/PgSqlHandle.php b/src/Internal/PgSqlHandle.php index f9cb262..b3077d2 100644 --- a/src/Internal/PgSqlHandle.php +++ b/src/Internal/PgSqlHandle.php @@ -316,7 +316,7 @@ private function createResult(\PgSql\Result $result, string $sql): PostgresResul \assert($this->types !== null, 'Expected type array to be populated before creating a result'); - switch (\pg_result_status($result)) { + switch ($status = \pg_result_status($result)) { case \PGSQL_EMPTY_QUERY: throw new SqlQueryError("Empty query string"); @@ -353,7 +353,11 @@ private function createResult(\PgSql\Result $result, string $sql): PostgresResul default: // @codeCoverageIgnoreStart $this->close(); - throw new SqlException("Unknown result status"); + throw new SqlException(\sprintf( + "Unknown result status: %d; error: %s", + $status, + \pg_result_error($result) ?: 'none', + )); // @codeCoverageIgnoreEnd } } @@ -471,7 +475,7 @@ public function prepare(string $sql): PostgresStatement $future = async(function () use ($name, $modifiedSql, $sql): string { $result = $this->send(\pg_send_prepare(...), $name, $modifiedSql); - switch (\pg_result_status($result, \PGSQL_STATUS_LONG)) { + switch ($status = \pg_result_status($result)) { case \PGSQL_COMMAND_OK: return $name; // Statement created successfully. @@ -488,7 +492,11 @@ public function prepare(string $sql): PostgresStatement default: // @codeCoverageIgnoreStart - throw new SqlException("Unknown result status"); + throw new SqlException(\sprintf( + "Unknown result status: %d; error: %s", + $status, + \pg_result_error($result) ?: 'none', + )); // @codeCoverageIgnoreEnd } });