Clear up some legacy cruft and straighten inheritance
[dbsrgits/DBIx-Class.git] / t / inflate / datetime_sybase.t
CommitLineData
7d17f469 1use strict;
2use warnings;
3
4use Test::More;
5use Test::Exception;
6use lib qw(t/lib);
7use DBICTest;
8
9my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_SYBASE_${_}" } qw/DSN USER PASS/};
10
11if (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
25my @storage_types = (
26 'DBI::Sybase',
27 'DBI::Sybase::NoBindVars',
28);
29my $schema;
30
31for 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
5137d252 46# coltype, col, date
7d17f469 47 my @dt_types = (
5137d252 48 ['DATETIME', 'last_updated_at', '2004-08-21T14:36:48.080Z'],
49# minute precision
50 ['SMALLDATETIME', 'small_dt', '2004-08-21T14:36:00.000Z'],
7d17f469 51 );
52
53 for my $dt_type (@dt_types) {
5137d252 54 my ($type, $col, $sample_dt) = @$dt_type;
7d17f469 55
56 eval { $schema->storage->dbh->do("DROP TABLE track") };
57 $schema->storage->dbh->do(<<"SQL");
58CREATE TABLE track (
59 trackid INT IDENTITY PRIMARY KEY,
60 cd INT,
61 position INT,
5137d252 62 $col $type,
7d17f469 63)
64SQL
65 ok(my $dt = DateTime::Format::Sybase->parse_datetime($sample_dt));
66
67 my $row;
68 ok( $row = $schema->resultset('Track')->create({
5137d252 69 $col => $dt,
7d17f469 70 cd => 1,
71 }));
72 ok( $row = $schema->resultset('Track')
5137d252 73 ->search({ trackid => $row->trackid }, { select => [$col] })
7d17f469 74 ->first
75 );
5137d252 76 is( $row->$col, $dt, 'DateTime roundtrip' );
7d17f469 77 }
78}
79
80# clean up our mess
81END {
82 if (my $dbh = eval { $schema->storage->_dbh }) {
83 $dbh->do('DROP TABLE track');
84 }
85}