Pg: Add text2bin() and bin2text() conversion methods
This commit is contained in:
parent
beeefcf337
commit
76f55f277b
4 changed files with 93 additions and 3 deletions
19
t/pgtypes.t
19
t/pgtypes.t
|
|
@ -42,7 +42,11 @@ sub v($type, $p_in, @args) {
|
|||
{
|
||||
my $bin = $conn->perl2bin($oid, $p_in);
|
||||
ok defined $bin;
|
||||
is_deeply $conn->bin2perl($oid, $bin), $p_out if $type !~ /\(/;
|
||||
if ($type !~ /\(/) {
|
||||
is_deeply $conn->bin2perl($oid, $bin), $p_out;
|
||||
is $conn->bin2text($oid, $bin), $s_out;
|
||||
is $conn->text2bin($oid, $s_out), $bin if $type ne 'jsonb'; # jsonb pretty-prints for some reason
|
||||
}
|
||||
}
|
||||
}
|
||||
sub f($type, $p_in) {
|
||||
|
|
@ -180,6 +184,19 @@ is $conn->q('SELECT ($1::int2[])[2]', [1,2,3,4])->val, 2;
|
|||
is $conn->q('SELECT ($1::int2vector)[1]', [1,2,3,4])->val, 2;
|
||||
is $conn->q('SELECT ($1::oidvector)[1]', [1,2,3,4])->val, 2;
|
||||
|
||||
is_deeply [$conn->bin2text(
|
||||
16, $conn->perl2bin(16, 1),
|
||||
25, 'Hello',
|
||||
1007, $conn->perl2bin(1007, [-3,1,undef])
|
||||
)], ['t', 'Hello', '{-3,1,NULL}'];
|
||||
|
||||
{
|
||||
my($b,$s,$a) = $conn->text2bin(16, 't', 25, 'Hello', 1007, '{-3,1,NULL}');
|
||||
is $conn->bin2perl(16, $b), 1;
|
||||
is $conn->bin2perl(25, $s), 'Hello';
|
||||
is_deeply $conn->bin2perl(1007, $a), [-3,1,undef];
|
||||
}
|
||||
|
||||
{
|
||||
my $v = $conn->q("SELECT '{t,f,NULL}'::bool[]")->val;
|
||||
is_deeply $v, [true, false, undef];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue