rename ::Sybase::ASA to ::SQLAnywhere, per mst
[dbsrgits/DBIx-Class.git] / t / inflate / datetime_sybase_asa.t
CommitLineData
ed720bc5 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_ASA_${_}" } qw/DSN USER PASS/};
10
11if (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
22my $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
32my @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
38for 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");
43CREATE TABLE track (
44 trackid INT IDENTITY PRIMARY KEY,
45 cd INT,
46 position INT,
47 $col $type,
48)
49SQL
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
64done_testing;
65
66# clean up our mess
67END {
68 if (my $dbh = eval { $schema->storage->_dbh }) {
69 $dbh->do('DROP TABLE track');
70 }
71}