Commit | Line | Data |
ed720bc5 |
1 | use strict; |
8273e845 |
2 | use warnings; |
ed720bc5 |
3 | |
4 | use Test::More; |
592ff7c4 |
5 | use Scope::Guard (); |
199fbc45 |
6 | use DBIx::Class::Optional::Dependencies (); |
ed720bc5 |
7 | use lib qw(t/lib); |
8 | use DBICTest; |
9 | |
374f18f2 |
10 | my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_SQLANYWHERE_${_}" } qw/DSN USER PASS/}; |
11 | my ($dsn2, $user2, $pass2) = @ENV{map { "DBICTEST_SQLANYWHERE_ODBC_${_}" } qw/DSN USER PASS/}; |
ed720bc5 |
12 | |
199fbc45 |
13 | plan skip_all => 'Test needs ' . |
14 | (join ' and ', map { $_ ? $_ : () } |
15 | DBIx::Class::Optional::Dependencies->req_missing_for('test_dt'), |
16 | (join ' or ', map { $_ ? $_ : () } |
17 | DBIx::Class::Optional::Dependencies->req_missing_for('test_rdbms_sqlanywhere'), |
18 | DBIx::Class::Optional::Dependencies->req_missing_for('test_rdbms_sqlanywhere_odbc'))) |
19 | unless |
20 | DBIx::Class::Optional::Dependencies->req_ok_for ('test_dt') && ( |
21 | $dsn && DBIx::Class::Optional::Dependencies->req_ok_for('test_rdbms_sqlanywhere') |
22 | or |
23 | $dsn2 && DBIx::Class::Optional::Dependencies->req_ok_for('test_rdbms_sqlanywhere_odbc')) |
24 | or (not $dsn || $dsn2); |
25 | |
5be953ff |
26 | if (not ($dsn || $dsn2)) { |
27 | plan skip_all => <<'EOF'; |
374f18f2 |
28 | Set $ENV{DBICTEST_SQLANYWHERE_DSN} and/or $ENV{DBICTEST_SQLANYWHERE_ODBC_DSN} |
5be953ff |
29 | _USER and _PASS to run this test'. |
7bef80f1 |
30 | Warning: This test drops and creates a table called 'event'"; |
5be953ff |
31 | EOF |
ed720bc5 |
32 | } |
33 | |
5be953ff |
34 | my @info = ( |
35 | [ $dsn, $user, $pass ], |
36 | [ $dsn2, $user2, $pass2 ], |
37 | ); |
38 | |
592ff7c4 |
39 | my $schema; |
5be953ff |
40 | |
41 | foreach my $info (@info) { |
42 | my ($dsn, $user, $pass) = @$info; |
ed720bc5 |
43 | |
5be953ff |
44 | next unless $dsn; |
ed720bc5 |
45 | |
592ff7c4 |
46 | $schema = DBICTest::Schema->clone; |
5be953ff |
47 | |
48 | $schema->connection($dsn, $user, $pass, { |
7bef80f1 |
49 | on_connect_call => 'datetime_setup', |
5be953ff |
50 | }); |
51 | |
65d35121 |
52 | my $sg = Scope::Guard->new(sub { cleanup($schema) } ); |
ed720bc5 |
53 | |
7bef80f1 |
54 | eval { $schema->storage->dbh->do('DROP TABLE event') }; |
55 | $schema->storage->dbh->do(<<"SQL"); |
56 | CREATE TABLE event ( |
57 | id INT IDENTITY PRIMARY KEY, |
58 | created_on TIMESTAMP, |
59 | starts_at DATE |
60 | ) |
61 | SQL |
62 | |
ed720bc5 |
63 | # coltype, col, date |
5be953ff |
64 | my @dt_types = ( |
7bef80f1 |
65 | [ |
66 | 'TIMESTAMP', |
67 | 'created_on', |
68 | '2004-08-21 14:36:48.080445', |
69 | ], |
2b0076be |
70 | # date only (but minute precision according to ASA docs) |
7bef80f1 |
71 | [ |
72 | 'DATE', |
73 | 'starts_at', |
74 | '2004-08-21 00:00:00.000000', |
75 | ], |
5be953ff |
76 | ); |
77 | |
78 | for my $dt_type (@dt_types) { |
79 | my ($type, $col, $sample_dt) = @$dt_type; |
ed720bc5 |
80 | |
5be953ff |
81 | ok(my $dt = $schema->storage->datetime_parser->parse_datetime($sample_dt)); |
82 | |
83 | my $row; |
7bef80f1 |
84 | ok( $row = $schema->resultset('Event')->create({ $col => $dt, })); |
85 | ok( $row = $schema->resultset('Event') |
86 | ->search({ id => $row->id }, { select => [$col] }) |
5be953ff |
87 | ->first |
88 | ); |
592ff7c4 |
89 | is( $row->$col, $dt, "$type roundtrip" ); |
51b1115f |
90 | |
91 | is $row->$col->nanosecond, $dt->nanosecond, |
92 | 'nanoseconds survived' if 0+$dt->nanosecond; |
5be953ff |
93 | } |
ed720bc5 |
94 | } |
95 | |
96 | done_testing; |
97 | |
98 | # clean up our mess |
592ff7c4 |
99 | sub cleanup { |
65d35121 |
100 | my $schema = shift; |
592ff7c4 |
101 | if (my $dbh = $schema->storage->dbh) { |
7bef80f1 |
102 | eval { $dbh->do("DROP TABLE $_") } for qw/event/; |
ed720bc5 |
103 | } |
104 | } |