1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
# RT#55841 high-scale numbers incorrectly formatted
use strict;
use warnings;
use Test::More;
use DBI;
use lib 't','.';
use TestFirebird;
my $T = TestFirebird->new;
my ( $dbh, $error_str ) = $T->connect_to_database( { ChopBlanks => 1 } );
if ($error_str) {
BAIL_OUT("Unknown: $error_str!");
}
unless ( $dbh->isa('DBI::db') ) {
plan skip_all => 'Connection to database failed, cannot continue testing';
}
else {
plan tests => 52;
}
ok($dbh, 'Connected to the database');
my @Types = qw|NUMERIC DECIMAL|;
my @Tests = (
# Literal Precision Scale Expected
[ '-19.061', 18, 0, -19 ], # XXX - we coerce Expected
[ '-19.061', 18, 1, -19.1 ], # into a number
[ '-19.061', 18, 2, -19.06 ],
[ '-19.061', 18, 3, -19.061 ],
[ '-19.061', 18, 4, -19.061 ],
[ '-19.061', 18, 5, -19.061 ],
[ '-19.061', 18, 6, -19.061 ],
[ '-19.061', 18, 7, -19.061 ],
[ '-19.061', 18, 8, -19.061 ],
[ '-19.061', 18, 9, -19.061 ],
[ '-19.061', 18, 10, -19.061 ],
[ '-19.061', 18, 11, -19.061 ],
[ '-19.061', 18, 12, -19.061 ],
[ '-19.061', 18, 13, -19.061 ],
[ '-19.061', 18, 14, -19.061 ],
[ '-19.061', 18, 15, -19.061 ],
[ '-19.061', 18, 16, -19.061 ],
[ '0.00001', 12, 11, 0.00001 ],
[ '0.00001', 12, 10, 0.00001 ],
[ '0.00001', 12, 9, 0.00001 ],
[ '0.00001', 12, 8, 0.00001 ],
[ '0.00001', 12, 7, 0.00001 ],
[ '0.00001', 12, 6, 0.00001 ],
[ '0.00001', 12, 5, 0.00001 ],
[ '0.00001', 12, 4, 0 ],
);
# plan tests => (2 + (@Types * @Tests));
for my $type (@Types) {
for (@Tests) {
my ($literal, $prec, $scale, $expected) = @$_;
my $cast = "CAST($literal AS $type($prec, $scale))";
my ($r) = $dbh->selectrow_array("select $cast from RDB\$DATABASE");
is(0+$r, $expected, "$cast");
}
}
{
my ($r) = $dbh->selectrow_array('select 0+1 from RDB$DATABASE');
is($r, '1', "0+1"); # No decimal point on implicit zero-scale field
}
__END__
# vim: set et ts=4 ft=perl:
|