9 # tests stolen from 748informix.t
11 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_SYBASE_ASA_${_}" } qw/DSN USER PASS/};
12 my ($dsn2, $user2, $pass2) = @ENV{map { "DBICTEST_SYBASE_ASA_ODBC_${_}" } qw/DSN USER PASS/};
14 plan skip_all => <<'EOF' unless $dsn || $dsn2;
15 Set $ENV{DBICTEST_SYBASE_ASA_DSN} and/or $ENV{DBICTEST_SYBASE_ASA_ODBC_DSN},
16 _USER and _PASS to run these tests
20 [ $dsn, $user, $pass ],
21 [ $dsn2, $user2, $pass2 ],
26 foreach my $info (@info) {
27 my ($dsn, $user, $pass) = @$info;
31 my $schema = DBICTest::Schema->connect($dsn, $user, $pass, {
35 my $dbh = $schema->storage->dbh;
37 push @handles_to_clean, $dbh;
39 eval { $dbh->do("DROP TABLE artist") };
43 artistid INT IDENTITY PRIMARY KEY,
44 name VARCHAR(255) NULL,
45 charfield CHAR(10) NULL,
50 my $ars = $schema->resultset('Artist');
51 is ( $ars->count, 0, 'No rows at first' );
53 # test primary key handling
54 my $new = $ars->create({ name => 'foo' });
55 ok($new->artistid, "Auto-PK worked");
57 # test explicit key spec
58 $new = $ars->create ({ name => 'bar', artistid => 66 });
59 is($new->artistid, 66, 'Explicit PK worked');
60 $new->discard_changes;
61 is($new->artistid, 66, 'Explicit PK assigned');
68 $ars->create({ name => 'in_savepoint' });
69 die "rolling back savepoint";
72 ok ((not $ars->search({ name => 'in_savepoint' })->first),
73 'savepoint rolled back');
74 $ars->create({ name => 'in_outer_txn' });
75 die "rolling back outer txn";
79 like $@, qr/rolling back outer txn/,
80 'correct exception for rollback';
82 ok ((not $ars->search({ name => 'in_outer_txn' })->first),
83 'outer txn rolled back');
89 push @pop, { name => "Artist_$_" };
91 $ars->populate (\@pop);
94 # test populate with explicit key
98 push @pop, { name => "Artist_expkey_$_", artistid => 100 + $_ };
100 $ars->populate (\@pop);
103 # count what we did so far
104 is ($ars->count, 6, 'Simple count works');
107 my $lim = $ars->search( {},
111 order_by => 'artistid'
114 is( $lim->count, 2, 'ROWS+OFFSET count ok' );
115 is( $lim->all, 2, 'Number of ->all objects matches count' );
119 is( $lim->next->artistid, 101, "iterator->next ok" );
120 is( $lim->next->artistid, 102, "iterator->next ok" );
121 is( $lim->next, undef, "next past end of resultset ok" );
125 local $ars->result_source->column_info('artistid')->{is_auto_increment} = 0;
127 lives_ok { $ars->create({}) }
128 'empty insert works';
131 # test blobs (stolen from 73oracle.t)
132 eval { $dbh->do('DROP TABLE bindtype_test') };
134 CREATE TABLE bindtype_test
136 id INT NOT NULL PRIMARY KEY,
138 blob LONG BINARY NULL,
139 clob LONG VARCHAR NULL
141 ],{ RaiseError => 1, PrintError => 1 });
143 my %binstr = ( 'small' => join('', map { chr($_) } ( 1 .. 127 )) );
144 $binstr{'large'} = $binstr{'small'} x 1024;
146 my $maxloblen = length $binstr{'large'};
147 local $dbh->{'LongReadLen'} = $maxloblen;
149 my $rs = $schema->resultset('BindType');
152 foreach my $type (qw( blob clob )) {
153 foreach my $size (qw( small large )) {
156 # turn off horrendous binary DBIC_TRACE output
157 local $schema->storage->{debug} = 0;
159 lives_ok { $rs->create( { 'id' => $id, $type => $binstr{$size} } ) }
160 "inserted $size $type without dying";
162 ok($rs->find($id)->$type eq $binstr{$size}, "verified inserted $size $type" );
171 foreach my $dbh (@handles_to_clean) {
172 eval { $dbh->do("DROP TABLE $_") } for qw/artist bindtype_test/;