Remove use of Try::Tiny entirely (the missing part of ddcc02d1)
[dbsrgits/DBIx-Class.git] / t / icdt / engine_specific / firebird.t
1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
2 use DBIx::Class::Optional::Dependencies -skip_all_without => qw( ic_dt _rdbms_firebird_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 $env2optdep = {
13   DBICTEST_FIREBIRD => 'test_rdbms_firebird',
14   DBICTEST_FIREBIRD_INTERBASE => 'test_rdbms_firebird_interbase',
15   DBICTEST_FIREBIRD_ODBC => 'test_rdbms_firebird_odbc',
16 };
17
18 my @tdeps = values %$env2optdep;
19 plan skip_all => 'Test needs  ' . (join '  OR  ', map
20   { "[ @{[ DBIx::Class::Optional::Dependencies->req_missing_for( $_ ) ]} ]" }
21   @tdeps
22 ) unless scalar grep
23   { DBIx::Class::Optional::Dependencies->req_ok_for( $_ ) }
24   @tdeps
25 ;
26
27 my $schema;
28
29 for my $prefix (keys %$env2optdep) { SKIP: {
30
31   DBIx::Class::Optional::Dependencies->skip_without( $env2optdep->{$prefix} );
32
33   note "Testing with ${prefix}_DSN";
34
35   my ($dsn, $user, $pass) = map { $ENV{"${prefix}_$_"} } qw/DSN USER PASS/;
36
37   $schema = DBICTest::Schema->connect($dsn, $user, $pass, {
38     quote_char => '"',
39     name_sep   => '.',
40     on_connect_call => [ 'datetime_setup' ],
41   });
42
43   my $sg = scope_guard { cleanup($schema) };
44
45   eval { $schema->storage->dbh->do('DROP TABLE "event"') };
46   $schema->storage->dbh->do(<<'SQL');
47   CREATE TABLE "event" (
48     "id" INT PRIMARY KEY,
49     "starts_at" DATE,
50     "created_on" TIMESTAMP
51   )
52 SQL
53   my $rs = $schema->resultset('Event');
54
55   my $dt = DateTime->now;
56   $dt->set_nanosecond(555600000);
57
58   my $date_only = DateTime->new(
59     year => $dt->year, month => $dt->month, day => $dt->day
60   );
61
62   my $row;
63   ok( $row = $rs->create({
64     id => 1,
65     starts_at => $date_only,
66     created_on => $dt,
67   }));
68   ok( $row = $rs->search({ id => 1 }, { select => [qw/starts_at created_on/] })
69     ->first
70   );
71   is $row->created_on, $dt, 'TIMESTAMP as DateTime roundtrip';
72
73   cmp_ok $row->created_on->nanosecond, '==', $dt->nanosecond,
74     'fractional part of a second survived';
75
76   is $row->starts_at, $date_only, 'DATE as DateTime roundtrip';
77 } }
78
79 done_testing;
80
81 # clean up our mess
82 sub cleanup {
83   my $schema = shift;
84   my $dbh;
85   eval {
86     $schema->storage->disconnect; # to avoid object FOO is in use errors
87     $dbh = $schema->storage->dbh;
88   };
89   return unless $dbh;
90
91   eval { $dbh->do(qq{DROP TABLE "$_"}) } for qw/event/;
92 }