amphp / postgres

Async Postgres client for PHP based on Amp.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[v2.0.0-beta.5] Transaction suspend on the second request

PNixx opened this issue · comments

amphp/sql-common: v2.0.0-beta.7
amphp/postgres: v2.0.0-beta.5
amphp/sql: v2.0.0-beta.6

Example:

use Amp\Postgres;
use Amp\Postgres\PostgresConfig;

require 'vendor/autoload.php';

$config = new PostgresConfig('localhost', 5432, 'user', 'pass', 'dbtest');
$connection = Postgres\connect($config);

$transaction = $connection->beginTransaction();
$result = $transaction->execute('INSERT INTO customers (email,time_zone) VALUES (:email,:time_zone) RETURNING *', [
	'email'   => 'test@test.com',
	'time_zone' => 'UTC',
]);
print_r($result->fetchRow());
$result = $transaction->execute('INSERT INTO customers (email) VALUES (:email) RETURNING *', [
	'email'   => 'test2@test.com',
]); // <---- suspend here
print_r($result->fetchRow());
$transaction->rollback();

STDOUT:

Array
(
    [email] => test@test.com
    [time_zone] => UTC
)

Works correctly if request similar sql queries:

use Amp\Postgres;
use Amp\Postgres\PostgresConfig;

require 'vendor/autoload.php';

$config = new PostgresConfig('localhost', 5432, 'user', 'pass', 'dbtest');
$connection = Postgres\connect($config);

$transaction = $connection->beginTransaction();
$result = $transaction->execute('INSERT INTO customers (email,time_zone) VALUES (:email,:time_zone) RETURNING *', [
	'email'   => 'test@test.com',
	'time_zone' => 'UTC',
]);
print_r($result->fetchRow());
$result = $transaction->execute('INSERT INTO customers (email,time_zone) VALUES (:email,:time_zone) RETURNING *', [
	'email'   => 'test2@test.com',
	'time_zone' => 'UTC',
]);
print_r($result->fetchRow());
$transaction->rollback();

STDOUT:

Array
(
    [email] => test@test.com
    [time_zone] => UTC
)
Array
(
    [email] => test2@test.com
    [time_zone] => UTC
)

In v2.0.0-beta.4 works correctly.

This should be fixed by amphp/sql-common@v2.0.0-beta.8.