10 DBICTest::Schema->load_classes('ArtistGUID');
12 # tests stolen from 748informix.t
14 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_SYBASE_ASA_${_}" } qw/DSN USER PASS/};
15 my ($dsn2, $user2, $pass2) = @ENV{map { "DBICTEST_SYBASE_ASA_ODBC_${_}" } qw/DSN USER PASS/};
17 plan skip_all => <<'EOF' unless $dsn || $dsn2;
18 Set $ENV{DBICTEST_SYBASE_ASA_DSN} and/or $ENV{DBICTEST_SYBASE_ASA_ODBC_DSN},
19 _USER and _PASS to run these tests
23 [ $dsn, $user, $pass ],
24 [ $dsn2, $user2, $pass2 ],
29 foreach my $info (@info) {
30 my ($dsn, $user, $pass) = @$info;
34 $schema = DBICTest::Schema->connect($dsn, $user, $pass, {
38 my $guard = Scope::Guard->new(\&cleanup);
40 my $dbh = $schema->storage->dbh;
42 eval { $dbh->do("DROP TABLE artist") };
46 artistid INT IDENTITY PRIMARY KEY,
47 name VARCHAR(255) NULL,
48 charfield CHAR(10) NULL,
53 my $ars = $schema->resultset('Artist');
54 is ( $ars->count, 0, 'No rows at first' );
56 # test primary key handling
57 my $new = $ars->create({ name => 'foo' });
58 ok($new->artistid, "Auto-PK worked");
60 # test explicit key spec
61 $new = $ars->create ({ name => 'bar', artistid => 66 });
62 is($new->artistid, 66, 'Explicit PK worked');
63 $new->discard_changes;
64 is($new->artistid, 66, 'Explicit PK assigned');
71 $ars->create({ name => 'in_savepoint' });
72 die "rolling back savepoint";
75 ok ((not $ars->search({ name => 'in_savepoint' })->first),
76 'savepoint rolled back');
77 $ars->create({ name => 'in_outer_txn' });
78 die "rolling back outer txn";
80 } qr/rolling back outer txn/,
81 'correct exception for rollback';
83 ok ((not $ars->search({ name => 'in_outer_txn' })->first),
84 'outer txn rolled back');
90 push @pop, { name => "Artist_$_" };
92 $ars->populate (\@pop);
95 # test populate with explicit key
99 push @pop, { name => "Artist_expkey_$_", artistid => 100 + $_ };
101 $ars->populate (\@pop);
104 # count what we did so far
105 is ($ars->count, 6, 'Simple count works');
108 my $lim = $ars->search( {},
112 order_by => 'artistid'
115 is( $lim->count, 2, 'ROWS+OFFSET count ok' );
116 is( $lim->all, 2, 'Number of ->all objects matches count' );
120 is( $lim->next->artistid, 101, "iterator->next ok" );
121 is( $lim->next->artistid, 102, "iterator->next ok" );
122 is( $lim->next, undef, "next past end of resultset ok" );
126 local $ars->result_source->column_info('artistid')->{is_auto_increment} = 0;
128 lives_ok { $ars->create({}) }
129 'empty insert works';
132 # test blobs (stolen from 73oracle.t)
133 eval { $dbh->do('DROP TABLE bindtype_test') };
135 CREATE TABLE bindtype_test
137 id INT NOT NULL PRIMARY KEY,
139 blob LONG BINARY NULL,
140 clob LONG VARCHAR NULL
142 ],{ RaiseError => 1, PrintError => 1 });
144 my %binstr = ( 'small' => join('', map { chr($_) } ( 1 .. 127 )) );
145 $binstr{'large'} = $binstr{'small'} x 1024;
147 my $maxloblen = length $binstr{'large'};
148 local $dbh->{'LongReadLen'} = $maxloblen;
150 my $rs = $schema->resultset('BindType');
153 foreach my $type (qw( blob clob )) {
154 foreach my $size (qw( small large )) {
157 # turn off horrendous binary DBIC_TRACE output
158 local $schema->storage->{debug} = 0;
160 lives_ok { $rs->create( { 'id' => $id, $type => $binstr{$size} } ) }
161 "inserted $size $type without dying";
163 ok($rs->find($id)->$type eq $binstr{$size}, "verified inserted $size $type" );
167 my @uuid_types = qw/uniqueidentifier uniqueidentifierstr/;
169 # test uniqueidentifiers
170 for my $uuid_type (@uuid_types) {
171 local $schema->source('ArtistGUID')->column_info('artistid')->{data_type}
174 local $schema->source('ArtistGUID')->column_info('a_guid')->{data_type}
177 $schema->storage->dbh_do (sub {
178 my ($storage, $dbh) = @_;
179 eval { $dbh->do("DROP TABLE artist") };
181 CREATE TABLE artist (
182 artistid $uuid_type NOT NULL,
184 rank INT NOT NULL DEFAULT '13',
185 charfield CHAR(10) NULL,
187 primary key(artistid)
194 $row = $schema->resultset('ArtistGUID')->create({ name => 'mtfnpy' })
195 } 'created a row with a GUID';
198 eval { $row->artistid },
199 'row has GUID PK col populated',
204 eval { $row->a_guid },
205 'row has a GUID col with auto_nextval populated',
209 my $row_from_db = $schema->resultset('ArtistGUID')
210 ->search({ name => 'mtfnpy' })->first;
212 is $row_from_db->artistid, $row->artistid,
213 'PK GUID round trip';
215 is $row_from_db->a_guid, $row->a_guid,
216 'NON-PK GUID round trip';
223 eval { $schema->storage->dbh->do("DROP TABLE $_") } for qw/artist bindtype_test/;