Remove use of Try::Tiny entirely (the missing part of ddcc02d1)
[dbsrgits/DBIx-Class.git] / t / icdt / engine_specific / sqlanywhere.t
1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
2 use DBIx::Class::Optional::Dependencies -skip_all_without => qw( ic_dt _rdbms_sqlanywhere_common );
3
4 use strict;
5 use warnings;
6
7 use Test::More;
8 use DBIx::Class::_Util 'scope_guard';
9
10 use DBICTest;
11
12 my @tdeps = qw( test_rdbms_sqlanywhere test_rdbms_sqlanywhere_odbc );
13 plan skip_all => 'Test needs  ' . (join '  OR  ', map
14   { "[ @{[ DBIx::Class::Optional::Dependencies->req_missing_for( $_ ) ]} ]" }
15   @tdeps
16 ) unless scalar grep
17   { DBIx::Class::Optional::Dependencies->req_ok_for( $_ ) }
18   @tdeps
19 ;
20
21 my ($dsn, $user, $pass)    = @ENV{map { "DBICTEST_SQLANYWHERE_${_}" }      qw/DSN USER PASS/};
22 my ($dsn2, $user2, $pass2) = @ENV{map { "DBICTEST_SQLANYWHERE_ODBC_${_}" } qw/DSN USER PASS/};
23
24 my @info = (
25   [ $dsn,  $user,  $pass  ],
26   [ $dsn2, $user2, $pass2 ],
27 );
28
29 my $schema;
30
31 foreach my $info (@info) {
32   my ($dsn, $user, $pass) = @$info;
33
34   next unless $dsn;
35
36   $schema = DBICTest::Schema->clone;
37
38   $schema->connection($dsn, $user, $pass, {
39     on_connect_call => 'datetime_setup',
40   });
41
42   my $sg = scope_guard { cleanup($schema) };
43
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   )
51 SQL
52
53 # coltype, col, date
54   my @dt_types = (
55     [
56       'TIMESTAMP',
57       'created_on',
58       '2004-08-21 14:36:48.080445',
59     ],
60 # date only (but minute precision according to ASA docs)
61     [
62       'DATE',
63       'starts_at',
64       '2004-08-21 00:00:00.000000',
65     ],
66   );
67
68   for my $dt_type (@dt_types) {
69     my ($type, $col, $sample_dt) = @$dt_type;
70
71     ok(my $dt = $schema->storage->datetime_parser->parse_datetime($sample_dt));
72
73     my $row;
74     ok( $row = $schema->resultset('Event')->create({ $col => $dt, }));
75     ok( $row = $schema->resultset('Event')
76       ->search({ id => $row->id }, { select => [$col] })
77       ->first
78     );
79     is( $row->$col, $dt, "$type roundtrip" );
80
81     is $row->$col->nanosecond, $dt->nanosecond,
82         'nanoseconds survived' if 0+$dt->nanosecond;
83   }
84 }
85
86 done_testing;
87
88 # clean up our mess
89 sub cleanup {
90   my $schema = shift;
91   if (my $dbh = $schema->storage->dbh) {
92     eval { $dbh->do("DROP TABLE $_") } for qw/event/;
93   }
94 }