Commit | Line | Data |
7d17f469 |
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_${_}" } qw/DSN USER PASS/}; |
10 | |
11 | if (not ($dsn && $user)) { |
12 | plan skip_all => |
13 | 'Set $ENV{DBICTEST_SYBASE_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 | else { |
21 | plan tests => (4 * 2 * 2) + 2; # (tests * dt_types * storage_types) + storage_tests |
22 | } |
23 | } |
24 | |
25 | my @storage_types = ( |
26 | 'DBI::Sybase', |
27 | 'DBI::Sybase::NoBindVars', |
28 | ); |
29 | my $schema; |
30 | |
31 | for my $storage_type (@storage_types) { |
32 | $schema = DBICTest::Schema->clone; |
33 | |
34 | unless ($storage_type eq 'DBI::Sybase') { # autodetect |
35 | $schema->storage_type("::$storage_type"); |
36 | } |
37 | $schema->connection($dsn, $user, $pass, { |
38 | AutoCommit => 1, |
39 | on_connect_call => [ 'datetime_setup' ], |
40 | }); |
41 | |
42 | $schema->storage->ensure_connected; |
43 | |
44 | isa_ok( $schema->storage, "DBIx::Class::Storage::$storage_type" ); |
45 | |
46 | my @dt_types = ( |
47 | ['DATETIME', '2004-08-21T14:36:48.080Z'], |
48 | ['SMALLDATETIME', '2004-08-21T14:36:00.000Z'], # minute precision |
49 | ); |
50 | |
51 | for my $dt_type (@dt_types) { |
52 | my ($type, $sample_dt) = @$dt_type; |
53 | |
54 | eval { $schema->storage->dbh->do("DROP TABLE track") }; |
55 | $schema->storage->dbh->do(<<"SQL"); |
56 | CREATE TABLE track ( |
57 | trackid INT IDENTITY PRIMARY KEY, |
58 | cd INT, |
59 | position INT, |
60 | last_updated_on $type, |
61 | ) |
62 | SQL |
63 | ok(my $dt = DateTime::Format::Sybase->parse_datetime($sample_dt)); |
64 | |
65 | my $row; |
66 | ok( $row = $schema->resultset('Track')->create({ |
67 | last_updated_on => $dt, |
68 | cd => 1, |
69 | })); |
70 | ok( $row = $schema->resultset('Track') |
71 | ->search({ trackid => $row->trackid }, { select => ['last_updated_on'] }) |
72 | ->first |
73 | ); |
74 | is( $row->updated_date, $dt, 'DateTime roundtrip' ); |
75 | } |
76 | } |
77 | |
78 | # clean up our mess |
79 | END { |
80 | if (my $dbh = eval { $schema->storage->_dbh }) { |
81 | $dbh->do('DROP TABLE track'); |
82 | } |
83 | } |