fix stupid identity bug, test empty insert (works), test DTs (not working yet)
[dbsrgits/DBIx-Class.git] / t / inflate / datetime_sybase_asa.t
1 use strict;
2 use warnings;  
3
4 use Test::More;
5 use Test::Exception;
6 use lib qw(t/lib);
7 use DBICTest;
8
9 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_SYBASE_ASA_${_}" } qw/DSN USER PASS/};
10
11 if (not $dsn) {
12   plan skip_all =>
13     'Set $ENV{DBICTEST_SYBASE_ASA_DSN}, _USER and _PASS to run this test' .
14     "\nWarning: This test drops and creates a table called 'track'";
15 } else {
16   eval "use DateTime; use DateTime::Format::Sybase;";
17   if ($@) {
18     plan skip_all => 'needs DateTime and DateTime::Format::Sybase for testing';
19   }
20 }
21
22 my $schema;
23
24 $schema = DBICTest::Schema->clone;
25
26 $schema->connection($dsn, $user, $pass, {
27   AutoCommit => 1,
28   on_connect_call => [ 'datetime_setup' ],
29 });
30
31 # coltype, col, date
32 my @dt_types = (
33   ['DATETIME', 'last_updated_at', '2004-08-21T14:36:48.080Z'],
34 # minute precision
35   ['SMALLDATETIME', 'small_dt', '2004-08-21T14:36:00.000Z'],
36 );
37
38 for my $dt_type (@dt_types) {
39   my ($type, $col, $sample_dt) = @$dt_type;
40
41   eval { $schema->storage->dbh->do("DROP TABLE track") };
42   $schema->storage->dbh->do(<<"SQL");
43 CREATE TABLE track (
44   trackid INT IDENTITY PRIMARY KEY,
45   cd INT,
46   position INT,
47   $col $type,
48 )
49 SQL
50   ok(my $dt = DateTime::Format::Sybase->parse_datetime($sample_dt));
51
52   my $row;
53   ok( $row = $schema->resultset('Track')->create({
54         $col => $dt,
55         cd => 1,
56       }));
57   ok( $row = $schema->resultset('Track')
58     ->search({ trackid => $row->trackid }, { select => [$col] })
59     ->first
60   );
61   is( $row->$col, $dt, 'DateTime roundtrip' );
62 }
63
64 done_testing;
65
66 # clean up our mess
67 END {
68   if (my $dbh = eval { $schema->storage->_dbh }) {
69     $dbh->do('DROP TABLE track');
70   }
71 }