Enable pg test disabled god knows why, minor cleanup.
[dbsrgits/DBIx-Class.git] / t / inflate / datetime_sybase_asa.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
5be953ff 10my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_SYBASE_ASA_${_}" } qw/DSN USER PASS/};
11my ($dsn2, $user2, $pass2) = @ENV{map { "DBICTEST_SYBASE_ASA_ODBC_${_}" } qw/DSN USER PASS/};
ed720bc5 12
5be953ff 13if (not ($dsn || $dsn2)) {
14 plan skip_all => <<'EOF';
15Set $ENV{DBICTEST_SYBASE_ASA_DSN} and/or $ENV{DBICTEST_SYBASE_ASA_ODBC_DSN}
16_USER and _PASS to run this test'.
17Warning: This test drops and creates a table called 'track'";
18EOF
ed720bc5 19} else {
2b0076be 20 eval "use DateTime; use DateTime::Format::Strptime;";
ed720bc5 21 if ($@) {
2b0076be 22 plan skip_all => 'needs DateTime and DateTime::Format::Strptime for testing';
ed720bc5 23 }
24}
25
5be953ff 26my @info = (
27 [ $dsn, $user, $pass ],
28 [ $dsn2, $user2, $pass2 ],
29);
30
592ff7c4 31my $schema;
5be953ff 32
33foreach my $info (@info) {
34 my ($dsn, $user, $pass) = @$info;
ed720bc5 35
5be953ff 36 next unless $dsn;
ed720bc5 37
592ff7c4 38 $schema = DBICTest::Schema->clone;
5be953ff 39
40 $schema->connection($dsn, $user, $pass, {
41 on_connect_call => [ 'datetime_setup' ],
42 });
43
592ff7c4 44 my $sg = Scope::Guard->new(\&cleanup);
ed720bc5 45
46# coltype, col, date
5be953ff 47 my @dt_types = (
51b1115f 48 ['TIMESTAMP', 'last_updated_at', '2004-08-21 14:36:48.080445'],
2b0076be 49# date only (but minute precision according to ASA docs)
5be953ff 50 ['DATE', 'small_dt', '2004-08-21 00:00:00.000000'],
51 );
52
53 for my $dt_type (@dt_types) {
54 my ($type, $col, $sample_dt) = @$dt_type;
ed720bc5 55
5be953ff 56 eval { $schema->storage->dbh->do("DROP TABLE track") };
57 $schema->storage->dbh->do(<<"SQL");
58 CREATE TABLE track (
59 trackid INT IDENTITY PRIMARY KEY,
60 cd INT,
61 position INT,
62 $col $type,
63 )
ed720bc5 64SQL
5be953ff 65 ok(my $dt = $schema->storage->datetime_parser->parse_datetime($sample_dt));
66
67 my $row;
68 ok( $row = $schema->resultset('Track')->create({
69 $col => $dt,
70 cd => 1,
71 }));
72 ok( $row = $schema->resultset('Track')
73 ->search({ trackid => $row->trackid }, { select => [$col] })
74 ->first
75 );
592ff7c4 76 is( $row->$col, $dt, "$type roundtrip" );
51b1115f 77
78 is $row->$col->nanosecond, $dt->nanosecond,
79 'nanoseconds survived' if 0+$dt->nanosecond;
5be953ff 80 }
ed720bc5 81}
82
83done_testing;
84
85# clean up our mess
592ff7c4 86sub cleanup {
87 if (my $dbh = $schema->storage->dbh) {
5be953ff 88 eval { $dbh->do("DROP TABLE $_") } for qw/track/;
ed720bc5 89 }
90}