attempt to fix weird overload '0+' bug, modify tests to make sure it works
[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. ' .
7 'Warning: This test drops and creates a table called \'artist\''
8 unless ($dsn && $user && $pass);
9
10plan tests => 4;
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");
19};
20$dbh->do("CREATE SEQUENCE artist_seq START WITH 1 MAXVALUE 999999 MINVALUE 0");
21$dbh->do("CREATE TABLE artist (artistid NUMBER(12), name VARCHAR(255))");
22$dbh->do("ALTER TABLE artist ADD (CONSTRAINT artist_pk PRIMARY KEY (artistid))");
23$dbh->do(qq{
24 CREATE OR REPLACE TRIGGER artist_insert_trg
25 BEFORE INSERT ON artist
26 FOR EACH ROW
27 BEGIN
28 IF :new.artistid IS NULL THEN
29 SELECT artist_seq.nextval
30 INTO :new.artistid
31 FROM DUAL;
32 END IF;
33 END;
34});
35
36OraTest::Artist->load_components('PK::Auto::Oracle');
37
38# test primary key handling
39my $new = OraTest::Artist->create({ name => 'foo' });
c8f4b52b 40is($new->artistid, 1, "Oracle Auto-PK worked");
0567538f 41
42# test LIMIT support
43for (1..6) {
44 OraTest::Artist->create({ name => 'Artist ' . $_ });
45}
46my $it = OraTest::Artist->search( {},
47 { rows => 3,
48 offset => 2,
49 order_by => 'artistid' }
50);
51is( $it->count, 3, "LIMIT count ok" );
52is( $it->next->name, "Artist 2", "iterator->next ok" );
53$it->next;
54$it->next;
55is( $it->next, undef, "next past end of resultset ok" );
56
57# clean up our mess
58$dbh->do("DROP SEQUENCE artist_seq");
59$dbh->do("DROP TABLE artist");
60
61}
62
631;