Commit | Line | Data |
a964a928 |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use Test::More; |
5 | use lib qw(t/lib); |
6 | use DBICTest; |
c5ce7cd6 |
7 | use DBIx::Class::Storage::DBI::Sybase::DateTime; |
a964a928 |
8 | |
9 | my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_SYBASE_${_}" } qw/DSN USER PASS/}; |
10 | |
11 | plan skip_all => 'Set $ENV{DBICTEST_SYBASE_DSN}, _USER and _PASS to run this test' |
12 | unless ($dsn && $user); |
13 | |
d391697f |
14 | plan tests => 20*2; |
a964a928 |
15 | |
6b1f5ef7 |
16 | my @storage_types = ( |
17 | 'DBI::Sybase', |
18 | 'DBI::Sybase::NoBindVars', |
19 | ); |
20 | my $schema; |
21 | |
22 | for my $storage_type (@storage_types) { |
23 | $schema = DBICTest::Schema->clone; |
24 | |
25 | unless ($storage_type eq 'DBI::Sybase') { # autodetect |
26 | $schema->storage_type("::$storage_type"); |
27 | } |
28 | $schema->connection($dsn, $user, $pass, {AutoCommit => 1}); |
a964a928 |
29 | |
6b1f5ef7 |
30 | $schema->storage->ensure_connected; |
a964a928 |
31 | |
6b1f5ef7 |
32 | isa_ok( $schema->storage, "DBIx::Class::Storage::$storage_type" ); |
33 | |
34 | $schema->storage->dbh_do (sub { |
35 | my ($storage, $dbh) = @_; |
36 | eval { $dbh->do("DROP TABLE artist") }; |
6b1f5ef7 |
37 | $dbh->do(<<'SQL'); |
a964a928 |
38 | CREATE TABLE artist ( |
c5ce7cd6 |
39 | artistid INT IDENTITY PRIMARY KEY, |
a964a928 |
40 | name VARCHAR(100), |
41 | rank INT DEFAULT 13 NOT NULL, |
c5ce7cd6 |
42 | charfield CHAR(10) NULL |
a964a928 |
43 | ) |
c5ce7cd6 |
44 | SQL |
6b1f5ef7 |
45 | }); |
a964a928 |
46 | |
6b1f5ef7 |
47 | my %seen_id; |
a964a928 |
48 | |
6b1f5ef7 |
49 | # so we start unconnected |
50 | $schema->storage->disconnect; |
a964a928 |
51 | |
52 | # test primary key handling |
6b1f5ef7 |
53 | my $new = $schema->resultset('Artist')->create({ name => 'foo' }); |
54 | ok($new->artistid > 0, "Auto-PK worked"); |
a964a928 |
55 | |
6b1f5ef7 |
56 | $seen_id{$new->artistid}++; |
a964a928 |
57 | |
58 | # test LIMIT support |
6b1f5ef7 |
59 | for (1..6) { |
a964a928 |
60 | $new = $schema->resultset('Artist')->create({ name => 'Artist ' . $_ }); |
61 | is ( $seen_id{$new->artistid}, undef, "id for Artist $_ is unique" ); |
62 | $seen_id{$new->artistid}++; |
6b1f5ef7 |
63 | } |
a964a928 |
64 | |
b7505130 |
65 | ## avoid quoting bug with NoBindVars for now |
66 | # my $it = $schema->resultset('Artist')->search({artistid => { '>' => 0 }}, { |
67 | |
68 | my $it = $schema->resultset('Artist')->search({}, { |
a964a928 |
69 | rows => 3, |
70 | order_by => 'artistid', |
6b1f5ef7 |
71 | }); |
a964a928 |
72 | |
b7505130 |
73 | is( $it->count, 3, "LIMIT count ok" ); |
a964a928 |
74 | |
6b1f5ef7 |
75 | is( $it->next->name, "foo", "iterator->next ok" ); |
76 | $it->next; |
77 | is( $it->next->name, "Artist 2", "iterator->next ok" ); |
78 | is( $it->next, undef, "next past end of resultset ok" ); |
a964a928 |
79 | |
6b1f5ef7 |
80 | SKIP: { |
d391697f |
81 | skip 'quoting bug with NoBindVars', 8 |
6b1f5ef7 |
82 | if $storage_type eq 'DBI::Sybase::NoBindVars'; |
a964a928 |
83 | |
d391697f |
84 | # Test DateTime inflation with DATETIME |
85 | my @dt_types = ( |
86 | ['DATETIME', '2004-08-21T14:36:48.080Z'], |
87 | ['SMALLDATETIME', '2004-08-21T14:36:00.000Z'], # minute precision |
6b1f5ef7 |
88 | ); |
d391697f |
89 | |
90 | for my $dt_type (@dt_types) { |
91 | my ($type, $sample_dt) = @$dt_type; |
92 | |
93 | eval { $schema->storage->dbh->do("DROP TABLE track") }; |
94 | $schema->storage->dbh->do(<<"SQL"); |
95 | CREATE TABLE track ( |
96 | trackid INT IDENTITY PRIMARY KEY, |
97 | cd INT, |
98 | position INT, |
99 | last_updated_on $type, |
100 | ) |
101 | SQL |
102 | ok(my $dt = DBIx::Class::Storage::DBI::Sybase::DateTime |
103 | ->parse_datetime($sample_dt)); |
104 | |
105 | my $row; |
106 | ok( $row = $schema->resultset('Track')->create({ |
107 | last_updated_on => $dt, |
108 | cd => 1, |
109 | })); |
110 | ok( $row = $schema->resultset('Track') |
111 | ->search({ trackid => $row->trackid }, { select => ['last_updated_on'] }) |
112 | ->first |
113 | ); |
114 | is( $row->updated_date, $dt, 'DateTime inflation works' ); |
115 | } |
6b1f5ef7 |
116 | } |
117 | } |
a964a928 |
118 | |
119 | # clean up our mess |
120 | END { |
6b1f5ef7 |
121 | if (my $dbh = eval { $schema->storage->_dbh }) { |
122 | $dbh->do('DROP TABLE artist'); |
123 | $dbh->do('DROP TABLE track'); |
124 | } |
a964a928 |
125 | } |