Commit | Line | Data |
9cd0b325 |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use Test::More; |
5 | use Test::Exception; |
6 | use lib qw(t/lib); |
7 | use DBICTest; |
8 | use Scope::Guard (); |
9 | |
10 | # XXX we're only testing TIMESTAMP here |
11 | |
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/}; |
14 | |
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'"; |
20 | EOF |
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 | |
28 | my @info = ( |
29 | [ $dsn, $user, $pass ], |
30 | [ $dsn2, $user2, $pass2 ], |
31 | ); |
32 | |
33 | my $schema; |
34 | |
35 | foreach my $info (@info) { |
36 | my ($dsn, $user, $pass) = @$info; |
37 | |
38 | next unless $dsn; |
39 | |
40 | $schema = DBICTest::Schema->clone; |
41 | |
42 | $schema->connection($dsn, $user, $pass, { |
43 | on_connect_call => [ 'datetime_setup' ], |
44 | }); |
45 | |
46 | my $sg = Scope::Guard->new(\&cleanup); |
47 | |
48 | eval { $schema->storage->dbh->do("DROP TABLE event") }; |
49 | $schema->storage->dbh->do(<<"SQL"); |
50 | CREATE TABLE event ( |
51 | id INT PRIMARY KEY, |
52 | created_on TIMESTAMP |
53 | ) |
54 | SQL |
55 | my $now = DateTime->now; |
56 | my $row; |
57 | ok( $row = $schema->resultset('Event')->create({ |
58 | id => 1, |
59 | created_on => $now, |
60 | })); |
61 | ok( $row = $schema->resultset('Event') |
62 | ->search({ id => 1 }, { select => ['created_on'] }) |
63 | ->first |
64 | ); |
65 | is( $row->created_on, $now, 'DateTime roundtrip' ); |
66 | } |
67 | |
68 | done_testing; |
69 | |
70 | # clean up our mess |
71 | sub cleanup { |
72 | my $dbh; |
73 | eval { |
74 | $schema->storage->disconnect; # to avoid object FOO is in use errors |
75 | $dbh = $schema->storage->dbh; |
76 | }; |
77 | return unless $dbh; |
78 | |
79 | eval { $dbh->do("DROP TABLE $_") } for qw/event/; |
80 | } |