Fixup to Cursor, updated Changes
[dbsrgits/DBIx-Class.git] / t / run / 13oracle.tl
CommitLineData
0567538f 1sub run_tests {
1edaf6fe 2my $schema = shift;
0567538f 3
4my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_ORA_${_}" } qw/DSN USER PASS/};
5
6plan skip_all, 'Set $ENV{DBICTEST_ORA_DSN}, _USER and _PASS to run this test. ' .
2660b14e 7 'Warning: This test drops and creates tables called \'artist\', \'cd\' and \'track\''
0567538f 8 unless ($dsn && $user && $pass);
9
2660b14e 10plan tests => 5;
0567538f 11
70fe6d6e 12DBICTest::Schema->compose_connection('OraTest' => $dsn, $user, $pass);
0567538f 13
a953d8d9 14my $dbh = OraTest->schema->storage->dbh;
0567538f 15
16eval {
17 $dbh->do("DROP SEQUENCE artist_seq");
18 $dbh->do("DROP TABLE artist");
2660b14e 19 $dbh->do("DROP TABLE cd");
20 $dbh->do("DROP TABLE track");
0567538f 21};
22$dbh->do("CREATE SEQUENCE artist_seq START WITH 1 MAXVALUE 999999 MINVALUE 0");
23$dbh->do("CREATE TABLE artist (artistid NUMBER(12), name VARCHAR(255))");
2660b14e 24$dbh->do("CREATE TABLE cd (cdid NUMBER(12), artist NUMBER(12), title VARCHAR(255), year VARCHAR(4))");
25$dbh->do("CREATE TABLE track (trackid NUMBER(12), cd NUMBER(12), position NUMBER(12), title VARCHAR(255))");
26
0567538f 27$dbh->do("ALTER TABLE artist ADD (CONSTRAINT artist_pk PRIMARY KEY (artistid))");
28$dbh->do(qq{
29 CREATE OR REPLACE TRIGGER artist_insert_trg
30 BEFORE INSERT ON artist
31 FOR EACH ROW
32 BEGIN
33 IF :new.artistid IS NULL THEN
34 SELECT artist_seq.nextval
35 INTO :new.artistid
36 FROM DUAL;
37 END IF;
38 END;
39});
40
843f8ecd 41OraTest::Artist->load_components('PK::Auto');
2660b14e 42OraTest::CD->load_components('PK::Auto::Oracle');
43OraTest::Track->load_components('PK::Auto::Oracle');
0567538f 44
45# test primary key handling
46my $new = OraTest::Artist->create({ name => 'foo' });
c8f4b52b 47is($new->artistid, 1, "Oracle Auto-PK worked");
0567538f 48
2660b14e 49# test join with row count ambiguity
50my $cd = OraTest::CD->create({ cdid => 1, artist => 1, title => 'EP C', year => '2003' });
51my $track = OraTest::Track->create({ trackid => 1, cd => 1, position => 1, title => 'Track1' });
52my $tjoin = OraTest::Track->search({ 'me.title' => 'Track1'},
53 { join => 'cd',
54 rows => 2 }
55);
56
57is($tjoin->next->title, 'Track1', "ambiguous column ok");
58
59
0567538f 60# test LIMIT support
61for (1..6) {
62 OraTest::Artist->create({ name => 'Artist ' . $_ });
63}
64my $it = OraTest::Artist->search( {},
65 { rows => 3,
66 offset => 2,
67 order_by => 'artistid' }
68);
69is( $it->count, 3, "LIMIT count ok" );
70is( $it->next->name, "Artist 2", "iterator->next ok" );
71$it->next;
72$it->next;
73is( $it->next, undef, "next past end of resultset ok" );
74
75# clean up our mess
76$dbh->do("DROP SEQUENCE artist_seq");
77$dbh->do("DROP TABLE artist");
2660b14e 78$dbh->do("DROP TABLE cd");
79$dbh->do("DROP TABLE track");
0567538f 80
81}
82
831;