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