Commit | Line | Data |
e565d25e |
1 | use lib qw(lib t/lib); |
2 | use DBICTest::Schema; |
3 | |
4 | use Test::More; |
5 | |
6 | my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_ORA_${_}" } qw/DSN USER PASS/}; |
7 | |
8 | plan skip_all, 'Set $ENV{DBICTEST_ORA_DSN}, _USER and _PASS to run this test. ' . |
9 | 'Warning: This test drops and creates a table called \'artist\'' |
10 | unless ($dsn && $user && $pass); |
11 | |
4bb63dac |
12 | plan tests => 4; |
e565d25e |
13 | |
14 | DBICTest::Schema->compose_connection('OraTest' => $dsn, $user, $pass); |
15 | |
16 | my $dbh = OraTest::Artist->storage->dbh; |
17 | |
18 | eval { |
19 | $dbh->do("DROP SEQUENCE artist_seq"); |
20 | $dbh->do("DROP TABLE artist"); |
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))"); |
24 | $dbh->do("ALTER TABLE artist ADD (CONSTRAINT artist_pk PRIMARY KEY (artistid))"); |
25 | $dbh->do(qq{ |
26 | CREATE OR REPLACE TRIGGER artist_insert_trg |
27 | BEFORE INSERT ON artist |
28 | FOR EACH ROW |
29 | BEGIN |
30 | IF :new.artistid IS NULL THEN |
31 | SELECT artist_seq.nextval |
32 | INTO :new.artistid |
33 | FROM DUAL; |
34 | END IF; |
35 | END; |
36 | }); |
37 | |
38 | OraTest::Artist->load_components('PK::Auto::Oracle'); |
39 | |
4bb63dac |
40 | # test primary key handling |
e565d25e |
41 | my $new = OraTest::Artist->create({ name => 'foo' }); |
e565d25e |
42 | ok($new->artistid, "Oracle Auto-PK worked"); |
43 | |
4bb63dac |
44 | # test LIMIT support |
45 | for (1..6) { |
46 | OraTest::Artist->create({ name => 'Artist ' . $_ }); |
47 | } |
48 | my $it = OraTest::Artist->search( {}, |
49 | { rows => 3, |
50 | offset => 2, |
51 | order_by => 'artistid' } |
52 | ); |
53 | is( $it->count, 3, "LIMIT count ok" ); |
54 | is( $it->next->name, "Artist 2", "iterator->next ok" ); |
55 | $it->next; |
56 | $it->next; |
57 | is( $it->next, undef, "next past end of resultset ok" ); |
58 | |
59 | # clean up our mess |
e565d25e |
60 | $dbh->do("DROP SEQUENCE artist_seq"); |
61 | $dbh->do("DROP TABLE artist"); |
62 | |
63 | 1; |