Commit | Line | Data |
d867eeda |
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 = ( |
95787afe |
26 | 'DBI::Sybase::ASE', |
27 | 'DBI::Sybase::ASE::NoBindVars', |
d867eeda |
28 | ); |
29 | my $schema; |
30 | |
31 | for my $storage_type (@storage_types) { |
32 | $schema = DBICTest::Schema->clone; |
33 | |
95787afe |
34 | unless ($storage_type eq 'DBI::Sybase::ASE') { # autodetect |
d867eeda |
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 | # coltype, col, date |
47 | my @dt_types = ( |
48 | ['DATETIME', 'last_updated_at', '2004-08-21T14:36:48.080Z'], |
49 | # minute precision |
50 | ['SMALLDATETIME', 'small_dt', '2004-08-21T14:36:00.000Z'], |
51 | ); |
52 | |
53 | for my $dt_type (@dt_types) { |
54 | my ($type, $col, $sample_dt) = @$dt_type; |
55 | |
56 | eval { $schema->storage->dbh->do("DROP TABLE track") }; |
57 | $schema->storage->dbh->do(<<"SQL"); |
58 | CREATE TABLE track ( |
59 | trackid INT IDENTITY PRIMARY KEY, |
60 | cd INT, |
61 | position INT, |
62 | $col $type, |
63 | ) |
64 | SQL |
65 | ok(my $dt = DateTime::Format::Sybase->parse_datetime($sample_dt)); |
66 | |
67 | my $row; |
68 | ok( $row = $schema->resultset('Track')->create({ |
69 | $col => $dt, |
70 | cd => 1, |
71 | })); |
72 | ok( $row = $schema->resultset('Track') |
73 | ->search({ trackid => $row->trackid }, { select => [$col] }) |
74 | ->first |
75 | ); |
76 | is( $row->$col, $dt, 'DateTime roundtrip' ); |
77 | } |
78 | } |
79 | |
80 | # clean up our mess |
81 | END { |
82 | if (my $dbh = eval { $schema->storage->_dbh }) { |
83 | $dbh->do('DROP TABLE track'); |
84 | } |
85 | } |