1
0
mirror of https://github.com/danog/postgres.git synced 2025-01-22 05:11:14 +01:00

Store the statement name in the statement

Also reverted hashing in `Connection::execute` because that's not
actually a prepared statement
This commit is contained in:
Pieter Hordijk 2017-07-26 20:49:40 +02:00 committed by Aaron Piotrowski
parent 08e3432995
commit 53559d1910
3 changed files with 12 additions and 7 deletions

View File

@ -205,7 +205,7 @@ class PgSqlExecutor implements Executor {
*/
public function execute(string $sql, ...$params): Promise {
return call(function () use ($sql, $params) {
return $this->createResult(yield from $this->send("pg_send_query_params", sha1($sql), $params));
return $this->createResult(yield from $this->send("pg_send_query_params", $sql, $params));
});
}
@ -214,8 +214,9 @@ class PgSqlExecutor implements Executor {
*/
public function prepare(string $sql): Promise {
return call(function () use ($sql) {
yield from $this->send("pg_send_prepare", sha1($sql), $sql);
return new PgSqlStatement($sql, $this->executeCallback);
$name = "amphp" . sha1($sql);
yield from $this->send("pg_send_prepare", $name, $sql);
return new PgSqlStatement($name, $sql, $this->executeCallback);
});
}

View File

@ -5,6 +5,9 @@ namespace Amp\Postgres;
use Amp\Promise;
class PgSqlStatement implements Statement {
/** @var string */
private $name;
/** @var string */
private $sql;
@ -15,7 +18,8 @@ class PgSqlStatement implements Statement {
* @param string $sql
* @param callable $execute
*/
public function __construct(string $sql, callable $execute) {
public function __construct(string $name, string $sql, callable $execute) {
$this->name = $name;
$this->sql = $sql;
$this->execute = $execute;
}
@ -35,6 +39,6 @@ class PgSqlStatement implements Statement {
* @throws \Amp\Postgres\FailureException If executing the statement fails.
*/
public function execute(...$params): Promise {
return ($this->execute)(sha1($this->sql), $params);
return ($this->execute)($this->name, $params);
}
}

View File

@ -215,14 +215,14 @@ class PqExecutor implements Executor {
* {@inheritdoc}
*/
public function execute(string $sql, ...$params): Promise {
return new Coroutine($this->send([$this->handle, "execParamsAsync"], sha1($sql), $params));
return new Coroutine($this->send([$this->handle, "execParamsAsync"], $sql, $params));
}
/**
* {@inheritdoc}
*/
public function prepare(string $sql): Promise {
return new Coroutine($this->send([$this->handle, "prepareAsync"], sha1($sql), $sql));
return new Coroutine($this->send([$this->handle, "prepareAsync"], "amphp" .sha1($sql), $sql));
}
/**