pg: Statement preparing + inspection; less wonky object handling?

This commit is contained in:
Yorhel 2025-02-05 11:49:22 +01:00
parent c51b5f3598
commit 187417f160
5 changed files with 186 additions and 10 deletions

View file

@ -17,10 +17,11 @@ okerr FATAL => connect => qr/missing "=" after "invalid"/;
ok FU::PG::lib_version() > 100000;
my $conn = FU::PG->connect($ENV{FU_TEST_DB});
$conn->_debug_trace(0);
is ref $conn, 'FU::PG::conn';
ok $conn->server_version() > 100000;
is $conn->lib_version(), FU::PG::lib_version();
ok $conn->server_version > 100000;
is $conn->lib_version, FU::PG::lib_version();
ok !eval { $conn->exec('COPY (SELECT 1) TO STDOUT'); };
okerr FATAL => exec => qr/unexpected status code/;
@ -31,4 +32,26 @@ okerr ERROR => exec => qr/syntax error/;
ok !defined $conn->exec('');
is $conn->exec('SELECT 1'), 1;
ok !eval { $conn->q('SELEXT')->params; };
okerr ERROR => prepare => qr/syntax error/;
{
my $st = $conn->q('SELECT 1');
is_deeply $st->params, [];
is_deeply $st->columns, [{ name => '?column?', oid => 23 }];
is $conn->exec('SELECT 1 FROM pg_prepared_statements'), 1;
}
is $conn->exec('SELECT 1 FROM pg_prepared_statements'), 0;
{
my $st = $conn->q("SELECT \$1::int AS a, \$2::char(5) AS \"\x{1F603}\"");
undef $conn; # statement keeps the connection alive
is_deeply $st->params, [ { oid => 23 }, { oid => 1042 } ];
is_deeply $st->columns, [
{ oid => 23, name => 'a' },
{ oid => 1042, name => "\x{1F603}", typemod => 9 },
];
}
done_testing;