+ refactor things a bit so that send & recv functions use the same context struct, because the way they're setup is pretty much the same for both. This also adds recursive type resolution for bind parameters.
30 lines
1.2 KiB
Perl
30 lines
1.2 KiB
Perl
use v5.36;
|
|
use Test::More;
|
|
|
|
plan skip_all => $@ if !eval { require FU::PG; } && $@ =~ /Unable to load libpq/;
|
|
die $@ if $@;
|
|
plan skip_all => 'Please set FU_TEST_DB to a PostgreSQL connection string to run these tests' if !$ENV{FU_TEST_DB};
|
|
|
|
my $conn = FU::PG->connect($ENV{FU_TEST_DB});
|
|
|
|
ok !eval { $conn->q('SELECT $1::aclitem', '')->exec; 1 };
|
|
like $@, qr/Unable to send or receive/;
|
|
|
|
{
|
|
my $txn = $conn->txn;
|
|
$txn->exec("CREATE TYPE fupg_test_enum AS ENUM('a', 'b', 'ccccccccccccccccccc')");
|
|
is $txn->q("SELECT 'a'::fupg_test_enum")->val, 'a';
|
|
is $txn->q('SELECT $1::fupg_test_enum', 'ccccccccccccccccccc')->val, 'ccccccccccccccccccc';
|
|
|
|
is_deeply $txn->q("SELECT '{a,b,null}'::fupg_test_enum[]")->val, ['a','b',undef];
|
|
is $txn->q('SELECT $1::fupg_test_enum[]', ['a','b',undef])->text_results->val, '{a,b,NULL}';
|
|
|
|
$txn->exec("CREATE DOMAIN fupg_test_domain AS fupg_test_enum CHECK(value IN('a','b'))");
|
|
is $txn->q("SELECT 'a'::fupg_test_domain")->val, 'a';
|
|
is $txn->q('SELECT $1::fupg_test_domain', 'b')->val, 'b';
|
|
|
|
is_deeply $txn->q("SELECT '{a,b,null}'::fupg_test_domain[]")->val, ['a','b',undef];
|
|
is $txn->q('SELECT $1::fupg_test_domain[]', ['a','b',undef])->text_results->val, '{a,b,NULL}';
|
|
}
|
|
|
|
done_testing;
|