DBD-Firebird

 view release on metacpan or  search on metacpan

t/45-datetime.t  view on Meta::CPAN


my @is_match = (
    sub {
        my $ref = shift->[0]->[0];
        return ($$ref[0] == $times[0]) &&
               ($$ref[1] == $times[1]) &&
               ($$ref[2] == $times[2]) &&
               ($$ref[3] == $times[3]) &&
               ($$ref[4] == $times[4]) &&
               ($$ref[5] == $times[5]);
    },
    sub {
        my $ref = shift->[0]->[1];
        return ($$ref[3] == $times[3]) &&
               ($$ref[4] == $times[4]) &&
               ($$ref[5] == $times[5]);
    },
    sub {
        my $ref = shift->[0]->[2];
        return ($$ref[0] == $times[0]) &&
               ($$ref[1] == $times[1]) &&
               ($$ref[2] == $times[2]);
    }
);

#
#   Create a new table
#

my $def =<<"DEF";
CREATE TABLE $table (
    A_TIMESTAMP  TIMESTAMP,
    A_DATE       DATE,
    A_TIME       TIME
)
DEF

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

#
#   Insert some values
#
my $stmt =<<"END_OF_QUERY";
INSERT INTO $table
    (
    A_TIMESTAMP,
    A_DATE,
    A_TIME
    )
    VALUES (?, ?, ?)
END_OF_QUERY

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

ok($insert->execute(\@times, \@times, \@times));

#
#   Select the values
#
ok(
    my $cursor = $dbh->prepare(
        "SELECT * FROM $table",
        {
            ib_timestampformat => 'TM',
            ib_dateformat      => 'TM',
            ib_timeformat      => 'TM',
        }
    )
);

ok($cursor->execute);

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

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

for (my $i = 0; $i < $fields; $i++) {
    ok(( $is_match[$i]->($res) ), "field: $names->[$i] ($types->[$i])");
}

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

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

#  NUM_OF_FIELDS should be zero (Non-Select)
ok(($cursor->{'NUM_OF_FIELDS'}), "NUM_OF_FIELDS == 0");

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



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