Pg: Add perl2bin() and bin2perl() conversion methods

This commit is contained in:
Yorhel 2025-04-30 17:07:44 +02:00
parent af9340f908
commit beeefcf337
4 changed files with 69 additions and 2 deletions

View file

@ -19,9 +19,12 @@ sub v($type, $p_in, @args) {
my $s_out = @args > 2 && defined $args[2] ? $args[2] : $s_in;
my $test = "$type $s_in" =~ s/\n/\\n/rg;
my $oid;
utf8::encode($test);
{
my $array = $conn->q("SELECT \$1::$type", $s_in)->text_params->flat;
my $st = $conn->q("SELECT \$1::$type", $s_in)->text_params;
$oid = $st->param_types->[0];
my $array = $st->flat;
my $res = $array->[0];
ok is_bool($res), "$test is bool" if $type eq 'bool';
ok created_as_number($res), "$test is number" if $type =~ /^(int|float)\d/;
@ -36,6 +39,11 @@ sub v($type, $p_in, @args) {
my $res = $conn->q("SELECT \$1::$type", $p_in)->val;
is_deeply $res, $p_out, "$test bin->bin";
}
{
my $bin = $conn->perl2bin($oid, $p_in);
ok defined $bin;
is_deeply $conn->bin2perl($oid, $bin), $p_out if $type !~ /\(/;
}
}
sub f($type, $p_in) {
my $test = "$type $p_in" =~ s/\n/\\n/rg;