Patches from Andreas Hartmeier applied to PK::Auto
[dbsrgits/DBIx-Class.git] / t / run / 13oracle.tl
1 sub run_tests {
2
3 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_ORA_${_}" } qw/DSN USER PASS/};
4
5 plan 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
9 plan tests => 4;
10
11 DBICTest::Schema->compose_connection('OraTest' => $dsn, $user, $pass);
12
13 my $dbh = OraTest::Artist->storage->dbh;
14
15 eval {
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
35 OraTest::Artist->load_components('PK::Auto::Oracle');
36
37 # test primary key handling
38 my $new = OraTest::Artist->create({ name => 'foo' });
39 is($new->artistid, 1, "Oracle Auto-PK worked");
40
41 # test LIMIT support
42 for (1..6) {
43     OraTest::Artist->create({ name => 'Artist ' . $_ });
44 }
45 my $it = OraTest::Artist->search( {},
46     { rows => 3,
47       offset => 2,
48       order_by => 'artistid' }
49 );
50 is( $it->count, 3, "LIMIT count ok" );
51 is( $it->next->name, "Artist 2", "iterator->next ok" );
52 $it->next;
53 $it->next;
54 is( $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
62 1;