amphp / postgres

Async Postgres client for PHP based on Amp.
MIT License
96 stars 20 forks source link

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

Closed PNixx closed 11 months ago

PNixx commented 11 months ago
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.

trowski commented 11 months ago

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