fix mystery tabs in changes file
[dbsrgits/DBIx-Class.git] / t / run / 13oracle.tl
CommitLineData
0567538f 1sub run_tests {
2
3my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_ORA_${_}" } qw/DSN USER PASS/};
4
5plan skip_all, 'Set $ENV{DBICTEST_ORA_DSN}, _USER and _PASS to run this test. ' .
6 'Warning: This test drops and creates a table called \'artist\''
7 unless ($dsn && $user && $pass);
8
9plan tests => 4;
10
11DBICTest::Schema->compose_connection('OraTest' => $dsn, $user, $pass);
12
13my $dbh = OraTest::Artist->storage->dbh;
14
15eval {
16 $dbh->do("DROP SEQUENCE artist_seq");
17 $dbh->do("DROP TABLE artist");
18};
19$dbh->do("CREATE SEQUENCE artist_seq START WITH 1 MAXVALUE 999999 MINVALUE 0");
20$dbh->do("CREATE TABLE artist (artistid NUMBER(12), name VARCHAR(255))");
21$dbh->do("ALTER TABLE artist ADD (CONSTRAINT artist_pk PRIMARY KEY (artistid))");
22$dbh->do(qq{
23 CREATE OR REPLACE TRIGGER artist_insert_trg
24 BEFORE INSERT ON artist
25 FOR EACH ROW
26 BEGIN
27 IF :new.artistid IS NULL THEN
28 SELECT artist_seq.nextval
29 INTO :new.artistid
30 FROM DUAL;
31 END IF;
32 END;
33});
34
35OraTest::Artist->load_components('PK::Auto::Oracle');
36
37# test primary key handling
38my $new = OraTest::Artist->create({ name => 'foo' });
39ok($new->artistid, "Oracle Auto-PK worked");
40
41# test LIMIT support
42for (1..6) {
43 OraTest::Artist->create({ name => 'Artist ' . $_ });
44}
45my $it = OraTest::Artist->search( {},
46 { rows => 3,
47 offset => 2,
48 order_by => 'artistid' }
49);
50is( $it->count, 3, "LIMIT count ok" );
51is( $it->next->name, "Artist 2", "iterator->next ok" );
52$it->next;
53$it->next;
54is( $it->next, undef, "next past end of resultset ok" );
55
56# clean up our mess
57$dbh->do("DROP SEQUENCE artist_seq");
58$dbh->do("DROP TABLE artist");
59
60}
61
621;