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, {
33 [ blob_setup => log_on_update => 1 ], # this is a safer option
37 $schema->storage->ensure_connected;
39 isa_ok( $schema->storage, "DBIx::Class::Storage::$storage_type" );
41 $schema->storage->dbh_do (sub {
42 my ($storage, $dbh) = @_;
43 eval { $dbh->do("DROP TABLE artist") };
46 artistid INT IDENTITY PRIMARY KEY,
48 rank INT DEFAULT 13 NOT NULL,
49 charfield CHAR(10) NULL
56 # so we start unconnected
57 $schema->storage->disconnect;
59 # test primary key handling
60 my $new = $schema->resultset('Artist')->create({ name => 'foo' });
61 ok($new->artistid > 0, "Auto-PK worked");
63 $seen_id{$new->artistid}++;
66 $new = $schema->resultset('Artist')->create({ name => 'Artist ' . $_ });
67 is ( $seen_id{$new->artistid}, undef, "id for Artist $_ is unique" );
68 $seen_id{$new->artistid}++;
72 is ($schema->resultset('Artist')->count, 7, 'count(*) of whole table ok');
75 my $it = $schema->resultset('Artist')->search({
76 artistid => { '>' => 0 }
79 order_by => 'artistid',
82 is( $it->count, 3, "LIMIT count ok" );
84 is( $it->next->name, "foo", "iterator->next ok" );
86 is( $it->next->name, "Artist 2", "iterator->next ok" );
87 is( $it->next, undef, "next past end of resultset ok" );
90 $it = $schema->resultset('Artist')->search({}, {
93 order_by => 'artistid',
96 is( $it->count, 3, "LIMIT with offset count ok" );
98 is( $it->next->name, "Artist 3", "iterator->next ok" );
100 is( $it->next->name, "Artist 5", "iterator->next ok" );
101 is( $it->next, undef, "next past end of resultset ok" );
103 # now try a grouped count
104 $schema->resultset('Artist')->create({ name => 'Artist 6' })
107 $it = $schema->resultset('Artist')->search({}, {
111 is( $it->count, 7, 'COUNT of GROUP_BY ok' );
113 # Test DateTime inflation with DATETIME
115 ['DATETIME', '2004-08-21T14:36:48.080Z'],
116 ['SMALLDATETIME', '2004-08-21T14:36:00.000Z'], # minute precision
119 for my $dt_type (@dt_types) {
120 my ($type, $sample_dt) = @$dt_type;
122 eval { $schema->storage->dbh->do("DROP TABLE track") };
123 $schema->storage->dbh->do(<<"SQL");
125 trackid INT IDENTITY PRIMARY KEY,
128 last_updated_on $type,
131 ok(my $dt = DateTime::Format::Sybase->parse_datetime($sample_dt));
134 ok( $row = $schema->resultset('Track')->create({
135 last_updated_on => $dt,
138 ok( $row = $schema->resultset('Track')
139 ->search({ trackid => $row->trackid }, { select => ['last_updated_on'] })
142 is( $row->updated_date, $dt, 'DateTime inflation works' );
145 # mostly stole the blob stuff Nniuq wrote for t/73oracle.t
146 my $dbh = $schema->storage->dbh;
148 local $SIG{__WARN__} = sub {};
149 eval { $dbh->do('DROP TABLE bindtype_test') };
152 CREATE TABLE bindtype_test
159 ],{ RaiseError => 1, PrintError => 1 });
162 my %binstr = ( 'small' => join('', map { chr($_) } ( 1 .. 127 )) );
163 $binstr{'large'} = $binstr{'small'} x 1024;
165 my $maxloblen = length $binstr{'large'};
166 note "Localizing LongReadLen to $maxloblen to avoid truncation of test data";
167 local $dbh->{'LongReadLen'} = $maxloblen;
169 my $rs = $schema->resultset('BindType');
172 foreach my $type (qw(blob clob)) {
173 foreach my $size (qw(small large)) {
174 no warnings 'uninitialized';
177 eval { $rs->create( { 'id' => $id, $type => $binstr{$size} } ) };
178 ok(!$@, "inserted $size $type without dying");
182 $rs->search({ id=> $id }, { select => [$type] })->single->$type
183 } eq $binstr{$size}, "verified inserted $size $type" );
190 if (my $dbh = eval { $schema->storage->_dbh }) {
191 $dbh->do('DROP TABLE artist');
192 $dbh->do('DROP TABLE track');
193 $dbh->do('DROP TABLE bindtype_test');