DBD-Firebird

 view release on metacpan or  search on metacpan

t/48-numeric.t  view on Meta::CPAN

)
DEF
ok( $dbh->do($def), qq{CREATE TABLE '$table'} );

#
#   Insert some values
#

my $stmt =<<"END_OF_QUERY";
INSERT INTO $table (
    NUMERIC_2_DIGITS,
    NUMERIC_3_DIGITS,
    NUMERIC_NO_DIGITS
) VALUES (?, ?, ?)
END_OF_QUERY

ok(my $insert = $dbh->prepare($stmt), 'PREPARE INSERT');

# Insert positive numbers
ok($insert->execute(
    123456.7895,
    86753090000.8675309,
    10.9),
   'INSERT POSITIVE NUMBERS'
);

# Insert negative numbers
ok($insert->execute(
    -123456.7895,
    -86753090000.8675309,
    -10.9),
   'INSERT NEGATIVE NUMBERS'
);

# Insert with some variations in the precision part

ok($insert->execute(
    123456.01,
    80.080,
    10.0),
   'INSERT NUMBERS WITH VARIOUS PREC 1'
);

ok($insert->execute(
    -123456.09,
    -80.080,
    0.0),
   'INSERT NUMBERS WITH VARIOUS PREC 2'
);

ok($insert->execute(
    10.9,
    10.9,
    10.9),
   'INSERT NUMBERS WITH VARIOUS PREC 3'
);

#
#   Select the values
#
ok( my $cursor = $dbh->prepare( qq{SELECT * FROM $table}, ), 'PREPARE SELECT' );

ok($cursor->execute, 'EXECUTE SELECT');

ok((my $res = $cursor->fetchall_arrayref), 'FETCHALL arrayref');

my ($types, $names, $fields) = @{$cursor}{qw(TYPE NAME NUM_OF_FIELDS)};

for (my $i = 0; $i < @$res; $i++) {
    for (my $j = 0; $j < $fields; $j++) {
        my $prec = $expected->{ $names->[$j] }{prec};
        my $result = sprintf("%.${prec}f", $res->[$i][$j]);
        my $corect = sprintf("%.${prec}f", $expected->{$names->[$j]}{test}{$i});
        is($result, $corect, "Field: $names->[$j]");
    }
}

#
#  Drop the test table
#
$dbh->{AutoCommit} = 1;

ok( $dbh->do("DROP TABLE $table"), "DROP TABLE '$table'" );

#
#   Finally disconnect.
#
ok($dbh->disconnect, 'DISCONNECT');



( run in 0.663 second using v1.01-cache-2.11-cpan-39bf76dae61 )