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 | |
6b1f5ef7 |
14 | plan tests => 16*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") }; |
37 | eval { $dbh->do("DROP TABLE track") }; |
38 | $dbh->do(<<'SQL'); |
a964a928 |
39 | CREATE TABLE artist ( |
c5ce7cd6 |
40 | artistid INT IDENTITY PRIMARY KEY, |
a964a928 |
41 | name VARCHAR(100), |
42 | rank INT DEFAULT 13 NOT NULL, |
c5ce7cd6 |
43 | charfield CHAR(10) NULL |
a964a928 |
44 | ) |
c5ce7cd6 |
45 | SQL |
a964a928 |
46 | |
c5ce7cd6 |
47 | # we only need the DT |
6b1f5ef7 |
48 | $dbh->do(<<'SQL'); |
c5ce7cd6 |
49 | CREATE TABLE track ( |
50 | trackid INT IDENTITY PRIMARY KEY, |
51 | cd INT, |
52 | position INT, |
53 | last_updated_on DATETIME, |
54 | ) |
a964a928 |
55 | SQL |
6b1f5ef7 |
56 | }); |
a964a928 |
57 | |
6b1f5ef7 |
58 | my %seen_id; |
a964a928 |
59 | |
6b1f5ef7 |
60 | # so we start unconnected |
61 | $schema->storage->disconnect; |
a964a928 |
62 | |
63 | # test primary key handling |
6b1f5ef7 |
64 | my $new = $schema->resultset('Artist')->create({ name => 'foo' }); |
65 | ok($new->artistid > 0, "Auto-PK worked"); |
a964a928 |
66 | |
6b1f5ef7 |
67 | $seen_id{$new->artistid}++; |
a964a928 |
68 | |
69 | # test LIMIT support |
6b1f5ef7 |
70 | for (1..6) { |
a964a928 |
71 | $new = $schema->resultset('Artist')->create({ name => 'Artist ' . $_ }); |
72 | is ( $seen_id{$new->artistid}, undef, "id for Artist $_ is unique" ); |
73 | $seen_id{$new->artistid}++; |
6b1f5ef7 |
74 | } |
a964a928 |
75 | |
6b1f5ef7 |
76 | my $it = $schema->resultset('Artist')->search( {}, { |
a964a928 |
77 | rows => 3, |
78 | order_by => 'artistid', |
6b1f5ef7 |
79 | }); |
a964a928 |
80 | |
6b1f5ef7 |
81 | TODO: { |
a964a928 |
82 | local $TODO = 'Sybase is very very fucked in the limit department'; |
83 | |
84 | is( $it->count, 3, "LIMIT count ok" ); |
6b1f5ef7 |
85 | } |
a964a928 |
86 | |
6b1f5ef7 |
87 | is( $it->next->name, "foo", "iterator->next ok" ); |
88 | $it->next; |
89 | is( $it->next->name, "Artist 2", "iterator->next ok" ); |
90 | is( $it->next, undef, "next past end of resultset ok" ); |
a964a928 |
91 | |
6b1f5ef7 |
92 | SKIP: { |
93 | skip 'quoting bug with NoBindVars', 4 |
94 | if $storage_type eq 'DBI::Sybase::NoBindVars'; |
a964a928 |
95 | |
c5ce7cd6 |
96 | # Test DateTime inflation |
6b1f5ef7 |
97 | ok(my $dt = DBIx::Class::Storage::DBI::Sybase::DateTime |
98 | ->parse_datetime('2004-08-21T14:36:48.080Z')); |
99 | |
100 | my $row; |
101 | ok( $row = $schema->resultset('Track')->create({ |
102 | last_updated_on => $dt, |
103 | cd => 1, |
104 | })); |
105 | ok( $row = $schema->resultset('Track') |
106 | ->search({ trackid => $row->trackid }, { select => ['last_updated_on'] }) |
107 | ->first |
108 | ); |
109 | is( $row->updated_date, $dt, 'DateTime inflation works' ); |
110 | } |
111 | } |
a964a928 |
112 | |
113 | # clean up our mess |
114 | END { |
6b1f5ef7 |
115 | if (my $dbh = eval { $schema->storage->_dbh }) { |
116 | $dbh->do('DROP TABLE artist'); |
117 | $dbh->do('DROP TABLE track'); |
118 | } |
a964a928 |
119 | } |