pg: Rework txn implementation + statement config API

I liked the Perl implementation of transactions, but managing state
between Perl and C is a bit cumbersome, so I've moved the whole thing
into C.

Also added a few statement configuration methods that currently don't do
anything yet.
This commit is contained in:
Yorhel 2025-02-07 18:30:33 +01:00
parent 8f94dd0921
commit 166744dd51
7 changed files with 335 additions and 186 deletions

View file

@ -17,7 +17,7 @@ okerr FATAL => connect => qr/missing "=" after "invalid"/;
ok FU::PG::lib_version() > 100000;
my $conn = FU::PG->connect($ENV{FU_TEST_DB});
my $conn = FU::PG->connect($ENV{FU_TEST_DB})->text;
$conn->_debug_trace(0);
is ref $conn, 'FU::PG::conn';
@ -153,11 +153,11 @@ subtest 'txn', sub {
like $@, qr/Invalid cross-transaction/;
ok !eval { $conn->exec('SELECT 1'); 1 };
like $@, qr/Invalid attempt to run a query/;
like $@, qr/Invalid operation on the top-level connection/;
ok !eval { $conn->q('SELECT 1'); 1 };
like $@, qr/Invalid attempt to run a query/;
like $@, qr/Invalid operation on the top-level connection/;
ok !eval { $conn->txn; 1 };
like $@, qr/Invalid attempt to run a query/;
like $@, qr/Invalid operation on the top-level connection/;
$txn->exec('INSERT INTO fupg_tst VALUES (1)');
$sst = $txn->q('SELECT 1');
@ -169,18 +169,18 @@ subtest 'txn', sub {
is $txn->status, 'done';
ok !eval { $txn->rollback; 1 };
like $@, qr/Unable to rollback/;
like $@, qr/Invalid operation on a transaction that has already been marked as done/;
ok !eval { $txn->commit; 1 };
like $@, qr/Unable to commit/;
like $@, qr/Invalid operation on a transaction that has already been marked as done/;
ok !eval { $txn->txn; 1 };
like $@, qr/Unable to create/;
like $@, qr/Invalid operation on a transaction that has already been marked as done/;
ok !eval { $txn->exec('select 1'); 1 };
like $@, qr/Invalid attempt to run a query/;
like $@, qr/Invalid operation on a transaction that has already been marked as done/;
ok !eval { $txn->q('select 1'); 1 };
like $@, qr/Invalid attempt to run a query/;
like $@, qr/Invalid operation on a transaction that has already been marked as done/;
ok !eval { $conn->exec('SELECT 1'); 1 };
like $@, qr/Invalid attempt to run a query/;
like $@, qr/Invalid operation on the top-level connection/;
}
is $conn->status, 'idle';
is $st->val, 1;
@ -214,7 +214,7 @@ subtest 'txn', sub {
ok !eval { $sub->exec('SELEXT'); 1 };
ok !eval { $txn->rollback; 1 };
like $@, qr/Invalid cross-transaction/;
like $@, qr/Invalid operation on transaction/;
is $conn->status, 'txn_error';
is $txn->status, 'txn_error';