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