Commit | Line | Data |
b0a4cf8e |
1 | use strict; |
68de9438 |
2 | use warnings; |
b0a4cf8e |
3 | |
4 | use Test::More; |
199fbc45 |
5 | use DBIx::Class::Optional::Dependencies (); |
b0a4cf8e |
6 | use lib qw(t/lib); |
7 | use DBICTest; |
8 | use Scope::Guard (); |
9 | |
199fbc45 |
10 | plan skip_all => 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for ('test_dt') |
11 | . ' and ' . |
12 | DBIx::Class::Optional::Dependencies->req_missing_for ('test_rdbms_informix') |
13 | unless DBIx::Class::Optional::Dependencies->req_ok_for ('test_dt') |
14 | && DBIx::Class::Optional::Dependencies->req_ok_for ('test_rdbms_informix'); |
15 | |
b0a4cf8e |
16 | my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_INFORMIX_${_}" } qw/DSN USER PASS/}; |
17 | |
18 | if (not $dsn) { |
19 | plan skip_all => <<'EOF'; |
20 | Set $ENV{DBICTEST_INFORMIX_DSN} _USER and _PASS to run this test'. |
21 | Warning: This test drops and creates a table called 'event'"; |
22 | EOF |
b0a4cf8e |
23 | } |
24 | |
25 | my $schema; |
26 | |
27 | { |
2c2bc4e5 |
28 | $schema = DBICTest->connect_schema($dsn, $user, $pass, { |
b0a4cf8e |
29 | on_connect_call => [ 'datetime_setup' ], |
30 | }); |
31 | |
65d35121 |
32 | my $sg = Scope::Guard->new(sub { cleanup($schema) } ); |
b0a4cf8e |
33 | |
34 | eval { $schema->storage->dbh->do('DROP TABLE event') }; |
35 | $schema->storage->dbh->do(<<'SQL'); |
36 | CREATE TABLE event ( |
37 | id INT PRIMARY KEY, |
38 | starts_at DATE, |
39 | created_on DATETIME YEAR TO FRACTION(5) |
40 | ); |
41 | SQL |
42 | my $rs = $schema->resultset('Event'); |
43 | |
44 | my $dt = DateTime->now; |
45 | $dt->set_nanosecond(555640000); |
46 | |
47 | my $date_only = DateTime->new( |
48 | year => $dt->year, month => $dt->month, day => $dt->day |
49 | ); |
50 | |
51 | my $row; |
52 | ok( $row = $rs->create({ |
53 | id => 1, |
8273e845 |
54 | starts_at => $date_only, |
b0a4cf8e |
55 | created_on => $dt, |
56 | })); |
57 | ok( $row = $rs->search({ id => 1 }, { select => [qw/starts_at created_on/] }) |
58 | ->first |
59 | ); |
60 | is $row->created_on, $dt, 'TIMESTAMP as DateTime roundtrip'; |
61 | |
62 | cmp_ok $row->created_on->nanosecond, '==', $dt->nanosecond, |
63 | 'fractional part of a second survived'; |
64 | |
65 | is $row->starts_at, $date_only, 'DATE as DateTime roundtrip'; |
66 | } |
67 | |
68 | done_testing; |
69 | |
70 | # clean up our mess |
71 | sub cleanup { |
65d35121 |
72 | my $schema = shift; |
8273e845 |
73 | my $dbh; |
b0a4cf8e |
74 | eval { |
75 | $dbh = $schema->storage->dbh; |
76 | }; |
77 | return unless $dbh; |
78 | |
79 | eval { $dbh->do(qq{DROP TABLE $_}) } for qw/event/; |
80 | } |