fix savepoints for Firebird ODBC
[dbsrgits/DBIx-Class.git] / t / inflate / datetime_firebird.t
CommitLineData
9cd0b325 1use strict;
2use warnings;
3
4use Test::More;
5use Test::Exception;
6use lib qw(t/lib);
7use DBICTest;
8use Scope::Guard ();
9
10# XXX we're only testing TIMESTAMP here
11
12my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_FIREBIRD_${_}" } qw/DSN USER PASS/};
13my ($dsn2, $user2, $pass2) = @ENV{map { "DBICTEST_FIREBIRD_ODBC_${_}" } qw/DSN USER PASS/};
14
15if (not ($dsn || $dsn2)) {
16 plan skip_all => <<'EOF';
17Set $ENV{DBICTEST_FIREBIRD_DSN} and/or $ENV{DBICTEST_FIREBIRD_ODBC_DSN}
18_USER and _PASS to run this test'.
19Warning: This test drops and creates a table called 'event'";
20EOF
21} else {
22 eval "use DateTime; use DateTime::Format::Strptime;";
23 if ($@) {
24 plan skip_all => 'needs DateTime and DateTime::Format::Strptime for testing';
25 }
26}
27
28my @info = (
29 [ $dsn, $user, $pass ],
30 [ $dsn2, $user2, $pass2 ],
31);
32
33my $schema;
34
32323fc2 35foreach my $conn_idx (0..$#info) {
36 my ($dsn, $user, $pass) = @{ $info[$conn_idx] };
9cd0b325 37
38 next unless $dsn;
39
32323fc2 40 $schema = DBICTest::Schema->connect($dsn, $user, $pass, {
9cd0b325 41 on_connect_call => [ 'datetime_setup' ],
42 });
43
44 my $sg = Scope::Guard->new(\&cleanup);
45
46 eval { $schema->storage->dbh->do("DROP TABLE event") };
47 $schema->storage->dbh->do(<<"SQL");
48 CREATE TABLE event (
49 id INT PRIMARY KEY,
50 created_on TIMESTAMP
51 )
52SQL
53 my $now = DateTime->now;
32323fc2 54 $now->set_nanosecond(555600000);
9cd0b325 55 my $row;
56 ok( $row = $schema->resultset('Event')->create({
57 id => 1,
58 created_on => $now,
59 }));
60 ok( $row = $schema->resultset('Event')
61 ->search({ id => 1 }, { select => ['created_on'] })
62 ->first
63 );
32323fc2 64 is $row->created_on, $now, 'DateTime roundtrip';
65
66 if ($conn_idx == 0) { # skip for ODBC
67 cmp_ok $row->created_on->nanosecond, '==', 555600000,
68 'fractional part of a second survived';
69 }
9cd0b325 70}
71
72done_testing;
73
74# clean up our mess
75sub cleanup {
76 my $dbh;
77 eval {
78 $schema->storage->disconnect; # to avoid object FOO is in use errors
79 $dbh = $schema->storage->dbh;
80 };
81 return unless $dbh;
82
83 eval { $dbh->do("DROP TABLE $_") } for qw/event/;
84}