Commit | Line | Data |
0567538f |
1 | sub run_tests { |
1edaf6fe |
2 | my $schema = shift; |
0567538f |
3 | |
4 | my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_ORA_${_}" } qw/DSN USER PASS/}; |
5 | |
6 | plan 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 | |
10 | plan tests => 4; |
11 | |
70fe6d6e |
12 | DBICTest::Schema->compose_connection('OraTest' => $dsn, $user, $pass); |
0567538f |
13 | |
14 | my $dbh = OraTest::Artist->storage->dbh; |
15 | |
16 | eval { |
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 | |
36 | OraTest::Artist->load_components('PK::Auto::Oracle'); |
37 | |
38 | # test primary key handling |
39 | my $new = OraTest::Artist->create({ name => 'foo' }); |
c8f4b52b |
40 | is($new->artistid, 1, "Oracle Auto-PK worked"); |
0567538f |
41 | |
42 | # test LIMIT support |
43 | for (1..6) { |
44 | OraTest::Artist->create({ name => 'Artist ' . $_ }); |
45 | } |
46 | my $it = OraTest::Artist->search( {}, |
47 | { rows => 3, |
48 | offset => 2, |
49 | order_by => 'artistid' } |
50 | ); |
51 | is( $it->count, 3, "LIMIT count ok" ); |
52 | is( $it->next->name, "Artist 2", "iterator->next ok" ); |
53 | $it->next; |
54 | $it->next; |
55 | is( $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 | |
63 | 1; |