pg: Support binary bind params
This commit is contained in:
parent
166744dd51
commit
30b457d2b8
6 changed files with 226 additions and 78 deletions
41
t/pgtypes.t
41
t/pgtypes.t
|
|
@ -10,19 +10,40 @@ plan skip_all => 'Please set FU_TEST_DB to a PostgreSQL connection string to run
|
|||
my $conn = FU::PG->connect($ENV{FU_TEST_DB});
|
||||
$conn->_debug_trace(0);
|
||||
|
||||
sub v($type, $v, $sql=$v) {
|
||||
$sql = "($sql)::$type";
|
||||
my $res = $conn->q("SELECT $sql")->text_results(0)->val;
|
||||
ok is_bool($res), "recv bool $sql" if $type eq 'bool';
|
||||
ok created_as_number($res), "recv number $sql" if $type =~ /^int/;
|
||||
is $res, $v, "recv value $sql";
|
||||
# TODO: Test behavior of magic bind params
|
||||
|
||||
sub v($type, $p_in, @args) {
|
||||
my $p_out = @args > 0 && ref $args[0] ne 'SCALAR' ? $args[0] : $p_in;
|
||||
my $s_in = @args > 1 && ref $args[1] ne 'SCALAR' ? $args[1] : $p_in;
|
||||
my $s_out = @args > 2 && ref $args[2] ne 'SCALAR' ? $args[2] : $s_in;
|
||||
|
||||
{
|
||||
my $res = $conn->q("SELECT \$1::$type", $s_in)->text_params->val;
|
||||
ok is_bool($res), "$type $s_in is bool" if $type eq 'bool';
|
||||
ok created_as_number($res), "$type $s_in is number" if $type =~ /^int/;
|
||||
is_deeply $res, $p_out, "$type $s_in text->bin";
|
||||
}
|
||||
{
|
||||
my $res = $conn->q("SELECT \$1::$type", $p_in)->text_results->val;
|
||||
is $res, $s_out, "$type $s_out bin->text";
|
||||
}
|
||||
{
|
||||
my $res = $conn->q("SELECT \$1::$type", $p_in)->val;
|
||||
is_deeply $res, $p_out, "$type $s_in bin->bin";
|
||||
}
|
||||
}
|
||||
sub f($type, $p_in) {
|
||||
ok !eval { $conn->q("SELECT \$1::$type", $p_in)->val; 1 }, "$type $p_in fail";
|
||||
}
|
||||
|
||||
v bool => true, 'true';
|
||||
v bool => false, 'false';
|
||||
v bool => true, 1, 'true', 't';
|
||||
v bool => false, '', 'false', 'f';
|
||||
|
||||
v int2 => $_ for (1, -1, -32768, 32767, 12345, -12345);
|
||||
v int2 => $_ for (1, -1, -32768, 32767, '12345', -12345, 123.0);
|
||||
f int2 => $_ for (-32769, 32768, [], '', 'a', 1.5);
|
||||
v int4 => $_ for (1, -1, -2147483648, 2147483647, 1234567890, -1234567890);
|
||||
v int8 => $_ for (1, -1, -9223372036854775808, 9223372036854775807, 1234567890123456789, -1234567890123456789);
|
||||
f int4 => $_ for (-2147483649, 2147483648, []);
|
||||
v int8 => $_ for (1, -1, -9223372036854775808, 9223372036854775807, 1234567890123456789, -1234567890123456789, 1e10);
|
||||
f int8 => $_ for ('aaa', '-9223372036854775809', '9223372036854775808', 1e20);
|
||||
|
||||
done_testing;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue