10 # XXX we're only testing TIMESTAMP here
12 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_FIREBIRD_${_}" } qw/DSN USER PASS/};
13 my ($dsn2, $user2, $pass2) = @ENV{map { "DBICTEST_FIREBIRD_ODBC_${_}" } qw/DSN USER PASS/};
15 if (not ($dsn || $dsn2)) {
16 plan skip_all => <<'EOF';
17 Set $ENV{DBICTEST_FIREBIRD_DSN} and/or $ENV{DBICTEST_FIREBIRD_ODBC_DSN}
18 _USER and _PASS to run this test'.
19 Warning: This test drops and creates a table called 'event'";
22 eval "use DateTime; use DateTime::Format::Strptime;";
24 plan skip_all => 'needs DateTime and DateTime::Format::Strptime for testing';
29 [ $dsn, $user, $pass ],
30 [ $dsn2, $user2, $pass2 ],
35 foreach my $conn_idx (0..$#info) {
36 my ($dsn, $user, $pass) = @{ $info[$conn_idx] || [] };
40 $schema = DBICTest::Schema->connect($dsn, $user, $pass, {
43 on_connect_call => [ 'datetime_setup' ],
46 my $sg = Scope::Guard->new(\&cleanup);
48 eval { $schema->storage->dbh->do('DROP TABLE "event"') };
49 $schema->storage->dbh->do(<<'SQL');
50 CREATE TABLE "event" (
53 "created_on" TIMESTAMP
56 my $rs = $schema->resultset('Event');
58 my $dt = DateTime->now;
59 $dt->set_nanosecond($dsn =~ /odbc/i ? 0 : 555600000);
61 my $date_only = DateTime->new(
62 year => $dt->year, month => $dt->month, day => $dt->day
66 ok( $row = $rs->create({
68 starts_at => $date_only,
71 ok( $row = $rs->search({ id => 1 }, { select => [qw/starts_at created_on/] })
74 is $row->created_on, $dt, 'TIMESTAMP as DateTime roundtrip';
76 cmp_ok $row->created_on->nanosecond, '==', $dt->nanosecond,
77 'fractional part of a second survived' if 0+$dt->nanosecond;
79 is $row->starts_at, $date_only, 'DATE as DateTime roundtrip';
88 $schema->storage->disconnect; # to avoid object FOO is in use errors
89 $dbh = $schema->storage->dbh;
93 eval { $dbh->do(qq{DROP TABLE "$_"}) } for qw/event/;