8 use DateTime::Format::Sybase;
10 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_SYBASE_${_}" } qw/DSN USER PASS/};
12 plan skip_all => 'Set $ENV{DBICTEST_SYBASE_DSN}, _USER and _PASS to run this test'
13 unless ($dsn && $user);
15 plan tests => (26 + 4*2)*2;
19 'DBI::Sybase::NoBindVars',
23 for my $storage_type (@storage_types) {
24 $schema = DBICTest::Schema->clone;
26 unless ($storage_type eq 'DBI::Sybase') { # autodetect
27 $schema->storage_type("::$storage_type");
29 $schema->connection($dsn, $user, $pass, {AutoCommit => 1});
31 $schema->storage->ensure_connected;
33 isa_ok( $schema->storage, "DBIx::Class::Storage::$storage_type" );
35 $schema->storage->dbh_do (sub {
36 my ($storage, $dbh) = @_;
37 eval { $dbh->do("DROP TABLE artist") };
40 artistid INT IDENTITY PRIMARY KEY,
42 rank INT DEFAULT 13 NOT NULL,
43 charfield CHAR(10) NULL
50 # so we start unconnected
51 $schema->storage->disconnect;
53 # test primary key handling
54 my $new = $schema->resultset('Artist')->create({ name => 'foo' });
55 ok($new->artistid > 0, "Auto-PK worked");
57 $seen_id{$new->artistid}++;
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}++;
66 is ($schema->resultset('Artist')->count, 7, 'count(*) of whole table ok');
69 my $it = $schema->resultset('Artist')->search({
70 artistid => { '>' => 0 }
73 order_by => 'artistid',
76 is( $it->count, 3, "LIMIT count ok" );
78 is( $it->next->name, "foo", "iterator->next ok" );
80 is( $it->next->name, "Artist 2", "iterator->next ok" );
81 is( $it->next, undef, "next past end of resultset ok" );
84 $it = $schema->resultset('Artist')->search({}, {
87 order_by => 'artistid',
90 is( $it->count, 3, "LIMIT with offset count ok" );
92 is( $it->next->name, "Artist 3", "iterator->next ok" );
94 is( $it->next->name, "Artist 5", "iterator->next ok" );
95 is( $it->next, undef, "next past end of resultset ok" );
97 # now try a grouped count
98 $schema->resultset('Artist')->create({ name => 'Artist 6' })
101 $it = $schema->resultset('Artist')->search({}, {
105 is( $it->count, 7, 'COUNT of GROUP_BY ok' );
107 # Test DateTime inflation with DATETIME
109 ['DATETIME', '2004-08-21T14:36:48.080Z'],
110 ['SMALLDATETIME', '2004-08-21T14:36:00.000Z'], # minute precision
113 for my $dt_type (@dt_types) {
114 my ($type, $sample_dt) = @$dt_type;
116 eval { $schema->storage->dbh->do("DROP TABLE track") };
117 $schema->storage->dbh->do(<<"SQL");
119 trackid INT IDENTITY PRIMARY KEY,
122 last_updated_on $type,
125 ok(my $dt = DateTime::Format::Sybase->parse_datetime($sample_dt));
128 ok( $row = $schema->resultset('Track')->create({
129 last_updated_on => $dt,
132 ok( $row = $schema->resultset('Track')
133 ->search({ trackid => $row->trackid }, { select => ['last_updated_on'] })
136 is( $row->updated_date, $dt, 'DateTime inflation works' );
139 # mostly stole the blob stuff Nniuq wrote for t/73oracle.t
140 my $dbh = $schema->storage->dbh;
142 local $SIG{__WARN__} = sub {};
143 eval { $dbh->do('DROP TABLE bindtype_test') };
146 CREATE TABLE bindtype_test
153 ],{ RaiseError => 1, PrintError => 1 });
156 my %binstr = ( 'small' => join('', map { chr($_) } ( 1 .. 127 )) );
157 $binstr{'large'} = $binstr{'small'} x 1024;
159 my $maxloblen = length $binstr{'large'};
160 note "Localizing LongReadLen to $maxloblen to avoid truncation of test data";
161 local $dbh->{'LongReadLen'} = $maxloblen;
163 my $rs = $schema->resultset('BindType');
167 local $TODO = 'TEXT/IMAGE columns don\'t work yet';
169 foreach my $type (qw(blob clob)) {
170 foreach my $size (qw(small large)) {
171 no warnings 'uninitialized';
174 eval { $rs->create( { 'id' => $id, $type => $binstr{$size} } ) };
175 ok(!$@, "inserted $size $type without dying");
177 $rs->search({ id=> $id }, { select => [$type] })->single->$type
178 } eq $binstr{$size}, "verified inserted $size $type" );
186 if (my $dbh = eval { $schema->storage->_dbh }) {
187 $dbh->do('DROP TABLE artist');
188 $dbh->do('DROP TABLE track');
189 $dbh->do('DROP TABLE bindtype_test');