Subject: | High-scale data conversion incorrect |
Overview:
NUMERIC and DECIMAL results of a high-enough scale are mangled when
converted to their perl equivalents. The attached script demonstrates
the problem in more detail, and the final section of this bug report has
a link to another user suffering the same problem.
How to reproduce:
my $dbh = DBI->connect('dbi:InterBase:...', $user, $pass);
my ($r) = $dbh->selectrow_array('SELECT CAST(1 AS NUMERIC(11, 10))
FROM rdb$database');
print "CAST(1 AS NUMERIC(11, 10)) => $r\n";
Expected output:
CAST(1 AS NUMERIC(11, 10)) => 1
Actual output:
CAST(1 AS NUMERIC(11, 10)) => -4.1410065408
Platform:
Linux x86, DBD-IB-0.48, DBI-1.609, perl-5.10.1, Firebird 2.1
See also:
http://perlmonks.org/?node_id=821607
("Wrong calculation result with data retrieved with DBD::InterBase
from view")
Subject: | scale.t.pl |
#! /usr/bin/perl
# Usage: scale.pl dbname [user [pass]]
# ./scale.pl employee.fdb SYSDBA masterkey
use strict;
use warnings;
use DBI;
use constant PRECISION => 18;
use Test::More tests => (PRECISION - 1);
my $dbh = DBI->connect(@ARGV, { RaiseError => 1});
diag "perl $^V";
diag "DBD::InterBase $DBD::InterBase::VERSION";
diag "DBI $DBI::VERSION";
diag "IB/FB server " . ($dbh->func('version', 'ib_database_info'))->{version};
for my $scale (1 .. (PRECISION - 1)) {
my $cast = 'CAST(1 AS NUMERIC(' . PRECISION . ", $scale))";
my ($r) = $dbh->selectrow_array("SELECT $cast FROM rdb\$database")
||
$dbh->err;
is($r, 1, "$cast => 1");
}
__END__
# vim: set et ts=4 ft=perl: